User:暁月凛奈/close-affp.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// <nowiki>
/* globals CloseAffp:true */
(function() {
if (typeof CloseAffp == 'undefined'){
CloseAffp = {};
}
if (typeof CloseAffp.summary == 'undefined') {
CloseAffp.summary = '使用[[User:暁月凛奈/close-affp.js|close-affp]]关闭报告';
}
if (mw.config.get('wgPageName') !== 'Wikipedia:防滥用过滤器/错误报告'
|| mw.config.get('wgAction') !== 'view'
|| mw.config.get('wgRevisionId') !== mw.config.get('wgCurRevisionId')) {
return;
}
mw.util.addCSS(`
a.close-affp-link {
color: red;
font-weight: bold;
}
a.close-affp-link-closed {
color: gray;
}
`)
var titles = $('#bodyContent').find('.mw-heading3');
var api = new mw.Api();
var content, curtimestamp, basetimestamp;
var getPageContent = new Promise(function(resolve, reject) {
api.get({
action: 'query',
prop: 'revisions',
rvprop: ['content', 'timestamp'],
rvslots: '*',
titles: 'Wikipedia:防滥用过滤器/错误报告',
formatversion: '2',
curtimestamp: true,
}).then(function(data) {
var page, revision;
if (!data.query || !data.query.pages) {
mw.notify('未能抓取页面内容(unknown)');
reject('unknown');
}
page = data.query.pages[0];
if (!page || page.invalid) {
mw.notify('未能抓取页面内容(invalidtitle)');
reject('invalidtitle');
}
if (page.missing) {
mw.notify('未能抓取页面内容(nocreate-missing)');
reject('nocreate-missing');
}
revision = page.revisions[0];
var content = revision.slots.main.content;
var basetimestamp = revision.timestamp;
var curtimestamp = data.curtimestamp;
resolve({
content: content,
basetimestamp: basetimestamp,
curtimestamp: curtimestamp,
});
})
}
);
function showCloseButton() {
titles.each(function(sectionid, current) {
var title = $(current).find('.mw-headline').first().text();
var sectionid = mw.util.getParamValue('section', $(current).find('.mw-editsection a')[0].href);
var closeLink = document.createElement('a');
closeLink.href = '#';
closeLink.className = 'close-affp-link';
closeLink.innerText = wgULS('关闭', '關閉');
$(closeLink).on('click', function() {
processClose(sectionid, title);
return false;
});
var node = current.getElementsByClassName('mw-editsection')[0];
var delDivider = document.createElement('span');
delDivider.appendChild(document.createTextNode(' | '));
node.insertBefore(delDivider, node.childNodes[1]);
node.insertBefore(closeLink, node.childNodes[1]);
});
}
function processClose(sectionid, title) {
mw.loader.using(['jquery.ui'], function() {
var html = '<div>';
html += '状态<br>';
html += '<select id="status">';
html += '<option value="cls">关闭</option>';
html += '<option value="res">已解决</option>';
html += '<option value="con">确认</option>';
html += '<option value="fdb">需要反馈</option>';
html += '<option value="reo">重开</option>';
html += '<option value="ack">认知</option>';
html += '<option value="ass">指定</option>';
html += '<option value="new">新近</option>';
html += '</select><br>';
html += '处理<br>';
html += '<select id="res">';
html += '<option value="inv">无效</option>';
html += '<option value="res">已解决</option>';
html += '<option value="wnf">未修复</option>';
html += '<option value="fix">已修复</option>';
html += '<option value="">无</option>';
html += '<option value="lat">待后</option>';
html += '<option value="wfm">无法重现</option>';
html += '<option value="dup">重复</option>';
html += '</select><br>';
html += '留言<br>';
html += '<select id="vip" onchange="$(this.parentElement).find(\'#comment\')[0].value += this.value; this.value = \'\';">';
html += '<option value="">选择</option>';
html += '<option value="{{Fixed}}">{{Fixed}}(已修复)</option>';
html += '<option value="{{Wontfix}}">{{Wontfix}}(不予修复)</option>';
html += '<option value="已协助编辑">已协助编辑</option>';
html += '<option value="无效报告">无效报告</option>';
html += '<option value="请再次尝试编辑">请再次尝试编辑</option>';
html += '<option value="请至[[Wikipedia:互助客栈/求助]]寻求协助">请至Wikipedia:互助客栈/求助寻求协助</option>';
html += '<option value="请详阅过滤器的警告讯息">请详阅过滤器的警告讯息</option>';
html += '<option value="过滤器无误">过滤器无误</option>';
html += '<option value="重复报告">重复报告</option>';
html += '</select><br>';
html += '<input type="text" id="comment" size="40" value=":">';
html += '</div>';
$(html).dialog({
title: '关闭过滤器错误报告 - ' + title,
minWidth: 515,
minHeight: 150,
buttons: [{
text: '确定',
click: function() {
processEdit(sectionid, title, $(this).find('#status').val(), $(this).find('#res').val(), $(this).find('#comment').val());
$(this).dialog('close');
}
}, {
text: '取消',
click: function() {
$(this).dialog('close');
}
}]
});
});
}
function processEdit(sectionid, title, status, res, comment) {
new mw.Api().edit('Wikipedia:防滥用过滤器/错误报告', function(revision) {
var content = revision.content;
const splittoken = 'CLOSE_RRD_SPLIT_TOKEN';
content = content.replace(/^===/gm, splittoken + '===');
var contents = content.split(splittoken);
var newtext = contents[sectionid - 1];
newtext = newtext.trim();
newtext = newtext.replace(/{{bugstatus(\|status=[^|\n}]*?)?(\|res=[^|\n}]*?)?}}/, '{{bugstatus|status=' + status + '|res=' + res + '}}');
if (comment.replace(/[\s:*]/g, '') !== '') {
comment = comment.trim();
if (comment.search(/[.?!;。?!;]$/) === -1) {
comment += '。';
}
newtext += '\n' + comment + '~~~~';
}
newtext += '\n\n';
$($('#bodyContent').find('h3')[sectionid - 2]).find('.close-affp-link span').css('color', 'grey');
return {
text: newtext,
section: sectionid,
basetimestamp: revision.timestamp,
summary: CloseAffp.summary,
minor: true
};
}).then(function() {
mw.notify('已关闭 ' + title);
}, function(e) {
if (e == 'editconflict') {
mw.notify('关闭 ' + title + ' 时发生编辑冲突');
} else {
mw.notify('关闭 ' + title + ' 时发生未知错误:' + e);
}
});
}
getPageContent.then(function(result) {
window.content = result.content;
var lenintext = result.content.split(/^===/gm).length - 1;
if ($('#bodyContent').find('h3').length !== lenintext) {
mw.notify('抓取章节错误,在HTML找到 ' + $('#bodyContent').find('h3').length + ' 个章节,在源代码找到 ' + lenintext + ' 个章节');
} else {
showCloseButton();
}
});
}
)();
// </nowiki>