User:Date delinker/EngvarB.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*************
*** Regex menu framework
*** by [[m:user:Pathoschild]] <http://meta.wikimedia.org/wiki/User:Pathoschild/Scripts/Regex_menu_framework>
*** - adds a sidebar menu of user-defined scripts.
*************/
importScriptURI('http://meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
/* menu links */
// In the function below, add more lines like "regexTool('link text','function_name()')" to add
// links to the sidebar menu. The function name is the function defined in rfmscripts() below.
function rmflinks() {
regexTool('Custom regex','custom()'); // a default tool which performs regex input in a dynamic form
regexTool('Edit my regexes ↗','function opennew(url) { window.open(url); }; opennew(wgServer + wgScript + "?title=User:" + wgUserName + "/EngvarB.js&action=edit");');
regexTool('• Protect words','protectwords()');
regexTool('• BRITISH spelling','SetEnglish("B")');
regexTool('• BRITISH (Oxford) passive','SetEnglish("P")');
regexTool('• BRITISH (Oxford)','SetEnglish("Ox")');
//Fix formatting of links in the sidebar
var r = document.getElementById('p-regex')
if (r){
r.className += ' portal'
var d = r.getElementsByTagName('div')
if (d[0]) d[0].className += ' pBody body'
}
}
/* 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
// http://meta.wikimedia.org/wiki/User:Pathoschild/Script:Regex_menu_framework .
function protectwords(){
var table = [
'(al)(uminum)',
'(ar)(tifact)',
'(ana|cata|hydro|para)(lyz)',
'(ly)(zing)',
'(di)(arrhea)',
'(de|of)(fense)',
'(fu)(ror)',
'(gr)(ay)',
'(je)(welry)',
'(ma)(neuver)',
'(pe)(diatric)',
'(pe)(dophil)',
'(sk)(eptic)',
'(in)(quiry)',
'(va)(por)',
'(on)(stage)',
'(break|clean|lock|pick)(up)',
'(he)(mo)',
'(or)(thopedic)',
'(ar)(cheo)',
'(pa)(leonto)',
'(en)(ology)',
'(es)(ophag)',
'(es)(trogen)',
'(es)(thetic)',
'(ho)(meopath)',
'(me)(dieval)',
'(ri)(gor)',
'(an|leuk|septic|tox)(emi)',
'(su)(lfur)',
'(lik|liv|rat|sal|siz|shak)(able)',
'(clam|glam|harb|neighb|rum|savi?)(or)',
'(behavi|col|fl?av|hon|hum|lab)(or)',
'(mo)(ld)',
'(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)(er)',
'(cent)(er)',
'(me)(ter)',
'(centi|milli|deci|pico|hecto)(liter)',
'(dema|peda|mono|syna)(gog)',
'(ana|cata|dia|epi|homo|mono|pro)(log)',
'(iz)(e[drs]?|able|ations?|ing)',
'(iz)(e[drs]?|able|ations?|ing)', //repeating to catch second instances within protected strings (quotations in particular)
'(bev|jew|lev|mod|pan|rev|trav)(el\\w)',
'([a-z]{2,8}\\wel)(e[dr]|est|ing)',
'(counci|dia)(le[dr]|ling|lor)',
'(app|enthr|riv|sign|tot)(ale[dr]|aling)',
];
for (i=0; i<table.length; i++) {
var expr = [
['(<.+?>[^<]+?)', '([^<]+?<\\/.+?>)'],
['(\\[Category:[^\\]]*?)', '([^\\]]*?\\])'],
['(\\[(?:file|image):[^\\.]{0,20})', '([^\\.]{0,20}\\.)'],
['({[^{]{0,6}quot[^\\|]{1,7}\\s?\\|[^}]*?)', '([^}]*?})'],
];
for (j=0; j<expr.length; j++) {
var re = new RegExp(expr[j][0] + table[i] + expr[j][1], 'g')
regex(re, '$1$2♫$3$4')
}
}
}
function Simple(){
//protectwords()
regex(/([^\w\d\-\/])aluminum/g, '$1aluminium');
regex(/([^\w\d\-\/])artifact/g, '$1artefact');
regex(/([^\w\d\-\/])(ana|cata|hydro|para)lyz(e|ing)/g, '$1$2lys$3');
regex(/([^\w\d\-\/])diarrhea/g, '$1diarrhoea');
regex(/([^\w\d\-\/])(de|of)fense/g, '$1$2fence');
regex(/([^\w\d\-\/])furor([^\w\d\-\/])/g, '$1furore$2');
regex(/([^\w\d\-\/])(light-|dark-|\s)gray/g, '$1$2grey');
// regex(/([^\w\d\-\/])judgment/g, '$1judgement');
regex(/([^\w\d\-\/])jewelry/g, '$1jewellery');
regex(/([^\w\d\-\/])maneuver(ab|ed|ing)/g, '$1manoeuvr$2');
regex(/([^\w\d\-\/])maneuver/g, '$1manoeuvre');
regex(/([^\w\d\-\/])ped(iatric|ophil)/g, '$1paed$2');
regex(/([^\w\d\-\/])skeptic/g, '$1sceptic');
regex(/([^\w\d\-\/])in(quir(?:e|ing))/g, '$1en$2');
regex(/([^\w\d\-\/])vapor(s?[^\w\d\-\/])/g, '$1vapour$2');
//composite words
// regex(/([^\w\d\-\/])onstage/g, '$1on-stage');
regex(/([^\w\d\-\/])(break|lock|pick)up/g, '$1$2-up');
//latin words
regex(/([^\w\d\-\/])gyneco/g, '$1gynaeco');
regex(/([^\w\d\-\/])hemo(globin|ly|phil)/g, '$1haemo$2');
regex(/([^\w\d\-\/])orthopedic/g, '$1orthopaedic');
regex(/([^\w\d\-\/])archeo/g, '$1archaeo');
regex(/([^\w\d\-\/])paleonto/g, '$1palaeonto');
regex(/([^\w\d\-\/])enology/g, '$1oenology');
regex(/([^\w\d\-\/])esophag/g, '$1oesophag');
regex(/([^\w\d\-\/])estrogen/g, '$1oestrogen');
regex(/([^\w\d\-\/])esthetic/g, '$1aesthetic');
regex(/([^\w\d\-\/])homeopath/g, '$1homoeopath');
// regex(/([^\w\d\-\/])medieval([^\w\d\-\/])/g, '$1mediaeval$2');
regex(/([^\w\d\-\/])rigor([^\w\d\-\/])/g, '$1rigour');
regex(/([^\w\d\-\/])(an|leuk|septic|tox)emi(a|c)/g, '$1$2aemi$3');
//'f' words
regex(/([^\w\d\-\/])sulfur/g, '$1sulphur');
// non-redundant e
regex(/([^\w\d\-\/])(lik|liv|rat|sal|siz|shak)(able)/g, '$1$2e$3');
//'~our' words
regex(/([^\w\d\-\/])(clam|glam|harb|neighb|rum|savi?)or(ed|ful|ing|less|ly|s|)([^\w\d\-\/])/g, '$1$2our$3$4');
regex(/([^\w\d\-\/])neighborhood/g, '$1neighbourhood');
regex(/([^\w\d\-\/])behavior(al|s?[^\w\d\-\/])/g, '$1behaviour$2');
regex(/([^\w\d\-\/])(fav|hon)or(abl[ey]|ed|ing|s|)([^\w\d\-\/])/g, '$1$2our$3$4');
regex(/([^\w\d\-\/])labor(e[dr]|ing|s?\W)/g, '$1labour$2');
regex(/([^\w\d\-\/\|])(flav|hum)or(ed|ful|fully|ings?|less|lessly|s\W)/g, '$1$2our$3');
regex(/([^\w\d\-\/\|])color(ed|ful|fully|ings?|less|lessly)/g, '$1colour$2');
// regex(/([^\w\d\-\/\|])colors([^\W\s]|[\s]*[^=])/g, '$1colours$2');
regex(/( [\w\D]*\-)(col|flav|hum)ored/g, '$1$2oured');
regex(/([^\w\d\-\/])mold(ed|ing|s?\W)/g, '$1mould$2');
//'~re~' words
regex(/([^\w\d\-\/=])(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(ed|ing)/g, '$1$2r$3');
regex(/([^\w\d\-\/])(calib|fib|goit|lust|mit|nit|reconnoit|sab|saltpet|spect|theat|tit)er(s?\W)/g, '$1$2re$3');
regex(/([^\w\d\-\/=])(cent|epicent|recent)er(ed|ing)/g, '$1$2r$3');
regex(/([^\w\d\-\/=])(cent|epicent|recent)ers/g, '$1$2res');
regex(/([^\w\d\-\/])(centi|kilo|milli|-|\d\s)meter/g, '$1$2metre');
regex(/([^\w\d\-\/])(centi|milli|deci|pico|hecto|\b)liter(s?\b)/g, '$1$2litre$3');
regex(/([^\w\d\-\/])(dema|peda|mono|syna)gog(s?\W)/g, '$1$2gogue$3');
regex(/([^\w\d\\\/\-])(ana|cata|dia|epi|homo|mono|pro)log(s?[^\w\d\-\/])/g, '$1$2logue$3');
// regex(/([^\w\d\-\/])(\W[a-z]{3,12}[^s\b])iz(e[drs]?|able|ations?|ing)/g, '$1$2is$3');
// regex(/([^\w\d\-\/])(empha)siz(e|ing)/g, '$1$2sis$3'); //rem synthesiser conversion - equally common
//'~l' words where the 'l' doubles as past and present participle
regex(/([^\w\d\-\/])(bev|jew|lev|mod|pan|rev|trav)el(e[dr]|ing|ist)/g, '$1$2ell$3');
regex(/([^\w\d\-\/])([a-z]{2,8}[^egl ])el(e[dr]|est|ing)([^\w\d\-\/])/g, '$1$2ell$3$4');
regex(/([^\w\d\-\/])(counci|dia)l(e[dr]|ing|ors?)([^\w\d\-\/])/gi, '$1$2ll$3$4');
regex(/([^\w\d\-\/])(app|enthr|riv|sign|tot)al(e[dr]|ing)/g, '$1$2all$3');
regex(/(\s[\w]*)ll(ful|ment)/g, '$1l$2');
//to add
// protestors
//reconvert special cases
regex(/(nobelpr|images|pics)ise/g, '$1ize');
// unprotectwords()
}
function SetEnglish(v) {
unprotectwords();
protectwords();
Simple();
switch (v) {
case 'Ox':
re_zwords();
break;
case 'B':
zwords();
break;
case 'P':
alert('Feature not implemented');
break;
}
unprotectwords();
insert_Engvar(v);
edit_summary();
}
function Simpleplus() {
unprotectwords();
Simple();
zwords();
unprotectwords();
insert_Engvar('B')
edit_summary();
}
function zwords(){
regex(/([^\w\d\-][a-z]{3,12}[^s ])iz(e[drs]?|able|ations?|ing)(\W)/g, '$1is$2$3');
regex(/(empha|synthe)siz(e|ing)/g, '$1sis$2');
}
function re_zwords(){
//converts s-words into Oxford z-words
regex(/([^\w\d\-][a-z]{5,12})is(ations?)(\W)/g, '$1iz$2$3');
regex(/([^\w\d\-][a-z]{0,12}(?:[aeiou][^aeiou]|al))is(e[drs]?|ing)(\W)/g, '$1iz$2$3');
regex(/(empha|synthe)sis(e|ing)/g, '$1siz$2');
//need to protect
//promise
}
function unprotectwords(){
regex(/(\w)♫(\w)/g, '$1$2');
}
function insert_Engvar(v1){
// Add a template to the article identifying English variant
var box=document.editform.wpTextbox1;
var txt = box.value;
var v2 = ('Ox' == v1)? 'B' : 'Ox';
var re1 = new RegExp('{{(Engvar' + v1 + ')}}', 'gi')
var re2 = new RegExp('{{(Engvar' + v2 + ')}}', 'gi')
txt=txt.replace(re2, '{{Engvar' + v1 + '}}');
if (txt.search(re1) == -1) box.value='{{Engvar' + v1 + '}}\r\n'+txt;
}
function edit_summary(){
//Add a tag to the summary box
setoptions(minor='true',watch='false');
setreason('rendering [[WP:ENGVAR|consistent British spelling]] by [[User:Ohconfucius/EngvarB|script]]', 'append');
doaction('diff');
}