NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 百度bing切换 // @author 影子 // @copyright 2018, yingzi (https://openuserjs.org//users/yingzi) // @license MIT // @version 4 // @description 百度bing切换 // @match *.bing.com/* // @match *.baidu.com/* // ==/UserScript== (function () { 'use strict'; var baiduBtn = document.getElementById("su"); // 百度搜索按钮 if (new String(window.location).indexOf("baidu") > 0) { document.getElementById("form").style.width = "705px"; document.getElementsByClassName("s_btn_wr")[0].style.width = "60px"; baiduBtn.style = "width:80px"; baiduBtn.value = "百度"; baiduBtn.addEventListener('click', function () { var input = document.getElementById("kw"); // 百度输入框 var keyword = input.value.replace(/(^\s*)|(\s*$)/g, ""); // 搜索关键字(去空格) if (keyword != "") { return ibaiduSearch(keyword); } }) var ibingBtn = document.createElement('span'); // ibing搜索按钮 ibingBtn.className = baiduBtn.parentNode.className; // 将ibing搜索按钮和百度搜索按钮的 class 名称设置为相同 ibingBtn.style = "width:80px;margin:0px 0px 0px 2px"; ibingBtn.innerHTML = "<input type='button' id='bing' value='必应' class='btn bg s_btn' style='width:60px;'>"; ibingBtn.addEventListener('click', function () { var input = document.getElementById("kw"); // 百度输入框 var keyword = input.value.replace(/(^\s*)|(\s*$)/g, ""); // 搜索关键字(去空格) if (keyword != "") { return ibingSearch(keyword); } }) var form = document.getElementsByClassName("fm")[0]; form.appendChild(ibingBtn); } else { // debugger var formSearch = document.getElementsByClassName("b_searchboxForm")[0]; //document.getElementById("sb_form_go").type = "hidden" var baiduSearch = document.createElement("img"); baiduSearch.style = "width:25px;height:25px;margin:10px 35px 0px 0px"; baiduSearch.style.paddingTop = 10; baiduSearch.style.className = "b_searchboxSubmit"; baiduSearch.style.backgroundImage = "https://s1.ax1x.com/2018/11/07/iTHcMn.png"; baiduSearch.src = "https://s1.ax1x.com/2018/11/07/iTHcMn.png"; baiduSearch.type = "input" baiduSearch.addEventListener("click", function () { var input = document.getElementById("sb_form_q"); // bing输入框 var keyword = input.value.replace(/(^\s*)|(\s*$)/g, ""); // 搜索关键字(去空格) if (keyword != "") { return ibaiduSearch(keyword); } }) var indexNode = formSearch.children[2]; formSearch.insertBefore(baiduSearch, indexNode); } function ibingSearch(keyword) { //ibing搜索 var link = "https://cn.bing.com/search?q=" + encodeURIComponent(keyword); window.location.href = link; //当前窗口打开链接 } function ibaiduSearch(keyword) { // 百度搜索 var link = "https://www.baidu.com/s?wd=" + encodeURIComponent(keyword); window.location.href = link; //当前窗口打开链接 } })();