User:Ohconfucius/script/tometricunits.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/tometricunits. |
// <nowiki>
function Ohc_CONVERT_TOMETRICUNITS(){
//unlinking main units before adding template
regex(/\[\[((?:acre|yard|f(ee|oo)t|inch|mile|pound|ounce)s?)\]\]/gi, '$1');
regex(/\[\[pound \(mass\)\|((?:lb|pound)s?)\]\]/gi, '$1');
regex(/\[\[foot \(unit\)\|(f[eo]{2}t)\]\]/gi, '$1');
//imperial conversion fixes
////velocity
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(mph|miles per hour)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|mph|km\/h}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(mph|miles per hour)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|mph|km\/h}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(ft\/s|f[eo]{2}t per second)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|ft\/s|m\/s}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(ft\/s|f[eo]{2}t per second)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|ft\/s|m\/s}}');
////ranges
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|$3|$4$5|lb|kg}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|$3|$4$5|lb|kg}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?([–—])\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?\.?)/g, '{{convert|$1$2|to|$4$5|lb|kg}}');
regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?:(?: |\s|)(?:inch(?:es|)|in\.?)|)\s?(to|-)\s?(\d{1,2}(?:\.\d+|))(?: |\s|)(?:inch(?:es|)|in)\.(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1|$2|$3|in|cm}}');
regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?:(?: |\s|)(?:inch(?:es|)|in\.?)|)\s?(to|-)\s?(\d{1,2}(?:\.\d+|))(?: |\s|)(?:inch(?:es|)|in)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1|$2|$3|in|cm}}');
regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?:(?: |\s|)(?:inch(?:es|)|in\.?)|)\s?([–—])\s?(\d{1,2}(?:\.\d+|))(?: |\s|)(?:inch(?:es|)|in\.)/g, '{{convert|$1|$2|$3|in|cm}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:feet|ft\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|$3|$4$5|ft|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:feet|ft\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|$3|$4$5|ft|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:yards|yds?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards|yds?)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|$3|$4$5|yd|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:yards|yds?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards|yds?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|$3|$4$5|yd|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:miles)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)mi(?:les|)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|$3|$4$5|mi|km}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:miles)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)miles(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|$3|$4$5|mi|km}}');
////multiple units
regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(feet|ft\.?),?(?: |\s|)([01]?\d)(?: |\s|)in(?:ches|ch|)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1|ft|$3|in}}');
regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(feet|ft\.?),?(?: |\s|)([01]?\d)(?: |\s|)in(?:ches|ch|)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1|ft|$3|in}}');
regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(pounds?|lbs?\.?),?(?: |\s|)([01]?\d)(?: |\s|)(?:oz|ounces?)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1|lb|$3|oz}}');
regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(pounds?|lbs?\.?),?(?: |\s|)([01]?\d)(?: |\s|)(?:oz|ounces?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1|lb|$3|oz}}');
////simple
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=[\.,;]?(?:\s+[a-z\(]|<|\n))/g, '{{convert|$1$2|lb|kg}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '{{convert|$1$2|lb|kg}}');
regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?: |\s|)in\.(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|in|cm}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)in(?:ches|ch)(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|in|cm}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|ft|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards?|yds?)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|yd|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(mi)(?:les|)\.?(?=[\.,;]?\s+[a-z\(])/g, '{{convert|$1$2|$3|km}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)inches/g, '{{convert|$1$2|in|cm}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)feet/g, '{{convert|$1$2|ft|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)yards/g, '{{convert|$1$2|yd|m}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)miles/g, '{{convert|$1$2|$3|km}}');
////adjectival
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(in)ch(?: |\s)(?!\()/g, '{{convert|$1$2|in|cm|adj=on}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(foot|ft)(?: |\s)(?!\()/g, '{{convert|$1$2|ft|m|adj=on}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(yard|yd)(?: |\s)(?!\()/g, '{{convert|$1$2|yd|m|adj=on}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(mi)le(?: |\s)(?!\()/g, '{{convert|$1$2|mi|km|adj=on}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(pound|lb)(?: |\s)(?!\()/g, '{{convert|$1$2|lb|kg|adj=on}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(acre)(?: |\s)(?!\()/g, '{{convert|$1$2|acre|ha|adj=on}}');
////area (shorthand)
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq\. ft\.|sq ?ft)( |\s)(?!\()/g, '{{convert|$1$2|sqft|m2}}$3');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq\. yd\.|sq ?yd)( |\s)(?!\()/g, '{{convert|$1$2|sqyd|m2}}$3');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq mi)( |\s)(?!\()/g, '{{convert|$1$2|sqmi|km2}}$3');
//area longhand
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square feet/g, '{{convert|$1$2|sqft|m2}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square yards?/g, '{{convert|$1$2|sqyd|m2}}');
regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square miles?/g, '{{convert|$1$2|sqmi|km2}}');
regex(/(?<![,\d\(\[])(\d+),?(\d+(?:\.\d+|))(?: |\s|)acres?/g, '{{convert|$1$2|acre|ha}}');
regex(/(?<![,\d\(\[])(\d+(?:\.\d+|))(?: |\s|)acres?/g, '{{convert|$1|acre|ha}}');
}
function Ohc_CONVERT_TOMETRICUNITS_driver(){
//Add a tag to the summary box
Ohc_CONVERT_TOMETRICUNITS();
setreason('Applying Convert template to non-metric units', 'appendonce');
}
$.when(mw.loader.using('mediawiki.util'), $.ready).done(function () {
if(document.forms.editform) {
mw.util.addPortletLink('p-tb', 'javascript:Ohc_CONVERT_TOMETRICUNITS_driver()', 'CONVERT to metric', 'convert', 'convert', '', '');
}
});
// </nowiki>