User:Will Pittenger/timeless.js

var aiHeadCnts = [];

for(let headCur of document.querySelectorAll('[class^="mw-heading"')) {	let bNewHeadLevel = false; let iOldHeadCurLevel = aiHeadCnts.length; let iLevelOfCurHead = parseInt((Array.from(headCur.classList).slice(-1)[0]).replace(/mw-heading/i, '')) - 1; if(iLevelOfCurHead < iOldHeadCurLevel) aiHeadCnts = aiHeadCnts.slice(0, iLevelOfCurHead); else if(iLevelOfCurHead > iOldHeadCurLevel) {		aiHeadCnts = aiHeadCnts.concat(new Array(iLevelOfCurHead - iOldHeadCurLevel).fill(1)); bNewHeadLevel = true; }	if(!bNewHeadLevel) aiHeadCnts[iLevelOfCurHead - 1]++; let spanCurLabel = headCur.querySelector('.header-label'); if(spanCurLabel == null) {		spanCurLabel = document.createElement("span"); spanCurLabel.className = "header-label"; headCur.prepend(spanCurLabel); }	spanCurLabel.innerText = aiHeadCnts.join('.') }