Jump to content

User:Creidieki/monobook.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function openAdahLinks(kk)
{
  var as = document.getElementsByTagName('a');
  var k = 0;
  for (n=0; n<as.length; n++) {
    if (as[n].innerHTML == 'diff') {
      if (k <= kk) {
        window.open(as[n].href, '_blank');
      }
      k++;
    }
  }
}

function addAdahLinks() 
{
  if (mw.config.get('wgCanonicalNamespace') == 'Special' && mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist') {
    var as = document.getElementsByTagName('a');
    var k = 0;
    for (n=0; n<as.length; n++) {
      if (as[n].innerHTML == 'diff') {
        var tn = document.createTextNode(') (');
        var link = document.createElement('a');
        link.href = 'javascript:openAdahLinks(' + (k++) + ')';
        link.appendChild(document.createTextNode('adah'), null);
        as[n].parentNode.insertBefore(tn , as[n].nextSibling.nextSibling);
        as[n].parentNode.insertBefore(link , as[n].nextSibling.nextSibling);
      }
    }
  }
}

addOnloadHook(addAdahLinks);


function externISBN() {

  var magicURL = "http://www.amazon.com/exec/obidos/ASIN/MAGICNUMBER/wikipedia08-20";
 
  var magicRegex = /MAGICNUMBER/ig;
  if(mw.config.get('wgPageName') != "Special:Booksources" && mw.config.get('wgPageName') != "Wikipedia:Book_sources"){
    for (var i = 0; i < document.links.length; i++) 
    {       
        if( document.links[i].href.match(/isbn=(.*)/) ) {
          document.links[i].href=magicURL.replace(magicRegex, RegExp.$1);
        }
    }
  }
}

addOnloadHook(externISBN);



// adds a 'logs for this page' link to the navigation bar
// if the page is a user's page, talk page or subpage, the link will go to logs for the user instead
// if the page is a special page, then no link is displayed

addOnloadHook(function () {
 
 // if this is a user, show the logs for the user rather than the page
 if ( mw.config.get('wgCanonicalNamespace') == "User" || mw.config.get('wgCanonicalNamespace') == "User_talk" ) {
  url = mw.config.get('wgServer') + "/w/index.php?title=Special:Log&user=" + mw.config.get('wgTitle').split("/")[0];
 } else if ( mw.config.get('wgCanonicalNamespace') == "Special" ) {
  // don't display link for special pages
  return;
 } else {
  url = mw.config.get('wgServer') + "/w/index.php?title=Special:Log&page=" + mw.config.get('wgPageName');
 }
 mw.util.addPortletLink("p-tb", url, "Logs", "pt-logs");

});

//




// adds a 'random redirect' link to the toolbox

addOnloadHook(function () {
  url = mw.config.get('wgServer') + "/w/index.php?title=Special:RandomRedirect";
 mw.util.addPortletLink("p-tb", url, "Random Redirect", "pt-randredirect");
});



// Adds a tab with redirect help to redirect pages.
addOnloadHook(function () {
 
 if (document.getElementById('contentSub').innerHTML == "Redirect page")
     {
     url = mw.config.get('wgServer') + "/w/index.php?title=Category:Redirect_templates";
 
     mw.util.addPortletLink("p-cactions", url, "Redirects", "pc-redirect");
     }

});

//



// Adds a tab with user talk templates to user talk pages.
addOnloadHook(function () {
 
if ( mw.config.get('wgCanonicalNamespace') == "User_talk" ) 
     {
     url = mw.config.get('wgServer') + "/w/index.php?title=Wikipedia:Template messages/User talk namespace";
 
     mw.util.addPortletLink("p-cactions", url, "Messages", "messages");
     }

});

//