Jump to content

User:Codehydro/Headless TOC/auto-open

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Codehydro (talk | contribs) at 20:56, 23 April 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

window.onload = (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 = "$('#" + tocheads[n].childNodes[1].id + "')") + "[0].innerText=='show')" + s + ".trigger('click')");
       if (tocnames[i].parentNode.href == window.location.href) h = i;
   }
   window.setTimeout($(tocnames[h]).trigger("click"), 999);

})()