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

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