User:Atrian/monobook.js/canenglish.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
//'winc' function allows buttons to be added toolbar
 
winc('User:Omegatron/monobook.js/addlink.js');
 
function canenglish() {
    var txt = document.editform.wpTextbox1;
 
    // -our, not -or, eg. colour 
    txt.value = txt.value.replace(/color/g, 'colour');
    txt.value = txt.value.replace(/Color/g, 'Colour');
    txt.value = txt.value.replace(/vapor/g, 'vapour');
    txt.value = txt.value.replace(/Vapor/g, 'vapour');
    txt.value = txt.value.replace(/neighbor/g, 'neighbour');
    txt.value = txt.value.replace(/Neighbor/g, 'Neighbour');
 
    // -re, not -er, eg. centre
    txt.value = txt.value.replace(/center/g, 'centre');
    txt.value = txt.value.replace(/Center/g, 'Centre');
    txt.value = txt.value.replace(/theater/g, 'theatre');
    txt.value = txt.value.replace(/Theater/g, 'Theatre');
 
    // Add a tag to the summary box
    var txt = document.editform.wpSummary;
    //Made summary more accurate: not all links are removed. Keep summary brief
    var summary = "Change to Canadian spelling";
	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()
}
 
addOnloadHook(function () {
    if(document.forms.editform) {
        addLink('p-cactions', 'javascript:canenglish()', 'canglish', 'ca-canadianenglish', 'Changes to Canadian spelling', '', '');
    }
});