User:Microchip08/swedify.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

/* When checked, the link'll display a prompt. Values types into the prompt will be converted into 'Swedish' and plonked in the edit summary. */
function rot (str) {
    return (str+'').replace(/[a-z]/gi, function(s){
        return String.fromCharCode(s.charCodeAt(0)+(s.toLowerCase()<'n'?13:-13));
    });
}

sendOnSummary = 'preview'; // override 
function summarise( summary, minor ) {
    var sum = document.getElementById( "wpSummary" );
    if( sum.value != "" && sum.value.charAt( sum.value.length - 2 ) != "/" ) {
        sum.value += ', ' + summary;
    } else {
        sum.value += summary;
    }
    if( sendOnSummary == "preview" ) {
        document.getElementById("wpPreview").click();
    } else if( sendOnSummary == "save" ) {
        document.getElementById("wpSave").click();
    }
}
 
importScript('user:Bawolff/mwapilib2.js'); // just in case, yo
$(function () {
if ( document.getElementById("editform") != null) {
mw.util.addPortletLink('p-tb', 'javascript:summarise(rot(prompt("Enter a string")));', 'Swedify', 't-rot', 'Convert the edit summary to Swedish');
}});