Jump to content

User:Eloquence/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 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);
        }
    }
  }
}

function global_append_tab(url, name, id)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);  
 
  var txt = document.createTextNode(name);
  na.appendChild(txt);
 
  var li = document.createElement('li');
  if(id) li.id = id;
  li.appendChild(na);

  // Grab the element we want to append the tab and append the tab to it.
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(li);
}

function add_britannica_tab() {
    var title=mw.config.get('wgPageName');
    if(mw.config.get('wgNamespaceNumber')==0) {
      global_append_tab('http://school.eb.com/search?query='+title+'&ct=eb','in britannica','eb-search');
    }
}

$(externISBN);
$(add_britannica_tab);