User:Hannes Röst/autoSearchAndReplace.js

function searchAndReplace(oldWord, newWord) {     txt = document.editform.wpTextbox1.value; // create regex, only match the old word at word boundaries var re = new RegExp("\\b" + oldWord + "\\b", 'g'); txt = txt.replace(re, newWord); document.editform.wpTextbox1.value = txt; document.editform.wpDiff.click; }

function doWPSave {    document.editform.wpSave.click; } function appendText(appendText) {     txt = document.editform.wpTextbox1.value; document.editform.wpTextbox1.value = txt + appendText; }

// Function to decode URL parameters // taken from http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter function getQueryParams(qs) { qs = qs.split("+").join(" ");

var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g;

while (tokens = re.exec(qs)) { params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); }   return params; }

addOnloadHook(function {    if (document.forms.editform) {        var query = getQueryParams(document.location.search);        if (query.doSearchAndReplace == "1") {            searchAndReplace(query.searchFor, query.replaceWith);        }         else if (query.doAppendAndSave == "1") {            // Append text, save and close            appendText(query.appendText);            doWPSave;            //close;        }     } });