User:Salix alba/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.
// [[User:Lupin/popups.js]]
 
importScript('User:Lupin/popups.js');
 
popupFixRedirs = true;
popupRedlinkRemoval = true;
popupFixDabs = true;
popupOnEditSelection = false;
 
// This will add an [edit top] link at the top of all pages except preview pages
// by User:Pile0nades
 
 
// Add an [edit top] link to pages
addOnloadHook(function () {
  // if this is preview page or generated page, stop
  if(document.getElementById("wikiPreview") || window.location.href.indexOf("/wiki/Special:") != -1) return;
 
  // get the page title
  var pageTitle = document.title.split(" - ")[0].replace(" ", "_"); 
 
  // create div and set innerHTML to link
  var divContainer = document.createElement("div");
  divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-right:15px;margin-top:3px;">[<a href="/w/index.php?title='+pageTitle+'&action=edit&section=0" title="'+document.title.split(" - ")[0]+'">edit top</a>]</div>';
 
  // insert divContainer into the DOM before the h1
  if(window.location.href.indexOf("&action=edit") == -1)
    document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
 
  if(window.location.href.indexOf("&action=edit&section=0") != -1)
    document.getElementById("wpSummary").value = "/* Intro */ ";
});
 
addOnloadHook(function () {
    var searchGoButton = document.getElementById('searchGoButton');
    if (!searchGoButton) return;
 
    var searchNsHidden = document.createElement('input');
    searchNsHidden.id = 'searchNsHidden';
    searchNsHidden.type = 'hidden';
    searchNsHidden.name = 'ns0';
    searchNsHidden.value = '1';
 
    var searchNsMenu = document.createElement('select');
    searchNsMenu.id = 'searchNsMenu';
    searchNsMenu.name = 'ns';
    searchNsMenu.innerHTML =
        '<option value="0">(Main)</option>\n' +
        '<option value="1">Talk</option>\n' +
        '<option value="2">User</option>\n' +
        '<option value="3">User talk</option>\n' +
        '<option value="4">Wikipedia</option>\n' +
        '<option value="5">Wikipedia talk</option>\n' +
        '<option value="6">Image</option>\n' +
        '<option value="7">Image talk</option>\n' +
        '<option value="8">MediaWiki</option>\n' +
        '<option value="9">MediaWiki talk</option>\n' +
        '<option value="10">Template</option>\n' +
        '<option value="11">Template talk</option>\n' +
        '<option value="12">Help</option>\n' +
        '<option value="13">Help talk</option>\n' +
        '<option value="14">Category</option>\n' +
        '<option value="15">Category talk</option>\n' +
        '<option value="100">Portal</option>\n' +
        '<option value="101">Portal talk</option>\n' ;
    searchNsMenu.onchange = function () {
        searchNsHidden.name = 'ns' + (this.selectedIndex < 0 ? '0' : this.options[this.selectedIndex].value);
    };
 
    // From /skins-1.5/monobook/main.css?5:
    searchNsMenu.style.width = '10.9em';
    searchNsMenu.style.margin = '0';
    searchNsMenu.style.fontSize = '95%';
 
    searchGoButton.parentNode.insertBefore(searchNsHidden, searchGoButton);
    searchGoButton.parentNode.insertBefore(searchNsMenu, searchGoButton);
});
 
addOnloadHook(function () {
    var searchform = document.getElementById('searchform');
    if (!searchform) return;
    searchform.setAttribute('target','_blank');
});
 
addOnloadHook(function () {
    addPortletLink ('p-tb', '/wiki/Help:Formula', 'Help:Formula');
    addPortletLink ('p-tb', '/wiki/Wikipedia:Template messages','List of available templates');
    addPortletLink ('p-tb', '/wiki/Wikipedia talk:WikiProject Mathematics','WT:WPM');
    addPortletLink ('p-tb', 'http://zeteo.info/','Zetro');
    addPortletLink ('p-tb', '/wiki/Template:Citation','Citation template');
    addPortletLink ('p-tb', '/wiki/Category:Mathematics referencing resources','Maths refs');
});