User:Lopullinen/gadgets/randomVariantLink.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$(function () {
const variantList = [
'zh-cn', 'zh-cn', 'zh-cn',
'zh-hk', 'zh-hk', 'zh-hk',
'zh-tw', 'zh-tw', 'zh-tw',
'zh-mo', 'zh-sg', 'zh-my'
// 'zh-hans', 'zh-hant', 'zh'
];
const el = document.querySelectorAll('#mw-content-text a');
for (let i = 0; i < el.length; i++) {
if (
el[i].href.match(mw.config.get('wgServer') + '/wiki/') &&
!(el[i].href.match('#'))
) {
const rand = Math.floor(Math.random() * variantList.length);
el[i].href += "?variant=" + variantList[rand];
}
}
});