在百度 Google一下

在百度搜索页面添加一个按钮可以快速跳转到 Google 搜索页面

当前为 2023-02-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         在百度 Google一下
// @namespace    none
// @version      1.8
// @description  在百度搜索页面添加一个按钮可以快速跳转到 Google 搜索页面
// @author       RainForest
// @match        https://www.baidu.com/*
// @grant        none
// @license      GNU GPL
// ==/UserScript==

(function() {
  'use strict';

  // 添加 Google 搜索按钮
  var span = document.querySelector("form#form span.bg.s_btn_wr");
  var input = document.createElement("input");
  input.type = "button";
  input.value = "Google一下";
  input.classList = "bg s_btn googlebutton";
  span.appendChild(input);
  span.classList.add("buttonbox");
  var suInput = document.getElementById("su");
  if (suInput) {
    suInput.classList.add("baidubutton");
  }

  // 注入样式
  var style = document.createElement("style");
  style.textContent = "#head_wrapper .s_form{width: 763px !important;}.buttonbox { display: inline-flex !important; }.baidubutton, .googlebutton{padding: 0 15px !important;width: auto !important;}.baidubutton { border-radius: 0 !important; }.googlebutton{ background-color: #34a853 !important;}";
  document.head.appendChild(style);

  // 添加自动更新功能
  var SCRIPT_NAME = "在百度 Google一下";
  var UPDATE_URL = "https://raw.githubusercontent.com/username/repo/master/baidu-google-button.user.js";
  var meta = GM_info.scriptMetaStr.match(/@version\s+([\d.]+)/);
  var version = meta ? meta[1] : null;

  GM_registerMenuCommand(`检查 ${SCRIPT_NAME} 更新`, checkForUpdate);

  function checkForUpdate() {
    fetch(UPDATE_URL)
      .then(response => response.text())
      .then(text => {
        var newVersion = text.match(/@version\s+([\d.]+)/)[1];
        if (version !== newVersion) {
          if (confirm(`${SCRIPT_NAME} 可以更新到版本 ${newVersion},是否立即更新?`)) {
            GM_setValue("updated", "pending");
            window.location.reload();
          }
        } else {
          alert(`${SCRIPT_NAME} 已经是最新版本!`);
        }
      });
  }

  var updated = GM_getValue("updated", "");
  if (updated === "pending") {
    GM_setValue("updated", "");
    alert(`${SCRIPT_NAME} 已经更新到最新版本!`);
  }

  // 点击按钮时搜索
  input.addEventListener("click", function() {
    var keyword = document.querySelector("input[name='wd']").value;
    window.open("https://www.google.com/search?q=" + encodeURIComponent(keyword), '_blank');
  });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址