User:SunAfterRain/js/sandbox/gadget-rollback-summary.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$(() => {
const batchConv = require('ext.gadget.HanAssist').batchConv;
const messages = batchConv({
prompt: {
hans: '请输入自定义回退摘要(留空则使用系统默认摘要)',
hant: '請輸入自定義回退摘要(留空則使用系統預設摘要)'
},
cancelNotify: {
hans: '已取消回退操作。',
hant: '已取消回退操作。'
},
summary: {
hans: '回退$1的编辑:$2',
hant: '回退$1的編輯:$2'
},
summaryUser: {
hans: '[[Special:Contributions/$1|$1]]([[User talk:$1|对话]])',
hant: '[[Special:Contributions/$1|$1]]([[User talk:$1|對話]])'
},
summaryNoUser: {
hans: '已隐藏用户',
hant: '已隱藏用戶',
tw: '已隱藏使用者'
},
});
const loadedMap = new WeakMap();
mw.hook('wikipage.content').add(() => {
for (const link of $('.mw-rollback-link a')) {
if (loadedMap.has(link)) {
continue;
}
loadedMap.set(link, true);
$(link)
.on('click', (ev) => {
const summary = prompt(messages.prompt);
if (summary === null) {
// 取消回退
ev.preventDefault();
mw.notify(messages.cancelNotify);
return;
} else if (summary === '') {
// 不自訂摘要
return;
}
ev.preventDefault();
const url = new URL(link.href);
const username = url.searchParams.get('from');
url.searchParams.set('summary', mw.format(
messages.summary,
username ? mw.format(messages.summaryUser, username) : messages.summaryNoUser,
summary
));
window.location.assign(url.href);
})
.css('color', '#099');
}
});
});