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-13 提交的版本,查看 最新版本

  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.2
  6. // @author jcunews
  7. // @include *://*/*
  8. // @grant none
  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. (function check() {
  34. if (window.rwt) {
  35. window.rwt = function() { return true };
  36. } else setTimeout(check, 10);
  37. })();
  38. } else {
  39. //other websites:
  40. //monitor for any CSE initialization
  41. orgCreateElement = document.createElement;
  42. document.createElement = function(tag) {
  43. var res = orgCreateElement.apply(this, arguments);
  44. if (tag.toLowerCase() === "script") res.addEventListener("load", checkCse);
  45. return res;
  46. };
  47. //disable ads
  48. HTMLElement.prototype.insertBefore = function(ele) {
  49. if ((/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) return ele;
  50. return Node.prototype.insertBefore.apply(this, arguments);
  51. };
  52. }
  53. })();