User:Hesperian/common.js

$(function {	$("#wpQuality-container").find(".quality0 input").click(function { var $textbox=$("#wpTextbox1");

var wipe=true; var proceed=true;

var stoppers = ["{{missing", "{{raw image"]; // if these are present then more than likely I misclicked for (var i=0; i<stoppers.length; i++) { if (-1 != $textbox.val.indexOf(stoppers[i])) return; }

var immune = ["{{iwpage", "{{elsewhere"]; // proceed without wiping this text for (var i=0; i<immune.length; i++) { if (-1 != $textbox.val.indexOf(immune[i])) wipe=false; }		$("#wpHeaderTextbox, #wpFooterTextbox").val(""); $("#wpHeaderTextbox, #wpFooterTextbox").val("");

if (wipe) { $textbox.val(""); } else { $("#wpSummary").val("/* Without text */ " + $textbox.val.trim); }

$("#wpSave").click; }); });

// $(function {	var qualityContainer = document.getElementById('wpQuality-container');	if (qualityContainer === null) return;

var quality2 = $(qualityContainer).find('.quality2').get; var problematic = quality2[0].childNodes[0];

problematic.addEventListener('click', function {		if (document.getElementsByName('wpTextbox1')[0].value == "{{missing image}}") {			document.getElementsByName('wpSummary')[0].value = "/* Problematic */ {{missing image}}";			document.getElementsByName('wpHeaderTextbox')[0].value = "";			document.getElementsByName('wpFooterTextbox')[0].value = "";			document.getElementsByName('wpSave')[0].click;		}		else if (document.getElementsByName('wpTextbox1')[0].value == "{{raw image|{{sub"+"st:PAGENAME}}}}") {			document.getElementsByName('wpSummary')[0].value = "/* Problematic */ {{raw image}}";			document.getElementsByName('wpHeaderTextbox')[0].value = "";			document.getElementsByName('wpFooterTextbox')[0].value = "";			document.getElementsByName('wpSave')[0].click;		}		else if (document.getElementsByName('wpTextbox1')[0].value == "{{bad page scan}}") {			document.getElementsByName('wpSummary')[0].value = "/* Problematic */ {{bad page scan}}"; document.getElementsByName('wpHeaderTextbox')[0].value = ""; document.getElementsByName('wpFooterTextbox')[0].value = ""; document.getElementsByName('wpSave')[0].click; }		else if (document.getElementsByName('wpTextbox1')[0].value == "{{bad image scan}}") { document.getElementsByName('wpSummary')[0].value = "/* Problematic */ {{bad image scan}}"; document.getElementsByName('wpHeaderTextbox')[0].value = ""; document.getElementsByName('wpFooterTextbox')[0].value = ""; document.getElementsByName('wpSave')[0].click; }		else if (document.getElementsByName('wpTextbox1')[0].value == "{{missing table}}") { document.getElementsByName('wpSummary')[0].value = "/* Problematic */ {{missing table}}"; document.getElementsByName('wpHeaderTextbox')[0].value = ""; document.getElementsByName('wpFooterTextbox')[0].value = ""; document.getElementsByName('wpSave')[0].click; }	}); }); //

// == IMPORT WORK-SPECIFIC INFORMATION ABOUT HEADERS, FOOTERS, REFS, ETC == //get specialFormats variable from work.js mw.loader.load('//en.wikisource.org/w/index.php?title=User:Hesperian/works.js&action=raw&ctype=text/javascript');

mw.loader.load('//en.wikisource.org/w/index.php?title=User:Hesperian/Promotable.js&action=raw&ctype=text/javascript');

/** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see https://meta.wikimedia.org/wiki/TemplateScript * @update-token */ // $.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	/*********	** Register scripts	*********/	// stuff I routinely do at the start	pathoschild.TemplateScript.add( [			{ name: 'header', script: header }, { name: 'blockcenter', script: blockcenter }, { name: 'clean up', script: function(editor) { cleanup(editor, false); } }, { name: 'clean up (poem)', script: function(editor) { cleanup(editor, true); } }, { name: 'uc', script: uc }, { name: 'hwe', script: hwe } ],		{ forNamespaces: 'page' } // common fields );

// stuff I can do any time pathoschild.TemplateScript.add([		{ name: 'title', script: maketitle, accessKey: 't' },		{ name: 'author', script: author, accessKey: 'a' },		{ name: 'author (surname first)', script: surnameFirst, accessKey: ',' },		{ name: 'small-caps', script: smallcaps, accessKey: 'c' },		{ name: 'upper', script: upper, accessKey: 'u' }	]);

// stuff I do at the end pathoschild.TemplateScript.add(		[			{ name: 'hws', script: hws },			{ name: 'makeref', script: makeref },			{ name: 'footer', script: footer }		],		{ forNamespaces: 'page' } // common fields	);

// stuff I only do via shortcuts; if I could create these shortcuts without adding them to the sidebar, I would. pathoschild.TemplateScript.add([		{ name: 'diaresis', script: diareses, accessKey: ':' },		{ name: 'acute', script: acute, accessKey: '\'' },		{ name: 'grave', script: grave, accessKey: '`' },		{ name: 'circumflex', script: circumflex, accessKey: '^' },		{ name: 'macron', script: macron, accessKey: '_' },		{ name: 'others', script: catchall, accessKey: '-' },		{ name: 'pagename', script: putpagename, accessKey: 'n' },		{ name: 'reload', script: reload_page_image }	]);

/*********	** Define scripts *********/	// === EXTRACT INFORMATION ABOUT PAGE === // These variables can be used to customize operations depending on whether you are working with unproofed OCR or already proofed text. var quality = (function getQuality {		var q = document.getElementById('pagequality');			if (q===null)				return "Nonexistent";		else {			var c = q.getAttribute("class");			switch(c) {				case "quality0": return "Without text";				case "quality1": return "Not proofread";				case "quality2": return "Problematic";				case "quality3": return "Proofread";				case "quality4": return "Validated";			}		}		return null;	}); var proofed = (quality != "Nonexistent" && quality != "Not proofread");

// === FOR CONVERSIONS === // Convenience function: converts some text into title case function titlecase(text) { // split text into individual words and examine them one by one var textArray = text.toLowerCase.split(" "); for (var i in textArray) { switch(textArray[i]) {				case "a": case "an": case "and": case "as": case "at": case "but": case "by": case "etcetera": case "etc.": case "for": case "from": case "in": case "nor": case "of": case "o'": case "on": case "or": case "the": case "to": case "with": case "versus": case "vs.": case "v.": case "yet": break; // don't capitalise articles, "to" as part of an infinitive, prepositions or short conjunctions default: // capitalise everything else textArray[i] = textArray[i].substring(0,1).toUpperCase + textArray[i].substring(1,textArray[i].length); break; }		}

// capitalise first word regardless textArray[0] = textArray[0].substring(0,1).toUpperCase + textArray[0].substring(1,textArray[0].length);

// capitalise last word regardless var last = textArray.length-1; textArray[last] = textArray[last].substring(0,1).toUpperCase + textArray[last].substring(1,textArray[last].length);

// reconstruct title var titleCase=""; for (i in textArray) { titleCase += textArray[i]; if (i < last) titleCase += " "; }

return titleCase; }

// == SIDEBAR TOOLS == function cleanup(editor, poem) { var headerbox = editor.forField('#wpHeaderTextbox'); var footerbox = editor.forField('#wpFooterTextbox');

headerbox.set(''); // can't stand the way index pages insert stuff here header(editor, false); // insert header only if there's a non-generic header defined

footerbox.set(''); // can't stand the way index pages insert stuff here footer(editor, false); // insert footer only if there's a non-generic header defined

// anything noincluded at the start or end of the edit box should be pushed into the header and footer respectively. if (editor.get.match(/^/)) { var e = editor.get.indexOf(" ");

// append to header a trimmed version of whatever is inside the leading noinclude editor.append('\n' + editor.get.substr(11, e-11).replace(/^\s+|\s+$/g, ''));

// remove leading noinclude from editbox editor.set(editor.get.substr(e+12)); }

if (editor.get.match(/<\/noinclude\>$/)) { var s = editor.get.lastIndexOf(" ");

// prepend to footer a trimmed version of whatever is inside the trailing noinclude footerbox.prepend(editor.get.substr(s+11, editor.get.length-s-11-12).replace(/^\s+|\s+$/g, '') + '\n');

// remove trailing noinclude from editbox editor.set(editor.get.substr(0, s)); }

editor // remove trailing spaces at the end of each line .replace(/ +\n/g, '\n')

// remove trailing whitespace preceding a hard line break .replace(/ +/g, ' ')

// remove trailing whitespace and numerals at the end of page text // (numerals are nearly always page numbers in the footer) .replace(/[\s\d]+$/g, '')

// remove trailing spaces at the end of refs .replace(/ +<\/ref>/g, ' ')

// remove trailing spaces at the end of template calls .replace(/ +}}/g, '}}')

// convert double-hyphen to mdash (avoiding breaking HTML comment syntax) .replace(/([^\!])--([^>])/g, '$1—$2')

// remove spacing around mdash, but only if it has spaces on both sides // (we don't want to remove the trailing space from "...as follows:— ",			// bearing in mind that the space will already be gone if at end of line). .replace(/ +— +/g, '—')

// join words that are hyphenated across a line break // (but leave "|-" table syntax alone) .replace(/([^\|])-\n/g, '$1');

// stuff to do only if the page doesn't contain a tag: if (editor.get.indexOf(' ') === -1) { editor // lines that start with " should probably be new lines,				// if the previous line ends in punctuation,				// other than a comma or semicolon				// and let's get rid of trailing space while we're at it				.replace(/([^\n\w,;])\n\" */g, '$1\n\n"')

// lines that end with " should probably precede a new line,				// unless preceded by a comma,				// or unless the new line starts with a lower-case letter;				// and let's get rid of preceding space while we're at it				.replace(/([^,])\ *\"\n([^a-z\n])/g, '$1"\n\n$2')

// if the final line ends in a ", then affix a trailing {{nop}}				.replace(/([^,])\"$/g, '$1"\n{{nop}}');

if (poem) { // for poems I want to preserve line breaks // by inserting hard breaks editor .replace(/([^>}\|\n])\n([^:#\*<{\|\n])/g, '$1 \n$2') .append(' '); }			else { // remove single line breaks; preserve multiple. // but not if there's a tag, template or table syntax either side of the line break editor.replace(/([^>}\|\n])\n([^:#\*<{\|\n])/g, '$1 $2'); }

// collapse sequences of spaces into a single space editor.replace(/ +/g, ' '); }

editor // dump spurious hard breaks at the end of paragraphs .replace(/\n\n/g, '\n\n')

// remove unwanted spaces around punctuation marks .replace(/ ([;:\?!,])/g, '$1')

// unicodify .replace(/&mdash;/g, '—') .replace(/–/g, '–') .replace(/&quot;/g, '"')

// double quotes .replace(/''/g, '"')

//OCR fixes // convert i9 to 19, etc.			.replace(/[il]([0-9])/g, '1$1')

// "that", the", "them", "their", etcetera			.replace(/\btli/g, 'th')

// "which", "enough", "wish", "with", etcetera .replace(/([cgst])li\b/g, '$1h')

// "what", "when", "where", "who", etcetera .replace(/\bwli/g, 'wh')

// "him", "his", etcetera .replace(/\blii/g, 'hi')

// "her", "hers" .replace(/\blier(s?)\b/g, 'her$1')

// "would", "with", "wh..." .replace(/\bAV/g, 'W') .replace(/\bAv([^aeiou])/g, 'w$1')

.replace(/\bAvay/g, 'way') .replace(/\bAvas\b/g, 'was') .replace(/\bAvith/g, 'with') .replace(/\bAvould/g, 'would')

// "U" -> "ll" when preceded by a lowercase letter. .replace(/([a-z])U/g, '$1ll')

// many works have apostrophes missing from OCR .replace(/([a-z]) s\b/g, '$1\'s') // it's he's etc .replace(/n t\b/g, 'n\'t') //can't isn't didn't etc .replace(/([a-zI]) ll\b/g, '$1\'ll') // I'll we'll etc .replace(/\bI m\b/g, 'I\'m') // I'm			.replace(/\b([Yy])ou re\b/g, '$1ou\'re') // you're			.replace(/\b([Ww])e re\b/g, '$1e\'re') // we're			.replace(/\b([Tt])hey re\b/g, '$1hey\'re') // they're			.replace(/([a-zI]) ve\b/g, '$1\'ve') // I've we've etc .replace(/([a-zI]) d\b/g, '$1\'d') // I'd he'd etc

// '11 -> 'll (constant OCR error in What Maisie Knew) .replace (/\'11\b/g, '\'ll')

// replace "float center" with "block center"; original template name was misleading enough be warrant routinely fixing .replace(/\{\{float center\|/g, '{{block center|') .replace(/\{\{hws\|/g, '{{hyphenated word start|') .replace(/\{\{hwe\|/g, '{{hyphenated word end|') .replace(/\{\{c\|/g, '{{center|') .replace(/\{\{sc\|/g, '{{small-caps|') .replace(/\{\{bar\|2\}\}/g, '{{longdash}}')

.replace(/ \s*([.\n]*?)\s*<\/center>/g, '{{center|$1}}')

// common weird scanno .replace(/&amp;[gl]t;/g, "'")

// common scanno .replace(/\b[FT]m\b/g, "I'm") .replace(/\b[FT]ve\b/g, "I've") .replace(/\b[FT]ll\b/g, "I'll")

// common quote mark scannos in The Awkward Age .replace(/['^*]['^*] ?/g, '"');

}

// get page number from URL var pagenum = (function {		var m = /\.djvu\/([0-9]+)&action=edit/g.exec(location.href);		if (m===null) return null;		return parseInt(m[1], 10);	});

// automatically insert running header into header box function header(editor, doGeneric) { doGeneric = doGeneric !== false; // default to true

if (pagenum===null) return;

var isEven = pagenum % 2 === 0;

var headerbox = editor.forField('#wpHeaderTextbox');

var generic = true; var headertext = '';

for (var f in specialFormats) { var format = specialFormats[f]; if (location.href.indexOf(encodeURI(format[0].replace(/ /g,"_")).replace(/\'/g,"%27")) !== -1) { if (isEven) headertext=format[1]; else headertext=format[2]; generic = false; break; }		}

// no special header matched, use a generic running header if (generic && doGeneric) { if (isEven) headertext = '{{running header|left=|center=}}'; // assume verso, with page number at left else headertext = '{{running header|center=|right=}}'; }

if (headerbox.get === "") headerbox.set(headertext); else headerbox.append('\n' + headertext);

// if this is unproofed text, then delete the first line of the OCR text, which presumably is raw OCR of the header we've just inserted if (!proofed) editor.set(editor.get.slice(editor.get.indexOf('\n') + 1)); }

// insert formatted references into footer box, if needed. function footer(editor, doGeneric) { doGeneric = doGeneric !== false; // default to true

var footerbox = editor.forField('#wpFooterTextbox'); var generic; var format; var f;

if (editor.get.indexOf(" ") === -1 && editor.get.indexOf("{{#tag:ref") === -1) { // page contains no refs generic = true; for (f in specialFormats) { format = specialFormats[f]; if (location.href.indexOf(encodeURI(format[0].replace(/ /g,"_")).replace(/\'/g,"%27")) !== -1) { footerbox.set(format[3]); generic = false; break; }			}

// no special footer matched, use just strip out the references tag if (generic && doGeneric) footerbox.set(''); }		else { generic = true; for (f in specialFormats) { format = specialFormats[f]; if (location.href.indexOf(encodeURI(format[0].replace(/ /g,"_")).replace(/\'/g,"%27")) !== -1) { footerbox.set(format[4]); generic = false; break; }			}

// no special footer matched, so use a generic ref tag if (generic && doGeneric) footerbox.set('{{block center|{{smallrefs}}}}'); }	}

// automatically insert block center wrapping into header box function blockcenter(editor) { editor.forField('#wpHeaderTextbox').append('\n{{block center/s}}'); editor.forField('#wpFooterTextbox').prepend('{{block center/e}}\n'); }

//Make selected text into appropriately capitalised title link // e.g. "THE MAN FROM SNOWY RIVER" —> "THE MAN FROM SNOWY RIVER" function maketitle(editor) { editor.replaceSelection(function(text) {			var target = titlecase(text);			return target == text				? +text+				: +text+;		}); }

//Make selected text into author link function author(editor) { editor.replaceSelection(function(name) {			// if name contains a comma, switch around when linking           var openPos = name.indexOf('('); var closePos = name.indexOf(')');           var target;            if (openPos === -1) {                target = name;            } else if (closePos === -1) {                target = name;            } else {                target = name.substr(openPos+1, closePos-openPos-1).trim + ' ' + name.substr(0, openPos).trim;            }			var commaPos = target.indexOf(',');			if (commaPos !== -1) {				target = target.substr(commaPos+1).trim + ' ' + target.substr(0, commaPos).trim;			}			// if name is all in capitals, convert target to title case			if (target == target.toUpperCase) {				target = titlecase(target);			}			return +name+;		}); }

function surnameFirst(editor) { editor.replaceSelection(function(name) {			// if name is all in capitals, convert target to title case			var target = name == name.toUpperCase				? titlecase(name)				: name;

// split text into individual words var nameArray = name.split(" ");

// put last first, followed by a comma, then all the rest preceded by spaces name = nameArray[nameArray.length-1] + ","; for (var i = 0; i < nameArray.length - 1; i++) name = name + " " + nameArray[i];

return +name+; });	}

//Mark selected text up with small-caps function smallcaps(editor) { editor.replaceSelection(function(pre) {			// Applying small-caps to all-caps text is pointless...			// ... unless the all-caps is OCR of text that is actually small-caps.			// Check if text is all-caps, and if it is, convert it to title case before applying small-caps.			if (pre == pre.toUpperCase)				pre = titlecase(pre);

return '{{small-caps|'+pre+'}}'; });	}

// As you work your way through the page, when you encounter a reference, just mark it with tags and continue. // Once you've got to the end of the page and proofed the references, simply highlight each reference in turn, // and use this function to move it to its proper position. function makeref { var editbox = $('#wpTextbox1').get(0); editbox.focus; var refStart = editbox.selectionStart; var refEnd = editbox.selectionEnd;

var firstref = editbox.value.indexOf(' '); if (-1 != firstref) { editbox.value = editbox.value.slice(0,firstref+5) + editbox.value.slice(refStart, refEnd) + editbox.value.slice(firstref+5, refStart) + editbox.value.slice(refEnd); }	}

//wrap first word in hwe template function hwe(editor) { var to = editor.get.search(/\W/); if (to == -1) to = editor.get.length;

var pre = editor.get.substring(0, to);

var post = '{{hyphenated word end|'+pre+'|…'+pre+'}}'; editor.set(post + editor.get.substring(to)); }

//wrap last word in hws template function hws(editor) { var from = editor.get.lastIndexOf(" "); if (from == -1) from = 0; else from = from + 1;

var pre = editor.get.substring(from); if (pre.slice(-1) == "-") pre = pre.slice(0, -1);

var post = '{{hyphenated word start|'+pre+'|'+pre+'…}}'; editor.set(editor.get.substring(0, from) + post); }

function putpagename(editor) { var pageName = mw.config.get('wgPageName').replace('_', ' '); editor.replaceSelection(pageName); }

function catchall(editor) { var editbox = $('#wpTextbox1').get(0); var selEnd = editbox.selectionEnd; var selStart;

var found=false; var pre; var post; if (selEnd >= 1) { // let's look for fixes that are one character long selStart = selEnd-1; pre = editbox.value.substring(selStart, selEnd);

switch (pre) { case 'c': post = 'ç'; found=true; break; case 'C': post = 'Ç'; found=true; break; case 'ç': // so that if I wanted an mdash I can simply invoke it again post = 'c—'; found=true; break; case 'Ç': // so that if I wanted an mdash I can simply invoke it again post = 'C—'; found=true; break; }		}

if (!found && selEnd >= 2) { // now lets look for fixes that are two characters long selStart = selEnd-2; pre = editbox.value.substring(selStart, selEnd);

switch (pre) { case 'ae': post = 'æ'; found=true; break; case 'AE': post = 'Æ'; found=true; break; case 'oe': post = 'œ'; found=true; break; case 'OE': post = 'Œ'; found=true; break; }		}

if (!found) { // final catchall: insert mdash; selStart = selEnd; post = '—'; //leave selStart as selEnd so it's an insertion found = true; }

if (found) { editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }	}

function diareses(editor) { var editbox = $('#wpTextbox1').get(0); var selStart = editbox.selectionStart; var selEnd = editbox.selectionEnd;

if (selStart == selEnd && selEnd !== 0) { selStart = selEnd-1; }

var pre = editbox.value.substring(selStart, selEnd);

switch(pre) {	       case 'a': post = 'ä'; break; case 'A': post = 'Ä'; break; case 'e': post = 'ë'; break; case 'E': post = 'Ë'; break; case 'i': post = 'ï'; break; case 'I': post = 'Ï'; break; case 'o': post = 'ö'; break; case 'O': post = 'Ö'; break; case 'u': post = 'ü'; break; case 'U': post = 'Ü'; break; case 'y': post = 'ÿ'; break; default: post = pre; break; }

editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }

function acute(editor) { var editbox = $('#wpTextbox1').get(0); var selStart = editbox.selectionStart; var selEnd = editbox.selectionEnd;

if (selStart == selEnd && selEnd !== 0) { selStart = selEnd-1; }

var pre = editbox.value.substring(selStart, selEnd);

switch(pre) {	       case 'a': post = 'á'; break; case 'A': post = 'Á'; break; case 'c': post = 'ć'; break; case 'C': post = 'Ć'; break; case 'e': post = 'é'; break; case 'E': post = 'É'; break; case 'g': post = 'ģ'; break; case 'i': post = 'í'; break; case 'I': post = 'Í'; break; case 'o': post = 'ó'; break; case 'O': post = 'Ó'; break; case 'l': post = 'ĺ'; break; case 'L': post = 'Ĺ'; break; case 'n': post = 'ń'; break; case 'N': post = 'Ń'; break; case 'r': post = 'ŕ'; break; case 'R': post = 'Ŕ'; break; case 's': post = 'ś'; break; case 'S': post = 'Ś'; break; case 'u': post = 'ú'; break; case 'U': post = 'Ú'; break; case 'y': post = 'ý'; break; case 'Y': post = 'Ý'; break; case 'z': post = 'ź'; break; case 'Z': post = 'Ź'; break; default: post = pre; break; }

editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }

function grave(editor) { var editbox = $('#wpTextbox1').get(0); var selStart = editbox.selectionStart; var selEnd = editbox.selectionEnd;

if (selStart == selEnd && selEnd !== 0) { selStart = selEnd-1; }

var pre = editbox.value.substring(selStart, selEnd);

switch(pre) {	       case 'a': post = 'à'; break; case 'A': post = 'À'; break; case 'e': post = 'è'; break; case 'E': post = 'È'; break; case 'i': post = 'ì'; break; case 'I': post = 'Ì'; break; case 'o': post = 'ò'; break; case 'O': post = 'Ò'; break; case 'u': post = 'ù'; break; case 'U': post = 'Ù'; break; default: post = pre; break; }

editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }

function macron(editor) { var editbox = $('#wpTextbox1').get(0); var selStart = editbox.selectionStart; var selEnd = editbox.selectionEnd;

if (selStart == selEnd && selEnd !== 0) { selStart = selEnd-1; }

var pre = editbox.value.substring(selStart, selEnd);

switch(pre) {	       case 'a': post = 'ā'; break; case 'A': post = 'Ā'; break; case 'e': post = 'ē'; break; case 'E': post = 'Ē'; break; case 'i': post = 'ī'; break; case 'I': post = 'Ī'; break; case 'o': post = 'ō'; break; case 'O': post = 'Ō'; break; case 'u': post = 'ū'; break; case 'U': post = 'Ū'; break; default: post = pre; break; }

editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }

function circumflex(editor) { var editbox = $('#wpTextbox1').get(0); var selStart = editbox.selectionStart; var selEnd = editbox.selectionEnd;

if (selStart == selEnd && selEnd !== 0) { selStart = selEnd-1; }

var pre = editbox.value.substring(selStart, selEnd);

switch(pre) {	       case 'a': post = 'â'; break; case 'A': post = 'Â'; break; case 'c': post = 'ĉ'; break; case 'C': post = 'Ĉ'; break; case 'e': post = 'ê'; break; case 'E': post = 'Ê'; break; case 'g': post = 'ĝ'; break; case 'G': post = 'Ĝ'; break; case 'h': post = 'ĥ'; break; case 'H': post = 'Ĥ'; break; case 'i': post = 'î'; break; case 'I': post = 'Î'; break; case 'j': post = 'ĵ'; break; case 'J': post = 'Ĵ'; break; case 'o': post = 'ô'; break; case 'O': post = 'Ô'; break; case 's': post = 'ŝ'; break; case 'S': post = 'Ŝ'; break; case 'u': post = 'û'; break; case 'U': post = 'Û'; break; case 'w': post = 'ŵ'; break; case 'W': post = 'Ŵ'; break; case 'y': post = 'ŷ'; break; case 'Y': post = 'Ŷ'; break; default: post = pre; break; }

editbox.value = editbox.value.substring(0, selStart) + post + editbox.value.substring(selEnd); editbox.setSelectionRange(selStart+post.length, selStart+post.length); }

function uc(editor) { editor.replace(/(\{\{[Uu]c\s*\|\s*)([^\}]+)(\}\})/g, function(match, before, text, after) {			return before + text.toUpperCase + after;		}); }

function upper(editor) { editor.replaceSelection(function(text) {			return text.toUpperCase;		}); }

function link(editor) { editor.replace(/\b([1-9][0-9]{0,2})\b/g, "{{subst:User:Hesperian/i|$1}}"); }

function reload_page_image(editor) { $('#ProofReadImage').attr('src', function(i, src) {			return src.replace(/-([0-9]+)px/, function(match, px) { return '-' + (px * 9 / 10) + 'px'; });		});	} }); //