User:TDS/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.
//Edit counter
 
//Interiot's javascript edit counter
if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) {
  document.write('<script type="text/javascript" src="' 
    + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' 
    + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); }
 
// 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>');
 
// [[User:Lupin/popups.js]]
 
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); 
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://en.wikipedia.org/wiki/User:Interiot/Tool2/code.js?username='+ myEscapedUName;
  addToToolbox('Count user edits', myURLString, 'Count edits by ' + myClearUName, 't-ucount');
 
  if (myTrigger.search(/\d+\.\d+\.\d+\./) > 0) { // 3 dots = assume IP adress
    myIPString = 'http://www.dnsstuff.com/tools/whois.ch?ip='+myClearUName+'&cache=off';
    addToToolbox('IP lookup', myIPString, 'Look up ' + myClearUName, 't-ulook');
 
  }
}
 
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 = "{{Canada-poligeo-stub}} => {{XXCanada-constituency-stub}} as per [[WP:SFD]]";
document.getElementsByName("wpMinoredit")[0].checked = "checked";
oldArticleText = document.getElementsByName("wpTextbox1")[0].value;
newArticleText = oldArticleText.replace(/\{\{[C|c]anada-poligeo-stub\}\}/, "{{XXCanada-constituency-stub}}");
document.getElementsByName("wpTextbox1")[0].value = newArticleText;
 
document.editform.submit();
 
}
 
function addStubConvLink() {
  addToToolbox('Canada poligeo convert', 'javascript:StubConvert();', 'Canada poligeo 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 changeLinks2Edit() { // Changes all internal links to ?action=edit
   for(
           var i=0; 
           thisLink = document.getElementsByTagName("a")[i]; 
           i++
       ) {
         newURL = thisLink.getAttribute('href')+"?action=edit&GWautosave=true";
         thisLink.setAttribute('href', newURL);
    }
}
 
function addChangeLinksLink() {
  addToToolbox('Autosave links', 'javascript:changeLinks2Edit();', 'Autosave links', 't-LinkConv');
}
 
function autosaveOnLoad() {
  if (window.location.search.indexOf("&GWautosave=true") > -1 && document.editform) document.editform.submit();
  // if (window.location.search.indexOf("&GWautosave=true") > -1 && document.editform) StubConvert();
}
 
 
 
function ArticleSkeletonPreload() {
 
 if (document.getElementById("wpTextbox1") && document.getElementById("newarticletext") && document.getElementById("ca-nstab-main") && !noarticleskeleton) {
    document.getElementById("wpTextbox1").value=
     "A '''pagetitle''' is ... (say what the article is about, with a bit of introductory detail)\n"
    +"\n"
    +"==More detail==\n"
    +"\n"
    +"(If there's more to say about it, put in sections with == == on the name of each section)\n"
    +"\n"
    +"==See also==\n"
    +"\n"
    +"==References==\n"
    +"*List the sources you used in writing this article)\n"
    +"*\n"
    +"*\n"
    +"\n"
    +"==External links==\n"
    +"* (List the few most relevant external web pages on the subject (home pages, etc) that you know of))\n"
    +"\n"
    +"[[Category:Newly created pages]]";
  }
}
noarticleskeleton = false;
 
// On page load, do the following
 
addLoadEvent(ArticleSkeletonPreload); 
 
addOnloadHook(addChangeLinksLink); 
addOnloadHook(autosaveOnLoad);
addOnloadHook(addPurgeLink);
addOnloadHook(addEditCountLink);
addOnloadHook(addCrossWPSearchLink);
//addOnloadHook(addStubConvLink);