User:Neur0X/monobook.js

// install User:Cacycle/wikEd in-browser text editor document.write(' '); ///////////////////////////// // By Alek Storm // Please see talk page for instructions /////////////////////////////////////////

var body; // shortcut for body node var xmlhttp; // XMLHTTPRequest object var startNode; // div that includes section header and edit link var editSec; // edit link var editForm; // spliced edit form var preview; // spliced preview or diff content var oldContent; // original content of section var xmlhttpDone = false; // kludge to prevent multiple calls to callback

importScript("User:Supadawg/util.js");

function inc(path) { var lt = String.fromCharCode(60); var gt = String.fromCharCode(62); document.writeln(lt+'script type="text/javascript" src="/w/index.php?title='+path+'&action=raw&ctype=text/javascript&dontcountme=s"'+gt+lt+'/script'+gt); }

function initSecEdit { body = document.getElementsByTagName("body")[0];

// apply to all divs of class "editsection" var editSecs = document.getElementsByTagName("span"); var secCount = 1; var pagetitleRe=/\/(wiki\/|w\/index\.php\?title=)([^&?]*)/; // from [Wikipedia:WikiProject User scripts/Techniques] for ( var i = 0; i < editSecs.length; i++ ) { if ( editSecs[i].getAttribute("class") == "editsection" ) { for ( var k = 0; k < editSecs[i].childNodes.length; k++ ) { if ( editSecs[i].childNodes[k].nodeName == "A" ) { // grab editing uri, escape it, then put it back in         var editURI = "http://en.wikipedia.org/w/index.php?title="+encodeURIComponent2(pagetitleRe.exec(decodeURI(editSecs[i].childNodes[k].getAttribute("href")))[2]).replace(/\"/gi, "%22").replace(/\'/gi, "%27")+"&action=edit&section="+secCount;          // give it a unique id          editSecs[i].childNodes[k].setAttribute( "id", "editSection"+secCount );          // swap the href with a function call, passing the original href as the second parameter          editSecs[i].childNodes[k].setAttribute( "href", "javascript:editSection( document.getElementById('editSection" + secCount + "'), '"+editURI+"' );" );          secCount++;        }      }    }  } }

// called on click of section edit link function editSection( elem, editURI ) { cancelEdit; // get rid of any other sections being edited editSec = elem; startNode = elem.parentNode.parentNode;

// initiate xmlhttprequest for section edit page xmlhttpDone = false; xmlhttp = null // kludge xmlhttp = createXMLHTTP( "GET", editURI, stateChange ); }

// put raw input returned from XMLHTTPRequest into a div so we can grab specific elements function makeDiv( rawHTML ) { var div = createNode( body, "div", {style: "visibility: hidden; position: absolute;"} ); div.innerHTML = rawHTML.replace(/]*><\/script>/gi, ""); // if script tags are placed into the DOM, they force reload of files, and nasty things happen return div; }

function isHTag( node ) { return node.nodeName.charAt(0) == 'H' && !isNaN( parseInt( node.nodeName.charAt(1) ) ); }

// callback for onclick of an edit link function stateChange { if ( xmlhttp && xmlhttp.readyState == 4 ) { if ( xmlhttp.status == 200 ) { if ( xmlhttpDone ) return; xmlhttpDone = true;

// store old content of section - loop until we hit header of same spot in hierarchy if ( !oldContent ) { oldContent = makeDiv(""); var curElem = startNode.nextSibling; while ( curElem ) { var hitSiblingSection = false; if ( isHTag( curElem ) ) { for ( var i = 0; i < curElem.childNodes.length; i++ ) { if ( curElem.childNodes[i].nodeName == "SPAN"                  && curElem.childNodes[i].getAttribute("class") == "editsection"                   && parseInt( curElem.nodeName.charAt(1) ) <= parseInt( startNode.nodeName.charAt(1) ) ) hitSiblingSection = true; }         }          else if ( curElem.nodeName == "DIV" && curElem.getAttribute("class") == "printfooter" ) break;

if ( hitSiblingSection ) break; var nextElem = curElem.nextSibling; oldContent.appendChild( curElem ); curElem = nextElem; }     }      else removeNode( oldContent );

var div = makeDiv( xmlhttp.responseText ); editForm = $("editform"); // change onclick of preview and diff buttons to our function $("wpPreview").setAttribute( "type", "button" ); $("wpPreview").setAttribute( "onclick", "javascript:getEditData( previewChanged, $('wpPreview') );" ); $("wpDiff").setAttribute( "type", "button" ); $("wpDiff").setAttribute( "onclick", "javascript:getEditData( diffChanged, $('wpDiff') );" ); insertAfter( editForm, startNode ); removeNode( div );

editSec.setAttribute( "oldHref", editSec.getAttribute("href") ); editSec.setAttribute( "href", "javascript:cancelEdit;" ); editSec.innerHTML = "cancel"; }   else alert("Problem retrieving data - status: "+xmlhttp.status); } }

// firefox hack, not sure if this is a problem in other browsers function encodeURIComponent2( content ) { // from content = content.replace(/\&lt\;/gi, "<"); content = content.replace(/\&gt\;/gi, ">"); content = content.replace(/\&quot\;/gi, "\""); content = content.replace(/\&amp\;/gi, "&");  return encodeURIComponent( content ); }

// encode differently based on type of form element function field2Post( node, allowButton ) { var reqBody = ""; switch ( node.nodeName ) { case "TEXTAREA": reqBody += "&"+node.getAttribute("name")+"="+encodeURIComponent2( node.value ); break; case "INPUT": var inputType = node.getAttribute("type"); if ( inputType == "checkbox" ) { if ( node.checked ) reqBody += "&"+node.getAttribute("name")+"=on" }     else if ( allowButton || (inputType != "submit" && inputType != "button") ) reqBody += "&"+node.getAttribute("name")+"="+encodeURIComponent2( node.value ); break; case "DIV": reqBody += form2Post( node, false ); break; } return reqBody; }

// manually encodes a form element for XMLHTTPRequest function form2Post( node ) { var reqBody = ""; for ( var i = 0; i < node.childNodes.length; i++ ) reqBody += field2Post( node.childNodes[i], false ); return reqBody; }

// get preview or diff data function getEditData( callback, clickedBut ) { xmlhttpDone = false; xmlhttp = null; // kludge var action = editForm.getAttribute("action"); xmlhttp = createXMLHTTP( "POST", "http://en.wikipedia.org"+action, callback, {   body: form2Post( editForm ) + field2Post( clickedBut, true ),    headers: {      "Content-Type": "application/x-www-form-urlencoded",      "Referer": "http://en.wikipedia.org" + action.substring( 0, action.indexOf('&') ) + "&action=edit&section="+(parseInt(editSec.getAttribute("id").substring(11))+1)    }  } ); }

// callback for preview data function previewChanged { if ( xmlhttp && xmlhttp.readyState == 4 ) { if ( xmlhttp.status == 200 ) { if ( xmlhttpDone ) return; xmlhttpDone = true; var div = makeDiv( xmlhttp.responseText ); if ( preview ) removeNode( preview ); preview = $("wikiPreview"); insertAfter( preview, startNode ); removeNode( div ); }   else alert("Problem retrieving data - status: "+xmlhttp.status); } }

// callback for diff data function diffChanged { if ( xmlhttp && xmlhttp.readyState == 4 ) { if ( xmlhttp.status == 200 ) { if ( xmlhttpDone ) return; xmlhttpDone = true; var div = makeDiv( xmlhttp.responseText ); if ( preview ) removeNode( preview ); preview = $("wikiDiff"); insertAfter( preview, startNode ); removeNode( div ); }   else alert("Problem retrieving data - status: "+xmlhttp.status); } }

// remove form and preview or diff data function cancelEdit { if ( preview ) removeNode( preview ); preview = null; if ( editForm ) removeNode( editForm ); editForm = null; if ( oldContent ) { oldContent.setAttribute( "style", "position: static; visibility: visible;" ); insertAfter( oldContent, startNode ); } oldContent = null; if ( editSec ) { editSec.setAttribute( "href", editSec.getAttribute("oldHref") ); editSec.innerHTML = "edit"; } }

addEventListener( "load", initSecEdit, false ); // Script from User:MarkS/extraeditbuttons.js importScript('User:MarkS/extraeditbuttons.js'); //User:MarkS/extraeditbuttons.js //'winc' function allows buttons to be added toolbar

winc('User:Omegatron/monobook.js/addlink.js');

function formatunits { var txt = document.editform.wpTextbox1;

// Convert degree symbols into ° symbol, ensure preceding space txt.value = txt.value.replace(/&deg;/g, '°'); txt.value = txt.value.replace(/º/g, '°');

// Celsius spelling errors txt.value = txt.value.replace(/celsius/gi, 'Celsius'); txt.value = txt.value.replace(/celcius/gi, 'Celsius'); //Fix common naming error (be careful with this one) txt.value = txt.value.replace(/centigrade/gi, 'Celsius');

//Celsius //txt.value = txt.value.replace(/\[\[(celsius)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[celsius\|([^\]]{1,30})\]\]/gi, '$1');

//Fahrenheit //txt.value = txt.value.replace(/\[\[(Fahrenheit)\]\]/gi, '$1'); // txt.value = txt.value.replace(/\[\[Fahrenheit\|([^\]]{1,30})\]\]/gi, '$1');

//Celsius or Fahrenheit 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, '$1 $2'); txt.value = txt.value.replace(/deg[^\(]([CF])/gi, '°$1');   txt.value = txt.value.replace(/deg\s([CF])/gi, '°$1');    txt.value = txt.value.replace(/deg\.?\s?([CF])/gi, '°$1');    txt.value = txt.value.replace(/degrees?\s([CF])(\W)/gi, '°$1$2');    txt.value = txt.value.replace(/(\d)\s?° ([CF])/g, '$1 °$2');

// Convert &sup to superscript txt.value = txt.value.replace(/&sup2;/g, '²'); txt.value = txt.value.replace(/&sup3;/g, '³');

// Convert micro symbol to actual micro symbol, make sure it's spaced txt.value = txt.value.replace(/(\d)\s?(&mu;|μ|&micro;)(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)(\W)/g, '$1 µ$3$4');

//metre //txt.value = txt.value.replace(/\[\[(metres?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(meters?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[metres?\|([^\]]{1,30})\]\]/gi, '$1'); //space before 'm' only when lower case txt.value = txt.value.replace(/(\d)\s?m(\W)/g, '$1 m$2'); txt.value = txt.value.replace(/(\d)\-m(\W)/g, '$1 m$2'); txt.value = txt.value.replace(/(\d)\s?sq\.?\s?m(\W)/gi, '$1 m²$2'); txt.value = txt.value.replace(/(\d)\-?sq\-?m(\W)/gi, '$1 m²$2'); txt.value = txt.value.replace(/m²\.\)/gi, 'm²)');

// millimetre //txt.value = txt.value.replace(/\[\[(mm)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(millimetres?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(millimeters?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[millimetres?\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[millimeters?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?mm(\W)/g, '$1 mm$2'); txt.value = txt.value.replace(/(\d)\-mm(\W)/g, '$1 mm$2');

// centimetre //txt.value = txt.value.replace(/\[\[(cm)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(centimetres?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(centimeters?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[centimetres?\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[centimeters?\|([^\]]{1,30})\]\]/gi, '$1');

// kilometre //txt.value = txt.value.replace(/\[\[(km)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(kilometres?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(kilometers?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[kilometres?\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[kilometers?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?kms?(\W)/gi, '$1 km$2'); txt.value = txt.value.replace(/(\d)\-kms?(\W)/gi, '$1 km$2'); txt.value = txt.value.replace(/(\d) kms?(\W)/gi, '$1 km$2'); //square kilometre //txt.value = txt.value.replace(/\[\[square kilometres?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?sq\.?\s?kms?/gi, '$1 km²'); txt.value = txt.value.replace(/sq\.?\s?kms?/gi, 'km²');

// kilometre per hour txt.value = txt.value.replace(/km\/hr(\W)/gi, 'km/h$1'); txt.value = txt.value.replace(/kph(\W)/gi, 'km/h$1'); txt.value = txt.value.replace(/kmph(\W)/gi, 'km/h$1'); txt.value = txt.value.replace(/(\d)\s?kmh/gi, '$1 km/h'); txt.value = txt.value.replace(/km\/h/gi, 'km/h'); 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'); txt.value = txt.value.replace(/(\d) km\/h/gi, '$1 km/h');

// cubic centimetre txt.value = txt.value.replace(/(\d)\s?cm(\W)/gi, '$1 cm$2'); txt.value = txt.value.replace(/(\d)\s?cc(\W)/gi, '$1 cc$2'); txt.value = txt.value.replace(/(\d)\-cc(\W)/gi, '$1 cc$2');

// millilitre txt.value = txt.value.replace(/(\d)\s?ml(\W)/g, '$1 ml$2'); txt.value = txt.value.replace(/(\d)\-ml(\W)/g, '$1 ml$2');

// second txt.value = txt.value.replace(/\[\[(s)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[(seconds?)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[seconds?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/\/sec(\W)/gi, '/s$1'); txt.value = txt.value.replace(/\/sec\)/gi, '/s)$1');

txt.value = txt.value.replace(/(\d)\s?ft\/second/gi, '$1 ft/s'); txt.value = txt.value.replace(/(\d)\s?m\/second/gi, '$1 m/s'); txt.value = txt.value.replace(/(\d)\s?km\/sec(\W)/gi, '$1 km/s$2'); txt.value = txt.value.replace(/frames\/s(\W)/gi, 'frame/s$1');

//minute txt.value = txt.value.replace(/\[\[(min)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[(minutes?)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[minutes?\|([^\]]{1,30})\]\]/gi, '$1');

// hour txt.value = txt.value.replace(/\[\[(h)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[(hours?)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[hours?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/\/hr(\W)/gi, '/h$1');

//day txt.value = txt.value.replace(/\[\[(d)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[(days?)\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[days?\|([^\]]{1,30})\]\]/gi, '$1');

// kilogram txt.value = txt.value.replace(/(kilogram)me/gi, '$1'); txt.value = txt.value.replace(/(\W)(gram)mes?(\W)/gi, '$1$2$3'); //txt.value = txt.value.replace(/\[\[(grams?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[grams?\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(kg)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(kilograms?)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[kilograms?\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?kg(\W)/gi, '$1 kg$2'); txt.value = txt.value.replace(/(\d)\-kg(\W)/gi, '$1 kg$2');

// newton metre //txt.value = txt.value.replace(/(\W)N[-.·•\/]m(\W)/gi, '$1N·m$2');

// kilowatt txt.value = txt.value.replace(/(\d)\s?kW(\W)/gi, '$1 kW$2'); txt.value = txt.value.replace(/(\d)\-kW(\W)/gi, '$1 kW$2');

// Hertz txt.value = txt.value.replace(/(\d)\s?(G|M|k)?hz/gi, '$1 $2Hz'); txt.value = txt.value.replace(/(\d)\-(G|M|k)?hz/gi, '$1 $2Hz'); txt.value = txt.value.replace(/khz/gi, 'kHz');

// ohm 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?(&Omega;|ohm|Ohm)s?(\W)/g, '$1 $2Ω$4');

// pound weight //txt.value = txt.value.replace(/(\d)\s?(\[\[lbs?\]\])/gi, '$1 lb'); //txt.value = txt.value.replace(/\[\[\pound\s\(mass\)\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?lbs?/gi, '$1 lb'); txt.value = txt.value.replace(/(\d\+?)\s?lbs?/gi, '$1 lb'); txt.value = txt.value.replace(/(\d) lbs?/gi, '$1 lb'); txt.value = txt.value.replace(/(\d)\slb.\)/gi, '$1 lb)');

//inch //txt.value = txt.value.replace(/\[\[(inch)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(inches)\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[inch\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[inches\|([^\]]{1,30})\]\]/gi, '$1');

//foot //txt.value = txt.value.replace(/\[\[foot\s\(unit\sof\slength\)\|([^\]]{1,30})\]\]/gi, '$1'); txt.value = txt.value.replace(/(\d)\s?ft(\W)/gi, '$1 ft$2'); txt.value = txt.value.replace(/(\d)\-ft(\W)/gi, '$1 ft$2'); txt.value = txt.value.replace(/(\W)ft\.\)/gi, '$1ft)');

// square foot txt.value = txt.value.replace(/sq\.?\s?ft/gi, 'sq ft');

// foot and inch //txt.value = txt.value.replace(/([^;°h]{1,4})(\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]([^NESW])/g, '$1$2 ft $3 in$4');   txt.value = txt.value.replace(/(ength[.]{1,3})(\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]/gi, '$1$2 ft $3 in'); txt.value = txt.value.replace(/(idth[.]{1,3})(\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]/gi, '$1$2 ft $3 in');   txt.value = txt.value.replace(/([\(\|:]\s?\d{1,4})\s?['’]\s?(\d{1,3})\s?["”]([^NESW])/g, '$1 ft $2 in$3');    txt.value = txt.value.replace(/(\d)\s?ft\s?(\d{1,3})\s?in/gi, '$1 ft $2 in');

// yard txt.value = txt.value.replace(/(\d)\s?yds(\W)/gi, '$1 yd$2'); txt.value = txt.value.replace(/(\d) yds(\W)/gi, '$1 yd$2'); txt.value = txt.value.replace(/sq\.?\s?yds?/gi, 'sq yd'); txt.value = txt.value.replace(/yd\.\)/gi, 'yd)');

// mile and mile per hour //txt.value = txt.value.replace(/\[\[miles?\|([^\]]{1,30})\]\]/gi, '$1'); //txt.value = txt.value.replace(/\[\[(miles?)\]\]/gi, '$1'); txt.value = txt.value.replace(/m\.p\.h\.(\W)/g, 'mph$1'); txt.value = txt.value.replace(/(\W)mph(\W)/gi, '$1mph$2'); txt.value = txt.value.replace(/(\d)\s?mph/gi, '$1 mph'); txt.value = txt.value.replace(/(\d)\-mph/gi, '$1 mph');

// square mile txt.value = txt.value.replace(/sq\.?\s?mi/gi, 'sq mi');

// foot pound txt.value = txt.value.replace(/ftlbs?(\W)/gi, 'ft·lbf$1'); txt.value = txt.value.replace(/ft[ -.·•\/]lb(\W)/gi, 'ft·lbf$1'); txt.value = txt.value.replace(/ft[ -.·•\/]lbs/gi, 'ft·lbf'); txt.value = txt.value.replace(/ft[ -.·•\/]lbf/gi, 'ft·lbf'); txt.value = txt.value.replace(/ft[ -.·•\/]lbff/gi, 'ft·lbf'); //the next two suspended until solution is found for wing loading (i.e. pounds per square foot) //txt.value = txt.value.replace(/lb[fs][ -.•\/]ft/gi, 'ft·lbf'); //txt.value = txt.value.replace(/lb[ -.•\/]ft/gi, 'ft·lbf');

// Give digital value a percent symbol '%' instead of word txt.value = txt.value.replace(/(\d)\s?per ?cent([^aei])/gi, '$1%$2'); txt.value = txt.value.replace(/(\d)\-per ?cent([^aei])/gi, '$1%$2');

// knot txt.value = txt.value.replace(/(\d)\s?kts(\W)/gi, '$1 knots$2'); txt.value = txt.value.replace(/(\d)\s?knt(\W)/gi, '$1 knots$2');

// horsepower txt.value = txt.value.replace(/(\d)\s?hp(\W)/gi, '$1 hp$2'); txt.value = txt.value.replace(/(\d)\s?bhp/gi, '$1 bhp'); txt.value = txt.value.replace(/(\d)\s?shp/gi, '$1 shp');

// rpm txt.value = txt.value.replace(/(\d)\s?rpm/gi, '$1 rpm'); txt.value = txt.value.replace(/(\d)\-rpm/gi, '$1 rpm');

// decibel txt.value = txt.value.replace(/(\d)\s?(dB)\b/g, '$1 $2');

// bits per second txt.value = txt.value.replace(/([KkMmGg])(bps|bits?\/s|b\/s)/g, '$1bit/s'); txt.value = txt.value.replace(/(\d)\s?(bps)/gi, '$1 bit/s'); txt.value = txt.value.replace(/(\d) bps/gi, '$1 bit/s'); txt.value = txt.value.replace(/bits?\/sec(\W)/gi, 'bit/s$1');

// bytes per second txt.value = txt.value.replace(/([KkMmGg])(Bps|bytes?\/s)/g, ' $1B/s'); txt.value = txt.value.replace(/bytes?\/s(\W)/gi, 'B/s$1');

// capitalization of prefix with bits and bytes txt.value = txt.value.replace(/K(bit|B)\/s/g, 'k$1/s'); txt.value = txt.value.replace(/m(bit|B)\/s/g, 'M$1/s'); txt.value = txt.value.replace(/g(bit|B)\/s/g, 'G$1/s');

// space with bits and bytes txt.value = txt.value.replace(/(\d)\s?(k|M|G)(bit|B)/g, '$1 $2$3');

// Common error with bits and bytes txt.value = txt.value.replace(/mibi(bit|byte)/g, 'mebi$1');

//Remove 'Easter egg' diversions (linking unit name to orders of magnitude articles) txt.value = txt.value.replace(/\[\[1\s?_?E\s?\-?\d{1,2}\s?..?\|([^\]]{1,50})\]\]/gi, '$1'); txt.value = txt.value.replace(/\[\[Orders\sof\smagnitude\s\([^\)]{1,30}\)\|([^\]]{1,50})\]\]/gi, '$1');

// Add a tag to the summary box var txt = document.editform.wpSummary; var summary = "units"; if (txt.value.indexOf(summary) == -1) { if (txt.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { txt.value += " | "; }		txt.value += summary; }

// Press the diff button to check it   document.editform.wpDiff.click }

$(function {    if(document.forms.editform) {        addLink('p-cactions', 'javascript:formatunits', 'units', 'ca-unitfixer', 'Fixes some unit formatting', , );    } }); // User:Outriggr/metadatatest.js importScript('User:Outriggr/metadatatest.js');