User:Fred Gandt/sectionLinks.js

$( document ).ready( => {	// TODO while previewing etc. or on every page?	const SCTNS = Array.from( $(":header") );	if ( SCTNS && SCTNS.length ) {		mw.loader.load( "/w/index.php?title=User:Fred_Gandt/sectionLinks.css&action=raw&ctype=text/css", "text/css" );		const CNS = mw.config.get( "wgCanonicalNamespace" ),			PN = mw.config.get( "wgPageName" ),			TTL = mw.config.get( "wgTitle" ),			CCNS = CNS ? `${CNS}:` : "",			LO = location.origin,			cycleSectionLinks = function( evt ) {				evt.preventDefault;				let i = this.sectionLinks.indexOf( this.textContent ) + ( evt.deltaY > 0 ? 1 : -1 );				this.textContent = this.sectionLinks[ i > 3 ? 0 : ( i < 0 ? 3 : i ) ];			};		let stc;		SCTNS.forEach( h => { stc = h.textContent; h.sectionLinks = [ stc, `${CCNS}${TTL}`, ``,				`${LO}/wiki/${PN}#${mw.util.wikiUrlencode( stc )}` ];			h.addEventListener( "wheel", cycleSectionLinks ); } );	} } );