User:Ohconfucius/script/formatgeneral.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Ohconfucius/script/formatgeneral. |
function Ohc_formatgeneral() {
var txt=document.editform.wpTextbox1;
//improper capitalisation within section headings
txt.value=txt.value.replace(/(==[ ]*Notable )(?:Births)/g, '$1births');
txt.value=txt.value.replace(/(==[ ]*Notable )(?:Deaths)/g, '$1deaths');
txt.value=txt.value.replace(/(==[ ]*Notable )(?:Alumn)/g, '$1alum');
//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)[ ]{2,3}(\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, '—');
//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');
//nbsp fixes
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*a\.?m\.?/gi, '$1 am');
txt.value=txt.value.replace(/([\d:\.]\d?\d| \d?\d)[ ]*p\.?m\.?/gi, '$1 pm');
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/gi, 'Celsius');
txt.value=txt.value.replace(/celcius/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 Ohc_run_formatgeneral() {
var txt=document.editform.wpTextbox1;
Ohc_formatgeneral();
// Add a tag to the summary box
var txt=document.editform.wpSummary;
var summary = "General formatting";
if (txt.value.indexOf(summary) == -1) {
if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) {
txt.value += " | ";
}
txt.value += summary;
}
document.forms.editform.wpMinoredit.checked = true;
// document.editform.wpDiff.click();
}
addOnloadHook(function () {
if(document.forms.editform) {
addPortletLink('p-tb', 'javascript:Ohc_run_formatgeneral()', 'Add metric units', 't-addmetric', 'Fixes some unit formatting', '', '');
}
});