brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2020-03-25
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
阅读:4351回复:6

[求助]修改禁止google的搜索结果重定向脚本

楼主#
更多 发布于:2014-04-15 15:02
我在用禁止google的搜索结果重定向脚本
https://userscripts.org/scripts/show/186798
怎么修改这个脚本适配goole自定义搜索,比如这个
https://www.google.com/cse/home?cx=001218728609057809719:zt-a0ntt7t0&ie=UTF-8&sa=%E6%90%9C%E7%B4%A2&siteurl=www.google.com/cse/home
// ==UserScript==
// @name           stopGoogleRedirection
// @author         NLF
// @description    禁止google的搜索结果重定向,加快访问速度,防止撞墙(support (opera,firefox(GreaseMonkey),chrome) Latest Stable,IE9+)
// @version        1.0.0.5
// @created        2013-12-26
// @lastUpdated    2013-2-5
// @grant          none
// @run-at         document-start
// @namespace      http://userscripts.org/users/NLF
// @homepage       http://userscripts.org/scripts/show/186798
// @downloadURL    https://userscripts.org/scripts/source/186798.user.js
// @updateURL      https://userscripts.org/scripts/source/186798.meta.js
// @include        http*
// @match          *://*/*
// ==/UserScript==
  
;(function () {
    'use strict';
  
    // 将在真实环境下执行的实际函数。
    function contentScript() {
        'use strict';
          
        // 匹配应用本脚本的网页
        if (!/^https?:\/\/www\.google(?:\.[A-z]{2,3}){1,2}\//i.test(location.href)) {
            return;
        };
          
        var emptyFn = function () {
        };
          
        // 覆盖google处理重定向的函数
        if (typeof Object.defineProperty == 'function') {
            Object.defineProperty(window, 'rwt', {
                configurable: false,
                enumerable: true,
                get: function () {
                    return emptyFn;
                },
            });
        } else if (typeof window.__defineGetter__ == 'function') {
            window.__defineGetter__('rwt', function () {
                return emptyFn;
            });
        };
          
    };
  
  
    // 如果发生通信的话,需要一个独一无二的ID
    var messageID = Math.random().toString();
      
    // 把指定函数丢到真实环境中执行,规避一切脚本管理器乱七八糟的执行环境产生的奇葩Bug,
    // 特别是chrome上的那个坑爹tampermonkey。。。
    function runInPageContext(fn) {
        if (typeof fn !== 'function') {
            return;
        };
          
        // 创建一个脚本插入到pageContext执行
        var script = document.createElement('script');
        script.type = 'text/javascript';
          
        // 去掉函数名,防止污染全局环境。
        var sContent = ';(' + fn.toString().replace(/[^(]+/, 'function ') + ')(' + JSON.stringify(messageID) + ');';
          
        // console.log('执行的脚本实际内容\n', sContent);
          
        script.textContent = sContent;
  
        // 检测html元素是否可访问
        // scriptish @run-at document-start时,html元素在第一时间不可访问
        var de = document.documentElement;
          
        if (de) {
            de.appendChild(script);
            de.removeChild(script);
        } else {
            new (window.MutationObserver || window.WebKitMutationObserver)(function (ms, observer) {
              
                var de = document.documentElement;
                if (de) {
                    // console.log(de.outerHTML);
                    observer.disconnect();
                      
                    de.appendChild(script);
                    de.removeChild(script);
                };
            }).observe(document, {
                childList: true,
            });
        };
          
    };
  
    runInPageContext(contentScript);
})();
@brucmao
文科
千年狐狸
千年狐狸
  • UID39959
  • 注册日期2013-10-17
  • 最后登录2019-07-27
  • 发帖数2069
  • 经验1328枚
  • 威望4点
  • 贡献值340点
  • 好评度256点
  • 最爱沙发
  • 社区居民
  • 忠实会员
1楼#
发布于:2014-04-15 17:23
这脚本来就是全局的 对于这样的站点有效呀
brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2020-03-25
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
2楼#
发布于:2014-04-16 09:43
文科:这脚本来就是全局的 对于这样的站点有效呀回到原帖

在链接上点右键,可以看到在状态栏有google的重定向
@brucmao
文科
千年狐狸
千年狐狸
  • UID39959
  • 注册日期2013-10-17
  • 最后登录2019-07-27
  • 发帖数2069
  • 经验1328枚
  • 威望4点
  • 贡献值340点
  • 好评度256点
  • 最爱沙发
  • 社区居民
  • 忠实会员
3楼#
发布于:2014-04-16 16:03
brucmao:在链接上点右键,可以看到在状态栏有google的重定向回到原帖

图片:2014-04-16_160206.png


没有问题
aaaa007cn
千年狐狸
千年狐狸
  • UID23968
  • 注册日期2008-05-03
  • 最后登录2022-03-07
  • 发帖数1924
  • 经验1138枚
  • 威望1点
  • 贡献值232点
  • 好评度164点
4楼#
发布于:2014-04-16 17:42
最近发现https的结果
google会用https的域名来做跳转
然后我的privoxy转向规则就跪了
白左
千年狐狸
千年狐狸
  • UID34985
  • 注册日期2010-12-29
  • 最后登录2023-11-13
  • 发帖数2039
  • 经验655枚
  • 威望0点
  • 贡献值364点
  • 好评度69点
  • 社区居民
  • 忠实会员
5楼#
发布于:2014-04-16 18:18
自定义搜索根本没定义rwt函数,重定向目标是直接写死在html里的,重定向的实际作用函数暂时没找到
要在这个页面生效,脚本需要重新编制,不兼容rwt写法
-いたんですか? -ええ、ずっと
brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2020-03-25
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
6楼#
发布于:2014-04-17 09:15
白左:自定义搜索根本没定义rwt函数,重定向目标是直接写死在html里的,重定向的实际作用函数暂时没找到
要在这个页面生效,脚本需要重新编制,不兼容rwt写法
回到原帖
能不能修改这个脚本,让自定义搜索也生效
@brucmao
游客

返回顶部