MediaWiki:Gadget-pseudonamespace-UI.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
(function($, mw) {
//偽命名空間的討論頁亦需要提示。
if (mw.config.get('wgNamespaceNumber') !== 0 && mw.config.get('wgNamespaceNumber') !== 1) return;
const { conv } = require('ext.gadget.HanAssist');
//等待DOM加載完成
$(function() {
//偽命名空間表
var 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:'收錄標準捷徑' })
},
pseudoNS_tips = conv({ other: '(Pseudo namespace)', hans: '(伪命名空间)', hant: '(偽命名空間)' }),
pseudoNS_name = conv({ other: 'Pseudo namespace', hans: '伪命名空间', hant:'偽命名空間' });
var ns = (function(test) {
return test.length > 1 ? test[0] : ''
})(mw.config.get('wgPageName').replace(/[_\s]talk/i, '').replace(/talk:/i, '').split(':'));
var newregexp = function(test) {
return new RegExp(test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'ig')
};
var user_skin = mw.config.get('skin');
//依據皮膚偵測NS Tab
if (pseudoNS_list.hasOwnProperty(ns)) {
var nstab = (function() {
var parent_ele, child_ele;
var NSTab_selector = {
minerva: '.minerva__tab-container',
modern: 'div.pBody>ul>li',
monobook: 'div.pBody>ul>li',
timeless: 'div.mw-portlet-body>ul>li',
'vector-2022': '.vector-menu-content-list>li',
vector: '.vector-menu-content-list>li'
};
switch (user_skin) {
case 'minerva':
parent_ele = $(NSTab_selector[user_skin]);
child_ele = parent_ele.children().first();
break;
case 'modern':
case 'monobook':
case 'timeless':
case 'vector-2022':
case 'vector':
child_ele = $(NSTab_selector[user_skin]).filter(function() {
return this.id.match(/nstab/i);
}).first();
parent_ele = child_ele.closest('ul');
break;
}
return {
parent: parent_ele,
child: child_ele
};
})();
//顯示偽命名空間種類於NS Tab
if (nstab.parent && nstab.parent.length > 0) nstab.parent.html(nstab.parent.html().replace(newregexp(nstab.child.text()), pseudoNS_list[ns.toUpperCase()]));
//提示文字選擇器
var tips_selector = ({
minerva: '#section_0',
modern: '#mw_header',
monobook: '#firstHeading',
timeless: '#firstHeading',
'vector-2022': '#firstHeading',
vector: '#firstHeading'
})[user_skin];
//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><td>' + pseudoNS_name + '</td><td>' + ns + ' (' + pseudoNS_list[ns] + ')</td></tr>').insertAfter('#mw-pageinfo-length');
//非處空式的設備上顯示提示文字,並避免與POPUP小工具衝突
if (!('ontouchstart' in document.documentElement)) $(tips_selector).html($(tips_selector).html().replace(ns.toUpperCase() + ':', $('<abbr>' + ns.toUpperCase() + ':</abbr>').attr('title', pseudoNS_list[ns.toUpperCase()] + ' ' + pseudoNS_tips)[0].outerHTML));
}
})
})(jQuery, mw);