首页 > 代码库 > userscripts.org最新网址

userscripts.org最新网址

stopGoogleRedirection:

http://userscripts.org:8080/scripts/show/186798

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// ==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);
})();