User:Smalleditor/test.js

/************* mw.loader.load('https://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript'); function Ohc_formatgeneral { var	txt=document.editform.wpTextbox1;
 * regex menu framework
 * by m:user:Pathoschild 
 * - adds a sidebar menu of user-defined scripts.

//superscripted ordinals regex(/\[\[[\w]*_\d{4}#\d{4}_[\w]*_\d\d?\|(Jan(?:uary|\.|)|Feb(?:ruary|\.|)|Mar(?:ch|\.|)|Apr(?:il|\.|)|May\.?|Jun(?:e|\.|)|Jul(?:y|\.|)|Aug(?:ust|\.|)|Sep(?:tember|\.|t\.|)|Oct(?:ober|\.|)|Nov(?:ember|\.|)|Dec(?:ember|\.|))( \d\d?)\]\]/g, '$1$2');	regex(/(\d) (th|st|nd|rd)<\/sup>/gi, '$1$2');	regex(/(\d) (th|st|nd|rd)<\/small>/gi, '$1$2');

//rem linking within section headings regex(/(==[ ]{0,1})\[\[([^\|\]]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3'); regex(/(==[ ]{0,1})\[\[(?:[^\|\]]+?\|)([\w\s\,]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3');

//rem empty parameters // 	regex(/\|[\n]*[ ]*[a-zA-Z][a-z0-9_ ]*=[ ]*[\n]?[ ]*(?=[\|\}])/g, "");

//improper capitalisation within section headings regex(/(==[ ]*External )(Links)(?=[ ]*=)/g, '$1links'); regex(/(==[ ]*See )(Also)(?=[ ]*=)/g, '$1also'); regex(/(==[ ]*)Notable ([A-Z]\w*?)/g, '$1$2'); regex(/(==[ ]*[\w]+? and )A(wards?|chievements?)(?=[ ]*=)/g, '$1a$2'); regex(/(==[ ]*[\w\s]+? )C(areer|hampionships?|ompositions)(?=[ ]*=)/g, '$1c$2'); regex(/(==[ ]*[\w\s]+? )E(ducation)(?=[ ]*=)/g, '$1e$2'); regex(/(st|nd|rd|th) G(rade)(?=[ ]*=)/g, '$1 g$2'); regex(/(==[ ]*[\w\s]+? )G(roup)(?=[ ]*=)/g, '$1g$2'); regex(/(==[ ]*[\w\s]+? )H(istory|onou?rs)(?=[ ]*=)/g, '$1h$2'); regex(/(==[ ]*[\w\s]+? )L(ife)(?=[ ]*=)/g, '$1l$2'); regex(/(==[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)(?=[ ]*=)/g, '$1q$2'); regex(/(==[ ]*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )R(ound)(?=[ ]*=)/g, '$1r$2'); regex(/(==[ ]*(?:CFL|N[BFH]L) )C(oaching )[Rr](ecords?)(?=[ ]*=)/g, '$1c$2r$3'); regex(/(==[ ]*[\w\s]+? )R(ankings?|esults?|ecords?|ecognition)(?=[ ]*=)/g, '$1r$2'); regex(/(==[ ]*[\w\s]+? )S(eason|tyle|tage|tatistics)(?=[ ]*=)/g, '$1s$2'); regex(/(==[ ]*[\w\s]+? )T(ournaments?)(?=[ ]*=)/g, '$1t$2'); regex(/(==[ ]*[\w\s]+? )Y(ears)(?=[ ]*=)/g, '$1y$2');

regex(/(==[ ]*Exhibition )Schedule(?=[ ]*=)/g, '$1schedule'); regex(/(==[ ]*Regular )Season Schedule(?=[ ]*=)/g, '$1season schedule'); regex(/(==[ ]*Terminated )(Destinations)(?=[ ]*=)/g, '$1destinations'); regex(/(==[ ]*Heraldic )(Items)(?=[ ]*=)/g, '$1items'); regex(/(==[ ]*Campaign )(Credits)(?=[ ]*=)/g, '$1credits'); regex(/(==[ ]*Combat )(Chronicle)(?=[ ]*=)/g, '$1chronicle'); //other improper capitalisation //	regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, '$1c$2'); //transferring to MOSNUM script //	regex(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ -]*(?:Fox|[A-Z]\w*))/g, '$1c$2'); regex(/(\s*(?:First|Second|Third|Fourth|[1-4](?:st|nd|rd|th)) )Q(uarter)(?=[ ]*)/g, '$1q$2'); regex(/(\s*(?:First|Second|Third|Fourth|\d(?:st|nd|rd|th)) )R(ound)(?=[ ]*)/g, '$1r$2'); regex(/\[\[(file|image):/g, '[[File:');

//remove flagicons from birth and death regex(/((?:birth|death)(?:_?place|)\s*=\s*)\{\{flagicon\|([^\}]+)\}\}/gi, '$1'); regex(/((?:nationality|residence)\s*=\s*)\{\{flag(?:country|icon|)\|([^\}]+)\}\}/gi, '$1');

//remove scroll bar for reflists regex(/(References ?==\n)[\n\s]*(?:]*)>([^<]*)<\/div>/g, '$1$2'); regex(/(References ?={1,4}\n)[\n\s]*(?:\{\{[Rr]eflist\}\}|<[Rr]eferences ?\/>)/g, '$1');

//rem redundant spaces underlining and punctuation regex(/′s/g, '\'s');		// replace prime symbol with straight apostrophe regex(/[ ]{1,3}(<\s?ref(?:>| >| n))/gi, '$1'); regex(/([\w\d\,\.\]\)>] )[ ]+([\[\w\d\(])/gi, '$1 $2'); regex(/(U\.)[ ]+((?:S|K)\.)/gi, '$1$2'); //U. S. and U. K. to U.S. and U.K.	regex(/(<\/?ref(?: name=[^\>\/]*?|)\/?>)[ ,\.]*(<\s?ref)/gi, '$1$2');

//rem bolding from linked AND bolded terms //	regex(/(\[\[)([^\|\]]+?\||)([^\]]+?\]\][:-–]?)/g, '$1$2$3');

//rem linked copyright symbol regex(/(\[\[copyright\|©\]\] |©)/g, '');

//rem leading and lagging spaces within wikilinks regex(/(\[\[)\s+([^\[\]]*?\]\])/g, '$1$2'); regex(/(\[\]*?)\s+(\]\])/g, '$1$2');	regex(/(\[\[[^\[\]\|]*?\s)\s+([^\[\*?\]\])/g, '$1$2');	regex(/(\[\]*?)\s(\|[^\[\*?\]\])/g, '$1$2');	regex(/(\[\]*?\|)\s([^\[\+?\]\])/g, '$1$2');

//symbol for 'times' and dashes regex(/&times;/gi, '×'); regex(/([ \.][\d]+)x([\d]+(?:\.[\d]+|)\s)/gi, '$1 × $2'); regex(/(\d) x (\d)/gi, '$1 × $2'); //	regex(/–/gi, '–'); //	regex(/([^<][^!] *)--( *[^>])/gi, '$1–$2'); //disabling - causes false positives with urls and some images regex(/&mdash;/gi, '—'); regex(/([\w\d]) — (?=[\w\d])/gi, '$1 – ');		// tweak to avoid replacing emdashes in strings that are in non-roman unicode characters

regex(/(\[\[\d{4})-(\d{2} in [\w ]*football\|)/gi, '$1–$2'); regex(/(\[\[\d{4})-(\d{2} [A-Z]* season\|)/gi, '$1–$2');

//add missing space between wikilinks regex(/(\]\])(\[\[)(?!file:)/gi, '$1 $2');

//hash fixes regex(/([^=] )#(\d{1,3},?\s)/g, '$1No. $2');

//full stop and nbsp fixes //protection for strings within wikilinks regex(/(\[(?:[^\|\]]*)\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})([ ]*(?:[cgkm])[^\|\]]*?[\|\]])/gi, '$1♭$2'); regex(/(\[(?:[^\|\]]*)(?:\d?\d[:\.]\d?\d| \d?\d))([ ]*(?:[ap]\.m\.|[ap]m)[^\|\]]*?[\|\]])/gi, '$1♭$2');

regex(/(Ph)(?:\.\s?|\s)(D)\.?/g, '$1$2'); regex(/((?:\d?\d[:\.]\d?\d| \d?\d) [ap])(?:\.m\.)([^[^\w-]-])/gi, '$1m$2'); regex(/\b(\d?\d[:\.]\d?\d| \d?\d)[ ]*(?:a\.m\.|am)([^\w-])/gi, '$1 am$2'); regex(/\b(\d?\d[:\.]\d?\d| \d?\d)[ ]*(?:p\.m\.|pm)([^\w-])/gi, '$1 pm$2'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kw)\b/gi, '$1 kW'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:khz)\b/gi, '$1 kHz'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m[Hh]z)\b/gi, '$1 MHz'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:g[Hh]z)\b/gi, '$1 GHz'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:kph|kphr|kmh|kmhr|kmph|kmphr|km\/hr)\b/gi, '$1 km/h'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:m\.p\.h\.)\b/gi, '$1 mph'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(gm|kg|km)s?\b/g, '$1 $2'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*(?:K(g|m))s?\b/g, '$1 k$2'); regex(/(\d\.\d?\d| \d{1,3}| \d{1,3},\d{3})[ ]*cms?/gi, '$1 cm'); //	regex(/([^\|\[=]\d{1,3})\s(m|b|tr)illion(\b[^}])/g, '$1 $2illion$3');

//turn letter 'x' into symbol '×' regex(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in ('); regex(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');

// Convert degree symbols into ° symbol, ensure preceding space regex(/&deg;/g, '°'); //	regex(/º/g, '°');

// Celsius spelling errors regex(/(?:celsius|celcius|centigrade)/gi, 'Celsius');

//Fix common naming error (be careful with this one) //	regex(/centigrade/gi, 'Celsius'); //Celsius or Fahrenheit regex(/(\d) (?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2'); regex(/(\d)(?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2'); regex(/(\d) (?:°|deg|degree|degrees)([CF]\W)/g, '$1 °$2'); regex(/(\d)(?:\s|)(?:°|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1 °$2'); regex(/(\d) (\[\[Celsius|°C\]\])/gi, '$1 $2'); regex(/(\d)(?:\s|)(\[\[Celsius|°C\]\])/gi, '$1 $2'); regex(/(\d) (\[\[Fahrenheit|°F\]\])/gi, '$1 $2'); regex(/(\d)(?:\s|)(\[\[Fahrenheit|°F\]\])/gi, '$1 $2'); regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)°F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1$2 °F$3'); regex(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)(?:deg|degree|degrees)(?:\s|-| |)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1$2 °F$3');

// Convert &sup to superscript regex(/&sup2;/g, '²'); regex(/&sup3;/g, '³');

//remove commas from numerical values in convert template regex(/({convert\|\d+),(\d)/g, '$1$2'); regex(/({convert\|\d+),(\d)/g, '$1$2'); regex(/({convert\|\d+),(\d)/g, '$1$2'); regex(/({convert\|\d+),(\d)/g, '$1$2'); regex(/({convert\|\d+),(\d)/g, '$1$2');

//remove leading zeros from convert template regex(/({convert\|)0(\d)/g, '$1$2'); regex(/({convert\|)0(\d)/g, '$1$2'); regex(/({convert\|)0(\d)/g, '$1$2');

//Remove surprise or 'Easter egg' diversions linking unit name to orders of magnitude articles regex(/\[\[1\s?_?E\s?[\-\+]?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1'); regex(/\[\[Orders\sof\smagnitude\s\([^\)]+\)\|([^\]]{1,50})\]\]/gi, '$1');

regex(/(\d)♭(\w| )/g, '$1$2');

}

function unbold_word{ var txt=document.editform.wpTextbox1;

//rem bolding from linked AND bolded terms regex(/(\[\[|)([A-Z]\w+?)(\|[\w- ]+|)(\]\]|)/g, '$1$2$3$4'); setoptions(minor='true'); 		//removed ",watch='false'" in response to user notification 13 Nov. 2010 setreason('remove bold formatting', 'append'); }

function make_dates_bold{ //********************************************************************************************** // This script was originally written by Lightmouse to make dates bold - for timelines, etc. // For use mainly with timelines, it makes dates after bullet points into bold type var txt=document.editform.wpTextbox1;

//process date ranges containing a hyphen '* month dd - month dd:' regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');

//process date ranges containing a hyphen '* month dd dd:' regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?[-–]\s?\d\d?)\s?:\s?/gi, '* \'\'\'$1:\'\'\' ');

//protect date ranges containing a hyphen regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1xx$2'); regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–](\s?\d\d?)\s?:\s?/gi, '$1xx$2');

//process dates containing a hyphen regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)[-–]\s?/gi, '* \'\'\'$1:\'\'\' ');

//unprotect date ranges containing a hyphen regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?(?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?)\s?:\s?/gi, '$1–$2'); regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December) \d\d?\s?)xx(\s?\d\d?)\s?:\s?/gi, '$1–$2');

//process other dates regex(/\*\s?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d\d?(?:,\s?\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' '); regex(/\*\s?(\d\d?\s(?:January|February|March|April|May|June|July|August|September|October|November|December)(?:\s\d{1,4})?\s?[-–—:])\s/gi, '* \'\'\'$1\'\'\' ');

// edit_summary; }

function Ohc_run_formatgeneral { var txt=document.editform.wpTextbox1; Ohc_formatgeneral;

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

} $(function { if(document.forms.editform) {  mw.util.addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral', 'General formatting', 't-addmetric', 'Fixes some unit formatting', , );  mw.util.addPortletLink('p-tb', 'javascript:make_dates_bold', 'BOLD dates', 'ca-unitfixer', 'Fixes some unit formatting', , );  mw.util.addPortletLink('p-tb', 'javascript:unbold_word', 'UNBOLD single words', 'ca-unitfixer', 'Removed bold formatting from single words', , );  } });