Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getTextNodes(main) {
- var arr = [];
- var loop = function(main) {
- do {
- if(main.nodeType == 3)
- arr.push(main);
- if(main.hasChildNodes())
- loop(main.firstChild);
- }
- while (main = main.nextSibling);
- }
- loop(main);
- return arr;
- }
- function replaceStringInNodes(match, replace, nodes) {
- var items = getTextNodes(nodes);
- items.forEach(function(item) { item.nodeValue = item.nodeValue.replace(match, replace); });
- }
- function fixTopSearchInput() {
- var q = document.getElementById("q");
- if (q && (q.value === "Signe Jardarp")) {
- q.value = "Eli Jardarp";
- }
- }
- function callback(e) {
- if (e.target) {
- replaceStringInNodes(/\bSigne( Jardarp)?\b/g, "Eli$1", e.target);
- }
- else {
- console.log("got a weird e");
- console.log(e);
- }
- }
- replaceStringInNodes(/\bSigne( Jardarp)?\b/g, "Eli$1", document.children[0]);
- fixTopSearchInput();
- document.addEventListener("DOMSubtreeModified", callback);
- document.addEventListener("DOMSubtreeModified", fixTopSearchInput);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement