跳转到内容

User:魔琴/gadgets/origintitle/index.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*
用来显示页面的原始标题,显示在上方标签页左侧。
Author: [[User:Shizhao]], 2021
Edit: [[User:魔琴]], 2025
*/

mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib',/*'ext.gadget.HanAssist'*/]).done(function () {
	function han(s, t) {
		return wgULS(s, t);
		//return HanAssist.localize( { hans: s, hant: t } );
	}


	function main() {

		var clips = []
		var path = 'https:' + mw.config.get('wgServer') + '/wiki/'
		var title = mw.config.get('wgTitle');
		var nsnumber = mw.config.get('wgNamespaceNumber');
		var cns = mw.config.get('wgCanonicalNamespace').replace(/_/g, ' ') + (nsnumber === 0 ? '' : ':');
		var cname = cns + title;
		clips.push(cname);
		clips.push(link(cname))
		var skin = mw.config.get('skin');
		var indom = '';
		var nextnode = '';

		switch (skin) {
			case 'vector':
				indom = 'p-namespaces';
				break;
			case 'vector-2022':
			case 'minerva':
				indom = 'p-associated-pages';
				break;
			case 'timeless':
				indom = 'p-namespaces';
				nextnode = '#ca-unwatch';
				break;
			case 'monobook':
			case 'modern':
				indom = 'p-cactions';
				nextnode = '#ca-view';
				break;
			case 'cologneblue':
				indom = 'p-pageoptions';
				break;
			default:
				break;
		}


		switch (nsnumber) {
			case 4:
				const wpns = 'Wikipedia:'
				var wpname = wpns + title
				clips.push(wpname)
				clips.push(link(wpname))
				break;
			case 5:
				const wtns = 'Wikipedia talk:'
				var wtname = wtns + title
				clips.push(wtname)
				clips.push(link(wtname))
				break;
			case 6:
			case 14:
				clips.push(link(':' + cname))
				break;
			case 10: 
				clips.push('{{' + title + '}}')
				clips.push('{{tl|1=' + title + '}}')
				break;
			case 828:
				clips.push('{{#invoke:' + cname + '|}}')
				break;
			default:
				break;
		}


		if (nsnumber === 0) {
			clips.push('{{lb|1=' + title + '}}')
		} else if (nsnumber === 4) {
			clips.push('{{wlb|1=' + title + '}}')
			clips.push('{{lb|1=Wikipedia:' + title + '}}')
		} else if (nsnumber === 5) {
			clips.push('{{lb|2=|1=' + cname + '}}')
			clips.push('{{lb|1=Wikipedia talk:' + title + '}}')
		} else {
			clips.push('{{lb|2=|1=' + cname + '}}')
			clips.push('{{lb|1=' + cname + '}}')
		}

		clips.push(path + encodeURI(cname));

		var portletLink = mw.util.addPortletLink(
			indom,
			'',
			han('原始标题', '原始標題'),
			'ca-origintitle',
			han('获取页面的原始标题', '獲取頁面的原始標題'),
			'o',
			nextnode
		);

		$(portletLink).click(function (e) {
			e.preventDefault();
			mw.loader.using('oojs-ui').then(function () {
				var $copy = $('<div>');
				for (i = 0; i < clips.length; i++) {
					$copy.append(new mw.widgets.CopyTextLayout({ title: '', copyText: clips[i] }).$element);
				}
				OO.ui.alert($copy);
			});
		});
	}

	function link(text) {
		return '[[' + text + ']]'
	}

	main()

}(jQuery, window, document));