User:Gimmetoo/vector.js
Appearance
(Redirected from User:Gimmetoo/monoboook.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin is at User:Gimmetoo/vector.css. |
//<pre><code>
//
importScript('User:Splarka/sysopdectector.js');
importScript('User:Dr_pda/prosesize.js'); // [[User:Dr_pda/prosesize.js]]
importScript('User:Dr_pda/editrefs.js'); // [[User:Dr_pda/editrefs.js]]
//<pre><code>
//
// Based on: User:Trilobite/Tools, User:Omegatron/monobook.js/replacetab.js
function regExp() {
var s = prompt("Search regexp?");
if(s) {
var r = prompt("Replace regexp?");
if(!r && r != '') return;
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(new RegExp(s, "g"), r);
}
}
function soloYears() {
var monthyear = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])\\]\\]", "g");
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/([^,\]] |[^,\] ])\[\[([0-9][0-9][0-9][0-9])\]\]/g, "$1$2");
txt.value = txt.value.replace(monthyear, "$1 $2");
//var summary = document.editform.wpSummary;
//summary.value = summary.value + " [[MOS:DATE]] ";
}
function emptyParm() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\|[\n]*[ ]*[a-zA-Z][a-zA-Z0-9_ ]*=[ ]*[\n]*[ ]*\|/g, "|");
txt.value = txt.value.replace(/\|[\n]*[ ]*[a-zA-Z][a-zA-Z0-9_ ]*=[ ]*[\n]*[ ]*}}/g, "}}");
}
function unspRefs() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/(<ref[^>/]*>)[ ]*/g, "$1");
txt.value = txt.value.replace(/(<ref[^>]*\/>)[ ]*([A-Za-z0-9[\(])/g, "$1 $2");
txt.value = txt.value.replace(/[ ]*<\/ref>[ ]*([A-Za-z0-9[\(])/g, "</ref> $1");
txt.value = txt.value.replace(/(<ref[^>]*\/>)[ ]*([\n\]\)])/g, "$1$2");
txt.value = txt.value.replace(/[ ]*<\/ref>[ ]*([\n\]\)])/g, "</ref>$1");
txt.value = txt.value.replace(/\{\{[ ]*/g, "{{");
txt.value = txt.value.replace(/[ ]*}}/g, "}}");
txt.value = txt.value.replace(/\[\[ ?([^\]\|]*?) ?\]\]/g, "[[$1]]"); // space in links
txt.value = txt.value.replace(/\[\[ ?([^\]\|]*?) ?\| ?([^\] ][^\]]*?) ?\]\]/g, "[[$1|$2]]");
txt.value = txt.value //whitespace
.replace(/\t/g, " ")
.replace(/^ ? ? \n/gm, "\n")
.replace(/(\n\n)\n+/g, "$1")
.replace(/== ? ?\n\n==/g, "==\n==")
.replace(/\n\n(\* ?\[?http)/g, "\n$1")
.replace(/^ ? ? \n/gm, "\n")
.replace(/\n\n\*/g, "\n*")
.replace(/[ \t][ \t]+([^= ])/g, " $1") // .replace(/[ \t][ \t]+/g, " ")
.replace(/([=\n]\n)\n+/g, "$1")
.replace(/ \n/g, "\n") //ending sections
.replace(/[ ]+,/g, ",") //before commas
.replace(/([^\.])[ ]+\. ([^\.])/g, "$1. $2"); //before periods, avoid spaced ellipsis
//.replace(/,/g, ", ") //after commas
}
function fixHTML() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value //whitespace
.replace(/\t/g, " ")
.replace(/^ ? ? \n/gm, "\n")
.replace(/(\n\n)\n+/g, "$1")
.replace(/== ? ?\n\n==/g, "==\n==")
.replace(/\n\n(\* ?\[?http)/g, "\n$1")
.replace(/^ ? ? \n/gm, "\n")
.replace(/\n\n\*/g, "\n*")
.replace(/[ \t][ \t]+([^= ])/g, " $1") // .replace(/[ \t][ \t]+/g, " ")
.replace(/([=\n]\n)\n+/g, "$1")
.replace(/ \n/g, "\n") //ending sections
//spacing, XHTML
//.replace(/<([bh])r\s*\/?\s*>/gi, '<$1r />')
//.replace(/<br\s*\/?\s*>/gi, '<br />')
//.replace(/<hr\s*\/?\s*>/gi, '<hr />')
.replace(/<br\s*\/?\s*>/gi, '<br>')
.replace(/<hr\s*\/?\s*>/gi, '<hr>')
.replace(/<ref/gi, '<ref')
.replace(/<\/ref>/gi, '</ref>')
.replace(/<references\s*\/?\s*>/gi, '<references />')
.replace(/<(\/?)TABLE/g, '<$1table')
.replace(/<(\/?)DIV/g, '<$1div')
.replace(/<(\/?)SPAN/g, '<$1span')
//repair bad internal links
// problems: .replace(/([^\[]|^)\[?\[([^\]]*?)\]\]?([^\]]|$)/gm, "$1[[$2]]$3")
// problem w/cats: .replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]")
.replace(/\[\[ ?([^\]\|]*?) ?\]\]/g, "[[$1]]")
.replace(/\[\[ ?([^\]\|]*?) ?\| ?([^\] ][^\]]*?) ?\]\]/g, "[[$1|$2]]")
.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]")
//.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4")
.replace(/\[\[([^\]\|]+)\|([^\]\|]*[^\]\|\'])\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4")
//repair bad external links
.replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]")
.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]")
// and https:
.replace(/\[?\[https:\/\/([^\]]*?)\]\]?/gi, "[https://$1]")
.replace(/\[https:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[https://$1 $2]")
.replace(/\[http:\/\/en\.wikipedia\.org\/wiki\/([^ ]*) ([^\]]*)\]/gi, "[[$1]]");
}
function formTemp() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/[ ]*\|[ ]*\n/g, "\n|");
txt.value = txt.value.replace(/\n\|[ ]*/g, "\n|");
}
function formTem2() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\n[ ]*\|[ ]*([^-\|\}])/g, "\n| $1");
}
function defSort() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/(\[Category:[^\|]*)\|[^ \]][^\]]*\]/g, "$1]");
}
function unSmart() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/[”“]/g, '"').replace(/[‘’]/g, "'");
}
// function spPuncs() {
// var txt = document.editform.wpTextbox1;
// txt.value = txt.value.replace(/,[ ]*/g, ", ").replace(/\.[ ]*([A-Z])/g, ". $1");
// txt.value = txt.value.replace(/, ([\n\)\]])/g, ",$1").replace(/\. ([\n\)\]])/g, ".$1");
// txt.value = txt.value.replace(/\. JPG/g, ".JPG").replace(/\. GIF/g, ".GIF").replace(/\. SVG/g, ".SVG");
// }
function staCombo() {
soloYears();
//emptyParm();
unspRefs();
fixHTML();
unSmart()
}
function mosdate() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value
//MOSDATE remove th in dates followed by -th, others
//.replace(/([^\[])(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1[[$2 $3]]')
.replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1 $2')
.replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)\]\](<sup>)?(th|st|nd|rd)(<\/sup>)?/gi, '[[$1 $2]]')
.replace(/(\D\d\d?)(<sup>)?(th|st|nd|rd)(<\/sup>)?\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$1 $5')
.replace(/\s(\d{3}0)'s(\W)/gi, ' $1s$2')
.replace(/the\s(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2')
.replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2')
.replace(/the\s(\d\d?)(th|st|nd|rd)\sof\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$3 $1')
.replace(/(\d\dth\s)Century/g, '$1century')
.replace(/20th century([ -])(Fox|Pictures|Limited|Film|Frog)/g, '20th Century$1$2');
}
function accessISO(option) {
var txt = document.editform.wpTextbox1;
var atg = "(\\|[ ]*accessdate[ ]*=[ ]*|[Aa]ccessed |[Aa]ccessed on |[Rr]etrieved |[Rr]etrieved on )[ ]*";
// atg = "(\\|[ ]*accessdate[ ]*=[ ]*)";
if (option == 1) { atg = "(\\|[ ]*archivedate[ ]*=[ ]*)"; }
if (option == 2) { atg = "(\\|[ ]*date[ ]*=[ ]*)"; }
if (option == 9) { atg = "(.)"; }
var btg = "";
var dig = "";
for (var opt=1; opt<13; opt++)
{
dig = "0" + opt;
if (opt== 1) { btg = "(January|Jan\\.|Jan)"; }
if (opt== 2) { btg = "(February|Feb\\.|Feb)"; }
if (opt== 3) { btg = "(March|Mar\\.|Mar)"; }
if (opt== 4) { btg = "(April|Apr\\.|Apr)"; }
if (opt== 5) { btg = "(May|May\\.)"; }
if (opt== 6) { btg = "(June|Jun\\.|Jun)"; }
if (opt== 7) { btg = "(July|Jul\\.|Jul)"; }
if (opt== 8) { btg = "(August|Aug\\.|Aug)"; }
if (opt== 9) { btg = "(September|Sep\\.|Sep|Sept\\.|Sept)"; }
if (opt==10) { btg = "(October|Oct\\.|Oct)"; dig = "10";}
if (opt==11) { btg = "(November|Nov\\.|Nov)"; dig = "11";}
if (opt==12) { btg = "(December|Dec\\.|Dec)"; dig = "12";}
txt.value = txt.value.replace(/[Rr]etrieved on/g, 'Retrieved');
txt.value = txt.value
.replace(new RegExp(atg+"([1-3][0-9]) "+btg+",? *([1-2][0-9][0-9][0-9])", "g"), "$1$4-"+dig+"-$2")
.replace(new RegExp(atg+btg+ " ([1-3][0-9]),? *([1-2][0-9][0-9][0-9])", "g"), "$1$4-"+dig+"-$3")
.replace(new RegExp(atg+ "0?([0-9]) "+btg+",? *([1-2][0-9][0-9][0-9])", "g"), "$1$4-"+dig+"-0$2")
.replace(new RegExp(atg+btg+ " 0?([0-9]),? *([1-2][0-9][0-9][0-9])", "g"), "$1$4-"+dig+"-0$3");
}
}
function ISOtodmy() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");
txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9])\]\]-\[\[([0-1][0-9]-[0-3][0-9])\]\]/g, "$1-$2");
//txt.value = txt.value.replace(/accesse?date[ ]*=[ ]*/gi, "QQQaccessdateQQQ"); // avoid, but fix a quirk
//txt.value = txt.value.replace(/accessed[ ]+/g, "QQQaccessedQQQ"); // avoid
//txt.value = txt.value.replace(/Accessed[ ]+/g, "QQQAccessedQQQ"); // avoid
txt.value = txt.value
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z])/g, "$1$3 January $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z])/g, "$1$3 February $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z])/g, "$1$3 March $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z])/g, "$1$3 April $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z])/g, "$1$3 May $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z])/g, "$1$3 June $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z])/g, "$1$3 July $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z])/g, "$1$3 August $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z])/g, "$1$3 September $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z])/g, "$1$3 October $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z])/g, "$1$3 November $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z])/g, "$1$3 December $2$4");
txt.value = txt.value
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 January $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 February $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 March $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 April $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 May $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 June $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 July $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 August $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 September $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 October $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 November $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 December $2$4");
//txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
//txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
//txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}
function ISOtomdy() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");
txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9])\]\]-\[\[([0-1][0-9]-[0-3][0-9])\]\]/g, "$1-$2");
//txt.value = txt.value.replace(/accesse?date[ ]*=[ ]*/gi, "QQQaccessdateQQQ"); // avoid, but fix a quirk
//txt.value = txt.value.replace(/accessed[ ]+/g, "QQQaccessedQQQ"); // avoid
//txt.value = txt.value.replace(/Accessed[ ]+/g, "QQQAccessedQQQ"); // avoid
txt.value = txt.value
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z])/g, "$1 January $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z])/g, "$1February $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z])/g, "$1March $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z])/g, "$1April $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z])/g, "$1May $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z])/g, "$1June $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z])/g, "$1July $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z])/g, "$1August $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z])/g, "$1September $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z])/g, "$1October $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z])/g, "$1November $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z])/g, "$1December $3, $2$4");
txt.value = txt.value
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z])/g, "$1January $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z])/g, "$1February $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z])/g, "$1March $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z])/g, "$1April $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z])/g, "$1May $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z])/g, "$1June $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z])/g, "$1July $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z])/g, "$1August $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z])/g, "$1September $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z])/g, "$1October $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z])/g, "$1November $3, $2$4")
.replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z])/g, "$1December $3, $2$4");
//txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
//txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
//txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}
function riskyISO() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");
txt.value = txt.value
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 January $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 February $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 March $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 April $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 May $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 June $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 July $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 August $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 September $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 October $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 November $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 December $2$4");
txt.value = txt.value
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 January $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 February $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 March $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 April $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 May $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 June $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 July $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 August $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 September $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 October $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 November $2$4")
.replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 December $2$4");
//txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
//txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
//txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}
function yearinX() {
var monthyear = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])\\]\\]", "g");
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/\[\[[1-2][0-9][0-9][0-9] in [A-Za-z ]+\|([1-2][0-9][0-9][0-9])\]\]/g, "[[$1]]");
txt.value = txt.value.replace(/([^,\]] |[^,\] ])\[\[([1-2][0-9][0-9][0-9])\]\]/g, "$1$2");
txt.value = txt.value.replace(monthyear, "$1 $2");
}
function dayMonth(option) {
var daymonth = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
var daymonth2 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g");
var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\]", "g");
var txt = document.editform.wpTextbox1;
if (option == 1) {
// dd Month
txt.value = txt.value.replace(monthday , "[[$2 $1]] [[$3]]");
txt.value = txt.value.replace(daymonth , "[[$1 $2]] [[$3]]");
txt.value = txt.value.replace(monthday2, "[[$2 $1]]");
txt.value = txt.value.replace(daymonth2, "[[$1 $2]]");
} else {
// Month dd
txt.value = txt.value.replace(monthday , "[[$1 $2]], [[$3]]");
txt.value = txt.value.replace(daymonth , "[[$2 $1]], [[$3]]");
txt.value = txt.value.replace(monthday2, "[[$1 $2]]");
txt.value = txt.value.replace(daymonth2, "[[$2 $1]]");
}
}
function addDLinks() {
var daymonth = new RegExp("([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])", "g");
var monthday = new RegExp("(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9]),? *([0-9][0-9][0-9][0-9])", "g");
var daymonth2 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *([0-9][0-9][0-9][0-9])", "g");
var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *([0-9][0-9][0-9][0-9])", "g");
var daymonth3 = new RegExp("([^0-9\[])([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)([^0-9\\]])", "g");
var monthday3 = new RegExp("([^0-9\[])(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])([^0-9\\]])", "g");
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(monthday, "[[$1 $2]], [[$3]]");
txt.value = txt.value.replace(daymonth, "[[$1 $2]] [[$3]]");
txt.value = txt.value.replace(monthday2, "[[$1 $2]], [[$3]]");
txt.value = txt.value.replace(daymonth2, "[[$1 $2]] [[$3]]");
txt.value = txt.value.replace(monthday3, "$1[[$2 $3]]$4");
txt.value = txt.value.replace(daymonth3, "$1[[$2 $3]]$4");
}
function remDLinks() {
var daymonth = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
var daymonth3 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g");
var monthday3 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\]", "g");
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(monthday, "$1 $2, $3");
txt.value = txt.value.replace(daymonth, "$1 $2 $3");
txt.value = txt.value.replace(monthday3, "$1 $2");
txt.value = txt.value.replace(daymonth3, "$1 $2");
}
function wards() {
var txt = document.editform.wpTextbox1;
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Dd][Dd][Ff][Ff][Dd][Dd]; ?vertical-align: ?middle;?"[ ]*\|[ ]*([^\n]*)/g, "{{won|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Ff][Ff][Dd][Dd][Dd][Dd]; ?vertical-align: ?middle;?"[ ]*\|[ ]*([^\n]*)/g, "{{nom|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Dd][Dd][Ff][Ff][Dd][Dd];?"[ ]*\|[ ]*([^\n]*)/g, "{{won|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Ff][Ff][Dd][Dd][Dd][Dd];?"[ ]*\|[ ]*([^\n]*)/g, "{{nom|$1}}");
txt.value = txt.value.replace(/align="center" style="background: ?#[Dd][Dd][Ff][Ff][Dd][Dd];?"[ ]*\|[ ']*Won[']*/g, "{{won}}");
txt.value = txt.value.replace(/align="center" style="background: ?#[Ff][Ff][Dd][Dd][Dd][Dd];?"[ ]*\|[ ]*Nominated/g, "{{nom}}");
txt.value = txt.value.replace(/style="background: ?#[Dd][Dd][Ff][Ff][Dd][Dd];?"[ ]*\|[ ']*Won[']*/g, "{{won}}");
txt.value = txt.value.replace(/style="background: ?#[Ff][Ff][Dd][Dd][Dd][Dd];?"[ ]*\|[ ]*Nominated/g, "{{nom}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Dd][Ff][Dd]; ?vertical-align: ?middle;?"[ ]*\|[ ]*([^\n]*)/g, "{{won|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Ff][Dd][Dd]; ?vertical-align: ?middle;?"[ ]*\|[ ]*([^\n]*)/g, "{{nom|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Dd][Ff][Dd];?"[ ]*\|[ ]*([^\n]*)/g, "{{won|$1}}");
txt.value = txt.value.replace(/style="text-align: ?center; ?background: ?#[Ff][Dd][Dd];?"[ ]*\|[ ]*([^\n]*)/g, "{{nom|$1}}");
txt.value = txt.value.replace(/align="center" style="background: ?#[Dd][Ff][Dd];?"[ ]*\|[ ']*Won[']*/g, "{{won}}");
txt.value = txt.value.replace(/align="center" style="background: ?#[Ff][Dd][Dd];?"[ ]*\|[ ]*Nominated/g, "{{nom}}");
txt.value = txt.value.replace(/style="background: ?#[Dd][Ff][Dd];?"[ ]*\|[ ']*Won[']*/g, "{{won}}");
txt.value = txt.value.replace(/style="background: ?#[Ff][Dd][Dd];?"[ ]*\|[ ]*Nominated/g, "{{nom}}");
}
function fixRefMarks() {
var qt = String.fromCharCode(34)
// var hb = String.fromCharCode(124)
var txt = document.editform.wpTextbox1;
// fact and other templates (geographic reference template, ref/note)
var FactTag = "({{[ ]*fact[ ]*}}|{{[ ]*fact[ ]*[\|][^}]*}}|{{[ ]*facts[ ]*}}|{{[ ]*citequote[ ]*}}|{{[ ]*citation needed[ ]*}}|{{[ ]*citation needed[ ]*[\|][^}]*}}|{{[ ]*cn[ ]*}}|{{[ ]*verification needed[ ]*}}|{{[ ]*verify source[ ]*}}|{{[ ]*verify credibility[ ]*}}|{{[ ]*who[ ]*}}|{{[ ]*failed verification[ ]*}}|{{[ ]*nonspecific[ ]*}}|{{[ ]*dubious[ ]*}}|{{[ ]*or[ ]*}}|{{[ ]*lopsided[ ]*}}|{{[ ]*GR[ ]*[\|][ ]*[^ ]+[ ]*}}|{{[ ]*[c]?r[e]?f[ ]*[\|][^}]*}}|{{[ ]*ref[ _]label[ ]*[\|][^}]*}}|{{[ ]*ref[ _]num[ ]*[\|][^}]*}})";
txt.value = txt.value
.replace(new RegExp("[\n\r\f\t ]+?"+FactTag, "gi"), "$1")
// one+ space/linefeed, avoid matching references tag as a named ref
.replace(new RegExp("[\n\r\f\t ]+?<ref([ >])", "gi"), "<ref$1")
// remove trailing spaces from named refs
.replace(new RegExp("<ref ([^>]*[^> ])[ ]*>", "gi"), "<ref $1>")
// remove some superscripted punctuation between refs (is between necessary?)
.replace(new RegExp("(</ref>|<ref[^>]*?/>)<sup>[ ]*[,;-]?[ ]*</sup><ref", "gi"), "$1<ref")
.replace(new RegExp("(</ref>|<ref[^>]*?/>)[ ]*[,;-]?[ ]*<ref", "gi"), "$1<ref")
.replace(new RegExp("(</ref>|<ref[^>]*?/>)[ \n\r\f\t]*([\.,])", "gi"), "$1$2");
var LacksPunctuation = "([^\.,;:!\?"+qt+"'’])";
var QuestionOrExclam = "([!\?])";
var MinorPunctuation = "([\.,;:])";
var Blockquote = "(</blockquote>)";
var Quote = "([" + qt + "'’]*)";
//var Space = "[\n\r\f\t ]*"; // to handle http://wiki.riteme.site/w/index.php?title=Cat&diff=99697351&oldid=99697026
var Space = "[ ]*";
var Space2 = "[\n\r\f\t ]*";
var AnyPunctuation = "([\.,;:!\?])";
var MajorPunctuation = "([,;:!\?])";
var Period = "([\.])";
// can this complicated close tag be simplified?
//var closetag = "(([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?)</ref>";
//var closetag = "((.*?))</ref>";
var RefTag1 = "(<ref>([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?</ref>)";
var RefTag2 = "(<ref[^>]*?[^/]>([^<]|<[^/]|</[^r]|</r[^e]|</re[^f]|</ref[^>])*?</ref>)";
var RefTag3 = "(<ref[^>]*?/>)";
//var Note = "("+RefTag1 + "|(" + RefTag2 + ")|(" + FactTag + "))";
var match0a = LacksPunctuation+Quote+FactTag+Space+AnyPunctuation;
var match0b = QuestionOrExclam+Quote+FactTag+Space+MajorPunctuation;
var match0c = MinorPunctuation+Quote+FactTag+Space+AnyPunctuation;
var match0d = QuestionOrExclam+Quote+FactTag+Space+Period;
var match1a = LacksPunctuation+Quote+RefTag1+Space+AnyPunctuation;
var match1b = QuestionOrExclam+Quote+RefTag1+Space+MajorPunctuation;
var match1c = MinorPunctuation+Quote+RefTag1+Space+AnyPunctuation;
var match1d = QuestionOrExclam+Quote+RefTag1+Space+Period;
var match2a = LacksPunctuation+Quote+RefTag2+Space+AnyPunctuation;
var match2b = QuestionOrExclam+Quote+RefTag2+Space+MajorPunctuation;
var match2c = MinorPunctuation+Quote+RefTag2+Space+AnyPunctuation;
var match2d = QuestionOrExclam+Quote+RefTag2+Space+Period;
var match3a = LacksPunctuation+Quote+RefTag3+Space+AnyPunctuation;
var match3b = QuestionOrExclam+Quote+RefTag3+Space+MajorPunctuation;
var match3c = MinorPunctuation+Quote+RefTag3+Space+AnyPunctuation;
var match3d = QuestionOrExclam+Quote+RefTag3+Space+Period;
for (var j=0; j<5; j++) // repeat for multiple refs together
{
txt.value = txt.value
.replace(new RegExp(match0a, "gi"), "$1$2$4$3")
.replace(new RegExp(match0b, "gi"), "$1$2$4$3")
.replace(new RegExp(match0c, "gi"), "$2$4$3")
.replace(new RegExp(match0d, "gi"), "$1$2$3")
.replace(new RegExp(match1a, "gi"), "$1$2$5$3")
.replace(new RegExp(match1b, "gi"), "$1$2$5$3")
.replace(new RegExp(match1c, "gi"), "$2$5$3")
.replace(new RegExp(match1d, "gi"), "$1$2$3")
.replace(new RegExp(match2a, "gi"), "$1$2$5$3")
.replace(new RegExp(match2b, "gi"), "$1$2$5$3")
.replace(new RegExp(match2c, "gi"), "$2$5$3")
.replace(new RegExp(match2d, "gi"), "$1$2$3")
.replace(new RegExp(match3a, "gi"), "$1$2$4$3")
.replace(new RegExp(match3b, "gi"), "$1$2$4$3")
.replace(new RegExp(match3c, "gi"), "$2$4$3")
.replace(new RegExp(match3d, "gi"), "$1$2$3");
}
// blockquotes (if trapped punctuation exists, remove it, and move blockquote past at least one ref)
txt.value = txt.value
.replace(new RegExp(Blockquote + AnyPunctuation + FactTag, "gi"), "$3$1")
.replace(new RegExp(Blockquote + AnyPunctuation + RefTag1, "gi"), "$3$1")
.replace(new RegExp(Blockquote + AnyPunctuation + RefTag2, "gi"), "$3$1")
.replace(new RegExp(Blockquote + AnyPunctuation + RefTag3, "gi"), "$3$1")
.replace(new RegExp(Blockquote + FactTag, "gi"), "$2$1")
.replace(new RegExp(Blockquote + RefTag1, "gi"), "$2$1")
.replace(new RegExp(Blockquote + RefTag2, "gi"), "$2$1")
.replace(new RegExp(Blockquote + RefTag3, "gi"), "$2$1");
var summary = document.editform.wpSummary;
//summary.value = summary.value + " various minor fixes ";
}
$(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:regExp()' , 'Regexp replace' , 't-regexp', 'Regexp replace', '', '');
mw.util.addPortletLink('p-tb', 'javascript:fixRefMarks()', 'Fix reference marks', 't-reffix', 'Ref fix', '', '');
mw.util.addPortletLink('p-tb', 'javascript:mosdate()' , 'Format mosdate ', 't-mosdate', 'Regexp mosdate', '', '');
mw.util.addPortletLink('p-tb', 'javascript:ISOtodmy()' , 'Format ISO->dmy ', 't-ISOtodmy', 'Regexp ISOtodmy', '', '');
mw.util.addPortletLink('p-tb', 'javascript:ISOtomdy()' , 'Format ISO->mdy ', 't-ISOtomdy', 'Regexp ISOtomdy', '', '');
mw.util.addPortletLink('p-tb', 'javascript:accessISO(0)', 'Format acd->ISO ', 't-acdtoISO', 'Regexp acdtoISO', '', '');
mw.util.addPortletLink('p-tb', 'javascript:accessISO(1)', '+Format arc->ISO ', 't-arctoISO', 'Regexp arctoISO', '', '');
mw.util.addPortletLink('p-tb', 'javascript:accessISO(2)', '+Format dat->ISO ', 't-dattoISO', 'Regexp dattoISO', '', '');
mw.util.addPortletLink('p-tb', 'javascript:accessISO(9)', '+Format all->ISO ', 't-alltoISO', 'Regexp alltoISO', '', '');
mw.util.addPortletLink('p-tb', 'javascript:riskyISO()' , 'Format riskyISO ', 't-riskyISO', 'Regexp riskyISO', '', '');
mw.util.addPortletLink('p-tb', 'javascript:yearinX()' , 'Format -year in X', 't-yearinX', 'Regexp yearinX', '', '');
mw.util.addPortletLink('p-tb', 'javascript:addDLinks()', 'Format +datelinks', 't-addlinks', 'Regexp links', '', '');
mw.util.addPortletLink('p-tb', 'javascript:dayMonth(1)', '=Format \[\[DMY]]', 't-daymonth', 'Regexp day month', '', '');
mw.util.addPortletLink('p-tb', 'javascript:dayMonth(2)', '=Format \[\[MDY]]', 't-monthday', 'Regexp month day', '', '');
mw.util.addPortletLink('p-tb', 'javascript:remDLinks()', 'Format -datelinks', 't-remlinks', 'Regexp links', '', '');
mw.util.addPortletLink('p-tb', 'javascript:wards()' , 'Awards' , 't-awards','Regexp awards', '', '');
mw.util.addPortletLink('p-tb', 'javascript:staCombo()' , 'DeusXL' , 't-staCombo', 'Regexp combo', '', '');
mw.util.addPortletLink('p-tb', 'javascript:soloYears()', '+DElink \[\[Year]]', 't-solo', 'Regexp years', '', '');
mw.util.addPortletLink('p-tb', 'javascript:unSmart()' , '+Unsmartquote' , 't-unsmart', 'Regexp unsmart quote', '', '');
mw.util.addPortletLink('p-tb', 'javascript:unspRefs()' , '+Space cites' , 't-unspRefs', 'Regexp unspace refs', '', '');
mw.util.addPortletLink('p-tb', 'javascript:fixHTML()' , '+XHTML/Links' , 't-fixHTML', 'Regexp HTML/spacing', '', '');
// mw.util.addPortletLink('p-tb', 'javascript:spPuncs()' , 'Space puncts.' , 't-spPuncs', 'Regexp space puncs', '', '');
mw.util.addPortletLink('p-tb', 'javascript:emptyParm()', 'Empty params' , 't-emptyParm','Regexp unused params', '', '');
mw.util.addPortletLink('p-tb', 'javascript:formTemp()' , 'Format |template' , 't-formTemp', 'Regexp format temp', '', '');
mw.util.addPortletLink('p-tb', 'javascript:formTem2()' , 'Format | template', 't-formTem2', 'Regexp format tem2', '', '');
mw.util.addPortletLink('p-tb', 'javascript:defSort()' , 'Defsort clear' , 't-defsort', 'Regexp defsort', '', '');
}
});
//</code></pre>