mariammrf_

READER INSERT CODE (THEME)

Jan 20th, 2018
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. document.getElementById("submit").addEventListener('click', function(){
  3.   walk(document.body, /\by\/n\b|\(y\/n\)/ig, document.getElementById("inputTxt").value);  
  4. });
  5.  
  6. function walk(node, v, p){
  7.     var child, next;
  8.     switch (node.nodeType){
  9.         case 1:  // Element
  10.         case 9:  // Document
  11.         case 11: // Document fragment
  12.             child = node.firstChild;
  13.             while (child){
  14.                 next = child.nextSibling;
  15.                 walk(child, v, p);
  16.                 child = next;
  17.             }
  18.             break;
  19.         case 3: // Text node
  20.             handleText(node, v, p);
  21.             break;
  22.     }
  23. }
  24.  
  25. function handleText(textNode, val, p){
  26.     var v = textNode.nodeValue;
  27.     v = v.replace(val, p);
  28.     textNode.nodeValue = v;
  29. }
  30. </script>
Advertisement
Add Comment
Please, Sign In to add comment