跳转到内容

User:SunAfterRain/js/pseudonamespace-UI.epVer.js

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

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

$(function() {
	//偽命名空間的討論頁亦需要提示。
	if (mw.config.get('wgNamespaceNumber') !== 0 && mw.config.get('wgNamespaceNumber') !== 1) {
		return;
	}

	//偽命名空間表
	var pseudoNSList = mw.libs.HanAssist.parse({
		MOS: {other: 'Shortcut of Manual of style', hans: '格式手册快捷方式', hant: '格式手冊捷徑' },
		LTA: {other: 'Shortcut of Long-term abuse', hans: '持续出没的破坏者快捷方式', hant: '持續出沒的破壞者捷徑'},
		NC: {other: 'Shortcut of Naming Conventions', hans: '命名常规快捷方式', hant: '命名常規捷徑'},
		NT: {other: 'Shortcut of Notability Guidelines', hans: '关注度指引快捷方式', hant: '關注度指引捷徑'}
	});
	const pseudoNamespaceName = mw.libs.HanAssist.localize({other: 'Pseudo namespace', hans: '伪命名空间', hant: '偽命名空間'});

	var pns = new mw.Title(mw.config.get('wgPageName')).title.split(':')[0];
	if (!Object.prototype.hasOwnProperty.call(pseudoNSList, pns)) {
		return;
	}

	var nstabSelector = 'li[id^="ca-nstab-"] > a';
	var tipsSelector = '#firstHeading';
	if (mw.config.get('skin') === 'minerva') {
		//行動版硬是跟別人長不一樣
		nstabSelector = 'a.minerva__tab[data-event-name="tabs.subject"]';
		tipsSelector = '#section_0';
	}
	//顯示偽命名空間種類於NS Tab
	$(nstabSelector).text(pseudoNSList[pns]);
	//link to [[WP:PNS+]]
	$('.mw-indicators').append(
		$('<div>').attr({
			'class': 'mw-indicator'
		}).append(
			$('<a>').attr({
				'href': mw.util.getUrl('WP:PNS+')
			}).append(
				$('<img>').attr({
					'src': '/w/resources/src/mediawiki.helplink/images/helpNotice.svg',
					'style': 'padding-right: 0.25em'
				}),
				$('<span>').text(pseudoNamespaceName)
			)
		)
	);
	$('<tr>').append(
		$('<td>').text(pseudoNamespaceName),
		$('<td>').text(pns + ' (' + pseudoNS_list[pns] + ')')
	).insertAfter('#mw-pageinfo-length');
	//非處空式的設備上顯示提示文字,並避免與POPUP小工具衝突
	if (!('ontouchstart' in document.documentElement)) {
		$(tipsSelector).html(
			$(tipsSelector).html().replace(
				pns + ':',
				$('<div>').append(
					$('<abbr>')
						.attr({
							'title': pseudoNSList[pns] + ' (' + pseudoNamespaceName + ')'
						}).text(pns + ':')
				).html()
			)
		);
	}
});