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 addPurgeLink() { // Adds a "Purge page" link to the toolbox

  // remove "action" variable from the URL and insert new one

  myURL = window.location;
  var myGetVars = myURL.search.substring(1,myURL.search.length).split("&");
  var myCleanGetVars = Array(); 
  for (i=0;i<myGetVars.length;++i) {
    if (myGetVars[i] && myGetVars[i].substr(0,6) != "action") {
      myCleanGetVars.push(myGetVars[i]);
    }
  }
  myCleanGetVars.push("action=purge");
  var myNewGetVars = "?" + myCleanGetVars.join("&");
  myURLString = myURL.protocol + "//" + myURL.hostname + myURL.pathname + myNewGetVars + myURL.hash;

  addToToolbox('Purge page', myURLString, 'Purge this page', 't-purge');
}

function addEditCountLink() { // Add "Count User edits" link to toolbox
  if (window.location.pathname.indexOf('index.php') > 0) { // GET mode
    myTrigger = window.location.search;
  } else { // Path mode
    myTrigger = window.location.pathname;
  }
  if (myTrigger.indexOf('User:') > 0) { // We're in User space
    myUName = extractUName('User:', myTrigger);
  } else if (myTrigger.indexOf('User_talk:') > 0) { // We're in User_talk space 
    myUName = extractUName('User_talk:', myTrigger);
  } else if (myTrigger.indexOf('Special:Contributions') > 0) { // We're viewing contributions
    myUName = extractUName('Special:Contributions/', myTrigger); 
  } else { // Bail out
    return false;
  }
  myEscapedUName = myUName.replace(/_/, "+");
  myClearUName = myUName.replace(/_/, " ");
  myURLString = 'http://kohl.wikimedia.org/~kate/cgi-bin/count_edits.cgi?user='+ myEscapedUName +'&dbname=enwiki';
  addToToolbox('Count user edits', myURLString, 'Count edits by ' + myClearUName, 't-ucount');
  myBlockString = 'http://en.wikipedia.org/w/index.php?title=Special:Blockip&ip='+myClearUName;
  addToToolbox('Block user', myBlockString, 'Block ' + myClearUName, 't-ublock');
}

function addCrossWPSearchLink() { // Search article in other WPs link to toolbox
  if (window.location.pathname.indexOf('index.php') > 0) { // GET mode
    myTrigger = window.location.search;
  } else { // Path mode
    myTrigger = window.location.pathname;
  }
  if (
myTrigger.indexOf('User:') < 0 && 
myTrigger.indexOf('User_talk:') < 0 && 
myTrigger.indexOf('Wikipedia:') < 0 && 
myTrigger.indexOf('Wikipedia_talk:') < 0 && 
myTrigger.indexOf('Category:') < 0 && 
myTrigger.indexOf('Category_talk:') < 0 && 
myTrigger.indexOf('Template:') < 0 && 
myTrigger.indexOf('Template_talk:') < 0 && 
myTrigger.indexOf('Image:') < 0 && 
myTrigger.indexOf('Image_talk:') < 0 && 
myTrigger.indexOf('Help:') < 0 && 
myTrigger.indexOf('Help_talk:') < 0 && 
myTrigger.indexOf('MediaWiki:') < 0 &&
myTrigger.indexOf('Special:') < 0 &&
myTrigger.indexOf('MediaWiki_talk:') < 0 ) { // We're in Article space
    myArticleName = extractUName('/wiki/', myTrigger);
  } else if (myTrigger.indexOf('Talk:') > 0) { // We're in Talk space 
    myArticleName = extractUName('Talk:', myTrigger);
  } else { // Bail out
    return false;
  }

  myURLString = 'http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=30&minor=1&search='+ myArticleName;

  addToToolbox('Other Wikipedias', myURLString, 'Look up ' + myArticleName + 'in other language Wikipedias', 't-uotherwp');
}

function StubConvert() {

document.getElementsByName("wpSummary")[0].value = "{" + "{Egypt-stub}} => {" + "{Ancient-Egypt-stub}} as per [[WP:SFD]]";
document.getElementsByName("wpMinoredit")[0].checked = "checked";
oldArticleText = document.getElementsByName("wpTextbox1")[0].value;
newArticleText = oldArticleText.replace(/\{\{[E|e]gypt-stub\}\}/, "{" + "{Ancient-Egypt-stub}}");
document.getElementsByName("wpTextbox1")[0].value = newArticleText;

document.editform.submit();

}

function addStubConvLink() {
  addToToolbox('Ancient Egypt convert', 'javascript:StubConvert();', 'Ancient Egypt convert', 't-AEConv');
}

function extractUName(namespace, myString) {
  myCleanedString = myString.substring(myString.indexOf(namespace) + namespace.length,myString.length);
  if (myCleanedString.indexOf('/') > 0) {
    mySliceEnd = myCleanedString.indexOf('/');
  } else {
    mySliceEnd = myCleanedString.length;
  }
  myCleanerString = myCleanedString.substring(0,mySliceEnd);
  return myCleanerString;
}

function addToToolbox(label, link, title, id) { // Create new child node of the toolbox object

  var myLinktext = document.createTextNode(label);
  var myLink = document.createElement("a");
  myLink.href = link;
  myLink.title = title;
  myLink.appendChild(myLinktext);
  var myListItem = document.createElement("li");
  myListItem.id = id;
  myListItem.appendChild(myLink);
  document.getElementById('p-tb').getElementsByTagName("ul")[0].appendChild(myListItem);

}

function reformatMyPage() { // execute all formatting functions...
  addPurgeLink();
  addEditCountLink();
  addCrossWPSearchLink();
//  addStubConvLink();
}

// when the page is loaded

if (window.addEventListener) window.addEventListener("load",reformatMyPage,false);
else if (window.attachEvent) window.attachEvent("onload",reformatMyPage);