User:Ta bu shi da yu/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// Veropedia script
importScript('User:^demon/vero.js');
 
// Script from [[User:Lupin/editcount.js]]
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/editcount.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
popupEditCounterTool='custom';
popupEditCounterUrl='http://en.wikipedia.org/wiki/User:$1?ectarget=$1';
 
// Script from [[User:Lupin/recent2.js]]
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/recent2.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
/* Lupo's tool */
 
function makerawlink (name, url) 
{
  /* Creates a link pointing to "url", displaying "name" */
  var link = document.createElement('a');
  link.setAttribute('href', url);  
  link.appendChild(document.createTextNode(name));
  return link;
}
 
function getElementsByClassName (class_name)
{
  /* Returns an array of all elements having the class "class_name". This simplified version
     works only for single classes. If the length of the returned array is zero, no such
     elements were found. */
  var all_obj;
  var result=new Array();
  var j = 0;
 
  if (document.all)   /* For IE */
     all_obj=document.all;
  else if (document.getElementsByTagName && !document.all) /* For Mozilla/Firefox */
     all_obj=document.getElementsByTagName ("*");
  for (i = 0; i < all_obj.length; i++)
  {
    if (all_obj[i].className == class_name)
    {
      result[j] = all_obj[i]; j++;
    }
  }
  return result;
} 
 
function addLeadSectionTab () {
  /* Only add new tab if the page is editable and has section editing links. */
  if (getElementsByClassName('editsection').length > 0) {
    var edit_tab = document.getElementById ('ca-edit');
    if (edit_tab != null) {
      var href_for_lead = edit_tab.firstChild.getAttribute ('href') + "&section=0";
      var first_title   = getElementsByClassName ('firstHeading');
      if (first_title.length > 0) {
        /* We have a "firstHeading": put "[edit]" to its right */
        var edit_div = document.createElement ('div');
        edit_div.setAttribute ('class', 'editsection');
        edit_div.setAttribute ('style', 'float:right;margin-left:5px;');
        edit_div.appendChild (document.createTextNode ('['));
        edit_div.appendChild (makerawlink ("edit", href_for_lead));
        edit_div.appendChild (document.createTextNode (']'));
        first_title[0].parentNode.insertBefore (edit_div, first_title[0]);
      } else {
        /* No first title found: create a tab */                                   
        var new_tab = document.createElement ('li');
        new_tab.id = 'ca-editlead';
        var link = makerawlink ("Edit lead", href_for_lead);
        new_tab.appendChild (link);
 
        edit_tab.parentNode.appendChild (new_tab);
      }
    }
  }
}
 
function myCustomizations ()
{
  addLeadSectionTab ();
  /* Add future customizations here... */
}
 
if (window.addEventListener) window.addEventListener("load",myCustomizations,false);
else if (window.attachEvent) window.attachEvent("onload",myCustomizations)