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.

От 25.01.2018. Виж последната версия.

// ==UserScript==
// @name        Disable Google Search Result URL Redirector
// @namespace   DisableGoogleSearchResultURLRedirector
// @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.
// @version     1.0.5
// @author      jcunews
// @include     *://*/*
// @grant       unsafeWindow
// @run-at      document-start
// ==/UserScript==

(function(createElement_, insertBefore_) {
  //wait for CSE to finish its initialization
  function waitCse() {
    if (window.google && google.search && google.search.B && google.search.B.prototype.Fq) {
      //disable redirector
      google.search.B.prototype.Fq = function(){};
    } else setTimeout(waitCse, 20);
  }

  //check if newly loaded script is CSE
  function checkCse(ev) {
    if (window.__gcse) {
      document.createElement = orgCreateElement;
      waitCse();
    }
  }

  if ((/www\.google\.[a-z]+(\.[a-z]+)?/).test(location.hostname)) {
    //Google website: disable URL redirector generator function
    var t = 0;
    function disableRwt() {
      unsafeWindow.rwt = function() { return true };
      unsafeWindow.rwt.hook = true;
    }
    (function waitRwt() {
      clearTimeout(t);
      if (unsafeWindow.rwt && !unsafeWindow.rwt.hook) {
        disableRwt();
      } else setTimeout(waitRwt, 20);
    })();
    addEventListener("load", function check() {
      clearTimeout(t);
      disableRwt();
    });
  } else {
    //other websites:
    //monitor for any CSE initialization
    createElement_ = Document.prototype.createElement;
    Document.prototype.createElement = function(tag) {
      var res = createElement_.apply(this, arguments);
      if (tag.toLowerCase() === "script") res.addEventListener("load", checkCse);
      return res;
    };
    //disable ads
    insertBefore_ = Node.prototype.insertBefore;
    Node.prototype.insertBefore = function(ele) {
      if ((/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) return ele;
      return insertBefore_.apply(this, arguments);
    };
  }
})();