User:Tom Morris/sectnums.js

function addSectionNumbers { var count = -1; var elems = document.getElementsByTagName("h2"); for (i = 0; i < elems.length; i++) { count++; var heading = elems[i]; if (heading.children[1]) { heading.children[1].firstChild.nodeValue = count.toString + " " + heading.children[1].firstChild.nodeValue; }   } }

addOnloadHook(function {  if(wgAction == 'edit' || (wgAction == 'submit' && document.getElementById('wikiDiff')) ){    addPortletLink('p-tb', 'javascript:alert("You need to preview the text for the prose size script to work in edit mode.")', 'Add sect nums', 't-sect-nums', 'Add section numbers', , );    document.getElementById("t-sect-nums").firstChild.style.cssText = "color:black;"  }  else if(wgAction == 'view' || wgAction == 'submit' || wgAction == 'historysubmit' || wgAction == 'purge'){    addPortletLink('p-tb', 'javascript:addSectionNumbers', 'Add sect nums', 't-sect-nums', 'Add section numbers', , );  } });