Misplaced Pages

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

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Ohconfucius Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 11:20, 1 May 2024 view sourceOhconfucius (talk | contribs)Autopatrolled, Extended confirmed users, Pending changes reviewers328,947 edits mouldy← Previous edit Revision as of 08:42, 3 May 2024 view source Ohconfucius (talk | contribs)Autopatrolled, Extended confirmed users, Pending changes reviewers328,947 edits tumourNext edit →
Line 260: Line 260:


// '~our' words // '~our' words
'(arm|clam|glam|harb|neighb|rum|savi?)or(ed|ful|ing|less|ly|s|\\b)': '$1$2our$3', '(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', '(arm|sav)or(ies|y|s|\\b)': '$1$2our$3',
'(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3', '(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3',
Line 401: Line 401:


// '~our' words // '~our' words
'(arm|clam|glam|harb|neighb|rum|savi?)or(ed|ful|ing|less|ly|s|\\b)': '$1$2our$3', '(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', '(arm|sav)or(ies|y|s|\\b)': '$1$2our$3',
'(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3', '(cand|hum|od)or((?:ful|less)(?:ly|)|\\b)': '$1$2our$3',
Line 535: Line 535:


// '~our' words // '~our' words
'(arm|clam|harb|neighb|rum|savi?)our(ed|ful|ing|less|ly|s|\\b)': '$1$2or$3', // removing "glamour" per user:coffeeandcrumbs (21/8/2018) '(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', '(arm|sav)our(ies|y|s|\\b)': '$1$2or$3',
'(cand|hum|od)our((?:ful|less)(?:ly|)|\\b)': '$1$2or$3', '(cand|hum|od)our((?:ful|less)(?:ly|)|\\b)': '$1$2or$3',

Revision as of 08:42, 3 May 2024

// *********************************************************************************************
 
//This is a test (non-production) script, and may have untested errors. Please exercise due care should you decide to use it.

// *********************************************************************************************
// <syntaxhighlight lang=javascript>
/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/TemplateScript
 * @update-token ]
 */
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', {
	dataType: 'script',
	cache: true
}).then(function () {
	pathoschild.TemplateScript.add([
		{
			category: 'EngvarB', name: 'Flip imperial units', isMinorEdit: true, script: function (editor) {
				ohc_imperial_units(editor);
			}
		},
		{
			category: 'EngvarB', name: 'Flip international units', isMinorEdit: true, script: function (editor) {
				ohc_international_units(editor);
			}
		},
		{
			category: 'EngvarB', name: 'AMERICAN', isMinorEdit: true, script: function (editor) {
				ohc_ENGVAR_set_variation(editor, "U");
			}
		},
		{
			category: 'EngvarB', name: 'COMMONWEALTH', isMinorEdit: true, script: function (editor) {
				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 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 replace_string = function (match) {
		protected_map.push(match);
		return '⍌' + (protected_map.length - 1) + '⍍';
	};
	var protect_string = function (string) {
		text = text.replace(string, replace_string);
	};

//	protect_string(/(pre)(string)(post)/gi); // template
	protect_string(/(<blockquote>)(.*?)(<\/blockquote>)/gi);
	protect_string(/({\| *class *= *"wikitable *")(*?)(\|})/gi);
	protect_string(/(<table*?>)(*)(<\/table>)/gi);
	protect_string(/(<timeline*?>)(*)(<\/timeline>)/gi);
	protect_string(/(<span\sstyle\s*=)(color)(*>)/gi);
	protect_string(/(=\s*)(color)(\s*:#)/gi);
	protect_string(/(\{)((?:meta |font |)color)(*\|)/gi); //color box templates
	protect_string(/(+)(color)(\w)/gi);
	protect_string(/({{\w*\scolor\|)(]*)(}})/gi); // 

	protect_string(/(<\/?*)(center)(*>)/gi); // <center> tags
	protect_string(/(align\/?*=\/?**)(center)(*)/gi); // align="center" in tables

	protect_string(/(\{\{)(Medical cases chart\/bar colors)(+\}\})/gi);
	protect_string(/(\{\{)(bar percent)(\|+\}\})/gi);

	protect_string(/(<ref*?>)(*)(<\/ref>)/gi);
	protect_string(/(<ref name=)(*)(\/>)/gi);
	protect_string(/()(*)()/gi); // double quotes
	protect_string(/({{0,12}(?:quot{1,7}\s?|sic|(?:not a |)typo|as written)\|)(+)(})/gi);

	protect_string(/((?:Category|File|Image):)(]*)(])/gi); // cats, images
	protect_string(/((?:image\d?|image_skyline|imagelocation\d?|image(?:map|name)|img|pic)\s*=)(*)()/gi); // images within templates infoboxes etc
	protect_string(/(citeencyclopedia\s*\|)/gi);
	protect_string(/((?:url)\s*=)(*)()/gi); // urls within templates infoboxes etc
	protect_string(/(\]*)(])/gi);
	protect_string(/(\]*)(])/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(/({Party name with colou?r)(\s+)/gi);
	protect_string(/({Infobox )((?:*)organization)(\s+)/gi);
	protect_string(/({Infobox )((?:* )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*licene ?(?: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}|organiation|catalog\snumber)(\s*=)/g);
	protect_string(/(\|\s*)(encyclopedia|\w*colors|(?:org|rom)anization|license)(\s?=)/gi);
	protect_string(/(\|\s*)(localauthority)(\s?=)/gi);
	protect_string(/(\|\s*)(hip(?:armou?r|honou?rs))(*?=)/g);
	protect_string(/(\|\s*title\s?=)(]*)(\|)/gi);

//white list
	protect_string(/(Back in the U.S.S.R.)/g); // title of work
	protect_string(/(Born in the U.S.A.)/g); // title of work
	protect_string(/(Dear Mom|Serial Mom)/g); // title of work
	protect_string(/(Traveling Wilburys?|Rockerfeller)/g); // proper noun
	protect_string(/(to license)/gi);  // verb
	protect_string(/(non-cooperation)/gi);
	protect_string(/(Organisation for Economic Co-operation and Development)/gi);
	protect_string(/(prmis(?:e|ing)|paradise)/gi);
	protect_string(/(solid gry)/gi);
	protect_string(/(rigor mortis)/gi);
	protect_string(/(penises)/gi);
	protect_string(/(World Health Organization)/gi);

	// protect from hyphenation
	protect_string(/(\breed(?:|s)|eegan)/g);

	// whitelisting: protect from doubling of "L" 
	protect_string(/(conceal|adrenaline|rebel|Rockerfeller)/gi);

	// whitelisting: protect from function ohc_ENGVAR_restore_z
	protect_string(/(?:ar|de|enterpr|improv|parad|prec|prom|rev|surpr|treat|telev)(?:ise??|ing)/gi);
	protect_string(/(?: anti)(?:c|dote|mon|path|q)/g);
	protect_string(/(denise|excell(ed|ing))/gi);
	protect_string(/(?:(?:mercury|nobel)pri|imagesi|picsi)(?:ze)/g);

	editor.set(text);
}

function ohc_ENGVAR_unprotect(editor) {
	// restore words protected at runtime
	editor.replace(//g, '');

	// restore words protected beforehand
	var text = editor.get();

	var matches;
	do {
		text = text.replace(/⍌(+)⍍/g, function (match, index) {
			return protected_map;
		});
		matches = text.match(/⍌(+)⍍/g);
	} 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
	editor.replace(/B\.B\.C\./g, 'BBC');
	editor.replace(/U\.S\.A\./g, 'U.S.');
	editor.replace(/U\.S\.S\.R\./g, 'USSR');
	editor.replace(/U\.K\./g, 'UK');
	editor.replace(/E\.U\./g, 'EU');
	editor.replace(/(fill )out/gi, '$1in');

	// agrammatical
	editor.replace(/(comprised )of /gi, '$1');

	// hyphenation
//	editor.replace(/(co)(ordinat(e\b|ing|ion))/g, '$1-$2');
//	editor.replace(/\b(re)(e\w\w{4,})/gi, '$1-$2');
//	editor.replace(/\b(over|under)(r\w{4,})/gi, '$1-$2');

	// capitalisation
	// rem geographical regions - too many false positives
//	editor.replace(/(local )authority/g, '$1council');

	editor.replace(/w(estern European Union)/g, 'W$1');
	editor.replace(/(New )s(outh Wales)/g, '$1S$2');
}

function ohc_ENGVAR_simple_b(editor) {
	var table = {
		'aging': '$1ageing',
		'aluminum': '$1aluminium',
		'adrenalin(\\b)': '$1adrenaline$2',
		'annex(\\b)': '$1annexe$2',
		'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
		'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',
		'(light-|dark-|\\b)gray': '$1$2grey',
		'guerilla': '$1guerrilla',
		'jewelry': '$1jewellery',
		'(judg)(ment)': '$1e$2',
		'maneuver(ab|ed|ing)': '$1manoeuvr$2',
		'maneuver': '$1manoeuvre',
		'meager': '$1meagre',
		'louve(red|ring)': '$1louv$2',
		'(louv|somb)er': '$1$2re',
		'ped(iatric|ophil)': '$1paed$2',
		'encyclopedi(a|c)': '$1encyclopaedi$2',
		'skeptic': '$1sceptic',
		'mollusk': '$1mollusc',
		'vapor(s?\\b)': '$1vapour$2',
		'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',
		'orthopedic': '$1orthopaedic',
		'archeo': '$1archaeo',
		'paleonto': '$1palaeonto',
		'enology': '$1oenology',
		'esophag': '$1oesophag',
		'estrogen': '$1oestrogen',
		'(an|)esthe(sia|tic|tist)': '$1$2aesthe$3',
		'anesthesiologist': '$1anaesthetist',
		'homeopath': '$1homoeopath',
//		'medieval(\\b)': '$1mediaeval$2',
		'omelet(\\b)': '$1omelette$2',
		'rigor(\\b)': '$1rigour$2',
		'(an|leuk|septic|tox)emi(a|c)': '$1$2aemi$3',

		// 'f' words
		//'(S|s)ulfur': '$1$2ulphur',  //disabled per WP:ARTCOM

		'anymore': '$1any more',
		'specialty': '$1speciality',

		// non-redundant e
		'(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',
		'favor(abl|ed|i*|s|\\b)': '$1favour$2',
		'honor(abl|ed|ing|s|\\b)': '$1honour$2',
		'(endeav|lab)or(e|ing|s|\\W)': '$1$2our$3',
		'mol(dy?|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(?:|\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(?:|\d{2,3}|one|two|three|four|five|six|seven|eight|nine|ten)\b) story': '$1-storey',
//		'(\\W{3,12})iz(e?|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|ist|ing)': '$1$2ell$3',
		'(bev|jew|lev|mod|rev|trav)el(e|ing)': '$1$2ell$3',
		'({2,8})el(e|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|ing)': '$1$2all$3' // appalled/appalling is also American
	};

	for (var word in table) {
		try {
			editor.replace(new RegExp('()' + word, 'g'), table);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	var table2 = {
		// '~our' words
		'()(col|flav|hum)or(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2our$3',
		'( *\\-)(col|flav|hum)ored': '$1$2oured',
		'()(col)or(\\W)': '$1$2our$3',

		// '~re~' words
		'()(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(ed|ing)': '$1$2re$3',
		'()(cent|epicent|recent)er(ed|ing)': '$1$2r$3',
		'()(cent|epicent|recent)er(s?\\b)': '$1$2re$3',

		// '~logu~' words
		'()(ana|cata|dia|epi|homo|mono|pro)log(ed|ing)': '$1$2logu$3',
		'()(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)l(e|ing|ors?)(\\b)': '$1$2ll$3$4',
		'\\b(*)ll(ful|ment)': '$1l$2',
		'(movie theat(er|re))': 'cinema',

		'()airplane': '$1aeroplane',
//		'()\\b(um|om(my|))\\b': '$1mother',  // disabled 10 June – frequent false positives
		'()sidewalk': '$1pavement'
	};

	for (word in table2) {
		try {
			editor.replace(new RegExp(word, 'g'), table2);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table2 + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	// remove US spelling from {{convert}} template output
	editor.replace(/({{convert\|*)\|(?:sp|spell)*=*us/gi, '$1');
	editor.replace(/({{(?:in|ft|yd|?m)?+to+*)\|(?:sp|spell)*=*(?:American|us)/gi, '$1');
	editor.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');

}

function ohc_ENGVAR_simple_c(editor) {
	var table = {
		'ageing': '$1aging',
		'aluminum': '$1aluminium',
		'adrenalin(\\b)': '$1adrenaline$2',
		'annex(\\b)': '$1annexe$2',
		'(ana|breatha|cata|hydro|para)lyz(e|ing)': '$1$2lys$3',
		'(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',
		'(light-|dark-|\\b)gray': '$1$2grey',
		'guerilla': '$1guerrilla',
		'maneuver(ab|ed|ing)': '$1manoeuvr$2',
		'maneuver': '$1manoeuvre',
		'louve(red|ring)': '$1louv$2',
		'louver': '$1louvre',
		'encyclopaedi(a|c)': '$1encyclopedi$2',
		'skeptic': '$1sceptic',
		'mollusk': '$1mollusc',
		'vapor(s?\\b)': '$1vapour$2',
		'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',
		'foetus': '$1fetus',
		'gyneco': '$1gynaeco',
		'haemo(globin|ly|phil|rr)': '$1hemo$2',
		'orthopaedic': '$1orthopedic',
		'oenology': '$1enology',
		'oesophag': '$1esophag',
		'oestrogen': '$1estrogen',
		'homoeopath': '$1homeopath',
		'omelet(\\b)': '$1omelette$2',
		'paed(iatric|ophil)': '$1ped$2',
		'palaeonto': '$1paleonto',
		'rigor(\\b)': '$1rigour$2',
		'(an|leuk|septic|tox)aemi(a|c)': '$1$2emi$3',

		// 'f' words
		//'(S|s)ulfur': '$1$2ulphur',  //disabled per WP:ARTCOM

		'anymore': '$1any more',
		'speciality': '$1specialty',

		// non-redundant e
		'(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',
		'favor(abl|ed|i*|s|\\b)': '$1favour$2',
		'honor(abl|ed|ing|s|\\b)': '$1honour$2',
		'(endeav|lab)or(e|ing|s|\\W)': '$1$2our$3',
		'mol(dy?|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',
		'(centi|milli|deci|pico|hecto|\\b)liter(s?\\b)': '$1$2litre$3',
		'(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|ist|ing)': '$1$2ell$3',
		'(bev|jew|lev|mod|rev|trav)el(e|ing)': '$1$2ell$3',
		'({2,8})el(e|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|ing)': '$1$2all$3' // appalled/appalling is also American
	};

	for (var word in table) {
		try {
			editor.replace(new RegExp('()' + word, 'g'), table);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	var table2 = {
		// '~our' words
		'()(col|flav|hum)or(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2our$3',
		'( *\\-)(col|flav|hum)ored': '$1$2oured',
		'()(col)or(\\W)': '$1$2our$3',

		// '~re~' words
		'()(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(ed|ing)': '$1$2r$3',
		'()(cent|epicent|recent)er(ed|ing)': '$1$2r$3',
		'()(cent|epicent|recent)er(s?\\b)': '$1$2re$3',

		// '~logu~' words
		'()(ana|cata|dia|homo|mono|pro)log(ed|ing)': '$1$2logu$3',
		'()(ana|cata|dia|homo|mono|pro)log(s?\\b)': '$1$2logue$3',

		// '~l' words where the 'l' doubles as past and present participle
		'\\b(counc)l(e|ing|ors?)\\b': '$1ll$2',
//		'(movie theat(er|re))': 'cinema',
		'\\b(*)ll(ful|ment)': '$1l$2'
	};

	for (word in table2) {
		try {
			editor.replace(new RegExp(word, 'g'), table2);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table2 + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	// remove US spelling from {{convert}} template output
	editor.replace(/({{convert\|*)\|(?:sp|spell)*=*us/gi, '$1');
	editor.replace(/({{(?:in|ft|yd|?m)?+to+*)\|(?:sp|spell)*=*(?:American|us)/gi, '$1');
	editor.replace(/({{(?:pd|pop+density)+(?:km|mi)2*)\|(?:sp|spell)*=*(?:American|us)/gi, '$1');

	// remove ambiguous dollar sign; rem incidental intervening space
	editor.replace(/$ ?(\d)/g, '$$1');
	//editor.replace(/rigour mortis/g, 'rigor mortis');
	// reconvert special cases
}

function ohc_ENGVAR_simple_a(editor) {
	var table = {
		'ageing': '$1aging',
		'aluminium': '$1aluminum',
		'adrenaline(\\b)': '$1adrenalin$2',
		'annexe(\\b)': '$1annex$2',
		'artefact': '$1artifact',
		'(ana|breatha|cata|hydro|para)lys(e|ing)': '$1$2lyz$3',
//		'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',
		'(light-|dark-|\\b)grey': '$1$2gray',
		'guerilla': '$1guerrilla',
		'jewellery': '$1jewelry',
		'manoeuvr(ab|ed?|ing)': '$1maneuver$2',
		'louv(red|ring)': '$1louve$2',
		'louvre': '$1louver',
		'paed(iatric|ophil)': '$1ped$2',
		'encyclopaedi(a|c)': '$1encyclopedi$2',
		'sceptic': '$1skeptic',
		'mollusc': '$1mollusk',
		'vapour(s?\\b)': '$1vapor$2',
		'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',
//		'mediaeval(\\b)': '$1medieval$2',
		'omelette(\\b)': '$1omelet$2',
		'rigour(\\b)': '$1rigor$2',
		'(an|leuk|septic|tox)aemi(a|c)': '$1$2emi$3',

		// 'f' words
		//'(S|s)ulfur': '$1$2ulphur',  //disabled per WP:ARTCOM

		'any more': '$1anymore',
		'speciality': '$1specialty',

		// non-redundant e
		'(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)our((?:ful|less)(?:ly|)|\\b)': '$1$2or$3',
		'neighbourhood': '$1neighborhood',
		'behaviour(al|s|\\b)': '$1behavior$2',
		'favour(abl|ed|i*|s|\\b)': '$1favor$2',
		'honour(abl|ed|ing|s|\\b)': '$1honor$2',
		'(endeav|lab)our(e|ing|s|\\W)': '$1$2or$3',
		'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',
		'(peda|mono|syna)gogue(s?\\W)': '$1$2gog$3', //rem "demagog"
//		'(\\W{3,12})iz(e?|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|ist|ing)': '$1$2el$3',
		'(bev|jew|lev|mod|rev|trav)ell(e|ing)': '$1$2el$3',
		'({2,8})ell(e|est|ing)(\\b)': '$1$2el$3$4', // added 'p' to avoid changing of "misspelling"
//		'(\\bexcel)((?:e|est|ing)\\b)': '$1l$2', // "excelling/excelled" is US English

		'(di|enthr|equ|initi|journ|riv|sign|tot)all(e|ing)': '$1$2al$3' // appalled/appalling is also American
	};

	for (var word in table) {
		try {
			editor.replace(new RegExp('()' + word, 'g'), table);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	var table2 = {
		// '~our' words
		'()(col|flav|hum)our(ed|ful|fully|ings?|less|lessly|s\\W)': '$1$2or$3',
		'( *\\-)(col|flav|hum)oured': '$1$2ored',
		'()(col)our(\\W)': '$1$2or$3',

		// '~re~' words
		'()(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)re(ed|ing)': '$1$2er$3',
		'()(cent|epicent|recent)re(ed|ing)': '$1$2er$3',
		'()(cent|epicent|recent)re(s?\\b)': '$1$2er$3',

		// '~logu~' words
		'()(ana|cata|epi|homo|mono|pro)logu(ed|ing)': '$1$2log$3', // removing "dialogue" per user:coffeeandcrumbs (21/8/2018)
		'()(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)ll(e|ing|ors?)(\\b)': '$1$2l$3$4',
		'\\b({3,})()l(ful|ment)': '$1$2ll$3', //added specific quantifier – false positive with "ailment"
//		'(movie theat(er|re))': 'cinema', // disabling per user:coffeeandcrumbs

		'()aeroplane': '$1airplane',
//		'()\\b(um|om(my|))\\b': '$1mother'  // disabled 10 June – frequent false positives
	};

	for (word in table2) {
		try {
			editor.replace(new RegExp(word, 'g'), table2);
		} catch (err) {
			alert('There was an error when changing "' + word + '" => "' + table2 + '".\n\n'
				+ 'Error: ' + err.message + '\n\n'
				+ 'Click OK to continue.\n\n');
		}
	}

	// remove US spelling from {{convert}} template output
	editor.replace(/({{convert\|*)\|(?:sp|spell)*=*us/gi, '$1');
	editor.replace(/({{(?:in|ft|yd|?m)?+to+*)\|(?:sp|spell)*=*(?:American|us)/gi, '$1');
	editor.replace(/({{(?:pd|pop+density)+(?:km|mi)2*)\|(?:sp|spell)*=*(?:American|us)/gi, '$1');

	// remove ambiguous dollar sign; rem incidental intervening space
	editor.replace(/$ ?(\d)/g, '$$1');
	//editor.replace(/rigour mortis/g, 'rigor mortis');
	// reconvert special cases
}

function ohc_ENGVAR_set_variation(editor, variation) {
	ohc_ENGVAR_protect(editor);

	switch (variation) {
		case 'B':
			ohc_ENGVAR_simple_b(editor);
			ohc_ENGVAR_remove_z(editor);
			break;
		case 'O':
			ohc_ENGVAR_simple_b(editor);
			ohc_ENGVAR_restore_z(editor);
			break;
		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);
			break;
		default:
			return;
	}

	ohc_ENGVAR_plain(editor);
	ohc_ENGVAR_unprotect(editor);

	ohc_retask_pipes(editor);

	ohc_ENGVAR_insert_template(editor, variation);
	ohc_ENGVAR_edit_summary(editor, variation);

	editor.clickDiff();
}

/** ------------------------------------------------------------------------ **/

function ohc_ENGVAR_remove_z(editor) {
	editor.replace(/({3,12})iz(e?|ations?|abl|ing)(\W)/g, '$1is$2$3');
	editor.replace(/(rgan|ecog)iz(e(?:?|rs)|ations)(\W)/g, '$1is$2$3');
	editor.replace(/(empha)siz(e|ing)/g, '$1sis$2');
	editor.replace(/(synthe)siz(e|ing)/g, '$1sis$2');

	editor.replace(/(burgl)ari(ed?|ing)/g, '$1$2');

}

function ohc_ENGVAR_restore_z(editor) {
	// converts 's-words' into 'z-words'
//	editor.replace(/()r()mis(e|ing)/g, '$1r$2m♫is$3'); // Premise, promise et al. //new protection below
	editor.replace(/({5,12})is(ations?)(\W)/g, '$1iz$2$3');
	editor.replace(/({0,12}(?:|ph|rd|thes))is(e?|ing)(\W)/g, '$1iz$2$3');
	editor.replace(/(rgan|ecogn)is(e(?:?|rs)|ations)(\W)/g, '$1iz$2$3');
}

/** ------------------------------------------------------------------------ **/

function ohc_imperial_units(editor) {
	// measurements and perception
//	editor.replace(/\]/gi, '$1$2');

	// Template:{{convert}}
//	editor.replace(/({{convert)(\s*\|)/gi, '$1/flip$2'); // rem linking within convert template (area) // needs resolving
	editor.replace(/({{convert\|+?\|(?:(?:sq|cu|)(?:?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\|+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template
	editor.replace(/({{convert\|+?\|(?:(?: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\|+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // flip hectares
	editor.replace(/({{convert\|+?\|(?:kmh|km\/h)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // flip kmh
	editor.replace(/({{convert\|+?\|(?:to|by|x)(?:\|+?\|(?:?m))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (input ranges only)
	editor.replace(/({{convert\|+?\|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\|+?\|(?:kg|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=+?)*(?=})/gi, '$1$2|disp=flip'); // putting pounds and °C first
//	editor.replace(/({{(?:in|ft|mi|?m)?\sto\s(?:in|ft|mi|?m)?*?)\|wiki=(?:yes|no)/gi, '$1');

	// manipulating "|disp=flip" parameter where already "flipped"
	editor.replace(/({{convert\|+?\|\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\|+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi|acre)(?:2|3|))(?:\|(?:sq|cu|)(?:?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\|+?\|(?: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(editor) {
	// measurements and perception
//	editor.replace(/\]/gi, '$1$2');

	// Template:{{convert}}
//	editor.replace(/({{convert)(\s*\|)/gi, '$1/flip$2'); // rem linking within convert template (area) // needs resolving
	editor.replace(/({{convert\|+?\|(?:(?:sq|cu|)(?:in|ft|yd|mi)(?:2|3|))(?:\|(?:sq|cu|)(?:?m)(?:2|3|))?(\|\d)?(\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template (area)
	editor.replace(/({{convert\|+?\|tonnes?(?:\|tons?)?(\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // rem linking within convert template
	editor.replace(/({{convert\|+?\|(?:(?:sq|)mi(?:2|3|)|acre))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*?(?=})/gi, '$1$2|disp=flip'); // putting metres and hectares behind
//	editor.replace(/({{convert\|+?\|(?:hectares?|ha)(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // flip hectares
//	editor.replace(/({{convert\|+?\|mp(?:\|\d)?(?:\|(?:sp|adj|abbr|lk|sigfig|sortable)=*)*)(?=})/gi, '$1|disp=flip'); // flip kmh
	editor.replace(/({{convert\|+?\|(?:to|by|x)(?:\|+?\|(?: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\|+?\|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\|+?\|(?:lb|oz|°?F))(\|(?:sp|adj|abbr|lk|sigfig|sortable)=+?)*(?=})/gi, '$1$2|disp=flip'); // putting pounds and °C first
//	editor.replace(/({{(?:in|ft|mi|?m)?\sto\s(?:in|ft|mi|?m)?*?)\|wiki=(?:yes|no)/gi, '$1');

	// manipulating "|disp=flip" parameter where already "flipped"
	editor.replace(/({{convert\|+?\|\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\|+?\|(?:(?:sq|cu|)(?:?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\|+?(?:\|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_retask_pipes(editor) {
	editor.replace(/(\+? |)+?iation)\|((?:+? |){3,12}i(?:e?|ations?|abl|ing))/g, '$1$2');
//	editor.replace(/(empha|synthe)siz(e|ing)/g, '$1sis$2');
}

/** ------------------------------------------------------------------------ **/

function ohc_ENGVAR_insert_template(editor, variation) {
	// Add a template to the article identifying English variant
	// Build a string with "Month YYYY"
	var date_object = new Date();
	var month_map = ;
	var date_string = month_map + ' ' + date_object.getFullYear();

	var template_string;
	switch (variation) {
		case 'B':
			template_string = '{{EngvarB|date=' + date_string + '}}';
			break;
		case 'O':
			template_string = '{{Use Oxford spelling|date=' + date_string + '}}';
			break;
		case 'C':
			template_string = '{{Use Canadian English|date=' + date_string + '}}';
			break;
		case 'U':
			template_string = '{{Use American English|date=' + date_string + '}}';
			break;
		default:
			return;
	}

	// Matcher for every English variation template
	var template_matcher = new RegExp('{{(?:*Template*:)?*(?:Use+(?:British(?:+\\(?(?:Oxford|IUPAC)\\)?)?|X|Hong Kong|European|Commonweal?th|Scottish|American|Canadian|Indian|Irish|Hiberno|Jamaican|Nigerian|Bangladeshi|Pakistani|Singapore(?:an)?|South African|Trinidadian|New Zealand|US|U.S.|Oxford|IUPAC)(?:(?:+|-)English)?(?:+Oxford)?(?:+spelling)?|Engvar(?:Au?|Ox?|)|U?BE|EB|Use BrE|En-(?:US|GB(?:-oxendict)?|CA|NZ))(?:/sandbox)?*(?:|\\|*date*=*)*}}', 'gi'); //removed Australian 24/9/19

	// If not already tagged
	if (!editor.contains(template_matcher)) {
		// Prepend new template
		editor.prepend(template_string + '\r\n');
	} else {
		// Replace old template
		editor.replace(template_matcher, template_string);
	}
}

function ohc_ENGVAR_edit_summary(editor, variation) {
	// Add a tag to the summary box
	var variation_string;
	switch (variation) {
		case 'B':
			variation_string = 'EngvarB';
			break;
		case 'O':
			variation_string = 'Oxford spelling';
			break;
		case 'C':
			variation_string = 'Canadian English';
			break;
		case 'U':
			variation_string = 'American English';
			break;
		default:
			return;
	}

	editor.appendEditSummary(variation_string);
}
// </syntaxhighlight>