User:Xiplus/js/close-move.js
外观
< User:Xiplus | js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// <nowiki>
/* globals CloseMove:true */
(function() {
if (typeof CloseMove == 'undefined')
CloseMove = {};
if (typeof CloseMove.summary == 'undefined') {
CloseMove.summary = ['已完成移動', '未完成移動,未提出理由', '未完成移動,根據討論頁意見', '未完成移動,未有共識'];
}
if (typeof CloseMove.summarySuffix == 'undefined') {
CloseMove.summarySuffix = ' via [[User:Xiplus/js/close-move.js|close-move]]';
}
if ($('.ambox-move').length === 0) {
return;
}
function showCloseButton() {
var button = document.createElement('a');
button.innerText = '移除模板';
button.setAttribute('style', 'font-size: small');
$(button).click(function() {
processClose();
return false;
});
$('.box-Requested_move').find("td.mbox-text").children('span').children('small').after(button);
}
function processClose() {
mw.loader.using(['jquery.ui'], function() {
var html = '<div>';
html += '編輯摘要<br>';
html += '<select id="summary">';
for (var i = 0; i < CloseMove.summary.length; i++) {
html += '<option value="' + CloseMove.summary[i] + '">' + CloseMove.summary[i] + '</option>'
}
html += '</select>';
html += '<br>';
html += '附加理由<br>';
html += '<input type="text" id="summary2" size="40">';
html += '</div>';
$(html).dialog({
title: '移除移動請求模板',
minWidth: 515,
minHeight: 150,
buttons: [{
text: '確定',
click: function() {
processEdit($(this).find('#summary').val(), $(this).find('#summary2').val());
$(this).dialog('close');
}
}, {
text: '取消',
click: function() {
$(this).dialog('close');
}
}]
});
});
}
function processEdit(reason, reason2) {
new mw.Api().edit(mw.config.get('wgPageName'), function(revision) {
var content = revision.content;
content = content.replace(/\{\{\s*Requested move\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/i, '');
if (reason2.trim() !== '') {
reason += ':' + reason2;
}
reason += CloseMove.summarySuffix;
return {
text: content,
basetimestamp: revision.timestamp,
summary: reason,
minor: false
};
}).then(function() {
mw.notify('已移除移動請求模板');
}, function(e) {
if (e == 'editconflict') {
mw.notify('移除移動請求模板時發生編輯衝突');
} else {
mw.notify('移除移動請求模板時發生未知錯誤:' + e);
}
});
}
showCloseButton();
}
)();
// </nowiki>