◆42Lab是非盈利性、非官方的云图计划维基百科。 ◆诚邀指挥官们加入编辑部共同建设wiki。点这里加入42Lab ◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易! ◆有任何意见、建议、纠错,欢迎在任意评论区评论 ◆编辑讨论QQ群741423564 微博@GFwiki少前百科 欢迎您 |
MediaWiki:Gadget-ElevateLeadingSection.js
来自42LAB
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
function elevateLeadingSection() {
var content = document.querySelector( '.mw-parser-output' ),
leadingP = null,
infoboxes = [],
foundL = false;
for (
var e = content.firstElementChild;
e !== null;
e = e.nextElementSibling
) {
if ( e.tagName === 'H2' ) {
break;
}
if ( e.tagName === 'P' && !foundL ) {
if ( e.querySelectorAll( ':scope > b' ).length !== 0 ) {
leadingP = e;
foundL = true;
}
}
if ( e.classList.contains( 'infobox' ) ) {
infoboxes.push( e );
}
}
infoboxes.forEach( function ( i ) {
$( i ).makeCollapsible( { collapsed: true } );
} );
if ( leadingP !== null && infoboxes.length !== 0 ) {
infoboxes[ 0 ].insertAdjacentElement(
'beforebegin',
content.removeChild( leadingP )
);
}
}
mw.loader.using( 'mw.gadget.detectmobilebrowsers' ).then( function () {
if ( window.mobileCheck() ) {
console.log( 'Mobile browser detected. Moving infoboxes.' );
elevateLeadingSection();
} else {
console.log( 'Mobile browser not detected.' );
}
} );