User:I80and/monobook.js

/* AddLink Helper Function */ importScript('User:AzaToth/morebits.js'); importScript('User:AzaToth/twinklewarn.js'); importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css'); importScript('User:AzaToth/twinkle.js');

//A helper function to add a button to one of the toolbars in the interface. //An improved(I hope) version of addlilink. //JesseW, the juggling janitor 05:33, 8 November *2005 (UTC)

function addLink(where, url, name, id, title, key, after){ //* where is the id of the toolbar where the button should be added; //  i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb". //   //* url is the URL which will be called when the button is clicked. //  javascript: urls can be used to do more complex things. //   //* name is what will appear as the name of the button. //   //* id is the id of the button; it's best to define one. //  Use a prefix to make sure its unique. Optional. //   //* title is the tooltip title that gives a longer description //  of the button; if you define a accesskey, mention it here. Optional. //   //* key is the char you want for the accesskey. Optional. //   //* after is the id of the button you want to follow this one. Optional. //   var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; if(after) { tabs.insertBefore(li,document.getElementById(after)); } else { tabs.appendChild(li); }   if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title];} }   // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

/* Add LI Link Helper Function */

function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {       if(key && title) {           ta[id] = [key, title]; }       else if(key) {           ta[id] = [key, '']; }       else if(title) {           ta[id] = ['', title]; }   }    // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

/* AddTab Helper Function */

function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key) };

/* Formatter Script */

function format { var txt = document.editform.wpTextbox1; txt.value = catFixer(txt.value); txt.value = entities(txt.value); txt.value = fixheadings(txt.value); txt.value = fixsyntax(txt.value); txt.value = linkfixer(txt.value, false); //txt.value = imagefixer(txt.value); txt.value = whitespace(txt.value); txt.value = linksimplifyer(txt.value); txt.value = trim(txt.value); }

function whitespace(str){ str = str.replace(/\t/g, " ");

str = str.replace(/^ ? ? \n/gm, "\n"); str = str.replace(/(\n\n)\n+/g, "$1"); str = str.replace(/== ? ?\n\n==/g, "==\n=="); str = str.replace(/\n\n(\* ?\[?http)/g, "\n$1");

str = str.replace(/^ ? ? \n/gm, "\n"); str = str.replace(/\n\n\*/g, "\n*"); str = str.replace(/[ \t][ \t]+/g, " "); str = str.replace(/([=\n]\n)\n+/g, "$1"); str = str.replace(/ \n/g, "\n");

//* bullet points str = str.replace(/^([\*#]+) /gm, "$1"); str = str.replace(/^([\*#]+)/gm, "$1 ");

//==Headings== str = str.replace(/^(={1,4}) ?(.*?) ?(={1,4})$/gm, "$1$2$3");

//dash — spacing str = str.replace(/ ?(–|–|–|–|–) ?/g, "$1"); str = str.replace(/ ?(—|—|—|—|—) ?/g, "$1"); str = str.replace(/(—|—|—|—|—|–|–|–|–|–)/g, " $1 ");

return trim(str); }

function entities(str){ //str = str.replace(//g, ""); str = str.replace(/–|–|–/g, "–"); str = str.replace(/—|—|—/g, "—"); // str = str.replace(/(cm| m|km|mi)2/g, "$1²"); str = str.replace(/²/g, "²"); str = str.replace(/°/g, "°");

return trim(str); }

//Fix ==See also== and similar section common errors. function fixheadings(str) { if( !str.match(/= ?See also ?=/) ) str = str.replace(/(== ?)(see also:?|related topics:?|related articles:?|internal links:?|also see:?)( ?==)/gi, "$1See also$3");

str = str.replace(/(== ?)(external links:?|outside links|web ?links:?|exterior links:?)( ?==)/gi, "$1External links$3"); str = str.replace(/(== ?)(external link:?|web ?link:?|exterior link:?)( ?==)/gi, "$1External link$3"); str = str.replace(/(== ?)(reference:?)(s? ?==)/gi, "$1Reference$3"); str = str.replace(/(== ?)(source:?)(s? ?==)/gi, "$1Source$3"); str = str.replace(/(== ?)(further readings?:?)( ?==)/gi, "$1Further reading$3");

return str; }

function catFixer(str){ str = str.replace(/\[\[ ?[Cc]ategory ?: ?/g, "[[Category:");

return trim(str); }

//fixes many common syntax problems function fixsyntax(str) { //replace html with wiki syntax if( !str.match(/'<\/?[ib]>|<\/?[ib]>'/gi) ) {   str = str.replace(/(.*?)<\/i>/gi, "$1"); str = str.replace(/(.*?)<\/b>/gi, "$1"); } str = str.replace(//gi, " "); return trim(str); }

//formats links in standard fashion function linkfixer(str, checkImages) {  str = str.replace(/\]\[/g, "] ["); var m = str.match(/\[?\^\*?\]\]?/g); if (m) {   for (var i = 0; i < m.length; i++) {     var x = m[i].toString; var y = x;

//internal links only if ( !y.match(/^\[?\[http:\/\//i) && !y.match(/^\[?\[image:/i) ) {       if (y.indexOf(":") == -1 && y.substr(0,3) != "_") == -1)        {          if (y.indexOf("|") == -1)            y = y.replace(/_/g, " ");          else            y = y.replace( y.substr(0, y.indexOf("|")), y.substr(0, y.indexOf("|")).replace(/_/g, " "));        }          y = y.replace(/ ?\| ?/, "|").replace("|", "| ]]"); }

str = str.replace(x, y); } }

//repair bad internal links str = str.replace(/([^\[]|^)\[?\[([^\]]*?)\]\]?([^\]]|$)/gm, "$1$2$3"); str = str.replace(/\[\[ ?([^\]]*?) ?\]\]/g, "$1"); str = str.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "$1");

//repair bad external links str = str.replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]"); str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]");

return trim(str); }

//fixes images function imagefixer(str) {

//remove external images str = str.replace(/\\]?/gi, "[http://$1]");

//fix links within internal images var m = str.match(/\[?\[image:[^\[\]]*?(\[?\^\*?\]*?[^\[\]]*?)*?\]+/gi); if (m) {   for (var i = 0; i < m.length; i++) {     var x = m[i].toString; var y = x;

y = y.replace(/^\[\[i/i, "I").replace(/\]\]$/, ""); y = y.replace(/(\^\*?)$/, "$1]"); y = linkfixer(y, true); y = "" + y + "";

str = str.replace(x, y); } }

return trim(str); }

//simplifies some links e.g. dog to dog and dogs to dogs function linksimplifyer(str){ var m = str.match(/\[\[([^[]*?)\|([^[]*?)\]\]/g); if (m) {   for (var i = 0; i < m.length; i++) {     var n_arr = m[i].toString.match(/\[\[([^[]*?)\|([^[]*?)\]\]/); var n = n_arr[0]; var a = n_arr[1]; var b = n_arr[2];

if (b.indexOf(a) == 0 || b.indexOf(TurnFirstToLower(a)) == 0) {       var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w]*?)\]\]/i, "$2$3"); str = str.replace(n, k); }   }  }

str = str.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "$2$3$4");

return str; }

//trim start and end, trim spaces from the end of lines function trim(str) { str = str.replace(/ $/gm, ""); return str.replace(/^\s*|\s*$/g, ""); }

//turns first character to lowercase function TurnFirstToLower(input) { if (input != "") {   var input = trim(input); var temp = input.substr(0, 1); return temp.toLowerCase + input.substr(1, input.length); } else return ""; }

//entities that should never be unicoded function noUnicodify(str) { str = str.replace(" & ", " & "); str = str.replace("&", "&amp;").replace("&lt;", "&amp;lt;").replace("&gt;", "&amp;gt;").replace("&quot;", "&amp;quot;").replace("&apos;", "&amp;apos;"); str = str.replace("−", "&minus;").replace("×", "&times;");

str = str.replace(" ", " ").replace(" ", "&thinsp;").replace("­", "&shy;"); str = str.replace("′", "&prime;"); str = str.replace(/&(#0?9[13];)/, "&$1"); str = str.replace(/&(#0?12[345];)/, "&$1");

return str; }

addOnloadHook(function {  if(document.forms.editform) {    addLink('p-cactions', 'javascript:format', 'format', 'ca-format', 'Format article', '', 'ca-history');  } });

/* Popup Navigation Script */

// User:Lupin/popups.js

mw.loader.load(            'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'             + '&action=raw&ctype=text/javascript&dontcountme=s'); /* Begin Configuration for Popup Navigation Script */ popupStructure='menus'; popupShortcutKeys=true; popupRedlinkRemoval=true; popupEditCounterTool='custom'; popupEditCounterUrl='http://tools.wikimedia.de/~interiot/cgi-bin/Tool1/wannabe_kate?username=$1&site=en.wikipedia.org'; popupRevertSummaryPrompt=true; popupQueriedRevertSummary="Revert to revision $1 dated $2 by $3 using popups"; popupQueriedRevertToPreviousSummary="Revert to the revision prior to revision $1 dated $2 by $3 using popups"; popupRedlinkSummary="Removed unnecessary redlink (%s)"; popupLazyDownloads=false; popupLazyPreviews=false; /* End configuration for Popup Navigation Script */

/* AutoLink Script */ /* // Autolink wikilinks and {templates} (especially useful for monobook.js and similar pages)

addOnloadHook(function {    // Get the HTML of just the main body of the page, not including textareas hopefully    if (document.title.indexOf("Editing ") != 0 && document.title.indexOf("Template:") != 0) {        targetdiv = document.getElementById('bodyContent');  // bodyContent div for most pages    } else     if (document.getElementById('wikiPreview')) {        targetdiv = document.getElementById('wikiPreview');  // wikiPreview if it's there    } else    if (document.getElementById('wikiDiff')) {        targetdiv = document.getElementById('wikiDiff');   // wikiDiff if it's there    } else {        return;    }    content = targetdiv.innerHTML;    content = content.replace(/([^\[])\[{2}([^\[\]\|\<\>\n]*)([^\[\]\<\>\n]*?)?\]{2}([^\]])/g, '$1$2$3$4'); // Make wikilink code into links    content = content.replace(/([^\{])\{{2}(subst\:|msg\:)?([^\{\}\|\<\>\n]*)([^\{\}\<\>\n]*?)?\}{2}([^\}])/g, '$1\{\{$2$3$4\}\}$5'); // Make template code into links targetdiv.innerHTML = content; // Write it back }); /* Changes since I last edited Script */

//From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510 function addSinceTab { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) { do_since_I_last_edited }   else if (!/wiki\/Special:|w\/index.php?title=Special:/.test(window.location.href)) { var thetitle=document.title.slice(0, String(document.title).indexOf(" - ")); var l=addlilink(tabs, "/w/index.php?title="+thetitle+"&action=history&gotosince=true", 'Changes since I last edited', ''); l.lastChild.title="Changes since I last edited"; } } function do_since_I_last_edited { var csub=document.getElementById("contentSub"); var msg=document.createElement("p"); msg.appendChild(document.createTextNode                       ("Parsing history... please wait...")); msg.className="error"; csub.insertBefore(msg, csub.firstChild)

var username=document.getElementById("pt-userpage").textContent; var hists=document.getElementById("pagehistory").getElementsByTagName('li'); for (n=0;n<hists.length;n++) { if (hists[n].getElementsByTagName("span")[0].getElementsByTagName('a')[0].textContent==username) { document.location=hists[n].childNodes[1].href; return; }       }

msg.replaceChild(document.createTextNode                        ("You have not edited this page! (recently)"),                         msg.firstChild); }

addOnloadHook(addSinceTab);

/* Add Purge Tab Script */

// addPurge addOnloadHook( function {   var x = document.getElementById('ca-history');    if(!x) return;    if(x.children) x = x.children[0].href;    else x = x.childNodes[0].href;    addLink("p-cactions", x.replace(/=history/, "=purge"), 'Purge', 'ca-purge', 'Purge the internal cache for this page', 0); });

/* Zocky's Picture Popups Script */

// User:Zocky/PicturePopups.js document.write(' ');

/* Zocky's Search Box Script */

// User:Zocky/SearchBox.js document.write(' ');

/* Add Intro Edit Link Script */

// This will add an [edit] link at the top of all pages except preview pages and the main page // by User:Pile0nades

// Add an [edit] 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;

// if this is a revision history, stop if(document.getElementById("histlegend‎") || window.location.href.indexOf("/wiki/Special:") != -1) return;

// if this is a diff page, stop if(document.getElementById("difference‎") || window.location.href.indexOf("/wiki/Special:") != -1) return;

// if this is a watchlist, stop if(document.getElementById("watchdetails") || window.location.href.indexOf("/wiki/Special:") != -1) return;

// if this is the main page, stop if(document.getElementById("mainpage") || 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 = ' [edit] ';

// insert divContainer into the DOM below 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 */ "; });

/* Navigation Shortcuts included for future; it's commented out */

/*

// User:Jsimlo/shortcuts.js document.write(' '); function shortcutsInit { shortcutsAddLink ('Navigation shortcuts', 'Wikipedia:Tools/Navigation shortcuts'); }