User:Adambiswanger1/monobook.js

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"); return trim(str); } function entities(str){ //str = str.replace(//g, ""); str = str.replace(/&#150;|&#8211;|&#x2013;/g, "–"); str = str.replace(/&#151;|&#8212;|&#x2014;/g, "&mdash;"); // str = str.replace(/(cm| m|km|mi)2/g, "$1²"); str = str.replace(/&sup2;/g, "²"); str = str.replace(/&deg;/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(/(== ?)(references?:?)( ?==)/gi, "$1References$3"); str = str.replace(/(== ?)(sources?:?)( ?==)/gi, "$1Sources$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, " ");  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(/\[\[ ?([^\]]*?) ?\]\]/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(/\");     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(" &amp; ", " & "); str = str.replace("&amp;", "&amp;amp;").replace("&amp;lt;", "&amp;amp;lt;").replace("&amp;gt;", "&amp;amp;gt;").replace("&amp;quot;", "&amp;amp;quot;").replace("&amp;apos;", "&amp;amp;apos;"); str = str.replace("&minus;", "&amp;minus;").replace("&times;", "&amp;times;"); str = str.replace(" ", "&amp;nbsp;").replace("&thinsp;", "&amp;thinsp;").replace("&shy;", "&amp;shy;"); str = str.replace("&prime;", "&amp;prime;"); str = str.replace(/&(#0?9[13];)/, "&amp;$1"); str = str.replace(/&(#0?12[345];)/, "&amp;$1"); return str; } $(function {  if(document.forms.editform) {    mw.util.addPortletLink('p-cactions', 'javascript:format', 'format', 'ca-format', 'Format article', '', document.getElementById('ca-edit'));  } });

/**** afd helper ****/ document.write(' ');

/* This is to keep track of who is using this extension: User:Jnothman/afd_helper/script.js */

function highlightmyname(n,p) //node, parent node { while(n!=null) {   if(n.nodeType==3) //text node {     if(n.data.toLowerCase.indexOf(wgUserName.toLowerCase)!=-1) {       var ix=n.data.toLowerCase.indexOf(wgUserName.toLowerCase); var t1=ix?document.createTextNode(n.data.substr(0,ix)):null; var t2=document.createTextNode(n.data.substr(ix,wgUserName.length)); var t3=ix+wgUserName.length==n.data.length?null: document.createTextNode(n.data.substr(ix+wgUserName.length)); var s1=document.createElement("SPAN"); s1.style.backgroundColor="#FF0000"; s1.appendChild(t2); var s2=document.createElement("SPAN"); if(t1!=null) s2.appendChild(t1); s2.appendChild(s1); if(t3!=null) s2.appendChild(t3); p.replaceChild(s2,n); if(t3!=null) highlightmyname(t3,s2); //find remaining occurences in the new nodes n=s2.nextSibling; }     else n=n.nextSibling; }   else {     if(n.firstChild!=null) highlightmyname(n.firstChild,n); n=n.nextSibling; } } } $(function {  if(location.href.indexOf("?ais523")==-1&&location.href.indexOf("&ais523")==-1&& location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&& location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&& location.href.indexOf("&action=raw")==-1&&wgPageName!="Special:Preferences")   highlightmyname(document.getElementById('bodyContent').firstChild, document.getElementById('bodyContent')); });

$(function {  if((location.href.indexOf("Special:Contributions")!=-1||      location.href.indexOf("Special%3AContributions")!=-1) &&location.href.indexOf("&ais523")==-1&&location.href.indexOf("?ais523")==-1) {    var i,li,a;    li=document.getElementById("bodyContent");    //li.getElementsByTagName("ul")[0].tagName="ol";    li=li.getElementsByTagName("li");    i=-1;    a=new Array;    while(++i0)        s="#CCCCFF";      else        s="#FFCCCC";      if(a[t]!=undefined) s=(a[t]=="#CCCCFF"?"#CCFFFF":"#FFFFCC"); else a[t]=s;      li[i].innerHTML=""+li[i].innerHTML+"";    }  } });

$(function{ if(location.href=="http://en.wikipedia.org/w/index.php?title=Special:Listusers&limit=5000&"+ "group=sysop&ais523update=y") {    var h=document.getElementById('bodyContent').innerHTML;    var a=new Array;    h=h.split(/\< *li *\>/i);    var i=0;    while(++i")[1].split("<")[0]]=h[i].split(/\< *\/ *li *\>/i)[0];    }    for(i in a)    {      document.write("adminrights['"+ encodeURIComponent(i).split("\\").join("\\\\").split("'").join("%27") .split("(").join("%28").split(")").join("%29") .split("!").join("%21").split(",").join("%2C") .split("%3A").join(":")+"']=1;");   }  } }); //Highlighting script. Based on User:ais523/highlightmyname.js. function highlightadmins(n,p) //node, parent node { while(n!=null) {   if(n.nodeType==1&&n.tagName.toLowerCase=="a") //anchor {     if(n.href.indexOf("http://en.wikipedia.org/wiki/User:")!=-1) {       var u=n.href.split("http://en.wikipedia.org/wiki/User:")[1]; if(adminrights[u.split("_").join("%20")]==1) {         n.style.backgroundColor="#00FFFF"; if(n.className==null||n.className=="") n.className="ais523_adminrights_admin"; else n.className+="ais523_adminrights_admin"; }       n=n.nextSibling; }     else if(n.href.indexOf("http://en.wikipedia.org/wiki/User_talk:")!=-1) {       var u=n.href.split("http://en.wikipedia.org/wiki/User_talk:")[1]; if(adminrights[u.split("_").join("%20")]==1) {         n.style.backgroundColor="#00FFFF"; if(n.className==null||n.className=="") n.className="ais523_adminrights_admin"; else n.className+=" ais523_adminrights_admin"; }       n=n.nextSibling; }     else {       if(n.firstChild!=null) highlightadmins(n.firstChild,n); n=n.nextSibling; }   }    else {     if(n.firstChild!=null) highlightadmins(n.firstChild,n); n=n.nextSibling; } } } $(function {  if(location.href.indexOf("?ais523")==-1&&location.href.indexOf("&ais523")==-1&& location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&& location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&& wgPageName!="Special:Preferences") {    highlightadmins(document.getElementById('bodyContent').firstChild, document.getElementById('bodyContent')); } });