mic_none

User:Fred Gandt/sectionFooters.js Source: en.wikipedia.org/wiki/User:Fred_Gandt/sectionFooters.js

$( document ).ready( () => {
	"use strict";
	const CONTENT = document.querySelector( "#mw-content-text .mw-parser-output" );
	if ( !CONTENT ) return;
	
	const SECTIONS = Array.from( CONTENT.querySelectorAll( "div.mw-heading" ) ),
		sectionLevel = section => parseInt( section.querySelector( "h2, h3, h4, h5, h6" ).tagName.replace( /h/i, "" ) );
	
	SECTIONS.forEach( ( section, i ) => {
		let section_level = sectionLevel( section ),
			section_clone = section.cloneNode( true ),
			next_section = SECTIONS.find( ( section, ii ) => ii > i && sectionLevel( section ) <= section_level ); // TODO still not quite right
		section_clone.style.opacity = 0.5;
		if ( next_section ) {
			next_section.before( section_clone );
		} else {
			CONTENT.append( section_clone );
		}
	} );
} );