Content deleted Content added
m updated from unitformatter.js |
maintenance: more info ReferenceError: Can't find variable: addLink |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1:
//'winc' function allows buttons to be added toolbar
if(typeof winc !== 'undefined') {
winc('User:Omegatron/monobook.js/addlink.js');▼
}
▲winc('User:Omegatron/monobook.js/addlink.js');
▲function formatunits() {
var txt = document.editform.wpTextbox1;
Line 11 ⟶ 12:
txt.value = txt.value.replace(/°\s?([CF])/g, '°$1');
txt.value = txt.value.replace(/°\s?(celsius)/gi, '°C');
txt.value = txt.value.replace(/(\d)\s?(°[CF])/g, '$
//Fix spelling errors
txt.value = txt.value.replace(/celsius/gi, 'Celsius');
Line 23 ⟶ 24:
// Convert the word ohm(s) or the html entity into the actual Ω symbol (Omega, not the actual ohm symbol Ω) and make sure it is spaced
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?(Ω|ohm|Ohm)s?([\s,.;:\)\(\\/)])/g, '$
// 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|M)([\s,.;:\)\(\\/)])/g, '$
// 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|M)([\s,.;:\)\(\\/)])/g, '$
txt.value = txt.value.replace(/(\d)\-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|M)([\s,.;:\)\(\\/)])/g, '$
txt.value = txt.value.replace(/(\d) 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|M)([\s,.;:\)\(\\/)])/g, '$1 k$2$3');
// Hertz
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/gi, '$
txt.value = txt.value.replace(/(\d)\-(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?hz/gi, '$
// Fix kilometres
txt.value = txt.value.replace(/(\d)\s?kms?([\s,.;:\)\(\\/)])/gi, '$
txt.value = txt.value.replace(/(\d)\-kms?([\s,.;:\)\(\\/)])/gi, '$
txt.value = txt.value.replace(/(\d) kms?([\s,.;:\)\(\\/)])/gi, '$1 km$2');
txt.value = txt.value.replace(/(\d)\s?sq\.?\s?kms?/gi, '$
txt.value = txt.value.replace(/sq\.?\s?kms?/gi, 'km²');
txt.value = txt.value.replace(/(\d)\s?sq\.?\s?m([^i])/gi, '$
txt.value = txt.value.replace(/m²\.\)/gi, 'm²)');
Line 51 ⟶ 52:
txt.value = txt.value.replace(/kph/gi, 'km/h');
txt.value = txt.value.replace(/kmph/gi, 'km/h');
txt.value = txt.value.replace(/(\d)\s?kmh/gi, '$
txt.value = txt.value.replace(/km\/h/gi, 'km/h');
txt.value = txt.value.replace(/(\d)\s?km\/h/gi, '$
txt.value = txt.value.replace(/(\d)\-km\/h/gi, '$
txt.value = txt.value.replace(/(\d) km\/h/gi, '$1 km/h');
// Standardise 'per second'
txt.value = txt.value.replace(/(\d)\s?ft\/second/gi, '$
txt.value = txt.value.replace(/(\d)\s?ft\/sec/gi, '$
txt.value = txt.value.replace(/(\d)\s?m\/second/gi, '$
txt.value = txt.value.replace(/(\d)\s?m\/sec/gi, '$
txt.value = txt.value.replace(/(\d)\s?km\/sec/gi, '$
// Space before horsepower symbol
txt.value = txt.value.replace(/(\d)\s?hp/gi, '$
txt.value = txt.value.replace(/(\d)\s?bhp/gi, '$
txt.value = txt.value.replace(/(\d)\s?shp/gi, '$
// Space before units▼
txt.value = txt.value.replace(/(\d)\s?cc([\s,.;:\)\(\\/)])/gi, '$1nbsp;cc$2');▼
txt.value = txt.value.replace(/(\d)\-cc([\s,.;:\)\(\\/)])/gi, '$1nbsp;cc$2');▼
txt.value = txt.value.replace(/(\d)\s?ft([\s,.;:\)\(\\/)])/gi, '$1nbsp;ft$2');▼
txt.value = txt.value.replace(/(\d)\-ft([\s,.;:\)\(\\/)])/gi, '$1nbsp;ft$2');▼
txt.value = txt.value.replace(/(\d)\s?rpm/gi, '$1nbsp;rpm');▼
txt.value = txt.value.replace(/(\d)\-rpm/gi, '$1nbsp;rpm');▼
txt.value = txt.value.replace(/(\d)\s?kg([\s,.;:\)\(\\/)])/gi, '$1nbsp;kg$2');▼
txt.value = txt.value.replace(/(\d)\-kg([\s,.;:\)\(\\/)])/gi, '$1nbsp;kg$2');▼
//space before 'm' only when lower case▼
txt.value = txt.value.replace(/(\d)\s?m([\s,.;:\)\(\\/)])/g, '$1nbsp;m$2');▼
txt.value = txt.value.replace(/(\d)\-m([\s,.;:\)\(\\/)])/g, '$1nbsp;m$2');▼
//txt.value = txt.value.replace(/(\d)\s?ml([\s,.;:\)\(\\/)])/g, '$1nbsp;ml$2');▼
//txt.value = txt.value.replace(/(\d)\-ml([\s,.;:\)\(\\/)])/g, '$1nbsp;ml$2');▼
txt.value = txt.value.replace(/(\d)\s?m(\W)/g, '$1nbsp;m$2');▼
txt.value = txt.value.replace(/(\d)\s?m(\w?\W)/g, '$1nbsp;m$2');▼
// miles per hour
txt.value = txt.value.replace(/m\.p\.h\./gi, 'mph');
txt.value = txt.value.replace(/mph([\s,.;:\)\(\\/)])/gi, 'mph$1');
txt.value = txt.value.replace(/(\d)\s?mph/gi, '$
txt.value = txt.value.replace(/(\d)\-mph/gi, '$
// Standardise symbol for pounds
txt.value = txt.value.replace(/(\d)\s?lbs?/gi, '$
txt.value = txt.value.replace(/(\d\+?)\s?lbs?/gi, '$
txt.value = txt.value.replace(/(\d) lbs?/gi, '$1 lb');
txt.value = txt.value.replace(/(\d)\s?(\[\[lbs\]\])/gi, '$
// Standardise symbol for newton metres
Line 102 ⟶ 86:
// Standardise symbol for kilowatts
txt.value = txt.value.replace(/(\d)\s?kW([\s,.;:\)\(\\/)])/g, '$
txt.value = txt.value.replace(/(\d)\-kW([\s,.;:\)\(\\/)])/g, '$
// Standardise symbol for foot pounds
Line 115 ⟶ 99:
// Symbols for feet and inches
txt.value = txt.value.replace(/([^;°][^;°]\s)(\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$1$
txt.value = txt.value.replace(/([\(\|]\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$
txt.value = txt.value.replace(/(\d)\s?ft\s(\d
txt.value = txt.value.replace(/(\d)\s?feet/gi, '$1 feet');
txt.value = txt.value.replace(/(\d)\s?foot/gi, '$1 foot');
txt.value = txt.value.replace(/(\d)\s?knots/gi, '$1 knots');
txt.value = txt.value.replace(/(\d)\s?nmi/gi, '$1 nmi');
txt.value = txt.value.replace(/(\d)\s?nm/gi, '$1 nm');
//Symbols for square feet
Line 128 ⟶ 119:
// Add a space before dB
txt.value = txt.value.replace(/(\d)\s?(dB)\b/g, '$
// Add a space before several units that were missed before
//txt.value = txt.value.replace(/(\d)\s?(G|M|k|K|h|da|d|c|m|µ|n)?(g|m|Hz|N|W|Pa|V|Ω|F|)([\s,.;:\)\(\\/)])/g, '$
// bps or b/s or bits/s --> bit/s
txt.value = txt.value.replace(/([KkMmGg])(bps|bits?\/s|b\/s)/g, '$1bit/s');
txt.value = txt.value.replace(/(\d)\s?(bps)/gi, '$
// Bps or byte/s or bytes/s --> B/s
Line 146 ⟶ 137:
// Ensure space is used
txt.value = txt.value.replace(/(\d)\s?(k|M|G)(bit|B)/g, '$
▲ // Space before units
▲ //space before 'm' only when lower case
// Common error
Line 165 ⟶ 175:
}
if(document.forms.editform) {
if(typeof addLink === 'undefined') return;
addLink('p-cactions', 'javascript:
}
});
|