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.

目前為 2018-04-25 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Disable Google Search Result URL Redirector
  3. // @namespace DisableGoogleSearchResultURLRedirector
  4. // @version 1.0.6
  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. // @include *://*/*
  9. // @grant unsafeWindow
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function(createElement_, appendChild_, insertBefore_) {
  14.  
  15. //===== CONFIGURATION BEGIN =====
  16.  
  17. var disableGoogleAdSense = true;
  18.  
  19. //===== CONFIGURATION END =====
  20.  
  21. function checkElement(ele, m, obj, fn) {
  22. if (ele.tagName === "SCRIPT") {
  23. if (disableGoogleAdSense && (/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) {
  24. return false;
  25. } else if (m = ele.src.match(/:\/\/www.googleapis.com\/customsearch\/.*callback=([^?]+)/)) {
  26. obj = unsafeWindow;
  27. m[1].split(".").forEach(function(k, i, a) {
  28. if (i < (a.length - 1)) {
  29. obj = obj[k];
  30. } else {
  31. fn = obj[k];
  32. obj[k] = function(data) {
  33. data.results.forEach(function(res) {
  34. delete res.clicktrackUrl;
  35. });
  36. return fn.apply(this, arguments);
  37. };
  38. }
  39. });
  40. }
  41. }
  42. return true;
  43. }
  44.  
  45. if ((/www\.google\.[a-z]+(\.[a-z]+)?/).test(location.hostname)) {
  46. //Google site
  47. var t = 0;
  48. function disableRwt() {
  49. unsafeWindow.rwt = function() { return true };
  50. unsafeWindow.rwt.hook = true;
  51. }
  52. (function waitRwt() {
  53. clearTimeout(t);
  54. if (unsafeWindow.rwt && !unsafeWindow.rwt.hook) {
  55. disableRwt();
  56. } else setTimeout(waitRwt, 20);
  57. })();
  58. addEventListener("load", function check() {
  59. clearTimeout(t);
  60. disableRwt();
  61. });
  62. } else {
  63. //other sites
  64. appendChild_ = Node.prototype.appendChild;
  65. Node.prototype.appendChild = function(ele) {
  66. if (checkElement(ele)) {
  67. return appendChild_.apply(this, arguments);
  68. } else return ele;
  69. };
  70. insertBefore_ = Node.prototype.insertBefore;
  71. Node.prototype.insertBefore = function(ele) {
  72. if (checkElement(ele)) {
  73. return insertBefore_.apply(this, arguments);
  74. } else return ele;
  75. };
  76. }
  77.  
  78. })();