User:Date delinker/formatgeneral.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
function formatgeneral() {
var txt=document.editform.wpTextbox1;
// capitalise month names
// txt.value=txt.value.replace(/(\s)jan(|uary|\.)(\s)/g, '$1Jan$2$3');
// txt.value=txt.value.replace(/(\s)feb(|ruary|\.)(\s)/g, '$1Feb$2$3');
// txt.value=txt.value.replace(/(\d\s)mar(|ch|\.)(\s)/g, '$1Mar$2$3');
// txt.value=txt.value.replace(/(\s)mar(|ch|\.)(\s\d)/g, '$1Mar$2$3');
// txt.value=txt.value.replace(/(\s)apr(|il|\.)(\s)/g, '$1Apr$2$3');
// txt.value=txt.value.replace(/(\d\s)may(,|\.)(\s)/g, '$1May$2$3');
// txt.value=txt.value.replace(/(\s)may(|\.)(\s\d)/g, '$1May$2$3');
// txt.value=txt.value.replace(/(\s)jun(|e|\.)(\s)/g, '$1Jun$2$3');
// txt.value=txt.value.replace(/(\s)jul(|y|\.)(\s)/g, '$1Jul$2$3');
// txt.value=txt.value.replace(/(\s)aug(|ust|\.)(\s)/g, '$1Aug$2$3');
// txt.value=txt.value.replace(/(\s)sep(|tember|\.)(\s)/g, '$1Sep$2$3');
// txt.value=txt.value.replace(/(\d{1,2}\s)sept(\s)/g, '$1Sep$2');
// txt.value=txt.value.replace(/(\s)oct(|ober|\.)(\s)/g, '$1Oct$2$3');
// txt.value=txt.value.replace(/(\s)nov(|ember|\.)(\s)/g, '$1Nov$2$3');
// txt.value=txt.value.replace(/(\s)dec(|ember|\.)(\s)/g, '$1Dec$2$3');
//rem linking within section headings
txt.value=txt.value.replace(/(==[ ]{0,1})\[\[([\w\s\,]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3');
txt.value=txt.value.replace(/(==[ ]{0,1})\[\[([^\|]{3,30}\||)([\w\s\,]+?)\]\]([ ]{0,1}==)/gi, '$1$2$3$4');
//improper capitalisation within section headings
txt.value=txt.value.replace(/(==[ ]*)Notable (Births|Deaths|Alumn)/g, '$1$2');
txt.value=txt.value.replace(/(==[ ]*Terminated )(Destinations)/g, '$1destinations');
txt.value=txt.value.replace(/(==[ ]*External )(Links)/g, '$1links');
txt.value=txt.value.replace(/(==[ ]*See )(Also)/g, '$1also');
//remove flagicons from birth and death
txt.value=txt.value.replace(/(birth\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1');
txt.value=txt.value.replace(/(death\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1');
txt.value=txt.value.replace(/(birth_?place\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1');
txt.value=txt.value.replace(/(death_?place\s?=\s?)\{\{flagicon\|[^\}]+\}\}/gi, '$1');
//rem redundant spaces
txt.value=txt.value.replace(/[ ]{1,3}(<\s?ref[^>]{0,15})/gi, '$1');
txt.value=txt.value.replace(/(\w\d)[ ][ ]+(\w\d)/gi, '$1 $2');
//symbol for 'times' and dashes
txt.value=txt.value.replace(/×/gi, '×');
// txt.value=txt.value.replace(/–/gi, '–');
txt.value=txt.value.replace(/—/gi, '—');
txt.value=txt.value.replace(/ — /gi, ' – ');
//rem leading and lagging spaces within wikilinks
txt.value=txt.value.replace(/(\[\[)\s([^\]]*\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]\|]*)\s(\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]]*\s)\s+([^\]]\]\])/gi, '$1$2');
txt.value=txt.value.replace(/(\[\[[^\]]*\d),(\]\])/gi, '$1$2');
//add missing space between wikilinks
txt.value=txt.value.replace(/(\]\])(\[\[)/gi, '$1 $2');
//full stop fixes
txt.value=txt.value.replace(/(Ph)(?:\.\s?|\s)(D).?/g, '$1$2');
txt.value=txt.value.replace(/(U)(?:\.\s?|\s)(K|N)\./g, '$1$2');
//nbsp fixes
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*(?:a\.m\.|am|A\.M\.|AM)(\W)/g, '$1 am$2');
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*(?:p\.m\.|pm|P\.M\.|PM)(\W)/g, '$1 pm$2');
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*kms?/gi, '$1 km');
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*cms?/gi, '$1 cm');
txt.value=txt.value.replace(/([^\|]\d{1,3})\s(m|b|tr)illion(\b[^}])/gi, '$1 $2illion$3');
//turn letter 'x' into symbol '×'
txt.value=txt.value.replace(/(\d)\sx\s(\d{1,3})\sin\s\(/gi, '$1 × $2 in (');
txt.value=txt.value.replace(/(\d)\sx\s(\d{1,3})\sinch\s/gi, '$1 × $2 inch ');
// Convert degree symbols into ° symbol, ensure preceding space
txt.value=txt.value.replace(/°/g, '°');
txt.value=txt.value.replace(/º/g, '°');
// Celsius spelling errors
txt.value=txt.value.replace(/(?:celsius|celcius|centigrade)/gi, 'Celsius');
//Fix common naming error (be careful with this one)
// txt.value=txt.value.replace(/centigrade/gi, 'Celsius');
//Celsius or Fahrenheit
txt.value=txt.value.replace(/(\d) (?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
txt.value=txt.value.replace(/(\d)(?:°|deg|degree|degrees) ([CF]\W)/g, '$1 °$2');
txt.value=txt.value.replace(/(\d) (?:°|deg|degree|degrees)([CF]\W)/g, '$1 °$2');
txt.value=txt.value.replace(/(\d)(?:\s|)(?:°|deg|degree|degrees)(?:\s|)([CF]\W)/g, '$1 °$2');
txt.value=txt.value.replace(/(\d) (\[\[Celsius|°C\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\d)(?:\s|)(\[\[Celsius|°C\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\d) (\[\[Fahrenheit|°F\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/(\d)(?:\s|)(\[\[Fahrenheit|°F\]\])/gi, '$1 $2');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)°?F([:;,\.?!]?\s[^\d\(\)\/\\])/g, '$1{{convert|$2|°F|°C|abbr=on}}$3');
txt.value=txt.value.replace(/([^\d\(\)\/\\]\s)(-?\d[\d,\.]*)(?:\s|-| |)(?:deg|degree|degrees)(?:\s|-| |)Fahrenheit([:;,\.?!]?\s[^\d\(\)\/\\])/gi, '$1{{convert|$2|°F|°C}}$3');
// Convert &sup to superscript
txt.value=txt.value.replace(/²/g, '²');
txt.value=txt.value.replace(/³/g, '³');
//remove commas from numerical values in convert template
txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|\d+),(\d)/g, '$1$2');
//remove leading zeros from convert template
txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2');
txt.value=txt.value.replace(/({convert\|)0(\d)/g, '$1$2');
//Remove surprise or 'Easter egg' diversions linking unit name to orders of magnitude articles
txt.value=txt.value.replace(/\[\[1\s?_?E\s?[\-\+]?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1');
txt.value=txt.value.replace(/\[\[Orders\sof\smagnitude\s\([^\)]+\)\|([^\]]{1,50})\]\]/gi, '$1');
}
function run_formatgeneral() {
var txt=document.editform.wpTextbox1;
formatgeneral();
edit_summary();
}
$(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:run_formatgeneral()', 'Add metric units', 't-addmetric', 'Fixes some unit formatting', '', '');
mw.util.addPortletLink('p-tb', 'javascript:label()', 'label', 't-label', 'adds unique function prefix', '', '');
}
});
function label(){
var txt=document.editform.wpTextbox1;
//inserting unique id prefix to all script functions
txt.value=txt.value.replace(/(\s)([^O\W]\w*(?:_\w*){0,5}[ ]*\(\))/gi, '$1Ohc_$2');
txt.value=txt.value.replace(/(javascript:)([^O]\w*(?:_\w*){0,5}[ ]*\(\))/gi, '$1Ohc_$2');
// edit_summary();
}