Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name Nothing before the 'but' counts
  3. // @namespace nothingbeforethebut
  4. // @description Replaces the string "I'm not Xist, but" with "I'm Xist, and"
  5. // @include *
  6. // @version 1.0.0
  7. // @grant none
  8. // ==/UserScript==
  9. (function() {
  10.  
  11.     function walk(node)
  12.     {
  13.         // I stole this function from here:
  14.         // http://is.gd/mwZp7E
  15.  
  16.         var child, next;
  17.  
  18.         switch ( node.nodeType )
  19.         {
  20.             case 1:  // Element
  21.             case 9:  // Document
  22.             case 11: // Document fragment
  23.                 child = node.firstChild;
  24.                 while ( child )
  25.                 {
  26.                     next = child.nextSibling;
  27.                     walk(child);
  28.                     child = next;
  29.                 }
  30.                 break;
  31.  
  32.             case 3: // Text node
  33.                 handleText(node);
  34.                 break;
  35.         }
  36.     }
  37.  
  38.     function handleText(textNode)
  39.     {
  40.         var v = textNode.nodeValue;
  41.  
  42.         v = v.replace(/\b(I|i)'?m not (\w)ist,? but/gi, "I'm $2ist, and");
  43.  
  44.         textNode.nodeValue = v;
  45.     }
  46.  
  47.     walk(document.getElementsByTagName('body')[0]);
  48.     walk(document.getElementsByTagName('title')[0]);
  49. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement