Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.85 KB | None | 0 0
  1. // ==UserScript==
  2. // @name          Coincidence Detector
  3. // @description   Detects coincidences.
  4. // @include       *
  5. // @grant         GM_getResourceText
  6. // @resource      theList https://gitlab.com/therightstuff/public/raw/master/theList.json
  7. // ==/UserScript==
  8.  
  9.  
  10. var theList = JSON.parse(GM_getResourceText("theList"));
  11. var regexp = new RegExp('\\b(' + theList.join('|') + ')\\b(?!\\)\\))', "gi");
  12.  
  13. function walk(node) {
  14.     // I stole this function from here:
  15.     // http://is.gd/mwZp7E
  16.  
  17.     var child, next;
  18.  
  19.     switch ( node.nodeType )
  20.     {
  21.         case 1:
  22.         case 9:
  23.         case 11:
  24.             child = node.firstChild;
  25.             while ( child )
  26.             {
  27.                 next = child.nextSibling;
  28.                 walk(child);
  29.                 child = next;
  30.             }
  31.             break;
  32.  
  33.         case 3:
  34.             handleText(node);
  35.             break;
  36.     }
  37. }
  38.  
  39. function handleText(textNode) {
  40.     textNode.nodeValue = textNode.nodeValue.replace(regexp, '((($1)))');
  41. }
  42.  
  43. walk(document.body);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement