跳转到内容

User:WhitePhosphorus/js/highlight.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
(function(mw, $) {
'use strict';

if (mw.config.get('wgAction') !== "history") {
	return;
}

let $highlight = $('<button />', {
	'name': 'highlight',
	'type': 'button',
	'class': 'historysubmit mw-ui-button',
	'title': '高亮显示选中的版本',
	'text': '高亮所选版本'
});
$highlight.on('click', function(e) {
	// Get all checked revision ids
	let ids = [];
	let idArr = null;
	const idRe = /ids\[(\d+)\]/;
	const highlightRe = /(&hilight=[^&]*)(&|$)/;
	for (let b of $('input')) {
		idArr = idRe.exec(b.name || '');
		if (b.type === 'checkbox' && b.checked && idArr !== null) {
			ids.push(idArr[1]);
		}
	}
	// Highlight them!
	let url = window.location.href;
	if (url.includes('&hilight=')) {
		// Drop previously highlighed revisions
		url = url.replace(highlightRe, `&hilight=${ids.join(',')}$2`);
	} else {
		url += `&hilight=${ids.join(',')}`;
	}
	// Reload the page & got highlighted
	window.location.href = url;
});
$(".historysubmit.mw-history-compareselectedversions-button").after($highlight);

})(mediaWiki, jQuery);