User:SunAfterRain/js/invertBlock.js
< User:SunAfterRain | js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$( () => {
const INVERT_BLOCK_IS_INVERT = 'invertBlock.isInvert';
const classList = [ 'inline-text-blocked', 'inline-text-block-hd', 'inline-text-block-sl', 'inline-text-block-hsd', 'inline-text-block-hsl' ];
mw.hook( 'wikipage.content' ).add( ( $content ) => {
const $nodeList = $content.find( classList.map( ( cls ) => `.${ cls }` ).join( ',' ) );
for ( const node of $nodeList ) {
const classNameList = Array.from( node.classList ).filter( ( cls ) => classList.includes( cls ) || cls === 'skin-invert' );
if ( !classNameList.length ) {
continue;
}
const $node = $( node );
const background = $node.css( 'background-color' );
$node.data( INVERT_BLOCK_IS_INVERT, false );
$node.on( 'click', () => {
const prevVal = !!$node.data( INVERT_BLOCK_IS_INVERT );
if ( !prevVal ) {
$node.removeClass( classNameList );
$node.css( 'background-color', 'initial' );
} else {
$node.addClass( classNameList );
$node.css( 'background-color', background );
}
$node.data( INVERT_BLOCK_IS_INVERT, !prevVal );
} );
}
} );
} );