User:WhitePhosphorus/js/DetectDeleteReasons.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// Not completed; do not use it.
(function($, mw) {
'use strict';
if (mw.config.get('wgAction') != "delete") return;
var $reason = $('#wpReason');
if (!$reason.length) return;
// Empty the default reasons.
if (/^内容为:/.test($reason.val())) {
$reason.val("");
}
// Do not modify customized reasons -- usu. included in URL.
if ($reason.val().length) return;
// Capture the title.
var $page = $('#contentSub > a');
if (!$page.length) return;
var title = $page.text();
// Query content of the page.
$.ajax({
url: mw.util.wikiScript('api'),
data: {
action: 'query',
prop: 'revisions',
titles: title,
rvprop: 'content',
format: 'json'
}
}).done(function(data) {
var content = null;
if (data.query) {
if (data.query.pages) {
for (var id in data.query.pages) {
if (data.query.pages[id]) {
var page = data.query.pages[id];
if (page.revisions && page.revisions.length) {
if (page.revisions[0]['*']) {
content = page.revisions[0]['*'];
}
}
}
}
}
}
if (content !== null) {
// Is there csd templates?
// Not support all redirects of Template:Delete.
// Only capture the first parameter.
// TODO: links or templates included in parameters.
var csdTemplates = /{{\s*(delete|db?|c?sd)\s*\|(bot=Jimmy-bot\|)?\s*([^|}]*)/i;
var rst = csdTemplates.exec(content);
if (rst !== null) {
var code = rst[3].toUpperCase();
if (/^[AGFOR]\d+$/.test(code)) {
var value = '['+'[WP:CSD#' + code + '|' + code + ']]';
var $value = $("#wpDeleteReasonList option[value^='" + value + "']");
if ($value.length > 0) {
// Yeah we've got it
$value.prop('selected', true);
return;
}
}
// Not a standard CSD reason; load it in the textbox.
$reason.val(code);
return;
}
// not mandarin, G14
if (/{{\s*(notmandarin|notchinese|非中文)\s*\|/i.test(content)) {
$("#wpDeleteReasonList option[value^='[[WP:CSD#G14|G14]]']").prop('selected', true);
}
// TODO: maybe afd?
}
});
})(jQuery, mw);