MediaWiki:Citizen.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* Accessible names for Citizen collapse buttons whose labels live in hidden icons. */
( function () {
'use strict';
function label() {
document.querySelectorAll( '#citizen-toc .citizen-toc-toggle' ).forEach( function ( b ) {
if ( b.getAttribute( 'aria-label' ) ) { return; }
var t = ( b.textContent || '' ).replace( /\s+/g, ' ' ).trim();
if ( t ) { b.setAttribute( 'aria-label', t ); }
} );
document.querySelectorAll( '.citizen-section-toggle' ).forEach( function ( b ) {
if ( b.getAttribute( 'aria-label' ) ) { return; }
var h = b.closest( '.citizen-section-heading' );
if ( !h ) { return; }
var clone = h.cloneNode( true );
clone.querySelectorAll( 'button, .citizen-section-toggle, .mw-editsection' ).forEach( function ( x ) { x.remove(); } );
var title = ( clone.textContent || '' ).replace( /\s+/g, ' ' ).trim();
if ( title ) { b.setAttribute( 'aria-label', '折叠或展开「' + title + '」章节' ); }
} );
}
function boot() { label(); setTimeout( label, 350 ); }
if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', boot ); }
else { boot(); }
} )();