User:Rich Farmbrough/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.
// See [[{{TALKPAGENAME}}|Talk page]]
if (mw.config.get('wgNamespaceNumber') >= 0)
$(function(){
 var pCactions = document.getElementById('p-cactions');
 if (!pCactions) return;
 var caMain = pCactions.getElementsByTagName('li')[0];
 var caTalk = document.getElementById('ca-talk');
 var caEdit = document.getElementById('ca-edit');
 if (!caEdit) caEdit = document.getElementById('ca-viewsource');
 var caHistory = document.getElementById('ca-history');
 if (!caMain || !caTalk || !caEdit || !caHistory) return;
 var el_move, el_create, id2;
 if (mw.config.get('wgNamespaceNumber') % 2) { //talk space
   el_move = caTalk; el_create = caMain; id2 = '';
 } else {
   el_move = caMain; el_create = caTalk; id2 = 'discussion';
 }
 caEdit.firstChild.innerHTML = 'edit';
 caHistory.firstChild.innerHTML = 'hist';
 el_move.parentNode.insertBefore(caHistory, el_move.nextSibling);
 el_move.parentNode.insertBefore(caEdit, el_move.nextSibling);
 var href = el_create.firstChild.getAttribute('href', 2);
 if (el_create.className.indexOf('new') < 0){
   addPortletLink('p-cactions', href + '?action=history', 'hist',
     'ca-history-'+id2, id2+' history', '', el_create.nextSibling);
   addPortletLink('p-cactions', href + '?action=edit', 'edit',
     'ca-edit-'+id2, 'Edit '+id2, '', el_create.nextSibling);
 } 
  caMain.style.marginRight = '0.3em'; 
  caTalk.style.marginRight = '0.3em'; 
  caTalk.style.marginLeft  = '1.6em'; 
})
//
/* Text character counter - appears in toolbox */
importScript('User:Dr pda/prosesize.js');
/*
==/*De-orphaner==
*//**/
importScript('User:Manishearth/orphantabs.js');
/*
==Suddenly, Tammy!==
*/
importScript('User:Topbanana/RLRL_SR_Utility.js' );
/*
==Ajax  Preview==
*/
importScript("User:Js/ajaxPreview.js");
ajaxPreviewPos = 'bottom';  //Buttons on the bottom, replacing standard buttons.

/*
</nowiki> </pre>
==clever watchlist stuff==
<pre> <nowiki>
*/

$(function (){
  if (mw.config.get('wgCanonicalSpecialPageName') !='Watchlist') return; // Are we (not) on a watchlist?
  //days = document.getElementById('bodyContent').getElementsByTagName('ul');
  days = document.querySelectorAll('ul.special')
  for (d = 0; d < days.length; d++) { //For each day
    day = days[d];
    newday = document.createElement('ul'); //This will replace the old listing
    while ((diffs = day.getElementsByTagName('li')).length > 0) { //Are there any diffs left?
      //Try to extract the namespace
      As = diffs[0].getElementsByTagName('a');
      if (As[0].innerHTML == 'diff')
        pagename = As[2].innerHTML;
      else
        pagename = As[1].innerHTML;
      if (pagename.indexOf(':') == -1)
        namespace = 'Main';
      else
        namespace = pagename.split(':')[0]; //This will fail for articles which contain ":" in name
      hdrs = newday.getElementsByTagName('h5'); //Get the list of namespace headers
      hdr = null;
      for (j=0; j<hdrs.length; j++) //Find the header
        if (hdrs[j].innerHTML==namespace) {
          hdr = hdrs[j]; break;
        }
      if (hdr==null) { //Not found? Make a new one!
        hdr = document.createElement('h5');
        hdr.innerHTML = namespace;
        newday.appendChild(hdr);
        namespacesub = document.createElement('ul');
        newday.appendChild(namespacesub);
      }
      hdr.nextSibling.appendChild(diffs[0]); //Move the diff
    }
    newday.appendChild(document.createElement('hr')); //For readability
    day.parentNode.replaceChild(newday,day);
  }
});
/*
</nowiki> </pre>
==closeafd==
<pre> <nowiki>
*/

function closeafd(bold, notbold){
  var txt = document.editform.wpTextbox1;
  txt.value = "{{subst:vt}} '''" + bold + "'''" + notbold + ". &ndash; ~~~~\n" + txt.value + "\n{{AfD bottom}}\n";
  txt = document.editform.wpSummary;
  txt.value = "close discussion: " + bold + notbold;
  document.editform.wpWatchthis.checked = false;
}
/*
</nowiki> </pre>
==Reg-ex==
<pre> <nowiki>
*/
function replace(){
    var s = prompt("Search reg exp?");
    if(s){
        var r = prompt("Replace reg exp?");
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}


/* Remember doesn't apply to pages outside main namespace */
msg="Copyedit. ";
insist=0;
diff=1;
preview=0;
submit=0;
function always(){
 
  var txt = document.editform.wpTextbox1;
  let is_dab = /{{\s*[Dd](isambiguation|ab\b)/.test(text.value);
  temp=txt.value;
  var test=0;
  txt.value = txt.value.replace(/ISBN:\s*/gm, "ISBN ");
  if (!txt.value.match(/<math>/)){
    txt.value = txt.value.replace(/ +$/gm, "");              /* trailing spaces get rid of */
  }
  txt.value = txt.value.replace(/==(\n)*/gm, "==$1"); /* remove blank line after headers */
  txt.value = txt.value.replace(/([^=])(\n)(\n*)==/gm, "$1$2$2=="); /* One blank line before headers */
/* ^ should also not match a comment after a header followed by another header */

  txt.value = txt.value.replace(/\[\[J\.* *R\.* *R\.* *Tolk($:ie|ei)n\]\]('|’)s/gim, "[[J. R. R. Tolkien$1s]]");
  txt.value = txt.value.replace(/\[\[Country Music\|(C|c)ountry\]\]/gm, "[[Country music|$1ountry]]");
  txt.value = txt.value.replace(/([a-z,] )\[\[Country Music\]\]/gm, "$1[[country music]]");
  txt.value = txt.value.replace(/(\n|\.|\=\s*) \[\[Country Music\]\]/gm, "$1 [[Country music]]");
  txt.value = txt.value.replace(/\(\[\[Country Music\]\]/gm, "([[Country music]]");
  txt.value = txt.value.replace(/{{template:/gim, "{{");
  txt.value = txt.value.replace(/{{cite-section}}/gim, "{{Cite-section|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{expand}}/gim, "{{Expand|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(cleanup|clean|clean up|clean-up|attention)}}/gim, "{{Cleanup|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{\s*(an|cn|citation(_|-| |)needed|citation required|cite(_|-| |)needed|needs( |_)citation|reference( |_)needed|uncited|fact)\s*\|*\s*}}/gim, "{{Citation needed|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{\s*(recently revised|rrevised|)\s*\|*\s*}}/gim, "{{Recently revised|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(unsourced|references|unreferenced|unref|sources)}}/gim, "{{Unreferenced|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(unsourced|references|unreferenced|unref|sources)(\|\w+)}}/gim, "{{Unreferenced$2|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(nn|notability)}}/gim, "{{Notability|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(nn|notability)(\|\w+)}}/gim, "{{Notability$2|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");  
  txt.value = txt.value.replace(/{{(significance|importance|explain significance)}}/gim, "{{Importance|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(importance-s)}}/gim, "{{Importance-s|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{Cleanup-section}}/gim, "{{Cleanup-section|{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(uncategorizedstub|uncatstub)}}/gim, "{{Uncategorizedstub|{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(unlinked|linkless|orphan)}}/gim, "{{Orphan|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
  txt.value = txt.value.replace(/{{(classify|categories needed|catneeded|categori(s|z)e|nocats*|categoryneeded|uncat|uncategori(s|z)ed)}}/gim, "{{Uncategorized|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}");
if (test==1 && temp!=txt.value){temp=txt.value;document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"4";}

  txt.value = txt.value.replace(/^(==+)\s*external\s*links*\s*(==+)/gm, "$1External links$1");
  txt.value = txt.value.replace(/^(==+)\s*references*\s*(==+)/gm, "$1References$1");
  txt.value = txt.value.replace(/\[\[U\.S\.\|/gm, "[[United States|");
  txt.value = txt.value.replace(/\[\[USA\|/gm, "[[United States|");
  txt.value = txt.value.replace(/\[\[US\|/gm, "[[United States|");
  txt.value = txt.value.replace(/\[\[\s*(USA|US|U\.S\.)\s*\]\](\.|)/gm, "[[United States|US]]");
  txt.value = txt.value.replace(/\[\[United States\|USA\]\](\.|)/gm, "[[United States|US]]");
  txt.value = txt.value.replace(/\[\[USA\]\]([^\.])/gm, "[[United States|US]]$1");
  txt.value = txt.value.replace(/\[\[U\.S\.\]\]/gm, "[[United States|US]]");
  if (!is_dab){
    txt.value = txt.value.replace(/\[\[(([^\]\[\|:]+), +(Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming|Washington, DC|Washington, D.C.|British Columbia|Alberta|Saskatchewan|Manitoba|Ontario|Quebec|New Brunswick|Nova Scotia|Prince Edward Island|Newfoundland and Labrador|Bedfordshire|Berkshire|City of Bristol|Buckinghamshire|Cambridgeshire|Cheshire|Cornwall|Cumbria|Derbyshire|Devon|Dorset|Durham|East Riding of Yorkshire|East Sussex|Essex|Gloucestershire|Greater London|Greater Manchester|Hampshire|Herefordshire|Hertfordshire|Isle of Wight|Kent|Lancashire|Leicestershire|Lincolnshire|City of London|Merseyside|Norfolk|Northamptonshire|Northumberland|North Yorkshire|Nottinghamshire|Oxfordshire|Rutland|Shropshire|Somerset|South Yorkshire|Staffordshire|Suffolk|Surrey|Tyne and Wear|Warwickshire|West Midlands|West Sussex|West Yorkshire|Wiltshire|Worcestershire|England|France|London|Paris|South Africa|Rome|Italy|New Zealand|Australia|Queensland|New South Wales|Tasmania|Queensland|South Australia|Victoria|Western Australia|Northern Territory|Australian Capital Territory|Spain|Germany|Portugal|Berlin|Greece|Europe|Turkey|Russia|Ukraine|Sweden|Norway|Finland|Denmark|Latvia|Lithuania|Estonia|Scotland|Wales|Ireland|Belgium|Netherlands|Luxemburg|Istanbul|Moscow|London|Paris|Madrid|Barcelona|Saint Petersburg|Milan|Rome|Athens|India|China|Mumbai|Calcutta|Punjab|MongoliaUlan Bator|Beijing|Tokyo|Kyoto|Osaka|Wellington|Washington|Usbekistan|Iraq|Iran|Afghanistan|Antarctica|Cuba|Brazil|Chuile|Jamaica|Mexico|Peru))\]\]/gim,"[[$1|$2]], $3");
    txt.value = txt.value.replace(/\[\[([^\]\[\|:]+)\|([^\]\[\|:]+), +(Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming|Washington, DC|Washington, D.C.|British Columbia|Alberta|Saskatchewan|Manitoba|Ontario|Quebec|New Brunswick|Nova Scotia|Prince Edward Island|Newfoundland and Labrador|Bedfordshire|Berkshire|City of Bristol|Buckinghamshire|Cambridgeshire|Cheshire|Cornwall|Cumbria|Derbyshire|Devon|Dorset|Durham|East Riding of Yorkshire|East Sussex|Essex|Gloucestershire|Greater London|Greater Manchester|Hampshire|Herefordshire|Hertfordshire|Isle of Wight|Kent|Lancashire|Leicestershire|Lincolnshire|City of London|Merseyside|Norfolk|Northamptonshire|Northumberland|North Yorkshire|Nottinghamshire|Oxfordshire|Rutland|Shropshire|Somerset|South Yorkshire|Staffordshire|Suffolk|Surrey|Tyne and Wear|Warwickshire|West Midlands|West Sussex|West Yorkshire|Wiltshire|Worcestershire|England|France|London|Paris|South Africa|Rome|Italy|New Zealand|Australia|Queensland|New South Wales|Tasmania|Queensland|South Australia|Victoria|Western Australia|Northern Territory|Australian Capital Territory|Spain|Germany|Portugal|Berlin|Greece|Europe|Turkey|Russia|Ukraine|Sweden|Norway|Finland|Denmark|Latvia|Lithuania|Estonia|Scotland|Wales|Ireland|Belgium|Netherlands|Luxemburg|Istanbul|Moscow|London|Paris|Madrid|Barcelona|Saint Petersburg|Milan|Rome|Athens|India|China|Mumbai|Calcutta|Punjab|Mongolia|Ulan Bator|Beijing|Tokyo|Kyoto|Osaka|Wellington|Washington|Usbekistan|Iraq|Iran|Afghanistan|Antarctica|Cuba|Brazil|Chuile|Jamaica|Mexico|Peru)\]\]/gim,"[[$1|$2]], $3");
    txt.value = txt.value.replace(/\[\[Rome, Italy\|Rome\]\]/gim, "[[Rome]]");
  }
  txt.value = txt.value.replace(/\{\{lifetime\|/gim, "{{subst:ltm|");
  if (temp==txt.value) {return;}
  // add any custom message to summary
  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + msg;
  /* fix specific typo, if in edit summary */
  document.forms.editform.wpSummary.value = document.forms.editform.wpSummary.value.replace(/([Tt])empalte/g, "$1emplate");
  if (diff==1) {document.editform.wpDiff.click();}
  else if (submit==1) {document.forms.editform.submit();}
}


function quick(){
  var txt = document.editform.wpTextbox1;
  temp=txt.value;
  txt.value = txt.value.replace(/\[\[::(User|Special|Template)/gi,"[[$1");
  txt.value = txt.value.replace(/\[\[::(File|Image|Category)/gi,"[[:$1");
  if (temp==txt.value) {return;}
  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + "Fix multiple : lint error.";
}


function spelling(){
    var txt = document.editform.wpTextbox1;
//  canonicalise bda
    txt.value = txt.value.replace(/{{bda\|/i,"{{Birth date and age|");
    txt.value = txt.value.replace(/{{dda\|/i,"{{Death date and age|");

/* Date order */
// Ranges first:
    txt.value = txt.value.replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s+((\d|[012]\d|30|31) *([-–—−\/]|through|to) *(\d|[012]\d|30|31))\b/ig, "$2 $1")
//single dates
    txt.value = txt.value.replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d|[012]\d|30|31)\b/ig, "$2 $1")
// normalise spacing
    txt.value = txt.value.replace(/(\b\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)/ig, "$1 $2")
// leading 0
    txt.value = txt.value.replace(/\b0(\d)\s+(January|February|March|April|May|June|July|August|September|October|November|December)/ig, "$1 $2")
// delink
    txt.value = txt.value.replace(/\[\[\s*\b(\d{1,2})\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s*\]\]/ig,"$1 $2")
// remove comma and delink year
    txt.value = txt.value.replace(/\b(\d{1,2}) +(January|February|March|April|May|June|July|August|September|October|November|December)\s*,*\s*\[\[(\d{1,4})\b(\s*)\]\](\s*)/ig,"$1 $2 $3$4$5")
// remove comma if year 
    txt.value = txt.value.replace(/\b(\d{1,2}) +(January|February|March|April|May|June|July|August|September|October|November|December)\s*,*\s*(\d{3,4})\b(\s*)(\s*)/ig,"$1 $2 $3$4$5")

// Fix up birth/death date templates mf=y/yes

    txt.value = txt.value.replace(/({{[\s_]*(?:(?:[Bb]irth[ _]*date|[Dd]eath[ _]*date)\s*(?:and[ _]*age)*|[Bb]irth[ _]+date[ _]+and[ _]+age2)\s*(?:\|\s*\d*\s*)*\|)\s*mf\s*=\s*[yY](?:es)*\s*(\||}|\n)/g,"$1df=y$2")
// Fix up birth/death date templates only digits
    txt.value = txt.value.replace(/({{[\s_]*(?:(?:[Bb]ir|[Dd]ea)th[ _]*date[ _]*(?:and[ _]*age)*|[Bb]irth[ _]+date[ _]+and[ _]+age2)\s*(?:\|[ \d]*)*)}}/g,"$1|df=y}}")

// Update any existing dmy tag
    oldtxt = txt.value;
    txt.value = txt.value.replace(/{{[_ ]*(Dmy|Use[_ ]*dmy|Use[_ ]+dmy[_ ]+dates)[_ ]*\|\s*date\s*=\s*[a-z]+\s+\d+\s*}}/i, "{{Use dmy dates|date={{Subst:CURRENTMONTHNAME}} {{Subst:CURRENTYEAR}}}}")
    if (oldtxt == txt.value) {
//     Add dmy template if not already here
       if (txt.value.indexOf('{{use dmy') == -1 && txt.value.indexOf('{{Use dmy') == -1) {
           txt.value = txt.value.replace(/\n*((?:{{DEFAULTSORT:[^}]*}}){0,1}\n\[\[Category:)/,"\n{{Use dmy dates|date={{Subst:CURRENTMONTHNAME}} {{Subst:CURRENTYEAR}}}}\n\n$1")
           if (txt.value.indexOf('{{dmy') == -1 && txt.value.indexOf('{{Use dmy') == -1) {
               txt.value = txt.value + "\n{{Use dmy dates|date={{Subst:CURRENTMONTHNAME}} {{Subst:CURRENTYEAR}}}}"
           }  
        }
        document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + "Date formats. ";
    }
    else {
        document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + "Update tag. ";
    }
    document.editform.wpDiff.click();
}

/*
</nowiki> </pre>
==Simplify wikilinks==
<pre> <nowiki>
*/
function decomma(){
  var txt = document.editform.wpTextbox1;
/*  txt.value = txt.value.replace(/\[\[(.*)?  (.*)?\]\]/g,"[[$1 $2]]");
  txt.value = txt.value.replace(/\[\[ /g,"[[");  
  txt.value = txt.value.replace(/ \]\]/g,"]]");
 */
  txt.value = txt.value.replace(/ ==$/gm, "==");
  txt.value = txt.value.replace(/^== /gm, "==");
/*De-pipe if possible */
  txt.value = txt.value.replace(/\[\[([^\]\|]+)\|\1([^\]\|\-\'\s]*)\]\]/gm, "[[$1]]$2"); 
/* Pull text inside piped link */
  txt.value = txt.value.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'])([\w\d]*)([\.\,\;\:\"\!\?\s]+)/gm, "[[$1|$2$3$4]]$5"); 
/*De-pipe if now possible */
  txt.value = txt.value.replace(/\[\[([^\]\|]+)\|\1([^\]\|\-\'\s]*)\]\]/gm, "[[$1]]$2"); 
  
  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + "Simplified wikilink. ";
  document.editform.wpDiff.click();
/* document.forms.editform.submit(); */
}
/*
</nowiki> </pre>
==Repeated links==
<pre> <nowiki>
*/
function replink(){
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(/\[\[([^\]\|]+)\|([^\]]*)\]\](.*[.\n]*)\[\[\1\|\2\]\]/gm, "[[$1|$2]]$3$2");
  txt.value = txt.value.replace(/\[\[([^\]]+)\]\](.*[.\n]*)\[\[\1\]\]/gm, "[[$1]]$2$1");
  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value + "Remove duplicate wikilink. ";
  document.editform.wpDiff.click();
}


function normcase(){
  var txt = document.editform.wpTextbox1;
//  txt.value = txt.value.replace(/ (==+)$/gm, "$1");
//  txt.value = txt.value.replace(/^(==+) /gm, "$1");  
/*  txt.value = txt.value.replace( /(==\s*\"*[\w])(.*==)/ig , 
     function($0,$1,$2) { 
        return($1.toUpperCase()+$2.toLowerCase());
      }
   );*/
  txt.value = txt.value.replace( /(==+\s*\"*)(.*?)(==+)/ig , 
     function($0,$1,$2,$3) {
        var result=$1+toHeaderCase($2)+$3;
        if ($0==result) {return (result);}
        result = result.replace (/^(==+)\s*(.*?[^\s])\s*(==+)$/,"$1"+"$2"+"$3");
        return (result);    
//        return($1+toHeaderCase($2)+$3)
      }      
   );
   var txt = document.editform.wpSummary;
   var summary = "Correct caps in section header.";
   if (txt.value.indexOf(summary) == -1) {
	if (txt.value.match(/.*[^\s]$/)) {
	    txt.value += " ";
        }
	txt.value += summary;
  }
  document.editform.wpDiff.click();
// document.forms.editform.submit(); 
}
/*
</nowiki> </pre>

==toHeaderCase==
<pre> <nowiki>
*/
function toHeaderCase(txt){
// All caps stay all caps if more than 1 letter
// First word gets a cap
// Words containing a fullstop unchanged
// DVD and LP to caps
// TV to Television
// USA to US
// & to and
// rest to lowercase
  var words = new Array();
  var result = "";
  words = txt.split(' ');

  for (var i=0;i<words.length;i++){
//    Replace specific abbreviations (don't worry about case)
      words[i]=words[i].replace(/^tv$/gim, "television");
      words[i]=words[i].replace(/^&$/gim, "and");

//    Ignore most other abbreviations for now 
      if ((( words[i].length > 1) && (words[i] == words[i].toUpperCase() )) 
        || ( words[i].indexOf('.')!= -1) || (words[i]=="I")
      ){
//        Do nothing
      }
//    Else capitalise first word 
      else if (i==0) {
          words[i]=words[i].substring(0,1).toUpperCase()+words[i].substring(1).toLowerCase();
      }
//    Lowercase the rest 
      else {words[i]=words[i].toLowerCase();}
//    Add the word to the result string 
      if (i==0) {result=words[i];}  else {result=result+" "+words[i];} 
  }
//Uppercase/correct specific abbreviations 
  result = result.replace(/\blp\b/gim, "LP");  
  result = result.replace(/\blps\b/gim, "LPs");  
  result = result.replace(/\bep\b/gim, "EP");  
  result = result.replace(/\beps\b/gim, "EPs");  
  result = result.replace(/\bdvd\b/gim, "DVD");  
  result = result.replace(/\bdvds\b/gim, "DVDs");  
  result = result.replace(/\bUSA\b/gim, "US");

  return(result);
}

/*
</nowiki> </pre>

==Units==
<pre> <nowiki>
*/
function census(){
    var txt = document.editform.wpTextbox1;

    // Convert &deg into ° symbol
    txt.value = txt.value.replace(/&deg;/g, '°');
    txt.value = txt.value.replace(/º/g, '°');


    // Convert &sup into superscript ² symbol
    txt.value = txt.value.replace(/&sup2;/g, '²');
    txt.value = txt.value.replace(/&sup3;/g, '³');

    // Convert the word ohm(s) or the html entity into the actual Ω symbol (Omega, not the actual ohm symbol &#8486;) and make sure it's spaced
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?\s?(&Omega;|ohm|Ohm)s?([\s,.\/\)])/g, '$1 $2Ω$4');

    // Convert various micro symbols into the actual micro symbol, make sure it's spaced
    txt.value = txt.value.replace(/(\d)\s?(&mu;|μ|&micro;)(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.\/\)])/g, '$1 µ$3$4');

    // Convert capital K to lowercase k in units
    txt.value = txt.value.replace(/(\d)\s?K(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.\/\)])/g, '$1 k$2$3');

    // Fix common spelling error
    txt.value = txt.value.replace(/celcius/gi, 'Celsius');

    // Capitalize units correctly
    txt.value = txt.value.replace(/(\d)\s?(khz)([\s,.\/\)])/gi, '$1 kHz$3');
    txt.value = txt.value.replace(/(\d)\s?(mhz)([\s,.\/\)])/gi, '$1 MHz$3');
    txt.value = txt.value.replace(/(\d)\s?(ghz)([\s,.\/\)])/gi, '$1 GHz$3');
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(hz|HZ)([\s,.\/\)])/g, '$1 $2Hz$4');
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(pa|PA)([\s,.\/\)])/g, '$1 $2Pa$4');

    // Fix kilometres
    txt.value = txt.value.replace(/(\d)\s?(kms)([\s,.\/\)])/gi, '$1 km$3');
    txt.value = txt.value.replace(/(\d)\s?(km)([\s,.\/\)])/gi, '$1 km$3');

    // Standardise kilometres per hour and add space
    txt.value = txt.value.replace(/(\d)\s?(km\/hr)([\s,.\/\)])/gi, '$1 km/h$3');
    txt.value = txt.value.replace(/(\d)\s?(kph)([\s,.\/\)])/gi, '$1 km/h$3');
    txt.value = txt.value.replace(/(\d)\s?(kmph)([\s,.\/\)])/gi, '$1 km/h$3');
    // txt.value = txt.value.replace(/(\d)\s?(kmh)([\s,.\/\)])/gi, '$1 km/h$3');

    // txt.value = txt.value.replace(/(\d)\s?(km\/h)([\s,.\/\)])/gi, '$1 km/h$3');

    // Space before horsepower symbol
    txt.value = txt.value.replace(/(\d)\s?(hp)([\s,.@])/gi, '$1 hp$3');
    txt.value = txt.value.replace(/(\d)\s?(bhp)([\s,.@])/gi, '$1 bhp$3');
    txt.value = txt.value.replace(/(\d)\s?(shp)([\s,.@])/gi, '$1 shp$3');

    // Space before other units
    txt.value = txt.value.replace(/(\d)\s?(cc)([\s,.\/\)])/gi, '$1 cc$3');
    txt.value = txt.value.replace(/(\d)\s?(ml)([\s,.\/\)])/gi, '$1 ml$3');
    txt.value = txt.value.replace(/(\d)\s?(mm)([\s,.\/\)])/gi, '$1 mm$3');
    txt.value = txt.value.replace(/(\d)\s?(km)([\s,.\/\)])/gi, '$1 km$3');

    // Standardise miles per hour and rpm
    txt.value = txt.value.replace(/(\d)\s?(m.p.h.)([\s,.\/\)])/gi, '$1 mph$3');
    txt.value = txt.value.replace(/(\d)\s?(mph)([\s,.\/\)])/gi, '$1 mph$3');
    txt.value = txt.value.replace(/(\d)&nbsp;(mph)([\s,.\/\)])/gi, '$1&nbsp;mph$3');

    txt.value = txt.value.replace(/(\d)\s?(rpm)([\s,.\/\)])/gi, '$1 rpm$3');
    txt.value = txt.value.replace(/(\d)&nbsp;(rpm)([\s,.\/\)])/gi, '$1&nbsp;rpm$3');

    // Standardise symbol for pounds
    txt.value = txt.value.replace(/(\d)\s?lbs/gi, '$1 lb');
    txt.value = txt.value.replace(/(\d\+?)\s?lbs/gi, '$1 lb');
    txt.value = txt.value.replace(/(\d&nbsp;lb)s/gi, '$1');
    txt.value = txt.value.replace(/(\d)\s?(\[\[lbs\]\])/gi, '$1 \[\[Pound (mass)|lb\]\]');

    // Standardise symbol for foot pounds
    txt.value = txt.value.replace(/(\d)\s?(ft[ -.•\/]lb[fs])/gi, '$1 ft·lbf');
    txt.value = txt.value.replace(/(\d)\s?(lb[fs][ -.•\/]ft)/gi, '$1 ft·lbf');
    txt.value = txt.value.replace(/(\d)\s?(lb[ -.•\/]ft)/gi, '$1 ft·lbf');
    txt.value = txt.value.replace(/(\d)\s?(ft[ -.•\/]lb)/gi, '$1 ft·lbf');

    txt.value = txt.value.replace(/(\d)&nbsp;(lb[fs][ -.•\/]ft)/gi, '$1&nbsp;ft·lbf');
    txt.value = txt.value.replace(/(\d)&nbsp;(ft[ -.•\/]lb[fs])/gi, '$1&nbsp;ft·lbf');
    txt.value = txt.value.replace(/(\d)&nbsp;(lb[ -.•\/]ft)/gi, '$1&nbsp;ft·lbf');
    txt.value = txt.value.replace(/(\d)&nbsp;(ft[ -.•\/]lb)/gi, '$1&nbsp;ft·lbf');

    // Symbols for feet and inches

    txt.value = txt.value.replace(/([^;°]\s?\s?)(\d{1,4})\s?(['’])\s?(\d{1,2})\s?(["”])/gi, '$1$2 ft $4 in');
    //txt.value = txt.value.replace(/([:=\/\(])\s*(\d{1,3)\s?(['’])\s?(1?\d)\s?(["”])/gi, '$1$2 ft $4 in');
    //txt.value = txt.value.replace(/(1?\d)\s?(["”])/gi, '$1 in');
    //txt.value = txt.value.replace(/(eight[:= ]{1,2})\s?(\d)-(\d{1,2})([\s,.\/\)])/gi, '$1 $2 ft $3 in');


    // Give digital value a percent symbol '%' instead of word
    txt.value = txt.value.replace(/(\d)[\s?-]per *cent([^aei])/gi, '$1%$2');

    // Add a space before dB or B
    txt.value = txt.value.replace(/(\d)\s?(dB|B)\b/g, '$1 $2');

    // Add a space before any units that were missed before
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|n|p|f|a|z|y)?(g|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|°F|M)([\s,.\\/)])/g, '$1 $2$3$4');

    // Separate one for seconds since they give a lot of false positives like "1970s".  Only difference is mandatory prefix.
    txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|n|p|f|a|z|y)(s)([\s,.\/\)])/g, '$1 $2$3$4');

    // bps or b/s or bits/s --> bit/s
    txt.value = txt.value.replace(/([KkMmGgTtPpEeYyZz])(bps|bits?\/s|b\/s)/g, ' $1bit/s');
    txt.value = txt.value.replace(/(\d)\s?(bps)/gi, '$1 bit/s');

    // Bps or byte/s or bytes/s --> B/s
    txt.value = txt.value.replace(/([KkMmGgTtPpEeYyZz])(Bps|bytes?\/s)/g, ' $1B/s');

    // After that, make capitalization correct
    txt.value = txt.value.replace(/K(bit|B)\/s/g, 'k$1/s');
    txt.value = txt.value.replace(/m(bit|B)\/s/g, 'M$1/s');
    txt.value = txt.value.replace(/g(bit|B)\/s/g, 'G$1/s');
    txt.value = txt.value.replace(/t(bit|B)\/s/g, 'T$1/s');
    txt.value = txt.value.replace(/e(bit|B)\/s/g, 'E$1/s');
    txt.value = txt.value.replace(/y(bit|B)\/s/g, 'Y$1/s');
    txt.value = txt.value.replace(/z(bit|B)\/s/g, 'Z$1/s');

    // Common error
    txt.value = txt.value.replace(/mibi(bit|byte)/g, 'mebi$1');

    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "units";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
			txt.value += " | ";
		}
		txt.value += summary;
	}

    // Press the diff button to check it
    document.editform.wpDiff.click()
}
/*
</nowiki> </pre>
==Day slash dates==
<pre> <nowiki>
*/
function slashdates(){
  var txt = document.editform.wpTextbox1;
/*Note a leading colon could well be an "EasyTimeline" */
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(\d\d\d\d)\/([0|1|2]?\d)\/([0|1|2|3]?\d)/gm, "$1$4 zz$3zz $2");
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)([0|1|2|3]?\d)\/([0|1|2]?\d)\/(\d\d\d\d)/gm, "$1$2 zz$3zz $4");

  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(\d+)\/(\d+)\/([01]\d)/gm, "$1$2 zz$3zz 20$4");
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(\d{1,2})\/(\d{1,2})\/([23456789]\d)/gm, "$1$2 zz$3zz 19$4");

  txt.value = txt.value.replace(/0(\d) zz/gm, "$1 zz");
  txt.value = txt.value.replace(/zz0(\d)zz/gm, "zz$1zz");

  txt.value = txt.value.replace(/zz1zz/gm, "January");
  txt.value = txt.value.replace(/zz2zz/gm, "February");
  txt.value = txt.value.replace(/zz3zz/gm, "March");
  txt.value = txt.value.replace(/zz4zz/gm, "April");
  txt.value = txt.value.replace(/zz5zz/gm, "May");
  txt.value = txt.value.replace(/zz6zz/gm, "June");
  txt.value = txt.value.replace(/zz7zz/gm, "July");
  txt.value = txt.value.replace(/zz8zz/gm, "August");
  txt.value = txt.value.replace(/zz9zz/gm, "September");
  txt.value = txt.value.replace(/zz10zz/gm, "October");
  txt.value = txt.value.replace(/zz11zz/gm, "November");
  txt.value = txt.value.replace(/zz12zz/gm, "December");

  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"Clarify date(s) from xx/xx/xxx format. ";    
}
/*
</nowiki> </pre>
==Month slash dates==
<pre> <nowiki>
*/
function slashdatesm(){ /* month day year - pox. */
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(0?[1-9]|1[012])\/(\d+)\/(\d\d\d\d)/gm, "$1$3 zz$2zz $4");
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(0?[1-9]|1[012])\/(\d+)\/([01]\d)/gm, "$1$3 zz$2zz 20$4");
  txt.value = txt.value.replace(/(\)|\>|\*|\||\(|\'|=|\s)(0?[1-9]|1[012])\/(\d+)\/([23456789]\d)/gm, "$1$3 zz$2zz 19$4");

  txt.value = txt.value.replace(/0(\d) zz/gm, "$1 zz");
  txt.value = txt.value.replace(/zz0(\d)zz/gm, "zz$1zz");


  txt.value = txt.value.replace(/zz1zz/gm, "January");
  txt.value = txt.value.replace(/zz2zz/gm, "February");
  txt.value = txt.value.replace(/zz3zz/gm, "March");
  txt.value = txt.value.replace(/zz4zz/gm, "April");
  txt.value = txt.value.replace(/zz5zz/gm, "May");
  txt.value = txt.value.replace(/zz6zz/gm, "June");
  txt.value = txt.value.replace(/zz7zz/gm, "July");
  txt.value = txt.value.replace(/zz8zz/gm, "August");
  txt.value = txt.value.replace(/zz9zz/gm, "September");
  txt.value = txt.value.replace(/zz10zz/gm, "October");
  txt.value = txt.value.replace(/zz11zz/gm, "November");
  txt.value = txt.value.replace(/zz12zz/gm, "December");

  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"Clarify date(s) from xx/xx/xxx format. ";    
}
/*
</nowiki> </pre>
==British Old English==
<pre> <nowiki>
*/

function british(){
  var txt = document.editform.wpTextbox1;

  txt.value = txt.value.replace(/\[\[Old English\]\]/gim, "[[Old English language|Old English]]");
  txt.value = txt.value.replace(/\[\[Old English\|/gim, "[[Old English language|");
  txt.value = txt.value.replace(/\[\[British\]\]/gim, "[[United Kingdom|British]]");
  txt.value = txt.value.replace(/\[\[British\|/gim, "[[United Kingdom|");
  txt.value = txt.value.replace(/\[\[United kingdom\]\]/gim, "[[United Kingdom]]");
  txt.value = txt.value.replace(/\[\[United kingdom\|/gim, "[[United Kingdom|");  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"dab/red UK/OE.";

}
/*
</nowiki> </pre>
==Math==
<pre> <nowiki>
*/
function math(){
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(/\\binom\s*\{([^\}]*)\}\s*\{([^\}]*)\}/gim, "{ $1 \\choose $2 }");
  txt.value = txt.value.replace(/\$\s*(.*?)\s*\$/gim, "\<math\>$1\<\/math\>");
  txt.value = txt.value.replace(/\\displaystyle/gim, "");
  txt.value = txt.value.replace(/\\partial/gim, "\\part");
  txt.value = txt.value.replace(/\\end\{array\}/gim, "\\end{matrix}");
  txt.value = txt.value.replace(/\\begin\{array\}\s*\(11\)/gim, "\\begin{matrix}");
  txt.value = txt.value.replace(/\\rvert/gim, "|");
  txt.value = txt.value.replace(/\\lvert/gim, "|");
  txt.value = txt.value.replace(/\.\<\/math\>/gim, "\<\/math\>\.");
  txt.value = txt.value.replace(/\,\<\/math\>/gim, "\<\/math\>\,");
  txt.value = txt.value.replace(/\\mbox/gim, "");
  txt.value = txt.value.replace(/\\mathscr/gim, "");
  txt.value = txt.value.replace(/“/gim, "\"");  
  txt.value = txt.value.replace(/”/gim, "\"");
  txt.value = txt.value + "<br>{{planetmath|id=|title=}} "
  txt.value = txt.value + "[[Category:combinatorics]]"
  document.forms.editform.wpSummary.value="Import from Planet Math";

}
/*
</nowiki> </pre>
==bold==
<pre> <nowiki>
*/
function bold(){
  var txt = document.editform.wpTextbox1;
/*  var title = document.title.value;
  txt.value = txt.value.replace(/\<\/b\>/gim, "'''");
 */
  txt.value = txt.value.replace(/\<\/b\>/gim, "'''");
  txt.value = txt.value.replace(/\<\/i\>/gim, "''");
  txt.value = txt.value.replace(/\<b\>/gim, "'''");
  txt.value = txt.value.replace(/\<i\>/gim, "''");

  document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"Bold/Italics";
}
/*
</nowiki> </pre>
==State names==
<pre> <nowiki>
*/
function statenames(){
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/\bAL\b/gm,"Alabama"); 
   txt.value = txt.value.replace(/\bAK\b/gm,"Alaska"); 
   txt.value = txt.value.replace(/\bAZ\b/gm,"Arizona"); 
   txt.value = txt.value.replace(/\bAR\b/gm,"Arkansas"); 
   txt.value = txt.value.replace(/\bCA\b/gm,"California"); 
   txt.value = txt.value.replace(/\bCO\b/gm,"Colorado"); 
   txt.value = txt.value.replace(/\bCT\b/gm,"Connecticut"); 
   txt.value = txt.value.replace(/\bDE\b/gm,"Delaware"); 
   txt.value = txt.value.replace(/\bDC\b/gm,"District of Columbia"); 
   txt.value = txt.value.replace(/\bFL\b/gm,"Florida"); 
   txt.value = txt.value.replace(/\bGA\b/gm,"Georgia"); 
   txt.value = txt.value.replace(/\bHI\b/gm,"Hawaii"); 
   txt.value = txt.value.replace(/\bID\b/gm,"Idaho"); 
   txt.value = txt.value.replace(/\bIL\b/gm,"Illinois"); 
   txt.value = txt.value.replace(/\bIN\b/gm,"Indiana"); 
   txt.value = txt.value.replace(/\bIA\b/gm,"Iowa"); 
   txt.value = txt.value.replace(/\bKS\b/gm,"Kansas"); 
   txt.value = txt.value.replace(/\bKY\b/gm,"Kentucky"); 
   txt.value = txt.value.replace(/\bLA\b/gm,"Louisiana"); 
   txt.value = txt.value.replace(/\bME\b/gm,"Maine"); 
   txt.value = txt.value.replace(/\bMD\b/gm,"Maryland"); 
   txt.value = txt.value.replace(/\bMA\b/gm,"Massachusetts"); 
   txt.value = txt.value.replace(/\bMI\b/gm,"Michigan"); 
   txt.value = txt.value.replace(/\bMN\b/gm,"Minnesota"); 
   txt.value = txt.value.replace(/\bMS\b/gm,"Mississippi"); 
   txt.value = txt.value.replace(/\bMO\b/gm,"Missouri"); 
   txt.value = txt.value.replace(/\bMT\b/gm,"Montana"); 
   txt.value = txt.value.replace(/\bNE\b/gm,"Nebraska"); 
   txt.value = txt.value.replace(/\bNV\b/gm,"Nevada"); 
   txt.value = txt.value.replace(/\bNH\b/gm,"New Hampshire"); 
   txt.value = txt.value.replace(/\bNJ\b/gm,"New Jersey"); 
   txt.value = txt.value.replace(/\bNM\b/gm,"New Mexico"); 
   txt.value = txt.value.replace(/\bNY\b/gm,"New York"); 
   txt.value = txt.value.replace(/\bNC\b/gm,"North Carolina"); 
   txt.value = txt.value.replace(/\bND\b/gm,"North Dakota"); 
   txt.value = txt.value.replace(/\bOH\b/gm,"Ohio"); 
   txt.value = txt.value.replace(/\bOK\b/gm,"Oklahoma"); 
   txt.value = txt.value.replace(/\bOR\b/gm,"Oregon"); 
   txt.value = txt.value.replace(/\bPA\b/gm,"Pennsylvania"); 
   txt.value = txt.value.replace(/\bRI\b/gm,"Rhode Island"); /* and Providence Plantations, naturally */
   txt.value = txt.value.replace(/\bSC\b/gm,"South Carolina"); 
   txt.value = txt.value.replace(/\bSD\b/gm,"South Dakota"); 
   txt.value = txt.value.replace(/\bTN\b/gm,"Tennessee"); 
   txt.value = txt.value.replace(/\bTX\b/gm,"Texas"); 
   txt.value = txt.value.replace(/\bUT\b/gm,"Utah"); 
   txt.value = txt.value.replace(/\bVT\b/gm,"Vermont"); 
   txt.value = txt.value.replace(/\bVA\b/gm,"Virginia"); 
   txt.value = txt.value.replace(/\bWA\b/gm,"Washington"); 
   txt.value = txt.value.replace(/\bWV\b/gm,"West Virginia"); 
   txt.value = txt.value.replace(/\bWI\b/gm,"Wisconsin"); 
   txt.value = txt.value.replace(/\bWY\b/gm,"Wyoming"); 
   txt.value = txt.value.replace(/\bAS\b/gm,"American Samoa"); 
   txt.value = txt.value.replace(/\bGU\b/gm,"Guam"); 
   txt.value = txt.value.replace(/\bMP\b/gm,"Northern Mariana Islands"); 
   txt.value = txt.value.replace(/\bPR\b/gm,"Puerto Rico"); 
   txt.value = txt.value.replace(/\bVI\b/gm,"Virgin Islands"); 
   txt.value = txt.value.replace(/\bFM\b/gm,"Federated States of Micronesia"); 
   txt.value = txt.value.replace(/\bMH\b/gm,"Marshall Islands"); 
   txt.value = txt.value.replace(/\bPW\b/gm,"Palau");
   txt.value = txt.value.replace(/\bCZ\b/gm,"Panama Canal Zone"); 
   txt.value = txt.value.replace(/\bPI\b/gm,"Philippines"); 
   txt.value = txt.value.replace(/\bTT\b/gm,"Trust Territory of the Pacific Islands"); 
   txt.value = txt.value.replace(/\bCM\b/gm,"Commonwealth of the Northern Mariana Islands");
  
   document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+" Expand US postal abbreviations.";
}
/*
</nowiki> </pre>
==Dates==
<pre> <nowiki>
*/
function dates(){
  var txt = document.editform.wpTextbox1;
/*
  if (document.forms.editform.wpSummary.value==" Date fixes.") {
    document.forms.editform.submit();
  }
  else
*/
 if(txt.value.indexOf("opyvio") == -1){
/* Prep accessdate= */
  txt.value = txt.value.replace(/accessdate\s*=\s*(\w)/gm,"accessdate = $1X");
/* Ranges of days within months */
  txt.value = txt.value.replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s*(\d{1,2})\s*-\s*(\d{1,2})(\D)/gm,"$1 $2-$1 $3$4");
  txt.value = txt.value.replace(/\b([1-9]|1\d|2\d|3[01])\s*-\s*([1-9]|1\d|2\d|3[01])\s*(January|February|March|April|May|June|July|August|September|October|November|December)/gm,"$1 $3-$2 $3");
/* standard formats */
  txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd|)(?:\s*)(January|February|March|April|May|June|July|August|September|October|November|December)(?:[\s,]*)(\d{3,4})/gim, "$1$2 $3 $4");
  txt.value = txt.value.replace(/([^\[\d])(January|February|March|April|May|June|July|August|September|October|November|December)(?:\s*)([1-9]|1\d|2\d|3[01])(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$2 $3 $4");
 txt.value = txt.value.replace(/([^=\[\d])([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd|)(?:\s)(January|February|March|April|May|June|July|August|September|October|November|December)(\W+)/gim, "$1$2 $3$4");
 txt.value = txt.value.replace(/([^=\[\d])(January|February|March|April|May|June|July|August|September|October|November|December)(?:\s*)([1-9]|1\d|2\d|3[01])(?:th|rd|st|nd|)([^\w])/gi, "$1$2 $3$4");

/* The xxx th of yyy */

 txt.value =
txt.value.replace(/(?:the)?(?:\s)([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd)?(?:\s*of\s*)(January|February|March|April|May|June|July|August|September|October|November|December)(?:[\s,]*)(\d{3,4})/gim, "$1 $2 $3");

 txt.value =
txt.value.replace(/(?:the)?(?:\s)([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd)?(?:\s*of\s*)(January|February|March|April|May|June|July|August|September|October|November|December)(\W+)/gim, "$1 $2$3");
/* xx th of yyy

 txt.value =
txt.value.replace(/([^=\[\d])([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd|)(January|February|March|April|May|June|July|August|September|October|November|December)(?:[\s,]*)(\d{3,4})/gim, "$1$2 $3 $4");

 txt.value =
txt.value.replace(/([^=\[\d])([1-9]|1\d|2\d|3[01])(?:\s*)(?:th|rd|st|nd|)(?:\s*of\s*)(January|February|March|April|May|June|July|August|September|October|November|December)(\W+)/gim, "$1$2 $3$4");
*/
/* jan.... */
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Jan\.?|January)(?:[\s,]*)(\d{3,4})/gim, "$1$2 January $4");
txt.value = txt.value.replace(/([^\[\d])(Jan\.?|January)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 January $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Jan\.?|January)(\W+)/gim, "$1$2 January$4");
txt.value = txt.value.replace(/([^\[\d])(Jan\.?|January])(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 January$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Feb)(?:[\s,]*)(\d{3,4})/gim, "$1$2 February $4");
txt.value = txt.value.replace(/([^\[\d])(Feb\.?|February)(?:\s*)([1-9]|1\d|2\d)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 February $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Feb)(\W+)/gim, "$1$2 February$4");
txt.value = txt.value.replace(/([^\[\d])(Feb\.?|February)(?:\s*)([1-9]|1\d|2\d)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 February$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Mar)(?:[\s,]*)(\d{3,4})/gim, "$1$2 March $4");
txt.value = txt.value.replace(/([^\[\d])(Mar\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 March $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Mar)(\W+)/gim, "$1$2 March$4");
txt.value = txt.value.replace(/([^\[\d])(Mar\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 March$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Apr)(?:[\s,]*)(\d{3,4})/gim, "$1$2 April $4");
txt.value = txt.value.replace(/([^\[\d])(Apr\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 April $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Apr)(\W+)/gim, "$1$2 April$4");
txt.value = txt.value.replace(/([^\[\d])(Apr\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 April$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Jun)(?:[\s,]*)(\d{3,4})/gim, "$1$2 June $4");
txt.value = txt.value.replace(/([^\[\d])(Jun\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 June $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Jun)(\W+)/gim, "$1$2 June$4");
txt.value = txt.value.replace(/([^\[\d])(Jun\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 June$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Jul)(?:[\s,]*)(\d{3,4})/gim, "$1$2 July $4");
txt.value = txt.value.replace(/([^\[\d])(Jul\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 July $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Jul)(\W+)/gim, "$1$2 July$4");
txt.value = txt.value.replace(/([^\[\d])(Jul\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 July$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Aug)(?:[\s,]*)(\d{3,4})/gim, "$1$2 August $4");
txt.value = txt.value.replace(/([^\[\d])(Aug\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 August $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Aug)(\W+)/gim, "$1$2 August$4");
txt.value = txt.value.replace(/([^\[\d])(Aug\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 August$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Sep|Sept)(?:[\s,]*)(\d{3,4})/gim, "$1$2 September $4");
txt.value = txt.value.replace(/([^\[\d])(Sep\.?|Sept\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 September $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Sep|Sept)(\W+)/gim, "$1$2 September$4");
txt.value = txt.value.replace(/([^\[\d])(Sep\.?|Sept\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 September$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Oct)(?:[\s,]*)(\d{3,4})/gim, "$1$2 October $4");
txt.value = txt.value.replace(/([^\[\d])(Oct\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 October $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Oct)(\W+)/gim, "$1$2 October$4");
txt.value = txt.value.replace(/([^\[\d])(Oct\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 October$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Nov)(?:[\s,]*)(\d{3,4})/gim, "$1$2 November $4");
txt.value = txt.value.replace(/([^\[\d])(Nov\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 November $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Nov)(\W+)/gim, "$1$2 November$4");
txt.value = txt.value.replace(/([^\[\d])(Nov\.?)(?:\s*)([1-9]|1\d|2\d|30)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 November$4");

txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s*)(Dec)(?:[\s,]*)(\d{3,4})/gim, "$1$2 December $4");
txt.value = txt.value.replace(/([^\[\d])(Dec\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|st|rd|nd|)(?:[\s,]+)(\d{3,4})/gim, "$1$3 December $4");
txt.value = txt.value.replace(/([^\[\d])([1-9]|1\d|2\d|30|31)(?:\s*)(?:th|rd|st|nd|)(?:\s)(Dec)(\W+)/gim, "$1$2 December$4");
txt.value = txt.value.replace(/([^\[\d\_])(Dec\.?)(?:\s*)([1-9]|1\d|2\d|30|31)(?:th|rd|st|nd|)([^\w])/gi, "$1$3 December$4");

/* accessmonthday, accessyear */
txt.value = txt.value.replace(/(accessmonthday\s*=\s*\[\[(?:\w+ \d+|\d+ \w+)\]\]\s*\|\s*accessyear\s*=\s*)(\d+)/gi, "$1$2");
txt.value = txt.value.replace(/(\s*accessyear\s*=\s*)(\d+)(\s*\|\s*accessmonthday\s*=\s*\[\[(?:\w+ \d+|\d+ \w+)\]\])/gi, "$1$2$3");


/* De-Prep accessdate= */
  txt.value = txt.value.replace(/ac+es+date(\s*=\s*)(\w)X/gm,"accessdate$1$2");

/* document.forms.editform.wpSummary.value=document.forms.editform.wpSummary.value+"tidy dates (where month and day both present)."; */
document.editform.wpDiff.click();
/*document.forms.editform.submit(); */
    } /* if not a copyvio */
}
/*
</nowiki> </pre>

==Capitals==
A crude first pass fixer for text that is almost all in lowercase
<pre> <nowiki>
*/
function capitals(){
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(/([\.|\n]) +a/gm, "$1 A");
  txt.value = txt.value.replace(/([\.|\n]) +b/gm, "$1 B");
  txt.value = txt.value.replace(/([\.|\n]) +c/gm, "$1 C");
  txt.value = txt.value.replace(/([\.|\n]) +d/gm, "$1 D");
  txt.value = txt.value.replace(/([\.|\n]) +e/gm, "$1 E");
  txt.value = txt.value.replace(/([\.|\n]) +f/gm, "$1 F");
  txt.value = txt.value.replace(/([\.|\n]) +g/gm, "$1 G");
  txt.value = txt.value.replace(/([\.|\n]) +h/gm, "$1 H");
  txt.value = txt.value.replace(/([\.|\n]) +i/gm, "$1 I");
  txt.value = txt.value.replace(/([\.|\n]) +j/gm, "$1 J");
  txt.value = txt.value.replace(/([\.|\n]) +k/gm, "$1 K");
  txt.value = txt.value.replace(/([\.|\n]) +l/gm, "$1 L");
  txt.value = txt.value.replace(/([\.|\n]) +m/gm, "$1 M");
  txt.value = txt.value.replace(/([\.|\n]) +n/gm, "$1 N");
  txt.value = txt.value.replace(/([\.|\n]) +o/gm, "$1 O");
  txt.value = txt.value.replace(/([\.|\n]) +p/gm, "$1 P");
  txt.value = txt.value.replace(/([\.|\n]) +q/gm, "$1 Q");
  txt.value = txt.value.replace(/([\.|\n]) +r/gm, "$1 R");
  txt.value = txt.value.replace(/([\.|\n]) +s/gm, "$1 S");
  txt.value = txt.value.replace(/([\.|\n]) +t/gm, "$1 T");
  txt.value = txt.value.replace(/([\.|\n]) +u/gm, "$1 U");
  txt.value = txt.value.replace(/([\.|\n]) +v/gm, "$1 V");
  txt.value = txt.value.replace(/([\.|\n]) +w/gm, "$1 W");
  txt.value = txt.value.replace(/([\.|\n]) +x/gm, "$1 X");
  txt.value = txt.value.replace(/([\.|\n]) +y/gm, "$1 Y");
  txt.value = txt.value.replace(/([\.|\n]) +z/gm, "$1 Z");
  document.forms.editform.wpSummary.value+=" Caps";
}
/*
</nowiki> </pre>
==Dewikify dates==
<pre> <nowiki>
*/
function dewikifydates() {
    var txt = document.editform.wpTextbox1;
    // century
    txt.value = txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))[ -](century)\]\]/gi, '$1 century');
    txt.value = txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)[ -]century\|(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)[ -]century\|(\d{1,2}(?:st|nd|rd|th)[ -]century)\]\]/gi, '$1 century');
    txt.value = txt.value.replace(/\[\[\d{1,2}(?:st|nd|rd|th)[ -]century\|(\d{1,2}(?:st|nd|rd|th))[ -](centuries)\]\]/gi, '$1 centuries');

    // decades
    txt.value = txt.value.replace(/\[\[(\d{1,4}s)\]\]/gi, '$1');

    // months
    txt.value = txt.value.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[January\|(Jan)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[February\|(Feb)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[March\|(Mar)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[April\|(Apr)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[May\|(May)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[June\|(Jun)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[July\|(Jul)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[August\|(Aug)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[September\|(Sep)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[October\|(Oct)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[November\|(Nov)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[December\|(Dec)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{3,4})\]\]/gi, '$1');

    // days of the week including optional plurals
    txt.value = txt.value.replace(/\[\[(Mondays?|Tuesdays?|Wednesdays?|Thursdays?|Fridays?|Saturdays?|Sundays?)\]\]/gi, '$1');
    // days of the week but leave out 'Sun' as potentially valid link to the Sun
    txt.value = txt.value.replace(/\[\[(Mon|Tue|Tues|Wed|Thu|Thur|Thurs|Fri|Sat)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Mondays?\|(Mondays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Tuesdays?\|(Tuesdays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Wednesdays?\|(Wednesdays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Thursdays?\|(Thursdays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Fridays?\|(Fridays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Saturdays?\|(Saturdays?)\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[Sundays?\|(Sundays?)\]\]/gi, '$1');

    // ranked days
    txt.value = txt.value.replace(/\[\[(\d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');


    // misconfigured
    txt.value = txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}(?:st|nd|rd|th))\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[(?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}\|(\d{1,2})\]\]/gi, '$1');

    // Month plus year
txt.value = txt.value.replace(/\[\[((?:January|February|March|April|May|June|July|August|September|October|November|December)\s*,*\s* \d\d\d+)\]\]/gi, '$1');

    // year
    //BC etc
    txt.value = txt.value.replace(/\[\[(\d{1,4} (?:AD|BC|CE|BCE))\]\]/gi, '$1');
    txt.value = txt.value.replace(/\[\[\d{1,4} (?:AD|BC|CE|BCE)\|(\d{1,4})\]\]/gi, '$1');
    //4 digits years piped into 2
    txt.value = txt.value.replace(/\[\[\d{1,4}\|(\d{1,2})\]\]/gi, '$1');
 var x=0;
  while (x<3) {x++;  
  //year: text on left, avoid links on right
    txt.value = txt.value.replace(/([\w\(\);:.\*\|\&]\s?,?\-?\s?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
    //year pair: text on left, avoid links on right
    txt.value = txt.value.replace(/([\w\(\);:.\*\|\&]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');

    //year:avoid links on left, text on right
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](\s?,?\-?\s?[\w\(\);:.\*\|\&])/gi, '$1$2$3');
    //year pair: avoid links on left, text on right
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?[\w\(\);:.\*\|\&])/gi, '$1$2$3$4$5');

    //year:avoid links on both sides
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
    //year pair: avoid links on both sides
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');

    //year: last character in link on left is not month or digit, avoid links on right
    txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3');
    //year pair: last character in link on left is not month or digit, avoid links on right
    txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\]([^\[]{4})/gi, '$1$2$3$4$5');

    //year: avoid links on left, first character in link on right is not month or digit
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3');
    //year pair: avoid links on left, first character in link on right is not month or digit
    txt.value = txt.value.replace(/([^\]]{4})\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');

    //year: last character in link on left is not month or digit, first character in link on right is not month or digit
    txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3');
    //year pair: last character in link on left is not month or digit, first character in link on right is not month or digit
    txt.value = txt.value.replace(/([^yhletr\d]\]\]\s?,?\-?\s?)\[\[(\d{1,4})\]\](.?.?.?.?.?.?)\[\[(\d{1,4})\]\](\s?,?\-?\s?\[\[[^jfmasond\d])/gi, '$1$2$3$4$5');
  
  }


    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    var summary = "Date fragments delinked.";
	if (txt.value.indexOf(summary) == -1) {
		if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
			txt.value += " ";
		}
		txt.value += summary;
	}

    // Press the diff button to check it
    document.editform.wpDiff.click()
}

/*
</nowiki> </pre>

==Cardinals==
Up to 99
<pre> <nowiki>
*/
function cardinals(){
  var txt = document.editform.wpTextbox1;
  txt.value = txt.value.replace(/ 10( |\. |\, )/gm, " ten$1");
  txt.value = txt.value.replace(/ 11( |\. |\, )/gm, " eleven$1");
  txt.value = txt.value.replace(/ 12( |\. |\, )/gm, " twelve$1");
  txt.value = txt.value.replace(/ 13( |\. |\, )/gm, " thirteen$1");
  txt.value = txt.value.replace(/ 14( |\. |\, )/gm, " fourteen$1");
  txt.value = txt.value.replace(/ 15( |\. |\, )/gm, " fifteen$1");
  txt.value = txt.value.replace(/ 16( |\. |\, )/gm, " sixteen$1");
  txt.value = txt.value.replace(/ 17( |\. |\, )/gm, " seventeen$1");
  txt.value = txt.value.replace(/ 18( |\. |\, )/gm, " eighteen$1");
  txt.value = txt.value.replace(/ 19( |\. |\, )/gm, " nineteen$1");
  txt.value = txt.value.replace(/ 20( |\. |\, )/gm, " twenty$1");
  txt.value = txt.value.replace(/ 30( |\. |\, )/gm, " thirty$1");
  txt.value = txt.value.replace(/ 40( |\. |\, )/gm, " forty$1");
  txt.value = txt.value.replace(/ 50( |\. |\, )/gm, " fifty$1");
  txt.value = txt.value.replace(/ 60( |\. |\, )/gm, " sixty$1");
  txt.value = txt.value.replace(/ 70( |\. |\, )/gm, " seventy$1");
  txt.value = txt.value.replace(/ 80( |\. |\, )/gm, " eighty$1");
  txt.value = txt.value.replace(/ 90( |\. |\, )/gm, " ninety$1");
  txt.value = txt.value.replace(/ 100( |\. |\, )/gm, " one hundred$1");
  txt.value = txt.value.replace(/ 2(\d)( |\. |\, )/gm, " twenty-$1$2");
  txt.value = txt.value.replace(/ 3(\d)( |\. |\, )/gm, " thirty-$1$2");
  txt.value = txt.value.replace(/ 4(\d)( |\. |\, )/gm, " forty-$1$2");
  txt.value = txt.value.replace(/ 5(\d)( |\. |\, )/gm, " fifty-$1$2");
  txt.value = txt.value.replace(/ 6(\d)( |\. |\, )/gm, " sixty-$1$2");
  txt.value = txt.value.replace(/ 7(\d)( |\. |\, )/gm, " seventy-$1$2");
  txt.value = txt.value.replace(/ 8(\d)( |\. |\, )/gm, " eighty-$1$2");
  txt.value = txt.value.replace(/ 9(\d)( |\. |\, )/gm, " ninety-$1$2");
  txt.value = txt.value.replace(/(-| )1( |\. |\, )/gm, "$1one$2");
  txt.value = txt.value.replace(/(-| )2( |\. |\, )/gm, "$1two$2");
  txt.value = txt.value.replace(/(-| )3( |\. |\, )/gm, "$1three$2");
  txt.value = txt.value.replace(/(-| )4( |\. |\, )/gm, "$1four$2");
  txt.value = txt.value.replace(/(-| )5( |\. |\, )/gm, "$1five$2");
  txt.value = txt.value.replace(/(-| )6( |\. |\, )/gm, "$1six$2");
  txt.value = txt.value.replace(/(-| )7( |\. |\, )/gm, "$1seven$2");
  txt.value = txt.value.replace(/(-| )8( |\. |\, )/gm, "$1eight$2");
  txt.value = txt.value.replace(/(-| )9( |\. |\, )/gm, "$1nine$2");
  document.forms.editform.wpSummary.value += " cardinals";
}
/*
</nowiki> </pre>
==Ordinals==
<pre> <nowiki>
*/
function ordinals(){
  var txt = document.editform.wpTextbox1;

  txt.value = txt.value.replace(/(mid-|early-|late-| )1st/gm, "$1first");
  txt.value = txt.value.replace(/(mid-|early-|late-| )2nd/gm, "$1second");
  txt.value = txt.value.replace(/(mid-|early-|late-| )3rd/gm, "$1third");
  txt.value = txt.value.replace(/(mid-|early-|late-| )4th/gm, "$1fourth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )5th/gm, "$1fifth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )6th/gm, "$1sixth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )7th/gm, "$1seventh");
  txt.value = txt.value.replace(/(mid-|early-|late-| )8th/gm, "$1eighth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )9th/gm, "$1ninth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )10th/gm, "$1tenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )11th/gm, "$1eleventh");
  txt.value = txt.value.replace(/(mid-|early-|late-| )12th/gm, "$1twelfth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )13th/gm, "$1thirteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )14th/gm, "$1fourteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )15th/gm, "$1fifteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )16th/gm, "$1sixteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )17th/gm, "$1seventeenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )18th/gm, "$1eighteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )19th/gm, "$1nineteenth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )20th/gm, "$1twentieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )30th/gm, "$1thirtieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )40th/gm, "$1fortieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )50th/gm, "$1fiftieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )60th/gm, "$1sixtieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )70th/gm, "$1seventieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )80th/gm, "$1eightieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )90th/gm, "$1ninetieth");
  txt.value = txt.value.replace(/(mid-|early-|late-| )2(\d)(st|nd|rd|th)/gm, "$1twenty-$2$3"); 
  txt.value = txt.value.replace(/ 3(\d)(st|nd|rd|th)/gm, " thirty-$1$2");
  txt.value = txt.value.replace(/ 4(\d)(st|nd|rd|th)/gm, " forty-$1$2");
  txt.value = txt.value.replace(/ 5(\d)(st|nd|rd|th)/gm, " fifty-$1$2");
  txt.value = txt.value.replace(/ 6(\d)(st|nd|rd|th)/gm, " sixty-$1$2");
  txt.value = txt.value.replace(/ 7(\d)(st|nd|rd|th)/gm, " seventy-$1$2");
  txt.value = txt.value.replace(/ 8(\d)(st|nd|rd|th)/gm, " eighty-$1$2");
  txt.value = txt.value.replace(/ 9(\d)(st|nd|rd|th)/gm, " ninety-$1$2");
  txt.value = txt.value.replace(/-1st/gm, "-first");
  txt.value = txt.value.replace(/-2nd/gm, "-second");
  txt.value = txt.value.replace(/-3rd/gm, "-third");
  txt.value = txt.value.replace(/-4th/gm, "-fourth");
  txt.value = txt.value.replace(/-5th/gm, "-fifth");
  txt.value = txt.value.replace(/-6th/gm, "-sixth");
  txt.value = txt.value.replace(/-7th/gm, "-seventh");
  txt.value = txt.value.replace(/-8th/gm, "-eighth");
  txt.value = txt.value.replace(/-9th/gm, "-ninth");
  document.forms.editform.wpSummary.value += " ordinals";
}
 
function afdresult(){
    var res = prompt("Result?");
    if(!res) return;
    document.editform.wpSummary.value = 'VFD result - ' + res.replace(/'/g, '');
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '==VFD==\nOn [[DAY MONTH]] [[2005]], this article was nominated for deletion. The result was ' + res + '. See [[Wikipedia:Articles for deletion/{{subst:PAGENAME}}]] for a record of the discussion. &ndash; ~~~~';
    txt.focus();
}

function hideafd(){
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("afd") != -1)
            divs[x].style.display = "none";
    document.getElementById('footer').style.display = 'none';
}

function showafd(){
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("afd") != -1)
            divs[x].style.display = "";
    document.getElementById('footer').style.display = '';
}

function afdlinks(){
    mw.util.addPortletLink( 'p-cactions', 'javascript:hideafd()', 'hide closed', 'ca-hide');
    mw.util.addPortletLink( 'p-cactions', 'javascript:showafd()', 'show closed', 'ca-show');
}

function addPurge(){
	if (!(mw.config.get('wgCanonicalNamespace') == 'Special'))
		mw.util.addPortletLink('p-cactions', mw.config.get('wgServer') + '/w/index.php?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=purge', 'Purge', 'ca-purge', 'Purge server cache for this page.', '0');
}

importScript('Wikipedia:WikiProject User scripts/Scripts/Add edit section 0');

function changeLinks(){
    if(!document.getElementById) return;
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions';
}

function addPreSaveTransform(){
    if(!/&action=edit/.test(window.location.href)) return;
    if(/&section=new/.test(window.location.href)) return;
    if(!document.forms.editform) return;
    document.forms.editform.wpSave.onclick = preSaveTransform;
}

function preSaveTransform(){
    updateSummary()
}

function updateSummary(){
    // Functionality for talk pages only follows:
    if (mw.config.get('wgNamespaceNumber') % 2 == 0) { return true }
    // If we've created a new second level section on a section edit, change the edit summary to reflect this.
    // Also update edit summary if section header changed.
    // Check if it's a section edit.  
    var summary = document.forms.editform.wpSummary.value;
    var old_header = summary.match(/(\/\* (.*) \*\/)/);
    if (!old_header) {return true} // No header in the summary so this wasn't a section edit. 
    // Since we haven't stashed the page, we assume that the last level 2 section is the new one. 
    // Let's load all the level 2 headers from the edit window
    var temp = document.editform.wpTextbox1.value;
    var headerRegex = /^==\s*([^=].*?)\s*==/gm; // Must only match level 2 for now.
    var headers = [...temp.matchAll(headerRegex)];
    if (headers.length == 0) {return true;} // No headers, nothing to do
    if (headers.length == 1 && old_header == 'top') {return true;} // Lets leave it in this case.
    // Grab the last header and use that.
    var editedSectionHeader = headers[headers.length - 1][1];
    summary_text = summary.match(/\/\* .* \*\/(.*)/)[1].trim();
    var new_summary = "/* " + editedSectionHeader + " */";
    if (summary_text) {
  		new_summary += " " + summary_text;
    }
    document.forms.editform.wpSummary.value = "/* " + editedSectionHeader + " */ " + summary_text;
    return true;
}


function afddelete(){
    var form = document.forms.deleteconfirm;
    form.wpReason.value = '[[Wikipedia:Articles for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')) + ']]';
    form.wpConfirm.checked = true;
}
/*
</nowiki> </pre>
==morelinks==
Basically afd results, shortcuts and non-mainspace pst
<pre> <nowiki>
*/
function morelinks(){
/*
    if(document.title.indexOf("Move ") == 0 && document.title.indexOf(" - ") != -1){
         var txt = document.editform.wpTextbox1;

         document.forms.editform.submit();
    }
 */
    if(document.title.indexOf("Editing Wikipedia:Articles for deletion") == 0){
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("keep", "")', 'keep', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'merge', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("redirect", " to [[" + prompt("Redirect to?") + "]]")', 'redir', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("transwiki", " to " + prompt("Transwiki to?"))', 'trans', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("transwiki", " to Wiktionary")', 'wikt', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("speedy delete", "")', 'speedy', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd("delete", "")', 'del', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:closeafd(prompt("Result?"), "")', 'other', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:replace()', 'replace', '');
    }else if(document.title.indexOf("Editing ") == 0){
        mw.util.addPortletLink( 'p-cactions', 'javascript:spelling()', 's', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:replink()', '[', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:normcase()', '.', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:replace()', 'r', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:ordinals()', 'ⁿ', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:cardinals()', '1', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:dewikifydates()', '–', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:bold()', 'b', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:decomma()', ',', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:census()', '2', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:dates()', 'd', 't');
        mw.util.addPortletLink( 'p-cactions', 'javascript:statenames()', '+', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:slashdates()', '/', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:slashdatesm()', 'm/', '');
//        mw.util.addPortletLink( 'p-cactions', 'javascript:math()', 'm', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:british()', 'B', '');
        mw.util.addPortletLink( 'p-cactions', 'javascript:capitals()', 'C', '');
 
        if ( document.title.indexOf("Editing Talk:")          == 0
          || document.title.indexOf("Editing User talk:")     == 0
          || document.title.indexOf("Editing Template:")      == 0
          || document.title.indexOf("Editing Template talk:") == 0
          || document.title.indexOf("Editing Category:")      == 0
          || document.title.indexOf("Editing Category talk:") == 0
          || document.title.indexOf("Editing Wikipedia talk:")== 0
          || document.title.indexOf("Editing File:")          == 0
          || document.title.indexOf("Editing File talk:")     == 0
          || document.title.indexOf("Editing User:")          == 0
          || document.title.indexOf("Editing Mediawiki:")     == 0
          || document.title.indexOf("Editing Mediawiki talk:")== 0
          || document.title.indexOf("Editing Wikipedia:")     == 0
          || document.title.indexOf("Editing Help:")          == 0
          || document.title.indexOf("Editing Help talk:")     == 0
          || document.title.indexOf("Editing Thread:")        == 0
          || document.title.indexOf("Editing Summary:")       == 0
          || document.title.indexOf("Editing Portal:")        == 0
          || document.title.indexOf("Editing Book:")          == 0
          || document.title.indexOf("Editing Thread talk:")   == 0
          || document.title.indexOf("Editing Summary talk:")  == 0
          || document.title.indexOf("Editing Portal talk:")   == 0
          || document.title.indexOf("Editing Book talk:")     == 0
        ){
            quick()
        }
        else  { 
            if(document.title.indexOf("/") == -1){
                if (document.forms.editform.wpSummary.value == msg && insist==1) {document.forms.editform.submit();}
                else if  (document.forms.editform.wpSummary.value != msg)  {always();}
            }
         };
        mw.util.addPortletLink( 'p-cactions', 'javascript:afdresult()', 'afd rst', '');
    }else if(document.title.indexOf("Confirm delete - Delete") == 0){
        mw.util.addPortletLink( 'p-cactions', 'javascript:afddelete()', 'afd', '');
    }
    if(document.title.indexOf("/") == -1){
/*        usermessage plainlinks */        
    }
}

function addToolBoxLinks(){
    mw.util.addPortletLink( 'p-tb', '/wiki/Special:Newpages', 'New pages', '');
    mw.util.addPortletLink( 'p-tb', '/wiki/Special:Shortpages', 'Short pages', '');
}
/*
</nowiki> </pre>
==myLoadFuncs==
<pre> <nowiki>
*/
function myLoadFuncs(){
    addPurge();
    changeLinks();
    addPreSaveTransform();
    if(document.title.indexOf("Wikipedia:Articles for deletion") != -1 && document.title.indexOf("Editing ") != 0) afdlinks();
    morelinks();
    addToolBoxLinks();
    if(document.title.indexOf("Confirm delete - Delete") == 0)
      addVfdLink();
//     document.forms.editform.wpSummary.value= "([[wikt:semi-automatic|SA]] )" +  document.forms.editform.wpSummary.value;
}
/*
</nowiki> </pre>
==main==
<pre> <nowiki>
*/
$.when($.ready,mw.loader.using('mediawiki.util')).then(myLoadFuncs)

/* </nowiki> </pre>*/