谷歌全面搜索按钮

Add to the Google Full Search button.

当前为 2015-05-30 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GoogleFullSearchButton
// @name:zh-CN   谷歌全面搜索按钮
// @namespace    http://www.coofly.com/
// @version      1.1
// @description  Add to the Google Full Search button.
// @description:zh-cn 给Google添加上全面搜索按钮。
// @author       Coofly
// @match        http://tampermonkey.net/scripts.php
// @include      /^https?://.+\.google\..+/.*$/
// @exclude      https://plus.google.*/*
// @exclude      http://plus.google.*/*
// @grant        none
// ==/UserScript==

(function(){
    var intervalId = -1;
    var waitTime = 0;
    console.log('GoogleFullSearchButton执行, url = ' + location.href);
    
    function AddFullSearchButton ()
    {
        var abCtls = document.getElementById('ab_ctls');
        if (null === abCtls)
        {
            waitTime = waitTime + 200;
             if(waitTime >= 5000 && intervalId >= 0)
             {
                 clearInterval(intervalId);
                 console.log('GoogleFullSearchButton等待超时');
             }
            return;
        }
        else
        {
            if (intervalId >= 0){
                clearInterval(intervalId);
                console.log('intervalId已取消');
            }
        }

        var targetUrl = '';
        var btnClass = '';
        if (location.href.indexOf('&safe=off') >= 0)
        {
            targetUrl = location.href.replace('&safe=off', '');
            btnClass = 'ab_button selected';
        }
        else
        {
            targetUrl = location.href + '&safe=off';
            btnClass = 'ab_button';
        }
        console.log('targetUrl = ' + targetUrl);

        var buttonHtml = '<li class="ab_ctl"><a href="' + targetUrl + '" class="' + btnClass + '">全面搜索</a></li>';

        abCtls.insertAdjacentHTML('afterbegin', buttonHtml);
    }
    
    var abCtls = document.getElementById('ab_ctls');
    if(null === abCtls)
    {
        intervalId = setInterval(AddFullSearchButton, 200);
        console.log('intervalId = ' + intervalId);
        return;
    }
    else
    {
        AddFullSearchButton();
    }
})();