Advertisement
Guest User

Untitled

a guest
Jun 4th, 2016
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Coincidence Detector
  3. // @description Detects coincidences.
  4. // @include *
  5. // @grant GM_getResourceText
  6. // @resource theList https://bit.no.com:43110/1As8nyiVibNzfjLiS1eCinYia2dK2ZgHiz/theList.json
  7. // ==/UserScript==
  8.  
  9. var theList = JSON.parse(GM_getResourceText("theList"));
  10. var regexp = new RegExp('\\b(' + theList.join('|') + ')\\b(?!\\)\\))', "gi");
  11.  
  12. function walk(node) {
  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:
  21. case 9:
  22. case 11:
  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:
  33. handleText(node);
  34. break;
  35. }
  36. }
  37.  
  38. function handleText(textNode) {
  39. textNode.nodeValue = textNode.nodeValue.replace(regexp, '((($1)))');
  40. }
  41.  
  42. walk(document.body);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement