Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getTextNodes(main) {
  2.     var arr = [];
  3.     var loop = function(main) {
  4.         do {
  5.             if(main.nodeType == 3)
  6.                 arr.push(main);
  7.         if(main.hasChildNodes())
  8.                 loop(main.firstChild);
  9.         }
  10.         while (main = main.nextSibling);
  11.     }
  12.     loop(main);
  13.     return arr;
  14. }
  15.  
  16. function replaceStringInNodes(match, replace, nodes) {
  17.     var items = getTextNodes(nodes);
  18.     items.forEach(function(item) { item.nodeValue = item.nodeValue.replace(match, replace); });
  19. }
  20.  
  21. function fixTopSearchInput() {
  22.     var q = document.getElementById("q");
  23.     if (q && (q.value === "Signe Jardarp")) {
  24.     q.value = "Eli Jardarp";
  25.     }
  26. }
  27.  
  28. function callback(e) {
  29.     if (e.target) {
  30.     replaceStringInNodes(/\bSigne( Jardarp)?\b/g, "Eli$1", e.target);
  31.     }
  32.     else {
  33.     console.log("got a weird e");
  34.     console.log(e);
  35.     }
  36. }
  37.  
  38. replaceStringInNodes(/\bSigne( Jardarp)?\b/g, "Eli$1", document.children[0]);
  39. fixTopSearchInput();
  40. document.addEventListener("DOMSubtreeModified", callback);
  41. document.addEventListener("DOMSubtreeModified", fixTopSearchInput);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement