User:Emojiwiki/module/SnippetController.js
外观
< User:Emojiwiki | module
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
"use strict";
// <nowiki>
$(function () {
let l = function (msg) {
console.log("[SnipperController] " + msg);
};
let PNAME = "User:Emojiwiki/Snippets";
let SNP_PREFIX = PNAME + "/";
if (mw.config.get("wgAction") != "view" || mw.config.get("wgPageName") != PNAME) {
l("Not on the proper page");
return;
}
let api = new mw.Api();
let $listDIV = $(".snippetList");
let $logDIV = $(".snippetStatus");
$logDIV.html("JavaScript Loaded... Getting list of snippets...");
$listDIV.html('');
api.get({
"action": "query",
"list": "prefixsearch",
"pssearch": SNP_PREFIX,
"pslimit": 500,
"psprofile": "strict"
}).done(function (data) {
$logDIV.html("List of snippets got... Rendering...");
for (let i = 0; i < data.query.prefixsearch.length; i++) {
let x = data.query.prefixsearch[i];
l("Working on " + x.title + " ID:" + i);
api.get({
"action": "parse",
"page": x.title,
"prop": ["text","wikitext"],
"disableeditsection": true
}).done(function (p_data) {
let txt = p_data.parse.text["*"];
let DISPtxt = txt;
let wikitext = p_data.parse.wikitext["*"];
let $SNP_C = $("<div>");
let $TITLE = $('<h2>' + x.title.slice(SNP_PREFIX.length) + ' </h2>');
let $editsection = $('<span>')
.addClass('mw-editsection')
.appendTo($TITLE);
$('<span class="mw-editsection-bracket">[</span>').appendTo($editsection);
$('<a>')
.attr('href',mw.util.getUrl(x.title))
.html('VIEW')
.appendTo($('<span>').appendTo($editsection));
$('<span class="mw-editsection-divider">|</span>').appendTo($editsection);
$SNP_C.addClass("snippetChild");
if (wikitext.includes("{{d|O1}}")) {
$("<a>")
.html("UNDEL")
.click(function (e) {
e.preventDefault();
let status = "UNDEL OK";
let $this = $(this);
$this.html('UNDELING');
api.edit(x.title,function (rev) {
if (!rev.content.includes('{{d|O1}}')) {
status = "AREADY";
return rev.content;
}
return {
"text": rev.content.replace( '{{d|O1}}', '' ),
"summary": "Undo CSD O1: [[" + x.title + "]] (SnippetController)"
};
}).done(function () {
$this.html(status);
});
})
.appendTo($editsection);
DISPtxt = "Pending for delete";
} else {
$("<a>")
.html("DEL")
.click(function (e) {
e.preventDefault();
let status = "DEL OK";
let $this = $(this);
$this.html('DELING');
api.edit(x.title,function (rev) {
if (rev.content.includes('{{d|O1}}')) {
status = "AREADY";
return rev.content;
}
return {
"prependtext": "{{d|O1}}",
"summary": "CSD O1: [[" + x.title + "]] (SnippetController)"
};
}).done(function () {
$this.html(status);
});
})
.appendTo($editsection);
}
$('<span class="mw-editsection-bracket">]</span>').appendTo($editsection);
$TITLE.appendTo($SNP_C);
$SNP_C.append(DISPtxt);
$listDIV.append($SNP_C);
l("Render of " + x.title + " done.");
}).catch(function (e) {
$logDIV.html('<b class="error">Rendering snippet ' + x.title + '...ERROR! ' + e + '</b>');
});
}
}).catch(function (e) {
$logDIV.html('<b class="error">Gettign list of snippets...ERROR! ' + e + '</b>');
});
});
// </nowiki>