MediaWiki:Gadget-noteTAvector.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$( function () {
var xNoteTAVector = 'x-noteTAvector';
function noteTAvector() {
var associatedPages = document.getElementById( 'p-associated-pages' );
var useLegacyMode = !associatedPages;
var makeSpan = function () {
return $( '<span style="padding:1px 3px; background: #d3e3f4; color:#000000;height:85%;">汉</span><span style="padding:1px 3px; background: #e9e9e9; color:#434343;height:85%;">漢</span>' );
};
var mapIndicatorLegacy = function() {
$( '<a href="#">' ).html( makeSpan() )
.click( function( e ) {
e.preventDefault();
} )
.wrap( '<ul><li><span></span></li></ul>' )
.parent().parent().parent().appendTo( this );
};
var mapIndicator = function () {
makeSpan().appendTo( this );
};
var $node = $( 'body.skin-vector-legacy,body.skin-vector-2022' )
.find( '.mw-indicator[id^=mw-indicator-noteTA-]' )
.removeAttr( 'style' )
.empty()
.each( useLegacyMode ? mapIndicatorLegacy : mapIndicator );
if ( useLegacyMode ) {
$node.addClass( xNoteTAVector )
.addClass( 'vector-menu' )
.addClass( 'vector-menu-tabs' )
.addClass( 'vector-menu-tabs-legacy' )
.css( 'float', 'left' )
.insertAfter( '#p-variants' );
} else {
if ( $node.length ) {
var plink = mw.util.addPortletLink( 'p-associated-pages', '#', '' );
plink.classList.add( xNoteTAVector );
var plinkAnchor = plink.querySelector( 'a' );
plink.style.maxHeight = '32px';
if ( plinkAnchor ) {
$node.appendTo( plinkAnchor );
}
}
}
}
mw.hook( 'wikipage.content' ).add( function () {
$( document.getElementsByClassName( xNoteTAVector ) ).remove(); // Will blink duing load preview, but this will avoid the icon won't removed if the TA template is removed, and avoid repeated click event listener from noteTAViewer.
setTimeout( noteTAvector, 1 );
} );
} );