Google & baidu Switcher (修改版)

分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。

当前为 2016-12-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name      Google & baidu Switcher (修改版)
// @namespace http://tampermonkey.net/
// @author    Zero
// @version   0.1
// @description  分别在百度和google的搜索结果页面增加搜索跳转按钮,使用到外链微软CDN的jquery-1.7.2.min.js,不懂跳墙使用GOOGLE的同学请自动忽略。自动判断百度和google对JQUERY的载入,并动态载入Jquery.js。

// @include        https://www.google.com.hk/*
// @include        http://www.google.com.hk/*
// @include        https://ipv6.google.com.hk/*
// @include        http://ipv6.google.com.hk/*
// @include        http://www.google.com/*
// @include        https://www.google.com/*
// @include        http://ipv4.google.com/*
// @include        https://ipv4.google.com/*
// @include        http://ipv6.google.com/*
// @include        https://ipv6.google.com/*
// @include        http://www.baidu.com/*
// @include        https://www.baidu.com/*
// @copyright      2015+, f9y4ng
// @grant          none

// ==/UserScript==


if ("undefined" == typeof(jQuery)){
    loadJs("for_google","https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js",callbackFunction);
}
else{
$(document).ready(function() {
    function baiduswitchgoogle() {
        $('.s_btn_wr').after('<div class="s_btn_wr bg" style="display:inline-block;margin-left:10px"><input type="button" id="ggyx" value="Google一下" class="bg s_btn" ></div>');
        $('#ggyx').on({
            click: function () {
                window.open("https://www.google.com.hk/ncr?gws_rd=ssl#newwindow=1&q=" + $('#kw') .val());
                return false;
            }
        });
    }
    if(window.location.search.lastIndexOf("wd=")>0){
        baiduswitchgoogle();
    }
    //检测从baidu首页进入的搜索(补漏)
    if(/^http(s)?:\/\/(www\.)?baidu\.com\/$/ig.test(window.location.href)){
        $("#kw").off('click').on({
            keydown: function () {
                if($('#ggyx').length<1 && $('#kw').val().length>0){baiduswitchgoogle();}
            }
        }).on({
             paste: function () {
                if($('#ggyx').length<1){baiduswitchgoogle();}
            }
        });
    }
});
}
function callbackFunction()
{
    $(document).ready(function() {
        function googleswitchbaidu() {
            $('#sfdiv').before('<div id="sblsbb_bd" class="lsbb kpbb" style="position: relative;height:39px;width:80px;float:right;"><button id="bdyx" class="lsb" style="padding-top:6px;color: white;font-family:arial,sans-serif;font-weigh:bold;;font-size: 16px;width: 100%;cursor:pointer">百度一下</button></div>');
            $('#bdyx').off('click') .on({
                click: function () {
                    window.open("https://www.baidu.com/s?wd=" + $('#lst-ib') .val());
                    return false;
                }
            });
        }
        if(window.location.hash.lastIndexOf("q=")>0 || window.location.search.lastIndexOf("q=")>0){
            googleswitchbaidu();
        }
        //检测Google的直接搜索(补漏)
        if(/(www\.|ipv4\.)?google\.com/ig.test(window.location.href)){
            $("#lst-ib").off('click') .on({
                keydown: function () {
                    if($('#bdyx').length<1){googleswitchbaidu();}
                }
            });
        }
    });
}
function loadJs(sid,jsurl,callback){
    var nodeHead = document.getElementsByTagName('head')[0];
    var nodeScript = null;
    if(document.getElementById(sid) === null){
        nodeScript = document.createElement('script');
        nodeScript.setAttribute('type', 'text/javascript');
        nodeScript.setAttribute('src', jsurl);
        nodeScript.setAttribute('id',sid);
        if (callback !== null) {
            nodeScript.onload = nodeScript.onreadystatechange = function(){
                if (nodeScript.ready) {
                    return false;
                }
                if (!nodeScript.readyState || nodeScript.readyState == "loaded" || nodeScript.readyState == 'complete') {
                    nodeScript.ready = true;
                    callback();
                }
            };
        }
        nodeHead.appendChild(nodeScript);
    } else {
        if(callback !== null){
            callback();
        }
    }
}