User:Bosco/rollback-summary.js: Difference between revisions
From Test Wiki
Content deleted Content added
PB2008 moved page User:PB2008/rollback-summary/en.js to User:PB2008/RollbackSummary V1/en.js |
mNo edit summary |
||
| Line 1: | Line 1: | ||
//https://zh.wikipedia.org/wiki/MediaWiki:Gadget-rollback-summary.js |
|||
/* #REDIRECT */mw.loader.load("https://dev.miraheze.org/wiki/User:PB2008/RollbackSummary_V1/en.js?action=raw&ctype=text/javascript"); |
|||
(() => { |
|||
const messages = { |
|||
prompt: 'Please enter a custom rollback summary (leave blank to use the default summary).', |
|||
cancelNotify: 'Rollback canceled', |
|||
summary: 'Reverted edit(s) by $1: $2', |
|||
summaryUser: '[[Special:Contributions/$1|$1]]([[User talk:$1|talk]])', |
|||
summaryNoUser: 'hidden user', |
|||
}; |
|||
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'); |
|||
} |
|||
}); |
|||
})(); |
|||