User:魔琴/gadgets/ILH-Greenexternal/ILH-Greenexternal.js

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

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

/* 主要代码来源:
     [[MediaWiki:Gadget-internalLinkHelper-external.js]]
     [[MediaWiki:Gadget-internalLinkHelper-redtipsy.js]]
   作者[[User:Liangent]]等。
   感谢[[User:AnYiLin]]的协助。  */

mw.loader.load('/w/index.php?title=User:魔琴/gadgets/ILH-Greenexternal/css.css&action=raw&ctype=text/css', 'text/css');

mw.loader.using(['ext.gadget.tipsyDeprecated']).done(function () {
( function( $, mw, window ) { $( function() {
	$('.ilh-all', mw.util.$content).each(function() {
        var exta = $('.ilh-link a', this);
        if (exta.length == 0) return;
        $('.ilh-page a', this).removeClass('new').addClass('extiw')
            .attr('href', exta.attr('href'))
            .attr('title', exta.attr('title'));
    });
	mw.hook( 'wikipage.content' ).add( function( $content ) {
		mw.loader.using(['ext.gadget.site-lib', 'jquery.tipsy', 'mediawiki.util']);
		$( '.ilh-all', $content ).not( '.ilh-blue' ).on( 'internalLinkHelper-close', function( event ) {
			var $this = $( this );
			if ( $this.data( 'internalLinkHelper-showing' ) ) {
				$( this ).removeClass( 'ilh-active' ).find( '.ilh-page a' ).tipsy( 'hide' ).end()
					.data( 'internalLinkHelper-showing', false );
			}
		} ).each( function() {
			var origTitle = $( this ).data( 'orig-title' ),
				$foreignSpan = $( '.ilh-link', this ),
				$linkAnchor = $( '.ilh-page a', this ),
				$langSpan = $( '.ilh-lang', this ),
				langName = $langSpan.text(),
				$that = $( this ).data( 'internalLinkHelper-showing', false );

			if ( !$linkAnchor.length ) {
				return;
			}

			var timeout = null;
			
			var maybeClearTimeout = function() {
				if ( timeout !== null ) {
					clearTimeout( timeout );
				}
			}, autoSetTimeout = function() {
				maybeClearTimeout();
				timeout = setTimeout.apply( null, arguments );
			};
			
			var mouseleave = function() {
				autoSetTimeout( function() {
					$that.trigger( 'internalLinkHelper-close' );
				}, 500 );
			}, mouseenter = function() {
				if ( $that.data( 'internalLinkHelper-showing' ) ) {
					maybeClearTimeout();
				} else {
					$( '.ilh-all', $content ).not( $that ).trigger( 'internalLinkHelper-close' );
					$that.addClass( 'ilh-active' ).data( 'internalLinkHelper-showing', true );
					var tipsy = $linkAnchor.tipsy( 'show' );
					// please revise as necessary
					if(tipsy) {
						tipsy = tipsy.tipsy( true );
						if(tipsy && tipsy.tip) {
							tipsy.tip().mouseleave( mouseleave ).mouseenter( mouseenter );
						}
					}
				}
			};
			$linkAnchor.tipsy( {
				className: 'ilh-tipsy',
				gravity: 'nw',
				html: true,
				trigger: 'manual',
				title: function() {
					return '<div>'
						+ wgUVS( '“', '「' )
						+ $( '<span/>' ).text( origTitle ).html()
						+ wgUVS( '”不存在。', '」不存在。' )
						+ $( '<span/>' ).text( langName ).html()
						+ wgUVS( ':', ':' )
						+ $foreignSpan.html()
						+ '</div>';
				}
			} )
			.mouseleave( mouseleave ).mouseenter( mouseenter );
		} );
	} );
} ); } )( jQuery, mediaWiki, window );
});