User:Ohconfucius/script/EngvarB.js: Difference between revisions

Content deleted Content added
tweak for false positive with "ailment" per User:DemonDays64, with thanks
Undid revision 1299042620 by Ohconfucius (talk)
 
(46 intermediate revisions by 2 users not shown)
Line 2:
// PLEASE READ THE DOCUMENTATION at [[User:Ohconfucius/EngvarB]] (click on the link above) before using.
 
// Feedback and constructive criticism are welcome. p
// As I am a scripting newbie, any technicalAny advice on the 'hows andimproving the wherefores'scripts are especially welcome.
// <syntaxhighlight lang=javascript>
 
/*************
* TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
*** Regex menu framework
*** by@see [[m:User:Pathoschild]] <https://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>TemplateScript
* @update-token [[File:Pathoschild/templatescript.js]]
*** - adds a sidebar menu of user-defined scripts.
*/
*************/
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', {
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Pathoschild/standardise.js&action=raw&ctype=text/javascript');
dataType: 'script',
importScriptURI('//meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
cache: true
/* menu links */
}).then(function () {
// In the function below, add more lines like "regexTool('link text','function_name()')" to add
pathoschild.TemplateScript.add([
// links to the sidebar menu. The function name is the function defined in rfmscripts() below.
{
function rmflinks() {
category: 'EngvarB', name: 'Flip imperial units', isMinorEdit: true, script: function (editor) {
//regexTool('Custom regex', 'custom()'); // a default tool which performs regex input in a dynamic form
ohc_imperial_units(editor);
//regexTool('Edit my regexes ↗', 'function opennew(url) { window.open(url); }; opennew(wgServer + wgScript + "?title=User:" + wgUserName + "/EngvarB.js&action=edit");');
}
 
},
//regexTool('• Protect words', 'ohc_ENGVAR_protect()');
{
regexTool('• Flip imperial units', 'ohc_imperial_units()');
regexTool( category: 'EngvarB', name: 'Flip international units', 'ohc_international_unitsisMinorEdit: true, script: function (editor)'); {
ohc_international_units(editor);
regexTool('• AMERICAN', 'ohc_ENGVAR_set_variation("U")');
}
regexTool('• COMMONWEALTH', 'ohc_ENGVAR_set_variation("B")');
},
regexTool('• BRITISH (Oxford)', 'ohc_ENGVAR_set_variation("Ox")');
{
regexTool('• CANADIAN', 'ohc_ENGVAR_set_variation("C")');
category: 'EngvarB', name: 'AMERICAN', isMinorEdit: true, script: function (editor) {
}
ohc_ENGVAR_set_variation(editor, "U");
 
}
/* scripts */
},
// Below, define the functions linked to from rmflinks() above. These functions can use any JavaScript,
{
// but there is a set of simplified tools documented at
category: 'EngvarB', name: 'BRITISH', isMinorEdit: true, script: function (editor) {
// https://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework
ohc_ENGVAR_set_variation(editor, "B");
}
},
{
category: 'EngvarB', name: 'OXFORD', isMinorEdit: true, script: function (editor) {
ohc_ENGVAR_set_variation(editor, "O");
}
},
{
category: 'EngvarB', name: 'CANADIAN', isMinorEdit: true, script: function (editor) {
ohc_ENGVAR_set_variation(editor, "C");
}
}
]);
});
// </nowiki>
 
/** ------------------------------------------------------------------------ **/
 
// PROTECTION FROM STRING SUBSTITUTION
var linkmap = []protected_map;
 
function ohc_ENGVAR_protect(editor) {
// protects categories, templates, link pipings, quotes, etc
// the sensitive part is stored and replaced with a unique identifier,
// which is later replaced with the stored part.
var text = editor.get();
protected_map = [];
 
var protect_functionreplace_string = function (s, begin, replace, endmatch) {
linkmapprotected_map.push(replacematch);
return begin + '⍌' + (linkmapprotected_map.length - 1) + '⍍' + end;
};
var protect_string = function (string) {
text = text.replace(string, replace_string);
};
 
// regexprotect_string(/(pre)(string)(post)/gi, protect_function); // template
regexprotect_string(/(<blockquote>)(.*?)(<\/blockquote>)/gi, protect_function);
regexprotect_string(/({\| *class *= ?\*"wikitable ?\*")([\S\s]*?)(\|})/gi, protect_function);
regexprotect_string(/(<table[^<>]*?>)([^<>]*)(<\/table>)/gi, protect_function);
regexprotect_string(/(<timeline[^<>]*?>)([^<>]*)(<\/timeline>)/gi, protect_function);
regexprotect_string(/(<span\|\s*stylesstyle\s*=[^|\"]*)(color|center)([^|:>]*\|>)/gi, protect_function);
regexprotect_string(/(<=\/?[ ]s*)(color|center)([ ]\s*>:#)/gi, protect_function); //<center> tags
regexprotect_string(/(align\/{)((?[:meta ]*=\/?[|font ]*[ "'][ ]*|)(color|center)([ ^|]*[ "']\|)/gi, protect_function); //align="center"color inbox tablestemplates
regexprotect_string(/([\s;:\|'\/?[ "]*+)(color|center)([ ]*\s;:\'\"]\|w)/gi, protect_function); //|center| in files
protect_string(/({{\w*\scolor\|)([^|=\[\]]*)(}})/gi); //
 
regexprotect_string(/(<ref\/?[^<> ]*?>)(center)([^<> ]*)(<\/ref>)/gi, protect_function); // <center> tags
protect_string(/(align\/?[ ]*=\/?[ ]*[ "'][ ]*)(center)([ ]*[ "'])/gi); // align="center" in tables
regex(/(<ref name=)([^<>]*)(\/>)/gi, protect_function);
regex(/(\{[\w ]{0,12}(?:quot[^\|]{1,7}\s?|sic|(?:not a |)typo|as written)\|)([^\}]+)(\})/gi, protect_function);
regex(/([\s\(]["“])([^"“”\n]*)(["”])/gi, protect_function); //double quotes
 
protect_string(/(\{\{)(Medical cases chart\/bar colors)([^\}]+\}\})/gi);
regex(/((?:Category|Image):)([^|\]]*)([\|\]])/gi, protect_function); //cats, images
protect_string(/(\{\{)(bar percent)(\|[^\}]+\}\})/gi);
regex(/((?:image\d?|image_skyline|image[ _]___location\d?|image[ _](?:map|name)|img|pic)\s*=)([^\|\}]*)([\|\}])/gi, protect_function); //images within templates infoboxes etc
regex(/(.)(cite encyclopedia\s*\|)(.)/gi, protect_function);
regex(/(\|)(\s*colors(?:_label|)\s*)(=)/gi, protect_function);
regex(/(\|)(\s*analog\s*)(=)/gi, protect_function);
regex(/((?:url)\s*=)([^\|\}]*)([\|\}])/gi, protect_function); //urls within templates infoboxes etc
regex(/(\[(?:https?:|ftp:))([^\]]*)(\])/gi, protect_function);
regex(/(\[(?:https?:|ftp:))([^\s\]]*)([\s\]])/gi, protect_function);
regex(/(\[\[)([^\|\]]*)(\|)/gi, protect_function); //pipings
regex(/(.)(Back in the U.S.S.R.)(.)/gi, protect_function); //title of work
regex(/(.)(Born in the U.S.A.)(.)/gi, protect_function); //title of work
regex(/(\{(?:See ?also|Main))(\|[^\}]*)(\})/gi, protect_function); //see also and main templates
regex(/(\{\{(?:external|wide )image\s?\|)([^\}]+)(\})/gi, protect_function);
regex(/(\{\{(?:harvnb|wikisource)\|)([^\}]+)(\})/gi, protect_function);
regex(/(\{\{)((?:NYT|WSJ)topic\|[^\}]*)(\}\})/gi, protect_function);
regex(/(\{\{\w*\scolor\|)([^\|=\[\]]*)(\}\})/gi, protect_function); //templates
regex(/(\{\{\w*)([^\|=\[\]]*)(\}\})/gi, protect_function); //templates
regex(/(\{Infobox )((?:[\w ]*)organization)(\s+)/gi, protect_function);
regex(/(\|\s*)(cleanup|color|coordinates\w*)([ ]*=)/gi, protect_function); //parameters within infoboxes
regex(/(\|(?:[^=\|\{\}]*))(cleanup|encyclopa?edia|enroll?ment|honors|lockup\w{1,4}|organi[sz]ation|catalog\snumber)(\s*=)/g, protect_function);
regex(/(\|\s*)(encyclopedia|\w*colors)(\s?=)/gi, protect_function);
regex(/(\|\s*)(local[ _]authority)(\s?=)/gi, protect_function);
regex(/(\|\s*)([Ss]hip[ _](?:armou?r|honou?rs))([ ]*?\=)/g, protect_function);
regex(/(\|\s*title\s?=)([^|\]]*)(\|)/gi, protect_function);
 
protect_string(/(<ref[^<>]*?>)([^<>]*)(<\/ref>)/gi);
regex(/(.)(solid gray)(.)/gi, protect_function);
protect_string(/(<ref name=)([^<>]*)(\/>)/gi);
protect_string(/([\s(]["“])([^"“”\n]*)(["”])/gi); // double quotes
protect_string(/({[\w ]{0,12}(?:quot[^|]{1,7}\s?|sic|(?:not a |)typo|as written)\|)([^}]+)(})/gi);
 
protect_string(/((?:Category|File|Image):)([^|\]]*)([|\]])/gi); // cats, images
//protect from hyphenation
protect_string(/((?:image\d?|image_skyline|image[ _]___location\d?|image[ _](?:map|name)|img|pic)\s*=)([^|}]*)([|}])/gi); // images within templates infoboxes etc
regex(/(.)(\breed(?:|s)[^aeiou]|[Rr]eegan)(.)/g, protect_function);
protect_string(/(cite[ _]encyclopedia\s*\|)/gi);
protect_string(/((?:url)\s*=)([^|}]*)([|}])/gi); // urls within templates infoboxes etc
protect_string(/(\[(?:https?:|ftp:))([^\]]*)(])/gi);
protect_string(/(\[(?:https?:|ftp:))([^\s\]]*)([\s\]])/gi);
protect_string(/(\[\[)([^|\]]*)(\|)/gi); // pipings
protect_string(/({(?:See ?also|Main))(\|[^}]*)(})/gi); // see also and main templates
protect_string(/({{(?:external|wide )image\s?\|)([^}]+)(})/gi);
protect_string(/({{(?:harvnb|wikisource)\|)([^}]+)(})/gi);
protect_string(/({{)((?:NYT|WSJ)topic\|[^}]*)(}})/gi);
protect_string(/({{\w*)([^|=\[\]}]*)(}})/gi); // templates
protect_string(/({Infobox )((?:[\w ]*)organization)(\s+)/gi);
protect_string(/({Infobox )((?:[\w]* )artifact)(\s+)/gi);
// parameters
protect_string(/(\|)(\s*colors(?:_label|)\s*)(=)/gi);
protect_string(/(\|)(\s*background color\s*)(=)/gi);
protect_string(/([\|\!]\s*style\s*=[^|:"]*)"[^|]*(color|center|gray)([^|]*\|)/gi);
protect_string(/(\|)(\s*organizations?\s*)(=)/gi);
protect_string(/(\\|\/?[ ]*)(center)([ ]*\\|)/gi); // |center| in files
protect_string(/(\|)(\s*analog\s*)(=)/gi);
protect_string(/(\|)(\s*licen[cs]e ?(?:place|date|)\s*)(=)/gi);
protect_string(/(\|\s*)(cleanup|color|coordinates\w*)([ ]*=)/gi); // parameters within infoboxes
protect_string(/(\|(?:[^=|{}]*))(cleanup|encyclopa?edia|enroll?ment|honorific_prefix|honors|lockup\w{1,4}|organi[sz]ation|catalog\snumber)(\s*=)/g);
protect_string(/(\|\s*)(encyclopedia|\w*colors|(?:org|rom)anization|license)(\s?=)/gi);
protect_string(/(\|\s*)(local[ _]authority)(\s?=)/gi);
protect_string(/(\|\s*)([Ss]hip[ _](?:armou?r|honou?rs))([ ]*?=)/g);
protect_string(/(\|\s*title\s?=)([^|\]]*)(\|)/gi);
 
//white list
//protect from function ohc_ENGVAR_restore_z
protect_string(/(Back in the U.S.S.R.)/g); // title of work
regex(/(.)((?:enterpri|promi|surpri|treati)(?:se[drs]?|ing))(.)/gi, protect_function);
protect_string(/(Born in the U.S.A.)/g); // title of work
regex(/(.)((?: anti)(?:c|dote|mon|path|q))(.)/g, protect_function);
protect_string(/(Dear Mom|Serial Mom)/g); // title of work
regex(/(.)((?:(?:mercury|nobel)pri|imagesi|picsi)(?:ze))(.)/g, protect_function);
protect_string(/(derailment)/gi);
protect_string(/(Traveling Wilburys?|Rockefeller)/g); // proper noun
protect_string(/(to license)/gi); // verb
protect_string(/(improvis)/gi);
protect_string(/(non-cooperation)/gi);
protect_string(/(Organisation for Economic Co-operation and Development)/gi);
protect_string(/(pr[eo]mis(?:e|ing)|paradise)/gi);
protect_string(/(solid gr[ae]y)/gi);
protect_string(/(rigor mortis)/gi);
protect_string(/(revis)/gi);
protect_string(/((?:analy|iri|peni)ses)/gi);
protect_string(/(World Health Organization)/gi);
protect_string(/(Royal Space Force: The Wings of Honnêamise)/g);
 
// protect from hyphenation
protect_string(/(\breed(?:|s)[^aeiou]|[Rr]eegan)/g);
 
// whitelisting: protect from doubling of "L"
protect_string(/(conceal|adrenaline|rebel|Rockefeller)/gi);
 
// whitelisting: protect from function ohc_ENGVAR_restore_z
protect_string(/(?:ar|de[mv]|enterpr|improv|parad|prec|prom|rev|surpr|treat|telev)(?:ise?[drs]?|ing)/gi);
protect_string(/(?: anti)(?:c|dote|mon|path|q)/g);
protect_string(/(denise|excell(ed|ing)|Rockefeller)/gi);
protect_string(/(?:(?:mercury|nobel)pri|imagesi|picsi)(?:ze)/g);
 
editor.set(text);
}
 
function ohc_ENGVAR_unprotect(editor) {
// restore words protected at runtime
//removes protection put in place by function ohc_protect_fmt (all cats, templates etc.)
regexeditor.replace(/[♫]/g, '');
 
regex(/⍌([0-9]+)⍍/g, function (x, n) {
// restore words protected beforehand
var res = linkmap[n];
var text = editor.get();
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
 
var res = linkmap[n];
var matches;
res = res.replace(/⍌([0-9]+)⍍/g, function (x, n) {
do {
var res = linkmap[n];
restext = restext.replace(/⍌([0-9]+)⍍/g, function (xmatch, nindex) {
return linkmapprotected_map[nindex];
});
return res;
});
return res;
});
matches = text.match(/⍌([0-9]+)⍍/g);
return res;
} while (matches !== null && matches.length > 0);
});
 
editor.set(text);
}
 
/** ------------------------------------------------------------------------ **/
 
function ohc_ENGVAR_plain(editor) {
// per https://www.gov.uk/guidance/style-guide/a-to-z-of-gov-uk-style
// redundancies
regexeditor.replace(/B\.B\.C\./g, 'BBC');
regexeditor.replace(/U\.S\.A\./g, 'U.S.USA');
regexeditor.replace(/U\.S\.S\.R\./g, 'USSRUS');
regexeditor.replace(/U\.KS\.S\.R\./g, 'UKUSSR');
regexeditor.replace(/EU\.UK\./g, 'EUUK');
regexeditor.replace(/(fill )outE\.U\./gig, '$1inEU');
editor.replace(/(fill )out/gi, '$1in');
// regex(/in order (to )/g, '$1'); // disabling per discussion on my talk (archive 35)
 
regex(/In order t(o )/g, 'T$1');
// agrammatical
editor.replace(/(comprised )of /gi, '$1');
 
// old-fashioned
//agrammatical
regex// editor.replace(/(comprised whil)ofst /gi, '$11e ');
// editor.replace(/(among)st /gi, '$1 ');
 
// hyphenation
regex// editor.replace(/(co)(o(?:per|rdin)atordinat(e\b|ing|ion))/g, '$1-$2');
regex// editor.replace(/\b(re)(e\w[aeiou]\w{4,})/gi, '$1-$2');
regex// editor.replace(/\b(over|under)(r\w{4,})/gi, '$1-$2');
regex(/\b(vice) (president|chairman|chancellor|minister)/gi, '$1-$2');
 
// capitalisation
// rem geographical regions - too many false positives
// regexeditor.replace(/(local )authority/g, '$1council');
 
regexeditor.replace(/w(estern European Union)/g, 'W$1');
regexeditor.replace(/(New )s(outh Wales)/g, '$1S$2');
}
 
function ohc_ENGVAR_simple_b(editor) {
var table = {
'aging': '$1ageing',
Line 158 ⟶ 213:
'artifact': '$1artefact',
'(ana|breatha|cata|hydro|para)lyz(e|ing)': '$1$2lys$3',
// 'bestsell': '$1best-sell', //disabled 24/04/24 following comment;word in OED
'ba(lk)': '$1u$2',
'diarrhea': '$1diarrhoea',
'(de|of)fense': '$1$2fence',
'license': '$1licence',
'(licen)c(ing|ed)': '$1$2s$3',
'percent(\\b)': '$1per cent$2',
'plow(s|ing|\\b)': '$1plough$2',
'(practi)c(ing|ed)': '$1$2s$3',
'furor(\\b)': '$1furore$2',
Line 168 ⟶ 226:
'guerilla': '$1guerrilla',
'jewelry': '$1jewellery',
'(judg)(ment)': '$1$2e$3',
'maneuver(ab|ed|ing)': '$1manoeuvr$2',
'maneuver': '$1manoeuvre',
'meager': '$1meagre',
'louve(red|ring)': '$1louv$2',
'louver(louv|somb)er': '$1louvre1$2re',
'ped(iatric|ophil)': '$1paed$2',
'encyclopedi(a|c)': '$1encyclopaedi$2',
Line 179 ⟶ 239:
'licorice': '$1liquorice',
 
// composite words
'(break|drop|clean|line|lock|pick)(out|up)': '$1$2-$3',
 
// oe/ae words
'gyneco': '$1gynaeco',
'hemo(globin|ly|phil|rr)': '$1haemo$2',
Line 199 ⟶ 259:
'(an|leuk|septic|tox)emi(a|c)': '$1$2aemi$3',
 
// 'f' words
//'(S|s)ulfur': '$1$2ulphur', //disabled per WP:ARTCOM
 
'anymore': '$1any more',
Line 208 ⟶ 268:
'(lik|liv|rat|sal|siz|shak)(able)': '$1$2e$3',
 
// '~our' words
'(arm|clam|glam|harb|neighb|rum|savi?|tum)or(ed|ful|ing|less|ly|s|\\b)': '$1$2our$3',
'(arm|sav)or(ies|y|s|\\b)': '$1$2our$3',
'(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3',
'neighborhood': '$1neighbourhood',
'behavior(al|s|\\b)': '$1behaviour$2',
Line 217 ⟶ 277:
'honor(abl[ey]|ed|ing|s|\\b)': '$1honour$2',
'(endeav|lab)or(e[dr]|ing|s|\\W)': '$1$2our$3',
'mol(ddy?|t)(ed|ing|s|\\W)': '$1moul$2$3',
 
// '~re~' words
'(calib|fib|goit|lust|mit|nit|och|reconnoit|sab|saltpet|spect|theat|tit)er(s?\\W)': '$1$2re$3',
'(\b(?:[2-9]|\d{2,3}|half|quarter|two|three|four|five|six|seven|eight|nine|ten)\b) (liter|(?:kilo|)meter)': '$1$2re$3',
'(centi|kilo|micro|milli|nano|-|hundred\\s|\\d\\s)meter': '$1$2metre',
'(centi|milli|deci|pico|hecto|\\b)liter(s?\\b)': '$1$2litre$3',
'(dema|peda|mono|syna)gog(s?\\W)': '$1$2gogue$3',
'(\b(?:[2-9]|\d{2,3}|one|two|three|four|five|six|seven|eight|nine|ten)\b) story': '$1-storey',
// '(\\W[a-z]{3,12}[^s\\b])iz(e[drs]?|ation(s|al|)|ing)': '$1$2is$3',
// '(\\W[a-zA-Z]{3,12}[^s\\b])iz(e[drs]?|ation(s|al|)|ing)': '$1$2is$3',
 
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))el(e[dr]|ist|ing)': '$1$2ell$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|revpan|prop|quarr|r[ei]v|sign|trav)el(e[dr]|ing)': '$1$2ell$3',
'([a-zA-Z]{2,8}[^eglpstz ])el(e[dr]|est|ing)(\\b)': '$1$2ell$3$4', // added 'p' to avoid changing of "misspelling"
'(app|di|enthr|equ|initi|journ|riv|sign|tot)al(e[dr]|ing)': '$1$2all$3' // appalled/appalling is also American
};
Line 235 ⟶ 297:
for (var word in table) {
try {
regexeditor.replace(new RegExp('([ \\|\\[\\*])' + word, 'g'), table[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_b(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
var tabletable2 = {
// '~our' words
'([ \\|\\[\\*])(col|flav|hum)or(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2our$3',
'( [\\w\\D]*\\-)(col|flav|hum)ored': '$1$2oured',
'([^\\w\\d\\-\\/=:])(col)or(\\W)': '$1$2our$3',
 
// '~re~' words
'([^\\w\\d\\-\\/=])(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(ed|ing)': '$1$2re$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)er(ed|ing)': '$1$2re2r$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)er(s?\\b)': '$1$2re$3',
 
// '~logu~' words
'([^\\w\\d\\-\\/])(ana|cata|dia|epi|homo|mono|pro)log(ed|ing)': '$1$2logu$3',
'([^\\w\\d\\-\\/])(ana|cata|dia|epi|homo|mono|pro)log(s?\\b)': '$1$2logue$3',
 
// '~l' words where the 'l' doubles as past and present participle
'([ \\|\\[])(counc[ie])l(e[dr]|ing|ors?)(\\b)': '$1$2ll$3$4',
'\\b([a-zzA-Z]*)ll(ful|ment)': '$1l$2',
'(movie theat(er|re))': 'cinema',
 
'([ \\|\\[\\*])airplane': '$1aeroplane',
// '([ \\|\\[\\*])\\b[Mm](um|om(my|))\\b': '$1mother', // disabled 10 June – frequent false positives
'([ \\|\\[\\*])sidewalk': '$1pavement'
};
 
for (var word in tabletable2) {
try {
regexeditor.replace(new RegExp(word, 'g'), tabletable2[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table2[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_b(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
// remove US spelling from {{convert}} template output
regexeditor.replace(/(\{\{convert\|[^\}]*)\|(?:sp|spell)[ ]*=[ ]*us/gi, '$1');
regexeditor.replace(/(\{\{(?:in|ft|yd|[mck]?m)[23]?[ ]+to[ ]+[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
regexeditor.replace(/(\{\{(?:pd|pop[ ]+density[ ])+(?:km|mi)2[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
 
// remove ambiguous pound sign; rem incidental intervening space
editor.replace(/₤ ?(\d)/g, '£$1');
 
editor.replace(/\b(vice) (president|chairman|chancellor|minister)/gi, '$1-$2');
 
//remove ambiguous pound sign; rem incidental intervening space
regex(/₤ ?(\d)/g, '£$1');
regex(/rigour mortis/g, 'rigor mortis');
//reconvert special cases
}
 
function ohc_ENGVAR_simple_c(editor) {
var table = {
'ageing': '$1aging',
'aluminiumaluminum': '$1aluminum1aluminium',
'adrenalin(\\b)': '$1adrenaline$2',
'annex(\\b)': '$1annexe$2',
'(ana|breatha|cata|hydro|para)lyz(e|ing)': '$1$2lys$3',
'bau(lk)': '$1ba$2',
'(de|of)fense': '$1$2fence',
'license': '$1licence',
'(licen)c(ing|ed)': '$1$2s$3',
'percent(\\b)': '$1per cent$2',
'(practi)s(ing|ed)': '$1$2c$3',
'furor(\\b)': '$1furore$2',
Line 316 ⟶ 378:
'liquorice': '$1licorice',
 
// composite words
// 'onstage': '$1on-stage',
'(break|drop|clean|line|lock|pick)(out|up)': '$1$2-$3',
 
// oe/ae words
'anaesthesiologist': '$1anesthetist',
'(an|)aesthe(sia|tic|tist)': '$1$2esthe$3',
'archaeo': '$1archeo',
'diarrhoea': '$1diarrhea',
Line 339 ⟶ 401:
'(an|leuk|septic|tox)aemi(a|c)': '$1$2emi$3',
 
// 'f' words
//'(S|s)ulfur': '$1$2ulphur', //disabled per WP:ARTCOM
 
'anymore': '$1any more',
Line 348 ⟶ 410:
'(lik|liv|rat|sal|siz|shak)(able)': '$1$2e$3',
 
// '~our' words
'(arm|clam|glam|harb|neighb|rum|savi?|tum)or(ed|ful|ing|less|ly|s|\\b)': '$1$2our$3',
'(arm|sav)or(ies|y|s|\\b)': '$1$2our$3',
'(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3',
'neighborhood': '$1neighbourhood',
'behavior(al|s|\\b)': '$1behaviour$2',
Line 357 ⟶ 419:
'honor(abl[ey]|ed|ing|s|\\b)': '$1honour$2',
'(endeav|lab)or(e[dr]|ing|s|\\W)': '$1$2our$3',
'mol(ddy?|t)(ed|ing|s|\\W)': '$1moul$2$3',
 
// '~re~' words
'(calib|fib|goit|lust|mit|nit|och|reconnoit|sab|saltpet|spect|theat|tit)er(s?\\W)': '$1$2re$3',
'(centi|kilo|micro|milli|nano|-|hundred\\s|\\d\\s)meter': '$1$2metre',
Line 365 ⟶ 427:
'(dema|peda|mono|syna)gog(s?\\W)': '$1$2gogue$3',
 
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))el(e[dr]|ist|ing)': '$1$2ell$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|revpan|prop|quarr|r[ei]v|sign|trav)el(e[dr]|ing)': '$1$2ell$3',
'([a-zA-Z]{2,8}[^eglpstz ])el(e[dr]|est|ing)(\\b)': '$1$2ell$3$4', // added 'p' to avoid changing of "misspelling"
'(app|di|enthr|equ|initi|journ|riv|sign|tot)al(e[dr]|ing)': '$1$2all$3' // appalled/appalling is also American
};
Line 374 ⟶ 436:
for (var word in table) {
try {
regexeditor.replace(new RegExp('([ \\|\\[\\*])' + word, 'g'), table[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_c(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
var tabletable2 = {
// '~our' words
'([ \\|\\[\\*])(col|flav|hum)or(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2our$3',
'( [\\w\\D]*\\-)(col|flav|hum)ored': '$1$2oured',
'([^\\w\\d\\-\\/=:])(col)or(\\W)': '$1$2our$3',
 
// '~re~' words
'([^\\w\\d\\-\\/=])(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(ed|ing)': '$1$2r$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)er(ed|ing)': '$1$2r$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)er(s?\\b)': '$1$2re$3',
 
// '~logu~' words
'([^\\w\\d\\-\\/])(ana|cata|dia|epi|homo|mono|pro)log(ed|ing)': '$1$2logu$3',
'([^\\w\\d\\-\\/])(ana|cata|dia|epi|homo|mono|pro)log(s?\\b)': '$1$2logue$3',
 
// '~l' words where the 'l' doubles as past and present participle
'\\b(counc[ie])l(e[dr]|ing|ors?)\\b': '$1ll$2',
// '(movie theat(er|re))': 'cinema',
Line 405 ⟶ 465:
};
 
for (var word in tabletable2) {
try {
regexeditor.replace(new RegExp(word, 'g'), tabletable2[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table2[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_c(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
// remove US spelling from {{convert}} template output
regexeditor.replace(/(\{\{convert\|[^\}]*)\|(?:sp|spell)[ ]*=[ ]*us/gi, '$1');
regexeditor.replace(/(\{\{(?:in|ft|yd|[mck]?m)[23]?[ ]+to[ ]+[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
regexeditor.replace(/(\{\{(?:pd|pop[ ]+density[ ])+(?:km|mi)2[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
 
// remove ambiguous dollar sign; rem incidental intervening space
regexeditor.replace(/$ ?(\d)/g, '$$1');
regex//editor.replace(/rigour mortis/g, 'rigor mortis');
// reconvert special cases
}
 
function ohc_ENGVAR_simple_a(editor) {
var table = {
'ageing': '$1aging',
Line 436 ⟶ 494:
'artefact': '$1artifact',
'(ana|breatha|cata|hydro|para)lys(e|ing)': '$1$2lyz$3',
'best-sellbau(lk)': '$1bestsell1ba$2',
// 'bestsell': '$1best-sell', //disabled 24/04/24 following comment;word in OED
'diarrhoea': '$1diarrhea',
'(de|of)fence': '$1$2fense',
'licence': '$1license',
'(licen)c(ing|ed)': '$1$2s$3',
'per cent(\\b)': '$1percent$2',
'(practi)s(ing|ed)': '$1$2c$3',
'furore(\\b)': '$1furor$2',
Line 456 ⟶ 516:
'liquorice': '$1licorice',
 
// composite words
'(break|drop|clean|line|lock|pick)-(out|up)': '$1$2$3',
 
// oe/ae words
'gynaeco': '$1gyneco',
'haemo(globin|ly|phil|rr)': '$1hemo$2',
'orthopaedic': '$1orthopedic',
// 'archaeo': '$1archeo', // disabling per user:coffeeandcrumbs (21/8/2018)
'palaeonto': '$1paleonto',
'oenology': '$1enology',
'oesophag': '$1esophag',
'oestrogen': '$1estrogen',
'(an|)aesthe(sia|tic|tist)': '$1$2esthe$3',
'anaesthetist': '$1anesthesiologist',
'homoeopath': '$1homeopath',
Line 476 ⟶ 536:
'(an|leuk|septic|tox)aemi(a|c)': '$1$2emi$3',
 
// 'f' words
//'(S|s)ulfur': '$1$2ulphur', //disabled per WP:ARTCOM
 
'any more': '$1anymore',
Line 485 ⟶ 545:
'(lik|liv|rat|sal|siz|shak)e(able)': '$1$2$3',
 
// '~our' words
'(arm|clam|harb|neighb|rum|savi?|tum)our(ed|ful|ing|less|ly|s|\\b)': '$1$2or$3', // removing "glamour" per user:coffeeandcrumbs (21/8/2018)
'(arm|sav)our(ies|y|s|\\b)': '$1$2or$3',
'(cand|hum|od)oruour((?:ful|less)(?:ly|)|\\b)': '$1$2or$3',
'neighbourhood': '$1neighborhood',
'behaviour(al|s|\\b)': '$1behavior$2',
Line 496 ⟶ 556:
'moul(d|t)(ed|ing|s|\\W)': '$1mol$2$3',
 
// '~re~' words
'(calib|fib|goit|lust|mit|nit|och|reconnoit|sab|saltpet|spect|theat|tit)re(s?\\W)': '$1$2er$3',
'(centi|kilo|micro|milli|nano|-|hundred\\s|\\d\\s)metre': '$1$2meter',
'(centi|milli|deci|pico|hecto|\\b)litre(s?\\b)': '$1$2liter$3',
'(dema|peda|mono|syna)gogue(s?\\W)': '$1$2gog$3', //rem "demagog"; rem "synagog" and "pedagog" June 2025
// '(\\W[a-zzA-Z]{3,12}[^s\\b])iz(e[drs]?|ation(s|al|)|ing)': '$1$2is$3',
 
// '~l' words where the 'l' doubles as past and present participle
'((?:\\w{3,9}[-–—]|)(?:fu|pan))ell(e[dr]|ist|ing)': '$1$2el$3',
'(bev|canc|couns|fu|jew|lab|lev|marv|mod|pan|prop|quarr|rev|sign|trav)ell?(e[dr]|ing)': '$1$2el$3',
'([a-zzA-Z]{2,8}[^eglpstz ])ell?(e[dr]|est|ing)(\\b)': '$1$2el$3$4', // added 'p' to avoid changing of "misspelling"
'(di|enthr|equ|initi|journ|riv|sign|tot)all?(e[dr]|ing)': '$1$2al$3' // appalled/appalling is also American
// '\\b(appal|excel)((?:e[dr]|est|ing)\\b)': '$1l$2', // "excelling/excelled" is US English
 
};
 
for (var word in table) {
try {
regexeditor.replace(new RegExp('([ \\|\\[\\*])' + word, 'g'), table[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_a(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
var tabletable2 = {
// '~our' words
'([ \\|\\[\\*])(col|flav|hum)our(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2or$3',
'( [\\w\\D]*\\-)(col|flav|hum)oured': '$1$2ored',
'([^\\w\\d\\-\\/=:])(col)our(\\W)': '$1$2or$3',
 
// '~re~' words
'([^\\w\\d\\-\\/=])(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)re(ed|ing)': '$1$2er$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)re(ed|ing)': '$1$2er$3',
'([^\\w\\d\\-\\/=:])(cent|epicent|recent)re(s?\\b)': '$1$2er$3',
 
// '~logu~' words
'([^\\w\\d\\-\\/])(ana|cata|epi|homo|mono|pro)logu(ed|ing)': '$1$2log$3', // removing "dialogue" per user:coffeeandcrumbs (21/8/2018)
'([^\\w\\d\\-\\/])(ana|cata|epi|homo|mono|pro)logue(s?\\b)': '$1$2log$3', // removing "dialogue" per user:coffeeandcrumbs
 
// '~l' words where the 'l' doubles as past and present participle
'([ \\|\\[])(counc[ie])ll(e[dr]|ing|ors?)(\\b)': '$1$2l$3$4',
'\\b([a-zA-Z]{3,})([^l])l(ful|ment)': '$1$2ll$3', //added fixedspecific quantifier false positive with "ailment"
// '(movie theat(er|re))': 'cinema', // disabling per user:coffeeandcrumbs
 
'([ \\|\\[\\*])aeroplane': '$1airplane',
// '([ \\|\\[\\*])\\b[Mm](um|om(my|))\\b': '$1mother' // disabled 10 June – frequent false positives
};
 
for (var word in tabletable2) {
try {
regexeditor.replace(new RegExp(word, 'g'), tabletable2[word]);
} catch (err) {
}
alert('There was an error when changing "' + word + '" => "' + table2[word] + '".\n\n'
catch (err) {
+ 'Error: ' + err.message + '\n\n'
var text = 'There was an error on function ohc_ENGVAR_simple_a(), when changing "' + word + '" => "' + table[word] + '".\n\n';
text += 'Error:Click 'OK +to errcontinue.message + '\n\n');
text += 'Click OK to continue.\n\n';
alert(text);
}
}
 
// remove US spelling from {{convert}} template output
regex// editor.replace(/(\{\{convert\|[^\}]*)\|(?:sp|spell)[ ]*=[ ]*us/gi, '$1');
regex// editor.replace(/(\{\{(?:in|ft|yd|[mck]?m)[23]?[ ]+to[ ]+[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
regex// editor.replace(/(\{\{(?:pd|pop[ ]+density[ ])+(?:km|mi)2[^\}]*)\|(?:sp|spell)[ ]*=[ ]*(?:American|us)/gi, '$1');
 
// remove ambiguous dollar sign; rem incidental intervening space
regexeditor.replace(/$ ?(\d)/g, '$$1');
// reconvert special cases
regex(/rigour mortis/g, 'rigor mortis');
//reconvert special cases
}
 
function ohc_ENGVAR_set_variation(veditor, variation) {
ohc_ENGVAR_protect(editor);
 
switch (vvariation) {
case 'B':
ohc_ENGVAR_simple_b(editor);
ohc_ENGVAR_remove_z(editor);
break;
ohc_ENGVAR_plain();
case 'O':
Ohc_format_MOSHASH();
ohc_ENGVAR_simple_b(editor);
ohc_ENGVAR_restore_z(editor);
break;
case 'Ox':
case 'C':
ohc_ENGVAR_simple_c(editor);
ohc_ENGVAR_restore_z(editor);
break;
case 'U':
ohc_ENGVAR_simple_a(editor);
ohc_ENGVAR_restore_z(editor);
ohc_international_units();
break;
default:
return;
}
 
ohc_ENGVAR_plain(editor);
ohc_ENGVAR_unprotect();
ohc_ENGVAR_unprotect(editor);
 
ohc_retask_pipes(editor);
 
ohc_ENGVAR_insert_template(veditor, variation);
ohc_Reorder_template(editor)
ohc_ENGVAR_edit_summary(v);
ohc_ENGVAR_edit_summary(editor, variation);
 
editor.clickDiff();
doaction('diff');
}
 
/** ------------------------------------------------------------------------ **/
 
function ohc_retask_pipesohc_ENGVAR_remove_z(editor) {
regexeditor.replace(/([^\w\-\.]\[\[)(?:(?:[a-z]+? |)[a-z]+?[^s ]i[sz]ation)\|((?:[a-z]+? |)[a-z]{3,12}[^s ]i[sz])iz(?:e[drs]?|ations?|abl[ey]|ing)(\W)/g, '$11is$2$3');
// regex editor.replace(/(empha[Oo]rgan|synthe[Rr]ecog)siziz(e(?:[drs]?|ingrs)|ations)(\W)/g, '$1sis1is$2$3');
editor.replace(/(empha)siz(e|ing)/g, '$1sis$2');
editor.replace(/(synthe)siz(e[ds]|ing)/g, '$1sis$2');
 
editor.replace(/(burgl)ari[sz](ed?|ing)/g, '$1$2');
 
}
 
function ohc_ENGVAR_remove_zohc_ENGVAR_restore_z(editor) {
// converts 's-words' into 'z-words'
regex(/([^\w\-\.][a-z]{3,12}[^s ])iz(e[drs]?|ations?|abl[ey]|ing)(\W)/g, '$1is$2$3');
// editor.replace(/([\w])r([eo])mis(e|ing)/g, '$1r$2m♫is$3'); // Premise, promise et al. //new protection below
regex(/(empha)siz(e|ing)/g, '$1sis$2');
regexeditor.replace(/(synthe)siz(e[ds^\w\-.\/]|ing[a-zA-Z]{5,12})is(ations?)(\W)/g, '$1sis1iz$2$3');
editor.replace(/([^\w\-.\/][a-zA-Z]{0,12}(?:[aeiou][^aeiosuw]|ph|rd|thes))is(e[drs]?|ing)(\W)/g, '$1iz$2$3');
editor.replace(/([Oo]rgan|[Rr]ecogn)is(e(?:[drs]?|rs)|ations)(\W)/g, '$1iz$2$3');
}
 
/** ------------------------------------------------------------------------ **/
function ohc_ENGVAR_restore_z() {
 
//converts 's-words' into 'z-words'
function ohc_imperial_units(editor) {
regex(/([^\w\-\.\/])(ar|de[mv]|improv|parad|(?:com|)pr[eo][cm]|(?:un|)rev|surm|telev)is(e|ing)/g, '$1$2♫is$3');
// measurements and perception
regex(/([\w]p?)remise/g, '$1rem♫ise');
regex// editor.replace(/(\[^\w\-\.\/][a-z]{5,12})is(ations?foobar)(\Ws|)]]/ggi, '$1iz1$2$3');
 
regex(/([^\w\-\.\/][a-z]{0,12}(?:[aeiou][^aeiosuw]|ph|rd|thes))is(e[drs]?|ing)(\W)/g, '$1iz$2$3');
// Template:{{convert}}
// editor.replace(/({{convert)(\s*\|)/gi, '$1/flip$2'); // rem linking within convert template (area) // needs resolving
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|cu|)(?:[mck]?m)(?:2|3|))(?:\|(?:sq|cu|)(?:in|ft|yd|mi)(?:2|3|))?(\|\d)?(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (area)
editor.replace(/({{convert\|[\d.,]+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|)(?:k?m)(?:2|3|)|hectare))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*?(?=})/gi, '$1$2|disp=flip'); // putting metres and hectares behind
editor.replace(/({{convert\|[\d.,]+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // flip hectares
editor.replace(/({{convert\|[\d.,]+?\|(?:kmh|km\/h)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // flip kmh
editor.replace(/({{convert\|[\d.,]+?\|(?:to|by|x)(?:\|[\d.,]+?\|(?:[mck]?m))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (input ranges only)
editor.replace(/({{convert\|[\d.,]+?\|nmi)(2|)(\|mi\2 km\2|\|km\2 mi\2|)(?=[|}])/gi, '$1$2|mi$2 km$2'); // putting miles first in nautical mile conversion
editor.replace(/({{convert\|[\d.,]+?\|(?:kg|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]+?)*(?=})/gi, '$1$2|disp=flip'); // putting pounds and °C first
// editor.replace(/({{(?:in|ft|mi|[mck]?m)[23]?\sto\s(?:in|ft|mi|[mck]?m)[23]?[^}]*?)\|wiki=(?:yes|no)/gi, '$1');
 
// manipulating "|disp=flip" parameter where already "flipped"
editor.replace(/({{convert\|[\d.,]+?\|\w{1,4}(?:\|\w{1,4}|)?(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(\|disp=flip)(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)+(?=})/gi, '$1$3$2'); // reordering flipping parameter within convert template (last parameter)
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi|acre)(?:2|3|))(?:\|(?:sq|cu|)(?:[mck]?m|ha)(?:2|3|))?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)\|disp=flip(?=})/gi, '$1$2'); // rem flipping within convert template (Imperial, sq and cubed)
editor.replace(/({{convert\|[\d.,]+?\|(?:mi|miles?|mph)(?:\|kph|km\/h|)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)\|disp=flip(?=})/gi, '$1$2'); // rem flipping within convert template (Imperial, sq and cubed)
}
 
function Ohc_format_MOSHASHohc_international_units(editor) {
// measurements and perception
//hash fixes
regex// editor.replace(/([^=] )#(\d{1,3}[,\.]?[<\(foobar)(s|)]])/gi, '$1No. 1$2');
 
// Template:{{convert}}
// editor.replace(/({{convert)(\s*\|)/gi, '$1/flip$2'); // rem linking within convert template (area) // needs resolving
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi)(?:2|3|))(?:\|(?:sq|cu|)(?:[mck]?m)(?:2|3|))?(\|\d)?(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (area)
editor.replace(/({{convert\|[\d.,]+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|)mi(?:2|3|)|acre))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*?(?=})/gi, '$1$2|disp=flip'); // putting metres and hectares behind
// editor.replace(/({{convert\|[\d.,]+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // flip hectares
// editor.replace(/({{convert\|[\d.,]+?\|mp[gh](?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // flip kmh
editor.replace(/({{convert\|[\d.,]+?\|(?:to|by|x)(?:\|[\d.,]+?\|(?:yd|f(?:oo|)t|in))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (input ranges only)
editor.replace(/({{convert\|[\d.,]+?\|nmi)(2|)(\|mi\2 km\2|\|km\2 mi\2|)(?=[|}])/gi, '$1$2|km$2 mi$2'); // putting miles first in nautical mile conversion
editor.replace(/({{convert\|[\d.,]+?\|(?:lb|oz|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]+?)*(?=})/gi, '$1$2|disp=flip'); // putting pounds and °C first
// editor.replace(/({{(?:in|ft|mi|[mck]?m)[23]?\sto\s(?:in|ft|mi|[mck]?m)[23]?[^}]*?)\|wiki=(?:yes|no)/gi, '$1');
 
// manipulating "|disp=flip" parameter where already "flipped"
editor.replace(/({{convert\|[\d.,]+?\|\w{1,4}(?:\|\w{1,4}|)?(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)(\|disp=flip)(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)+(?=})/gi, '$1$3$2'); // reordering flipping parameter within convert template (last parameter)
editor.replace(/({{convert\|[\d.,]+?\|(?:(?:sq|cu|)(?:[mck]?m|ha)(?:2|3|))(?:\|(?:sq|cu|)(?:in|ft|yd|mi|acre)(?:2|3|))?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)\|disp=flip(?=})/gi, '$1$2'); // rem flipping within convert template (Imperial, sq and cubed)
editor.replace(/({{convert\|[\d.,]+?(?:\|kph|km\/h|)(?:\|mi|miles?|mph)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^|}]*)*)\|disp=flip(?=})/gi, '$1$2'); // rem flipping within convert template (Imperial, sq and cubed)
}
function ohc_imperial_units() {
//measurements and perception
// regex(/\[\[(foobar)(s|)\]\]/gi, '$1$2');
 
/** ------------------------------------------------------------------------ **/
//Template:{{convert}}
// regex(/(\{\{convert)(\s*\|)/gi, '$1/flip$2'); //rem linking within convert template (area) //needs resolving
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|cu|)(?:[mck]?m)(?:2|3|))(?:\|(?:sq|cu|)(?:in|ft|yd|mi)(?:2|3|))?(\|\d)?(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template (area)
regex(/(\{\{convert\|[\d\.,]+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|)(?:k?m)(?:2|3|)|hectare))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*?(?=\})/gi, '$1$2|disp=flip'); //putting metres and hectares behind
regex(/(\{\{convert\|[\d\.,]+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //flip hectares
regex(/(\{\{convert\|[\d\.,]+?\|(?:kmh|km\/h)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //flip kmh
regex(/(\{\{convert\|[\d\.,]+?\|(?:to|by|x)(?:\|[\d\.,]+?\|(?:[mck]?m))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template (input ranges only)
regex(/(\{\{convert\|[\d\.,]+?\|nmi)(2|)(\|mi\2 km\2|\|km\2 mi\2|)(?=[|}])/gi, '$1$2|mi$2 km$2'); //putting miles first in nautical mile conversion
regex(/(\{\{convert\|[\d\.,]+?\|(?:kg|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]+?)*(?=\})/gi, '$1$2|disp=flip'); //putting pounds and °C first
// regex(/(\{\{(?:in|ft|mi|[mck]?m)[23]?\sto\s(?:in|ft|mi|[mck]?m)[23]?[^\}]*?)\|wiki=(?:yes|no)/gi, '$1');
 
function ohc_retask_pipes(editor) {
//manipulating "|disp=flip" parameter where already "flipped"
editor.replace(/([^\w\-.]\[\[)(?:(?:[a-zA-Z]+? |)[a-zA-Z]+?[^s ]i[sz]ation)\|((?:[a-zA-Z]+? |)[a-zA-Z]{3,12}[^s ]i[sz](?:e[drs]?|ations?|abl[ey]|ing))/g, '$1$2');
regex(/(\{\{convert\|[\d\.,]+?\|\w{1,4}(?:\|\w{1,4}|)?(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(\|disp=flip)(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)+(?=\})/gi, '$1$3$2'); //reordering flipping parameter within convert template (last parameter)
// editor.replace(/(empha|synthe)siz(e|ing)/g, '$1sis$2');
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi|acre)(?:2|3|))(?:\|(?:sq|cu|)(?:[mck]?m|ha)(?:2|3|))?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)\|disp=flip(?=\})/gi, '$1$2'); //rem flipping within convert template (Imperial, sq and cubed)
regex(/(\{\{convert\|[\d\.,]+?\|(?:mi|miles?|mph)(?:\|kph|km\/h|)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)\|disp=flip(?=\})/gi, '$1$2'); //rem flipping within convert template (Imperial, sq and cubed)
}
 
/** ------------------------------------------------------------------------ **/
function ohc_international_units() {
//measurements and perception
// regex(/\[\[(foobar)(s|)\]\]/gi, '$1$2');
 
function month_year() {
//Template:{{convert}}
const monthMap = [
// regex(/(\{\{convert)(\s*\|)/gi, '$1/flip$2'); //rem linking within convert template (area) //needs resolving
'January', 'February', 'March', 'April', 'May', 'June',
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi)(?:2|3|))(?:\|(?:sq|cu|)(?:[mck]?m)(?:2|3|))?(\|\d)?(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template (area)
'July', 'August', 'September', 'October', 'November', 'December'
regex(/(\{\{convert\|[\d\.,]+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template
];
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|)mi(?:2|3|)|acre))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*?(?=\})/gi, '$1$2|disp=flip'); //putting metres and hectares behind
const now = new Date();
// regex(/(\{\{convert\|[\d\.,]+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //flip hectares
return `${monthMap[now.getMonth()]} ${now.getFullYear()}`;
// regex(/(\{\{convert\|[\d\.,]+?\|mp[gh](?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //flip kmh
}
regex(/(\{\{convert\|[\d\.,]+?\|(?:to|by|x)(?:\|[\d\.,]+?\|(?:yd|f(?:oo|)t|in))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(?=\})/gi, '$1|disp=flip'); //rem linking within convert template (input ranges only)
regex(/(\{\{convert\|[\d\.,]+?\|nmi)(2|)(\|mi\2 km\2|\|km\2 mi\2|)(?=[|}])/gi, '$1$2|km$2 mi$2'); //putting miles first in nautical mile conversion
regex(/(\{\{convert\|[\d\.,]+?\|(?:lb|oz|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]+?)*(?=\})/gi, '$1$2|disp=flip'); //putting pounds and °C first
// regex(/(\{\{(?:in|ft|mi|[mck]?m)[23]?\sto\s(?:in|ft|mi|[mck]?m)[23]?[^\}]*?)\|wiki=(?:yes|no)/gi, '$1');
 
function remove_deprecated(editor) {
//manipulating "|disp=flip" parameter where already "flipped"
const deprecatedMatcher = /\{\{\s*Engvar(?:A|C)[^}]*\}\}\s*/gi; // Only remove EngvarA and EngvarC
regex(/(\{\{convert\|[\d\.,]+?\|\w{1,4}(?:\|\w{1,4}|)?(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)(\|disp=flip)(\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)+(?=\})/gi, '$1$3$2'); //reordering flipping parameter within convert template (last parameter)
editor.replace(deprecatedMatcher, '');
regex(/(\{\{convert\|[\d\.,]+?\|(?:(?:sq|cu|)(?:[mck]?m|ha)(?:2|3|))(?:\|(?:sq|cu|)(?:in|ft|yd|mi|acre)(?:2|3|))?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)\|disp=flip(?=\})/gi, '$1$2'); //rem flipping within convert template (Imperial, sq and cubed)
return editor;
regex(/(\{\{convert\|[\d\.,]+?(?:\|kph|km\/h|)(?:\|mi|miles?|mph)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=[^\|\}]*)*)\|disp=flip(?=\})/gi, '$1$2'); //rem flipping within convert template (Imperial, sq and cubed)
}
 
function ohc_ENGVAR_insert_template(veditor, variant) {
editor = remove_deprecated(editor);
// Add a template to the article identifying English variant
var box = document.editform.wpTextbox1;
var article = box.value;
 
const variantClass = {
// Build a string with "Month YYYY"
'U': [
var dateobj = new Date();
'Use American English', 'Use Liberian English', 'Use Philippine English'
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
],
var datestr = month[dateobj.getMonth()] + ' ' + dateobj.getFullYear();
'C': ['Use Canadian English'],
'O': ['Use Oxford spelling'],
'B': [
'Use Commonwealth English spelling', 'Use British English', 'Use Antiguan and Barbudan English',
'Use Australian English', 'Use Bangladeshi English', 'Use Ghanaian English', 'Use Hiberno-English',
'Use Hong Kong English', 'Use Indian English', 'Use Jamaican English', 'Use Kenyan English',
'Use Malaysian English', 'Use New Zealand English', 'Use Nigerian English',
'Use Pakistani English', 'Use Singapore English', 'Use Sri Lankan English', 'Use South African English',
'Use Trinidad and Tobago English', 'Use Ugandan English'
]
};
 
const allTemplates = new Set(Object.values(variantClass).flat());
// Matches "Use British English" or "EngvarB"
var reB = new RegExp('{{[_ ]*(?:[Uu]se[_ ]+(?:British|Hong Kong)[_ ]+English|[Ee]ngvarB)[_ ]*(?:|\\|[ ]*date[ ]*=[^{}\\|]*)[ ]*}}', 'gi');
// Matches "Use British (Oxford) English", "Use British English Oxford spelling" or "EngvarOx"
var reOx = new RegExp('{{[_ ]*(?:[Uu]se[_ ]+British[_ ]+\\(Oxford\\)[_ ]+English|[Uu]se[_ ]+British[_ ]+English[_ ]+Oxford[_ ]+[Ss]pelling|[Ee]ngvarOx)[_ ]*(?:|\\|[ ]*date[ ]*=[^{}\\|]*)[ ]*}}', 'gi');
// Matches "Use Canadian English" or "EngvarC"
var reC = new RegExp('{{[_ ]*(?:[Uu]se[_ ]+Canadian[_ ]+English|[Ee]ngvarC)[_ ]*(?:|\\|[ ]*date[ ]*=[^{}\\|]*)[ ]*}}', 'gi');
// Matches "Use American English"
var reU = new RegExp('{{[_ ]*(?:[Uu]se[_ ]+American[_ ]+English)[_ ]*(?:|\\|[ ]*date[ ]*=[^{}\\|]*)[ ]*}}', 'gi');
 
const templatePattern = Array.from(allTemplates)
var reg;
.map(name => name.replace(/[\s\-]/g, '[\\s\\-]+').replace(/([()])/g, '\\$1'))
var template;
.join('|');
 
const allVarTemplatesMatcher = new RegExp(
switch (v) {
`\{\{\s*(?:Template\s*:)?\s*(${templatePattern})(\s*\|[^}]*)?\}\}`,
case 'B':
'gi'
template = '{{EngvarB|date=' + datestr + '}}';
reg = reB );
break;
case 'Ox':
template = '{{Use British English Oxford spelling|date=' + datestr + '}}';
reg = reOx;
break;
case 'C':
template = '{{Use Canadian English|date=' + datestr + '}}';
reg = reC;
break;
case 'U':
template = '{{Use American English|date=' + datestr + '}}';
reg = reU;
break;
}
 
let foundVariantTemplate = false;
// Replace with existing variants
let engvarBFound = false;
article = article.replace(reB, template);
const currentDate = month_year();
article = article.replace(reOx, template);
const allowedTemplates = variantClass[variant] || [];
article = article.replace(reC, template);
article = article.replace(reU, template);
// Prepend template if not already tagged
if (article.search(reg) === -1) {
article = template + '\r\n' + article;
}
 
// Process existing templates
box.value = article;
editor.replace(allVarTemplatesMatcher, function (match, templateName, paramStr = '') {
const currentTemplate = templateName.trim();
 
if (!allowedTemplates.includes(currentTemplate)) {
console.log(`Removing non-matching variant template: {{${currentTemplate}}}`);
return '';
}
 
foundVariantTemplate = true;
 
let params = paramStr.split('|').map(p => p.trim()).filter(Boolean);
let paramMap = {};
 
for (const p of params) {
const [k, v] = p.split('=').map(s => s.trim());
paramMap[k] = v || true;
}
 
paramMap['date'] = currentDate;
 
const paramString = Object.entries(paramMap)
.map(([k, v]) => v === true ? k : `${k}=${v}`)
.join('|');
 
return `{{${templateName}|${paramString}}}`;
});
 
// Handle EngvarB specifically
const engvarBMatcher = /\{\{\s*EngvarB\s*(\|[^}]*)?\}\}/gi;
 
if (variant === 'B') {
editor.replace(engvarBMatcher, function (match, paramStr = '') {
engvarBFound = true;
 
let params = paramStr.split('|').map(p => p.trim()).filter(Boolean);
let paramMap = {};
 
for (const p of params) {
const [k, v] = p.split('=').map(s => s.trim());
paramMap[k] = v || true;
}
 
paramMap['date'] = currentDate;
 
const paramString = Object.entries(paramMap)
.map(([k, v]) => v === true ? k : `${k}=${v}`)
.join('|');
 
return `{{EngvarB|${paramString}}}`;
});
} else {
// Remove EngvarB when switching to non-Commonwealth variants
editor.replace(engvarBMatcher, '');
}
 
// Insert new template if needed
if (!foundVariantTemplate && !(variant === 'B' && engvarBFound)) {
let newTemplate = '';
 
if (variant === 'B') {
newTemplate = `{{Use British English|date=${currentDate}}}`;
} else if (allowedTemplates.length > 0) {
newTemplate = `{{${allowedTemplates[0]}|date=${currentDate}}}`;
}
 
if (newTemplate) {
const shortdescMatcher = /\{\{\s*short\s+description\s*\|[^}]+\}\}\s*(\r?\n)?/i;
 
if (editor.contains(shortdescMatcher)) {
editor.replace(shortdescMatcher, function (m) {
return m + newTemplate + '\n';
});
} else {
editor.prepend(newTemplate + '\n');
}
}
}
}
 
function ohc_ENGVAR_edit_summaryohc_Reorder_template(veditor) {
// Ensure Short description appears before EngvarB if both exist
//Add a tag to the summary box
editor.replace(/(\{\{Use \w+ (?:spelling|English) ?\|[^}]+\}\}\n?)((?:\{\{[\S\s]+\}\}\n?)+|)(\{\{[Ss]hort description ?\|[^}]+\}\}(<!--[^>{}]+-->|)\n?)/g, '$3$2$1');
setoptions(minor = 'true');
 
//removed ",watch='false'" in response to user notification 13 Nov. 2010
}
 
function ohc_ENGVAR_edit_summary(editor, variation) {
var variation = 'English';
// Add a tag to the summary box
switch (v) {
var variation_string;
switch (variation) {
case 'B':
variation_string = 'EngvarB by [[User:Ohconfucius/script/EngvarB|script]]';
variation = 'Commonwealth English';
break;
case 'OxO':
variation_string = 'Oxford by [[User:Ohconfucius/script/EngvarB|script]]';
variation = 'British English Oxford';
break;
case 'C':
variationvariation_string = 'Canadian Englishby [[User:Ohconfucius/script/EngvarB|script]]';
break;
case 'U':
variationvariation_string = 'American Englishby [[User:Ohconfucius/script/EngvarB|script]]';
break;
default:
return;
}
 
doaction('diff');
setreason(variation + ' spelling per [[WP:ENGVAR]] by [[User:Ohconfucius/EngvarB|script]]', 'append');
editor.appendEditSummary(variation_string);
}
// </syntaxhighlight>