跳转到内容

User:SunAfterRain/js/sandbox/gadget-rollback-summary.js

维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2025年6月9日 (一) 09:57 建立内容为“$(() => { const batchConv = require('ext.gadget.HanAssist').batchConv; const messages = batchConv({ prompt: { hans: '请输入自定义回退摘要(留空则使用系统默认摘要)', hant: '請輸入自定義回退摘要(留空則使用系統預設摘要)' }, cancelNotify: { hans: '已取消回退操作。', hant: '已取消回退操作。' }, summary: { hans: '回退$1的编辑:$2', hant: '回退$1的…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ 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');
		}
	});
});