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.

目前为 2017-10-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Disable Google Search Result URL Redirector
  3. // @namespace DisableGoogleSearchResultURLRedirector
  4. // @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.
  5. // @version 1.0.3
  6. // @author jcunews
  7. // @include *://*/*
  8. // @grant unsafeWindow
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. var orgCreateElement;
  14.  
  15. //wait for CSE to finish its initialization
  16. function waitCse() {
  17. if (window.google && google.search && google.search.B && google.search.B.prototype.Fq) {
  18. //disable redirector
  19. google.search.B.prototype.Fq = function(){};
  20. } else setTimeout(waitCse, 20);
  21. }
  22.  
  23. //check if newly loaded script is CSE
  24. function checkCse(ev) {
  25. if (window.__gcse) {
  26. document.createElement = orgCreateElement;
  27. waitCse();
  28. }
  29. }
  30.  
  31. if ((/www\.google\.[a-z]+(\.[a-z]+)?/).test(location.hostname)) {
  32. //Google website: disable URL redirector generator function
  33. addEventListener("load", function check() {
  34. unsafeWindow.rwt = function() { return true };
  35. });
  36. } else {
  37. //other websites:
  38. //monitor for any CSE initialization
  39. orgCreateElement = document.createElement;
  40. document.createElement = function(tag) {
  41. var res = orgCreateElement.apply(this, arguments);
  42. if (tag.toLowerCase() === "script") res.addEventListener("load", checkCse);
  43. return res;
  44. };
  45. //disable ads
  46. HTMLElement.prototype.insertBefore = function(ele) {
  47. if ((/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) return ele;
  48. return Node.prototype.insertBefore.apply(this, arguments);
  49. };
  50. }
  51. })();