Disable Google Search Result URL Redirector

Disable Google URL redirector (i.e. user data tracking) on Google Search result, including Google Custom Search Engine (CSE) which is used by many websites.

目前為 2019-03-19 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Disable Google Search Result URL Redirector
  3. // @namespace DisableGoogleSearchResultURLRedirector
  4. // @version 1.0.8
  5. // @license GNU AGPLv3
  6. // @description Disable Google URL redirector (i.e. user data tracking) on Google Search result, including Google Custom Search Engine (CSE) which is used by many websites.
  7. // @author jcunews
  8. // @website https://greasyfork.org/en/users/85671-jcunews
  9. // @include *://*/*
  10. // @grant unsafeWindow
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function(createElement_, appendChild_, insertBefore_) {
  15.  
  16. //===== CONFIGURATION BEGIN =====
  17.  
  18. var disableGoogleAdSense = true;
  19.  
  20. //===== CONFIGURATION END =====
  21.  
  22. function rwt_() { return true }
  23.  
  24. function checkElement(ele, m, obj, fn) {
  25. if (ele.tagName === "SCRIPT") {
  26. if (disableGoogleAdSense && (/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) {
  27. return false;
  28. } else if (m = ele.src.match(/:\/\/www.googleapis.com\/customsearch\/.*callback=([^?]+)/)) {
  29. obj = unsafeWindow;
  30. m[1].split(".").forEach(function(k, i, a) {
  31. if (i < (a.length - 1)) {
  32. obj = obj[k];
  33. } else {
  34. fn = obj[k];
  35. obj[k] = function(data) {
  36. data.results.forEach(function(res) {
  37. delete res.clicktrackUrl;
  38. });
  39. return fn.apply(this, arguments);
  40. };
  41. }
  42. });
  43. }
  44. }
  45. return true;
  46. }
  47.  
  48. if ((/www\.google\.[a-z]+(\.[a-z]+)?/).test(location.hostname)) {
  49. //Google site
  50. addEventListener("mousedown", function() {
  51. if (unsafeWindow.rwt && (unsafeWindow.rwt !== rwt_)) unsafeWindow.rwt = rwt_;
  52. }, true);
  53. //Google image search site
  54. let setAttribute = HTMLAnchorElement.prototype.setAttribute;
  55. HTMLAnchorElement.prototype.setAttribute = function(name, value) {
  56. if ((name === "href") && !this.dataset_) {
  57. let a = this, href = value;
  58. this.dataset_ = this.dataset;
  59. Object.defineProperty(this, "dataset", {
  60. value: new Proxy(this.dataset_, {
  61. set: function(tgt, prop, value, recv) {
  62. if ((prop === "cthref") && (/^\/url\?/).test(value)) {
  63. a.href = href;
  64. } else a.dataset_[prop] = val;
  65. return true;
  66. }
  67. })
  68. });
  69. }
  70. return setAttribute.apply(this, arguments);
  71. };
  72. } else {
  73. //other sites
  74. appendChild_ = Node.prototype.appendChild;
  75. Node.prototype.appendChild = function(ele) {
  76. if (checkElement(ele)) {
  77. return appendChild_.apply(this, arguments);
  78. } else return ele;
  79. };
  80. insertBefore_ = Node.prototype.insertBefore;
  81. Node.prototype.insertBefore = function(ele) {
  82. if (checkElement(ele)) {
  83. return insertBefore_.apply(this, arguments);
  84. } else return ele;
  85. };
  86. }
  87.  
  88. })();