Greasy Fork

切换百度谷歌搜索引擎

主要平常搜索的时候大部分都是谷歌和百度,用其他的一些,支持的平台多,但是相应加载速度变慢,所以自己写了一个,有喜欢的小伙伴可以使用。

当前为 2023-08-03 提交的版本,查看 最新版本

// ==UserScript==
// @name         切换百度谷歌搜索引擎
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  主要平常搜索的时候大部分都是谷歌和百度,用其他的一些,支持的平台多,但是相应加载速度变慢,所以自己写了一个,有喜欢的小伙伴可以使用。
// @author       Blazing
// @include        *://*.google.*/search*
// @match        https://www.baidu.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com.hk
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {

    let domain = window.location.href;

    if (domain.includes('baidu.com')) {

        let baiduValue = document.getElementById('kw').value;

        let div = document.querySelector('#s_tab div');

        div.insertAdjacentHTML("afterbegin", `
      <a href="https://www.google.com.hk/search?q=${baiduValue}" id="Blazingss" wdfield="kw" class="s-tab-item s-tab-item_1CwH- s-tab-ps_RRh00 s-tab-ps_RRh00">谷歌</a>
    `);

    } else if (domain.includes('google')) {

        insertGoogleLink();

    } else {
        console.log('');
    }

})();


function insertGoogleLink() {

    let url = window.location.href;
    let domain = url.split('?')[0];
    let query = url.split('?')[1];
    let params = new URLSearchParams(query);
    let googleValue = params.get('q');
    googleValue = googleValue.replaceAll(' ', '%20');


    const container = document.querySelector('.IUOThf');
    const firstLink = container.querySelector('a');

    const baiduLink = document.createElement('a');
    baiduLink.className = 'LatpMc nPDzT T3FoJb';
    baiduLink.id = 'Blazingss';
    baiduLink.href = `https://www.baidu.com/s?wd=${googleValue}`;
    baiduLink.innerHTML = '<div jsname="bVqjv" class="GKS7s"><span class="FMKtTb UqcIvb" jsname="pIvPIe">百度</span></div>';

    container.insertBefore(baiduLink, firstLink);

}