Skip to content

Instantly share code, notes, and snippets.

@pellepim
Created October 25, 2018 11:50
Show Gist options
  • Save pellepim/1422d593dd6c62d1f72c48252f8e2bc9 to your computer and use it in GitHub Desktop.
Save pellepim/1422d593dd6c62d1f72c48252f8e2bc9 to your computer and use it in GitHub Desktop.
Körvkörven
(function () {
var searchpattern1 = /budget/;
var searchpattern2 = /kris/;
var replacepattern = "körv";
var searchpattern3 = /regering/;
var replacepattern2 = "curry-wurst";
function replaceText(node) {
var current = node.nodeValue;
var replaced = current.replace(searchpattern1, replacepattern);
var replaced = replaced.replace(searchpattern2, replacepattern)
var replaced = replaced.replace(searchpattern3, replacepattern2);
node.nodeValue = replaced;
}
function traverse(node) {
var children = node.childNodes;
var childLen = children.length;
for (var i = 0; i < childLen; i++) {
var child = children.item(i);
if (child.nodeType == 3)//or if(child instanceof Text)
replaceText(child);
else
traverse(child);
}
}
traverse(document.body);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment