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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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.2
// @author      jcunews
// @include     *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

(function() {
    var orgCreateElement;

    //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
      (function check() {
        if (window.rwt) {
          window.rwt = function() { return true };
        } else setTimeout(check, 10);
      })();
    } else {
      //other websites:
      //monitor for any CSE initialization
      orgCreateElement = document.createElement;
      document.createElement = function(tag) {
        var res = orgCreateElement.apply(this, arguments);
        if (tag.toLowerCase() === "script") res.addEventListener("load", checkCse);
        return res;
      };
      //disable ads
      HTMLElement.prototype.insertBefore = function(ele) {
        if ((/:\/\/cse\.google\.com\/adsense\/search\/(async-)?ads\.js/).test(ele.src)) return ele;
        return Node.prototype.insertBefore.apply(this, arguments);
      };
    }
})();