User:WhitePhosphorus/js/peis-limit-links.js

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

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

(function($, mw) {

	mw.hook('wikipage.content').add(function($content) {
		// 显示成 Template: 或 #invoke: 开头的链接,可以筛掉绝大部分不符合的内链
		let template_links = $('a[title^="Template:"]');
		template_links = template_links.add($('a[href^="#invoke:"]'));
		// 下一个元素是注释,并且是 MediaWiki 的模板超限警告
		let omitted_template_links = template_links.filter((_, e) => e.nextSibling && e.nextSibling.nodeType === Node.COMMENT_NODE && e.nextSibling.textContent.includes("WARNING: template omitted"));

		var mouseleave = function() {
			return;
		}, mouseenter = function() {
			if ( 0 ) {
			} else {
				//$( '.ilh-all', $content ).not( $that ).trigger( 'internalLinkHelper-close' );
				//$that.addClass( 'ilh-active' ).data( 'internalLinkHelper-showing', true );
				var tipsy = $(this).tipsy( 'show' );
				// please revise as necessary
				if(tipsy) {
					tipsy = tipsy.tipsy( true );
					if(tipsy && tipsy.tip) {
						tipsy.tip().mouseleave(mouseleave).mouseenter(mouseenter);
					}
				}
			}
		};

		omitted_template_links.each(function() {
			$(this).tipsy({
				gravity: 'nw',
				html: true,
				trigger: 'manual',
				title: function() {
					return '<div>'
						+ wgUVS('本页面已超出维基百科的', '本頁面已超出維基百科的')
						+ '<a href="/wiki/Wikipedia:模板限制">模板大小限制</a>'
						+ wgUVS(',故该模板无法正常显示。', ',故該模板無法正常顯示。')
						+ '</div>';
				}
			});
		})
		.mouseleave(mouseleave).mouseenter(mouseenter);
	});

})(jQuery, mediaWiki);