Google Tracking-B-Gone

Strips click tracking from Google search results

  1. // Google Tracking-B-Gone
  2. // version 3.1
  3. // Release Date: 2019-10-20
  4. // https://greasyfork.org/en/scripts/1810-google-tracking-b-gone
  5. // https://github.com/stacybrock/google-tracking-b-gone
  6. //
  7. // ===== INSTRUCTIONS =====
  8. //
  9. // This is a Tampermonkey user script.
  10. //
  11. // To use this script, get Tampermonkey: https://tampermonkey.net
  12. // After you've installed it, come back to this page. A dialog box will
  13. // appear asking you if you want to install this script.
  14. //
  15. // To uninstall, open the Tampermonkey dashboard and click the delete
  16. // icon next to "Google Tracking-B-Gone" in the list of installed
  17. // scripts.
  18. //
  19. //
  20. // ==UserScript==
  21. // @name Google Tracking-B-Gone
  22. // @namespace http://notoriety.org
  23. // @version 3.1
  24. // @description Strips click tracking from Google search results
  25. //
  26. // @include http://www.google.*
  27. // @include https://www.google.*
  28. //
  29. // @grant none
  30. // ==/UserScript==
  31.  
  32. var debug = false;
  33.  
  34. debug && console.log("Google Tracking-B-Gone initialized.");
  35.  
  36. var checkMutation = function(mutation) {
  37. var target = mutation.target;
  38. if (target && target.nodeName.toLowerCase() === 'a') {
  39. cleanLink(target);
  40. } else if (target instanceof Element) {
  41. target.querySelectorAll('a').forEach(cleanLink);
  42. }
  43. };
  44.  
  45. var changeObserver = new MutationObserver(function(mutations) {
  46. if (mutations.target) {
  47. checkMutation(mutations);
  48. } else {
  49. mutations.forEach && mutations.forEach(checkMutation);
  50. }
  51. });
  52. changeObserver.observe(document.documentElement, {
  53. childList: true,
  54. subtree: true,
  55. attributes: true,
  56. attributeFilter: ['href']
  57. });
  58.  
  59. var blockEvent = function (event) {
  60. event.stopPropagation();
  61. };
  62.  
  63. var blockEvent2 = function (event) {
  64. this.getAttribute('role') !== 'button' && event.stopPropagation();
  65. };
  66.  
  67. function cleanLink(link) {
  68. debug && console.log("cleanLink() called...");
  69. link.onmousedown = link.onmouseup = link.onmouseenter = link.onmousemove =
  70. link.ondbclick = link.oncontextmenu = blockEvent;
  71. link.onclick = blockEvent2;
  72. }