Greasy Fork

Greasy Fork is available in English.

百度搜索页面添加 Google 搜索框

在百度搜索结果页面的百度一下按钮后面添加 Google 按钮,方便直接进行 Google 搜索

当前为 2018-07-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         百度搜索页面添加 Google 搜索框
// @namespace    http://mofiter.com/
// @version      0.1
// @description  在百度搜索结果页面的百度一下按钮后面添加 Google 按钮,方便直接进行 Google 搜索
// @author       mofiter
// @create       2018-07-22
// @match        https://www.baidu.com/s?*
// @match        http://www.baidu.com/s?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var baiduBtn = document.getElementById("su"); // 百度搜索按钮
    baiduBtn.style = "width:80px";
    baiduBtn.value = " 百度";
    var googleBtn = document.createElement('span'); // Google 搜索按钮
    googleBtn.className = baiduBtn.parentNode.className; // 将 Google 搜索按钮和百度搜索按钮的 class 名称设置为相同
    googleBtn.style = "width:80px;margin:0px 0px 0px 2px";
    googleBtn.innerHTML = "<input type='button' id='google' value='Google' class='bg s_btn'>";
    googleBtn.addEventListener('click', function () {
        var input = document.getElementById("kw"); // 百度输入框
        var keyword = input.value.replace(/(^\s*)|(\s*$)/g, ""); // 搜索关键字(去空格)
        if (keyword != "") {
            return googleSearch(keyword);
        }
    })
    var form = document.getElementsByClassName("fm")[0];
    form.appendChild(googleBtn);

    function googleSearch(keyword){ // Google 搜索
        var link = "https://www.google.com/search?q=" + keyword;
        // window.location.href = link; //当前窗口打开链接
        window.open(link); //新窗口打开链接
    }
})();