Baidu Google Switcher

add baidu -> google & google -> baidu capability

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Baidu Google Switcher
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  add baidu -> google & google -> baidu capability
// @author       rhinoc
// @match        https://www.baidu.com/*
// @match        https://www.google.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getQueryVariable(str) {
       var query = location.search.substring(1);
       var vars = query.split("&");
       for (var i = 0; i < vars.length; i++) {
           var pair = vars[i].split("=");
           if (pair[0] === str) return pair[1];
       }
       return false;
    }

    const BD_BASE = 'https://www.baidu.com/s?wd=';
    const GG_BASE = 'https://www.google.com/search?q=';
    const queryStr = getQueryVariable('q') || getQueryVariable('wd');

    function bd2gg() {
        document.getElementById("result_logo").href = GG_BASE + queryStr;
    }

    function gg2bd() {
        document.getElementById("logo").href = BD_BASE + queryStr;
    }

    location.host === "www.baidu.com" ? bd2gg() : gg2bd();
})();