Coincidence Detector

Detects coincidences.

目前为 2016-12-17 提交的版本,查看 最新版本

  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. // @homepageURL https://bit.no.com:43110/1As8nyiVibNzfjLiS1eCinYia2dK2ZgHiz/
  8. // @version 14.88.0
  9. // @namespace https://coincidencedetector.com/
  10. // ==/UserScript==
  11.  
  12.  
  13. var theList = JSON.parse(GM_getResourceText("theList"));
  14. var regexp = new RegExp('\\b(' + theList.join('|') + ')\\b(?!\\)\\))', "gi");
  15.  
  16. function walk(node) {
  17. // I stole this function from here:
  18. // http://is.gd/mwZp7E
  19.  
  20. var child, next;
  21.  
  22. switch ( node.nodeType )
  23. {
  24. case 1:
  25. case 9:
  26. case 11:
  27. child = node.firstChild;
  28. while ( child )
  29. {
  30. next = child.nextSibling;
  31. walk(child);
  32. child = next;
  33. }
  34. break;
  35.  
  36. case 3:
  37. handleText(node);
  38. break;
  39. }
  40. }
  41.  
  42. function handleText(textNode) {
  43. textNode.nodeValue = textNode.nodeValue.replace(regexp, '((($1)))');
  44. textNode.nodeValue = textNode.nodeValue.replace(/\bIsrael\b/, '(((Our Greatest Ally)))');
  45. }
  46.  
  47. walk(document.body);