User:Pasixxxx/monobook.js

From Wikimedia Incubator

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
 //Inserts links to toc if conditions are met [[:incubator:user:Pasixxxx]]
   
 function MyHtmlFrag(doc)
 {
     var sm,txt,a;

     this.ce=doc.createElement("center");
     sm=doc.createElement("small");
     a=doc.createElement("a");
     a.setAttribute("href","#toc");
     txt=doc.createTextNode("SisLuet");
 

     /*this.ce.appendChild(sm); 
     sm.appendChild(a);
     a.appendChild(txt);*/

     this.ce.appendChild(a); 
     a.appendChild(txt);
 
     return this.ce
 }
 
 function insertLinks(tg,doc)
 {
      var el,coll;
      var i;
 
      coll=doc.getElementsByTagName(tg);
        
      for(i=0;i<coll.length;i++)
      {
          el=coll.item(i);
        
          if(el.parentNode.tagName.toLowerCase()!="div") continue;
          if(el.parentNode.id!="bodyContent") continue; 
          if(el.id=="siteSub") continue;
 
          el.parentNode.insertBefore(new MyHtmlFrag(doc),el.nextSibling);
          //el.parentNode.insertBefore(new MyHtmlFrag(doc),el);
      }
 }
 
 function insertLinksToTOC()
 {
     var doc=window.document;
 
     if(doc.getElementById("toc")==undefined) return;           
 
     insertLinks("h2",doc);
     insertLinks("h3",doc);
     insertLinks("h4",doc);
 }
 
 addOnloadHook(insertLinksToTOC);