User:Codehydro/Headless TOC.js

window.onload = setTimeout(function {    for (i = 0, tocnames = document.getElementsByClassName("toctext"), tocheads = document.getElementsByClassName("collapseButton"); i < tocnames.length; i++) {        for (n = 0; n < tocheads.length; n++) if (tocheads[n].parentNode.getElementsByClassName("mw-headline").length && tocnames[i].innerHTML.trim == tocheads[n].parentNode.getElementsByClassName("mw-headline")[0].textContent.trim) tocnames[i].parentNode.setAttribute("onclick", "if(" + (s = "document.getElementById('" + tocheads[n].childNodes[1].id + "')") + ".textContent=='show')" + s + ".click;");        if (tocnames[i].parentNode.href == window.location.href) h = i;    }	window.setTimeout('tocnames[h].click', 99); }, 99);