User:Gimmetrow/MOS.js
From Wikipedia, the free encyclopedia
If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
//<pre><code> // This code requires addLink from: [[User:Omegatron/monobook.js/addlink.js]] // function formatFix() { // selections from [[User:AndyZ/peerreviewer.js]] var txt = document.editform.wpTextbox1; txt.value = txt.value //MOSNUM remove s .replace(/(\d)\s?(|kilo|hecto|deca|deci|centi|milli|micro|nano)(meter|metre|liter|litre|gram|byte)(s?\W])/gi, '$1 $2$3$4') .replace(/(\d)\s?(k|d|c|m|µ|µ|µ)(g|l|m)s?(\W)/gi, '$1 $2$3$4') .replace(/(\d)\s?(inche?|foot|feet|yard|mile|acre|pound|ounce|ton|gallon|quart|pint|cup|angstrom)(s?\W)/gi, '$1 $2$3') .replace(/(\d)\s?(lb|ft|yd|mi|oz)s?(\W)/gi, '$1 $2$3') //MOSNUM, first ones are currency fixes .replace(/\$US(\d)/gi, '[[United States dollar|US$]]$1') .replace(/(\W)EU€/gi, '$1€') //add leading zero to decimals .replace(/\s(\-?)\.(\d+)\s/g, ' $10.$2 ') //times fixing .replace(/\s(\d\d?)\s?(a|p)m\s/g, ' $1 $2.m. ') .replace(/\s(\d\d?)\s?AM\s/g, ' $1 a.m. ') .replace(/\s(\d\d?)\s?PM\s/g, ' $1 p.m. ') .replace(/\s(\d\d?)[\.:](\d\d)\s?(a|p)m\s/g, ' $1:$2 $3.m. ') .replace(/\s(\d\d?)[\.:](\d\d)\s?AM\s/g, ' $1:$2 a.m. ') .replace(/\s(\d\d?)[\.:](\d\d)\s?PM\s/g, ' $1:$2 p.m. ') .replace(/\s12\snoon(\W)/g, ' noon$1') //MOSDATE remove th in dates followed by -th, others .replace(/([^\[])(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)th/gi, '$1[[$2 $3]]') .replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)\]\](<sup>)?th(<\/sup>)?/gi, '[[$1 $2]]') .replace(/(\D\d\d?)(<sup>)?th(<\/sup>)?\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$1 $4') .replace(/\s(\d{3}0)'s(\W)/gi, ' $1s$2') //.replace(/\s(\d{4})'s(\W)/gi, ' $1s$2') .replace(/the\s(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2') .replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2') .replace(/the\s(\d\d?)th\sof\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$2 $1') .replace(/(\d\dth\s)Century/g, '$1century') .replace(/20th century([ -])(Fox|Pictures|Film|Frog)/g, '20th Century$1$2') //MSH to fix captalization issues in headings .replace(/\n(={2,3})(\s?)See\sAlso\s?={2,3}/g, '\n$1$2See also$2$1') .replace(/\n(={2,3})(\s?)Further\sReading\s?={2,3}/g, '\n$1$2Further reading$2$1') .replace(/\n(={2,3})(\s?)Works\sCited\s?={2,3}/g, '\n$1$2Works cited$2$1') .replace(/\n(={2,3})(\s?)External\slink(s?)\s?={2,3}/g, '\n$1$2External link$3$2$1') .replace(/\n(={2,3})(\s?)Foot\s[Nn]otes\s?={2,3}/g, '\n$1$2Footnotes$2$1') //miscellaneous in headings (remove special characters) .replace(/\n(={2,4})(.*)\s&\s(.*)={2,4}/g , '\n$1$2 and $3$1') //spacing, XHTML //.replace(/<([bh])r\s*\/?\s*>/gi, '<$1r />') .replace(/<br\s*\/?\s*>/gi, '<br />') .replace(/<hr\s*\/?\s*>/gi, '<hr />') .replace(/<ref/gi, '<ref') .replace(/<\/ref>/gi, '</ref>') .replace(/<references\s*\/?\s*>/gi, '<references />') .replace(/<(\/?)TABLE/g, '<$1table') .replace(/<(\/?)DIV/g, '<$1div') .replace(/<(\/?)SPAN/g, '<$1span'); txt.value = txt.value //whitespace .replace(/\t/g, " ") .replace(/^ ? ? \n/gm, "\n") .replace(/(\n\n)\n+/g, "$1") .replace(/== ? ?\n\n==/g, "==\n==") .replace(/\n\n(\* ?\[?http)/g, "\n$1") .replace(/^ ? ? \n/gm, "\n") .replace(/\n\n\*/g, "\n*") .replace(/[ \t][ \t]+([^= ])/g, " $1") // .replace(/[ \t][ \t]+/g, " ") .replace(/([=\n]\n)\n+/g, "$1") .replace(/ \n/g, "\n") //ending sections .replace(/(== ?)(external links:?|outside links|web ?links:?|exterior links:?)( ?==)/gi, "$1External links$3") .replace(/(== ?)(external link:?|web ?link:?|exterior link:?)( ?==)/gi, "$1External link$3") .replace(/(== ?)(reference:?)(s? ?==)/gi, "$1Reference$3") .replace(/(== ?)(source:?)(s? ?==)/gi, "$1Source$3") .replace(/(== ?)(further readings?:?)( ?==)/gi, "$1Further reading$3") .replace(/\[\[ ?[Cc]ategory ?: ?/g, "[[Category:") //categories //repair bad internal links // problems: .replace(/([^\[]|^)\[?\[([^\]]*?)\]\]?([^\]]|$)/gm, "$1[[$2]]$3") // problem w/cats: .replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]") .replace(/\[\[ ?([^\]\|]*?) ?\]\]/g, "[[$1]]") .replace(/\[\[ ?([^\]\|]*?) ?\| ?([^\] ][^\]]*?) ?\]\]/g, "[[$1|$2]]") .replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]") //repair bad external links .replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]") .replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]") // and https: .replace(/\[?\[https:\/\/([^\]]*?)\]\]?/gi, "[https://$1]") .replace(/\[https:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[https://$1 $2]") .replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4"); txt.value = txt.value.replace(/\[http:\/\/en\.wikipedia\.org\/wiki\/([^ ]*) ([^\]]*)\]/gi, "[[$1]]"); } addOnloadHook(function () { if(document.forms.editform) { // addLink('p-cactions', 'javascript:fixRefMarks()', 'fix refs', 'ca-reffix', 'Ref fix for the edit window', '', 'ca-history'); addPortletLink('p-tb', 'javascript:formatFix()', 'Fix format', 't-forfix', 'Format fix', '', ''); } }); //</code></pre>