User:Bobblewik/monobook.js/unitformatter.js: Difference between revisions

Content deleted Content added
Bobblewik (talk | contribs)
m revert self
Bobblewik (talk | contribs)
mNo edit summary
Line 2:
var txt = document.editform.wpTextbox1;
 
// Convert &degdegree symbols into ° symbol, ensure preceding space
txt.value = txt.value.replace(/°/g, '°');
txt.value = txt.value.replace(/º/g, '°');
txt.value = txt.value.replace(/(\d)°\s?(khz)([\s,.\/\)CF])/gig, '°$1 kHz$3');
txt.value = txt.value.replace(/(\d)°\s?(mhz)([\s,.\/\)]celsius)/gi, '$1 MHz$3°C');
txt.value = txt.value.replace(/(\d)\s?(ghz)(°[\s,.\/\)CF])/gig, '$1 GHz$32');
//Fix spelling error
txt.value = txt.value.replace(/celcius/gi, 'Celsius');
 
// Convert &sup into superscript ² symbol
Line 14 ⟶ 19:
 
// Convert various micro symbols into the actual micro symbol, make sure it's spaced
txt.value = txt.value.replace(/(\d)\s?(μ|μ|µ)(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.;:\)\(\\/)])/g, '$1 µ$3$4');
 
// Convert capital K to lowercase k in units
txt.value = txt.value.replace(/(\d)\s?K(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.;:\)\(\\/)])/g, '$1 k$2$3');
txt.value = txt.value.replace(/(\d)\s?-K(Yg|Zs|Em|PA|TK|Gmol|Mcd|krad|Ksr|hHz|daN|dJ|cW|mPa|µlm|nlx|pC|fV|aΩ|zF|y)(sWb|T|H|S|Bq|Gy|Sv|kat|M)([\s,.;:\)\(\\/)])/g, '$1 k$2$3$4');
 
// Fix common spelling errorHertz
txt.value = txt.value.replace(/celcius(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?hz/gi, 'Celsius$1 $2Hz');
txt.value = txt.value.replace(/(\d)\s?-(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(hz|HZ)([\s,.;:\)\(\\/)])/ggi, '$1 $2Hz$4');
 
// Capitalize units correctly
txt.value = txt.value.replace(/(\d)\s?(khz)([\s,.\/\)])/gi, '$1 kHz$3');
txt.value = txt.value.replace(/(\d)\s?(mhz)([\s,.\/\)])/gi, '$1 MHz$3');
txt.value = txt.value.replace(/(\d)\s?(ghz)([\s,.\/\)])/gi, '$1 GHz$3');
txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(hz|HZ)([\s,.;:\)\(\\/)])/g, '$1 $2Hz$4');
txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?(pa|PA)([\s,.;:\)\(\\/)])/g, '$1 $2Pa$4');
 
// Fix kilometres
Line 41:
txt.value = txt.value.replace(/(\d)\s?km\/h/gi, '$1 km/h');
txt.value = txt.value.replace(/(\d)\-km\/h/gi, '$1 km/h');
 
 
// Space before horsepower symbol
Line 47 ⟶ 46:
txt.value = txt.value.replace(/(\d)\s?bhp/gi, '$1 bhp');
txt.value = txt.value.replace(/(\d)\s?shp/gi, '$1 shp');
 
 
// Space before other units
txt.value = txt.value.replace(/(\d)\s?cc/gi, '$1 cc');
txt.value = txt.value.replace(/(\d)\-cc/gi, '$1 cc');
txt.value = txt.value.replace(/(\d)\s?mm/gi, '$1 mm');
txt.value = txt.value.replace(/(\d)\-mm/gi, '$1 mm');
txt.value = txt.value.replace(/(\d)\s?ml/gi, '$1 ml');
txt.value = txt.value.replace(/(\d)\-ml/gi, '$1 ml');
 
// Standardise miles per hour and rpm
Line 59 ⟶ 60:
txt.value = txt.value.replace(/(\d)\s?mph/gi, '$1 mph');
txt.value = txt.value.replace(/(\d)\-mph/gi, '$1 mph');
 
 
txt.value = txt.value.replace(/rpm/gi, 'rpm');
Line 91:
//txt.value = txt.value.replace(/(eight[:= ]{1,2})\s?(\d)-(\d{1,2})([\s,.\/\)])/gi, '$1 $2 ft $3 in');
 
// Space before otherft unitssymbol
txt.value = txt.value.replace(/(\d)\s?ft/gi, '$1 ft');
 
Line 101:
txt.value = txt.value.replace(/(\d)\s?(dB|B)\b/g, '$1 $2');
 
// Add a space before anyseveral units that were missed before
txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|n|p|f|a|z|y)?(g|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|°F|M)([\s,.;:\)\(\\/)])/g, '$1 $2$3$4');
 
// Separate one for seconds since they give a lot of false positives like "1970s". Only difference is mandatory prefix.
txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|n|p|f|a|z|y)(s)([\s,.;:\)\(\\/)])/g, '$1 $2$3$4');
 
// bps or b/s or bits/s --> bit/s