User:Ohconfucius/script/tometricunits.js

//

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, '$1$2 mph'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(mph|miles per hour)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 mph');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(ft\/s|f[eo]{2}t per second)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 ft\/s');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(ft\/s|f[eo]{2}t per second)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 ft\/s');

////ranges regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 $3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 $3');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:pounds|lbs?\.?)|)\s?([–—])\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?\.?)/g, '$1$2 to $4$5 lb');

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, '$1 $2'); 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, '$1 $2');	regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?:(?: |\s|)(?:inch(?:es|)|in\.?)|)\s?([–—])\s?(\d{1,2}(?:\.\d+|))(?: |\s|)(?:inch(?:es|)|in\.)/g, '$1 $2');

regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:feet|ft\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 $3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:feet|ft\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 $3');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:yards|yds?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards|yds?)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 $3');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:yards|yds?\.?)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards|yds?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 $3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:miles)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)mi(?:les|)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 $3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?:(?: |\s|)(?:miles)|)\s?(to|-)\s?(\d*),?(\d+(?:\.\d+|))(?: |\s|)miles(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 $3');

////multiple units regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(feet|ft\.?),?(?: |\s|)([01]?\d)(?: |\s|)in(?:ches|ch|)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1 ft'); regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(feet|ft\.?),?(?: |\s|)([01]?\d)(?: |\s|)in(?:ches|ch|)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1 ft');	regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(pounds?|lbs?\.?),?(?: |\s|)([01]?\d)(?: |\s|)(?:oz|ounces?)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1 lb');	regex(/(?<![,\d\(\[])(\d+)(?: |\s|)(pounds?|lbs?\.?),?(?: |\s|)([01]?\d)(?: |\s|)(?:oz|ounces?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1 lb');

////simple regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=[\.,;]?(?:\s+[a-z\(]|<|\n))/g, '$1$2 lb'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:pounds|lbs?)(?=\.\s+[A-Z]|\s.\W|\n)/g, '$1$2 lb');

regex(/(?<![,\d\(\[])(\d{1,2}(?:\.\d+|))(?: |\s|)in\.(?=[\.,;]?\s+[a-z\(])/g, '$1$2 in'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)in(?:ches|ch)(?=[\.,;]?\s+[a-z\(])/g, '$1$2 in'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:feet|ft)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 ft'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:yards?|yds?)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 yd'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(mi)(?:les|)\.?(?=[\.,;]?\s+[a-z\(])/g, '$1$2 $3');

regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)inches/g, '$1$2 in');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)feet/g, '$1$2 ft'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)yards/g, '$1$2 yd');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)miles/g, '$1$2 $3');

////adjectival regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(in)ch(?: |\s)(?!\/g, '$1$2 in'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(foot|ft)(?: |\s)(?!\/g, '$1$2 ft'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(yard|yd)(?: |\s)(?!\/g, '$1$2 yd'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(mi)le(?: |\s)(?!\/g, '$1$2 mi'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(pound|lb)(?: |\s)(?!\/g, '$1$2 lb'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))-(acre)(?: |\s)(?!\/g, '$1$2 acre');

////area (shorthand) regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq\. ft\.|sq ?ft)( |\s)(?!\/g, '$1$2 sqft$3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq\. yd\.|sq ?yd)( |\s)(?!\/g, '$1$2 sqyd$3'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)(?:sq mi)( |\s)(?!\/g, '$1$2 sqmi$3'); //area longhand regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square feet/g, '$1$2 sqft');	regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square yards?/g, '$1$2 sqyd'); regex(/(?<![,\d\(\[])(\d*),?(\d+(?:\.\d+|))(?: |\s|)square miles?/g, '$1$2 sqmi');	regex(/(?<![,\d\(\[])(\d+),?(\d+(?:\.\d+|))(?: |\s|)acres?/g, '$1$2 acre');

regex(/(?<![,\d\(\[])(\d+(?:\.\d+|))(?: |\s|)acres?/g, '$1 acre');

} 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', , );

} }); //