User:Bobblewik/monobook.js/units nbsp.js: Difference between revisions

Content deleted Content added
Bobblewik (talk | contribs)
mNo edit summary
maintenance: more info ReferenceError: Can't find variable: addLink
 
(5 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');
}
 
function units_nbsp() {
Line 68 ⟶ 69:
txt.value = txt.value.replace(/(\d)\s?bhp/gi, '$1 bhp');
txt.value = txt.value.replace(/(\d)\s?shp/gi, '$1 shp');
 
// Space before units
txt.value = txt.value.replace(/(\d)\s?cc([\s,.;:\)\(\\/)])/gi, '$1 cc$2');
txt.value = txt.value.replace(/(\d)\-cc([\s,.;:\)\(\\/)])/gi, '$1 cc$2');
txt.value = txt.value.replace(/(\d)\s?ft([\s,.;:\)\(\\/)])/gi, '$1 ft$2');
txt.value = txt.value.replace(/(\d)\-ft([\s,.;:\)\(\\/)])/gi, '$1 ft$2');
txt.value = txt.value.replace(/(\d)\s?rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\-rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\s?kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
txt.value = txt.value.replace(/(\d)\-kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
//space before 'm' only when lower case
txt.value = txt.value.replace(/(\d)\s?m([\s,.;:\)\(\\/)])/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\-m([\s,.;:\)\(\\/)])/g, '$1 m$2');
//txt.value = txt.value.replace(/(\d)\s?ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
//txt.value = txt.value.replace(/(\d)\-ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
txt.value = txt.value.replace(/(\d)\s?m(\W)/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\s?m(\w?\W)/g, '$1 m$2');
 
// miles per hour
Line 117 ⟶ 101:
txt.value = txt.value.replace(/([^;°][^;°]\s)(\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$1$2 ft $3 in');
txt.value = txt.value.replace(/([\(\|]\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$1 ft $2 in');
txt.value = txt.value.replace(/(\d)\s?ft\s(\d{1,2})\s?in/gi, '$1 ft $2 in');
 
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 147 ⟶ 138:
// Ensure space is used
txt.value = txt.value.replace(/(\d)\s?(k|M|G)(bit|B)/g, '$1 $2$3');
 
// Space before units
txt.value = txt.value.replace(/(\d)\s?cc([\s,.;:\)\(\\/)])/gi, '$1 cc$2');
txt.value = txt.value.replace(/(\d)\-cc([\s,.;:\)\(\\/)])/gi, '$1 cc$2');
txt.value = txt.value.replace(/(\d)\s?ft([\s,.;:\)\(\\/)])/gi, '$1 ft$2');
txt.value = txt.value.replace(/(\d)\-ft([\s,.;:\)\(\\/)])/gi, '$1 ft$2');
txt.value = txt.value.replace(/(\d)\s?rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\-rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\s?kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
txt.value = txt.value.replace(/(\d)\-kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
//space before 'm' only when lower case
txt.value = txt.value.replace(/(\d)\s?m([\s,.;:\)\(\\/)])/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\-m([\s,.;:\)\(\\/)])/g, '$1 m$2');
//txt.value = txt.value.replace(/(\d)\s?ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
//txt.value = txt.value.replace(/(\d)\-ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
txt.value = txt.value.replace(/(\d)\s?m(\W)/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\s?m(\w?\W)/g, '$1 m$2');
 
 
 
// Common error
Line 165 ⟶ 175:
}
 
addOnloadHook$(function () {
if(document.forms.editform) {
if(typeof addLink === 'undefined') return;
addLink('p-cactions', 'javascript:units_nbsp()', 'units_nbsp', 'ca-unitfixer', 'Fixes some unit formatting', '', '');
}