Created
October 25, 2018 11:50
-
-
Save pellepim/1422d593dd6c62d1f72c48252f8e2bc9 to your computer and use it in GitHub Desktop.
Körvkörven
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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