Google & baidu Switcher (修改版)

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

目前為 2018-12-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
    }
})();