Google & baidu Switcher (修改版)

基于Google_baidu_Switcher_(ALL_in_One)修改,分别在百度和google的搜索结果页面增加搜索跳转按钮。

当前为 2018-12-11 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴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      ZeroCode
// @version     0.2
// @description 基于Google_baidu_Switcher_(ALL_in_One)修改,分别在百度和google的搜索结果页面增加搜索跳转按钮。
// @include      https://www.google.*
// @include      http://www.google.*
// @include      https://ipv6.google.*
// @include      http://ipv6.google.*
// @include      http://www.baidu.com/*
// @include      https://www.baidu.com/*
// @include      http://image.baidu.com/*
// @include      https://image.baidu.com/*
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js

// ==/UserScript==
(function() {
    'use strict';
    if(location.host.indexOf("baidu.com") > -1){
        baidu2google();
    }else if(location.host.indexOf(".google.") > -1){
        google2baidu();
    }
    function baidu2google() {
        $('.s_btn_wr').after('<div class="s_btn_wr bg" style="display:inline-block;margin-left:10px"><input type="button" id="google_search" value="Google一下" class="bg s_btn" ></div>');
        var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp";
        if(getUrlParam("tn") == "baiduimage") {
            s_url = s_url + "&tbm=isch";
        }
        $('#google_search').on({
            click: function () {
                window.open(s_url + "&q=" + encodeURIComponent($('#kw').val()));
                return false;
            }
        });
    }
    function google2baidu(){
        //alert(location.host);
        $('#tsf').prepend('<div id="sfdiv_bd" style="display:inline-block;position:relative;height:0px;width:110px;right:-115px;\
top:0px;float:right;"><button id="bdyx" class="lsbb kpbb" style="width:120px;height:49px;margin-top:-2px;cursor:pointer;\
display: flex;border-radius: 8px;border: 1px solid #dfe1e5;box-shadow: none;border-radius: 24px;" type="button"><span \
class="sbico" id="bdyxss" style="color:#fff"><svg focusable="false" style="fill: #fff;" xmlns="http://www.w3.org/2000/svg"\
viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 \
4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z">\
</path></svg></span><span id="bdyxwz" style="font-size:16px;">百度一下</span></button></div>');
        var s_url = "https://www.google.com/search?newwindow=1&hl=zh-CN&source=hp";
        $('#sfdiv_bd').on(
            "click", function(){
                var kw = $('input[name="q"]').val();
                //获取属性标签容错
                if ("undefined" == typeof (kw)) {
                    kw = getUrlParam("q");
                }
                var s_url = "https://www.baidu.com/s?ie=utf-8&rqlang=cn";
                if(getUrlParam("tbm") == "isch") s_url = "https://image.baidu.com/search/index?tn=baiduimage&ie=utf-8&rqlang=cn";
                window.open(s_url + "&wd=" + encodeURIComponent(kw));
                return false;
            }
        );
    }

    function getUrlParam(name) {
        //构造一个含有目标参数的正则表达式对象
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        //匹配目标参数
        var r = window.location.search.substr(1).match(reg);
        //返回参数值
        if (r != null) return unescape(r[2]);
        return null;
    }
})();