MediaWiki:Gadget-pseudonamespace-UI.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
(function($, mw) {
const { conv } = require('ext.gadget.HanAssist');
//等待DOM加載完成
$(function() {
//偽命名空間表
const pseudoNS_list = {
MOS: conv({ other: 'Shortcut of Manual of style', hans: '格式手册快捷方式', hant: '格式手冊捷徑' }),
LTA: conv({ other: 'Shortcut of Long-term abuse', hans: '持续出没的破坏者快捷方式', hant: '持續出沒的破壞者捷徑' }),
NC: conv({ other: 'Shortcut of Naming Conventions', hans: '命名常规快捷方式', hant: '命名常規捷徑' }),
NT: conv({ other: 'Shortcut of Notability Guidelines', hans: '收录标准快捷方式', hant:'收錄標準捷徑' }),
RSP: conv({ other: 'Shortcut of Perennial sources', hans: '来源评级快捷方式', hant:'來源評級捷徑' })
},
pseudoNS_tips = conv({ other: '(Pseudo namespace)', hans: '(伪命名空间)', hant: '(偽命名空間)' }),
pseudoNS_name = conv({ other: 'Pseudo namespace', hans: '伪命名空间', hant:'偽命名空間' });
let ns = new mw.Title(mw.config.get('wgPageName')).title.split(':')[0];
const isMOSNameSpace = mw.config.get('wgNamespaceNumber') === 126 || mw.config.get('wgNamespaceNumber') === 127;
if (isMOSNameSpace) {
ns = 'MOS';
}
if (!Object.prototype.hasOwnProperty.call(pseudoNS_list, ns)) {
return;
}
//依據皮膚偵測NS Tab
let nstab = 'li[id^="ca-nstab-"] > a';
if (mw.config.get('skin') === 'minerva') {
nstab = 'a.minerva__tab-text[data-event-name="tabs.main"]';
if (isMOSNameSpace) {
nstab = 'a.minerva__tab-text[data-event-name="tabs.mos"]';
}
}
//顯示偽命名空間種類於NS Tab
$(nstab).text(pseudoNS_list[ns.toUpperCase()]);
//link to [[WP:PNS+]]
$('.mw-indicators').append($('<div id="mw-indicator-mw-helplink" class="mw-indicator">').append($('<a class="mw-helplink">').append($('<span class="mw-helplink-icon">')).append(pseudoNS_name).attr('href', '../wiki/WP:PNS%2B')));
//顯示偽造命名空間於頁面資訊
$('<tr><th scope="row">' + pseudoNS_name + '</th><td>' + ns + ' (' + pseudoNS_list[ns] + ')</td></tr>').insertAfter('#mw-pageinfo-length');
//非触控式的設備上顯示提示文字,並避免與POPUP小工具衝突
if (!window.matchMedia('(pointer: coarse)').matches) $('#firstHeading').html($('#firstHeading').html().replace(ns.toUpperCase(), $('<abbr>' + ns.toUpperCase() + '</abbr>').attr('title', pseudoNS_list[ns.toUpperCase()] + ' ' + pseudoNS_tips)[0].outerHTML));
})
})(jQuery, mw);