ผู้ใช้:Bebiezaza/iScript/modules/userTabs.js
หน้าตา
< ผู้ใช้:Bebiezaza | iScript
หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง
- ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
- กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
- ไมโครซอฟท์ เอดจ์: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
// ========================================================
// สคริปต์จัดให้: userTabs module
//
// Copyright (C) 2006-2022, Jutiphan Mongkolsuthree
// 2021-2022, Bebiezaza
// Certain functions are copyrighted by their
// respective copyright holders
//
// Created: 10/12/2006
// Rewritten: 22/03/2022
// Replaced: none
// ========================================================
/* <pre><nowiki> */
// ========== เพิ่มป้ายหน้าผู้ใช้+แจ้งตักเตือนอัจฉริยะ ==========
function statsButton() {
if (iScriptConfig.Edition == Editions.Uncyclopedia) return;
var link = mw.config.get("wgServer").slice(2);
var user = mw.config.get('wgTitle');
if (user.indexOf("/") !== -1) user = user.split("/")[0];
var href = "//xtools.wmflabs.org/ec-namespacetotals/" + link + "/" + user;
mw.util.addPortletLink("p-cactions", href, "สถิติ", "ca-stat", "ดูจำนวนครั้งที่แก้ไข");
}
function addWarnGeneral(text, noAPI) {
if (noAPI) text = document.editform.wpTextbox1.value;
var regex = /t-test([1-5]?)|\{\{test([1-5]?)\}\}/ig;
var result = regex.exec(text);
if (result != undefined) {
if (result[1].length == 0) {
no = 2;
} else {
no = eval(result[1]) + 1;
}
text = text.replace(/\{\| ?id=\"t-test([1-5]?)\" (.*\r?\n)*?\|\}|\{\{test([1-5]?)\}\}/, "{{subst:test" + no + "}}");
} else {
no = 1;
text = "{{subst:test}}\n\n" + text;
}
warnNo = no;
if (noAPI) {
document.editform.wpTextbox1.value = text;
document.editform.wpSummary.value = 'ตักเตือนผู้ใช้ครั้งที่ ' + no + " " + iScriptConfig.Tagline;
} else return text;
}
function addWarnVandal(text, pName, noAPI) {
if (noAPI) text = document.editform.wpTextbox1.value;
var monthsName = ["มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม"];
var time = new Date();
var year = time.getUTCFullYear() + 543;
var month = time.getUTCMonth();
var regex = new RegExp("\n?(\n|^)== " + monthsName[month] + " " + year + "(.*\n(?!==))*.*");
var result = regex.exec(text);
if(result == undefined) {
text = text + "\n== " + monthsName[month] + " " + year + " ==";
no = 1;
} else {
var curMonthText = result[0];
/\{\{uw-vandal(\d)\}\}/ig;
regex = /\{\{uw-vandal1\}\}/ig;
result = regex.exec(curMonthText);
no = 1;
if (result != undefined) {
text = text + '\n';
no = 2;
}
regex = /\{\{uw-vandal2\}\}/ig;
result = regex.exec(curMonthText);
if (result != undefined) {
no = 3;
}
}
text = text + "\n{{subst:uw-vandal" + no + "|" + pName + "}} --~~~~";
warnNo = no;
if (noAPI) {
document.editform.wpTextbox1.value = text;
document.editform.wpSummary.value = 'เตือนก่อกวนผู้ใช้ครั้งที่ ' + no + " " + iScriptConfig.Tagline;
} else return text;
}
function warnUser(type, article) {
var user = mw.config.get('wgTitle');
if (user.indexOf("/") !== -1) user = user.split("/")[0];
var pageTitle = 'User talk:' + user;
var text = iScriptAPI.getPageContent(pageTitle);
var summary;
if (type === "general") {
text = addWarnGeneral(text);
summary = 'ตักเตือนผู้ใช้ครั้งที่ ' + no + " " + iScriptConfig.Tagline;
} else if (type === "vandal") {
if (!article) article = prompt("กรุณาใส่ชื่อบทความที่ผู้ใช้นี้ได้ก่อกวน (จำเป็น)", "");
if (!article || article.length === 0) {
mw.notify($('<span style="color: red">ยกเลิกการแจ้งก่อกวนเนื่องจากว่าไม่ได้ระบุชื่อบทความ</span>'));
return;
}
text = addWarnVandal(text, article);
summary = 'เตือนก่อกวนผู้ใช้ครั้งที่ ' + no + " " + iScriptConfig.Tagline;
} else return;
mw.notify('กำลังแจ้งเตือนผู้ใช้:' + user + ' กรุณารอสักครู่...');
if (mw.config.get("wgNamespaceNumber") === 3) return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, true);
else return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, false);
}
function warnNothanks() {
var user = mw.config.get('wgTitle');
if (user.indexOf("/") !== -1) user = user.split("/")[0];
var pageTitle = 'User talk:' + user;
var text = iScriptAPI.getPageContent(pageTitle);;
if (mw.util.isIPAddress(mw.config.get('wgRelevantUserName'))) text = "{{subst:nothanks}}\n\n" + text; // IP
else { // User
var pName = mw.util.getParamValue("vanarticle");
if (!pName) {
pName = prompt("กรุณาใส่ชื่อบทความที่อาจละเมิดลิขสิทธิ์ (เว้นว่างและคลิก OK หากจะไม่ระบุ):", "");
if (pName == undefined) return;
}
if (pName.length == 0) text += "\n{{subst:nothanks0}} --~~~~";
else text += "\n{{subst:nothanks0|[[" + pName + "]]}} --~~~~";
}
summary = "พูดคุยเรื่องลิขสิทธิ์" + iScriptConfig.Tagline;
mw.notify('กำลังแจ้งเตือนผู้ใช้:' + user + ' กรุณารอสักครู่...');
if (mw.config.get("wgNamespaceNumber") === 3) return iScriptAPI.editPageWithCreate(pageTitle, text, summary, true, true);
else return iScriptAPI.editPageWithCreate(pageTitle, text, summary, true, false);
}
function warnDelete() {
var user = mw.config.get('wgTitle');
if (user.indexOf("/") !== -1) user = user.split("/")[0];
var pageTitle = 'User talk:' + user;
var text = iScriptAPI.getPageContent(pageTitle);
var article = mw.util.getParamValue("vanarticle");
if (!article) article = prompt("กรุณาใส่ชื่อบทความที่ผู้ใช้นี้ได้ทำหน้าว่าง (จำเป็น)", "");
if (!article || article.length === 0) {
mw.notify($('<span style="color: red">ยกเลิกการเตือนทำหน้าว่างเนื่องจากว่าไม่ได้ระบุชื่อบทความ</span>'));
return;
}
text = text + "\n{{subst:uw-delete|" + article + "}} --~~~~";
summary = article + " หน้าว่าง? " + iScriptConfig.Tagline;
mw.notify('กำลังแจ้งเตือนผู้ใช้:' + user + ' กรุณารอสักครู่...');
if (mw.config.get("wgNamespaceNumber") === 3) return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, true);
else return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, false);
}
function warnUsername() {
var user = mw.config.get('wgTitle');
if (user.indexOf("/") !== -1) user = user.split("/")[0];
var pageTitle = 'User talk:' + user;
var text = iScriptAPI.getPageContent(pageTitle);
text = text + "\n{{subst:uw-username}} --~~~~";
summary = "เตือนชื่อผู้ใช้ไม่เหมาะสม" + iScriptConfig.Tagline;
mw.notify('กำลังแจ้งเตือนผู้ใช้:' + user + ' กรุณารอสักครู่...');
if (mw.config.get("wgNamespaceNumber") === 3) return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, true);
else return iScriptAPI.editPageWithCreate(pageTitle, text, summary, false, false);
}
$(document).ready(function() {
if (mw.config.get('wgAction') == "view" || mw.config.get('wgAction') == "edit") {
if ([2, 3].indexOf(mw.config.get('wgNamespaceNumber')) !== -1) {
statsButton();
addMenu("Ψ เตือน", "ca-warnG", "ตักเตือน", "content", "javascript:warnUser('general', '')");
addMenu("Ψ เตือนก่อกวน", "ca-warnV", "เตือนก่อกวน", "content", "javascript:warnUser('vandal', '')");
if (iScriptConfig.Edition !== Editions.Uncyclopedia) {
addMenu("Ψ ละเมิด", "ca-nothanks", "เตือนละเมิดลิขสิทธิ์", "content", "javascript:warnNothanks()");
}
addMenu("Ψ ทำว่าง", "ca-wdelete", "เตือนการทำหน้าว่าง", "content", "javascript:warnDelete()");
if (iScriptConfig.Edition == Editions.Uncyclopedia) {
addMenu("Ψ ชื่อผู้ใช้ไม่เหมาะสม", "ca-wusername", "เตือนชื่อผู้ใช้ไม่เหมาะสม", "content", "javascript:warnUsername()");
}
}
}
if (mw.config.get('wgAction') == "edit") {
if (mw.util.getParamValue('iScriptAction') === "rollback-vand") {
addWarnVandal("", mw.util.getParamValue('vanarticle'), true);
} else if (mw.util.getParamValue('iScriptAction') === "rollback-agf" || mw.util.getParamValue('iScriptAction') === "rollback-norm") {
addWarnGeneral("", true);
}
}
});
/* </nowiki></pre> */