Baidu2Google

change search engine from baidu to google

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Baidu2Google
// @name:zh-CN  百度搜索切换到Google
// @description change search engine from baidu to google
// @description:zh-CN   百度搜索携带搜索词快速切换到google搜索
// @namespace   https://github.com/beijiyouyu/Browser
// @license     MIT
// @author      北极有鱼
// @include     *://www.baidu.com/*
// @run-at document-end
// @version     2.0.0
// ==/UserScript==

(function() {
    'use strict';
    let domain = window.location.host

    if (domain !== 'www.baidu.com') {
        return
    }
    console.log('Baidu2Google is running...')  // 控制台输出运行状态

    let insert = `
        <div class="engine" id="google">
          <a href="javascript:void(0);" onclick="window.location.href = 'https://www.google.com/search?q=' + document.getElementById('kw').value">换google</a>
        </div>
    `

    // 先生成div
    let insertDom = document.createElement('div')  // 生成待插入的元素
    let documentDom = document.getElementById('form')  // 获取需要插入的位置
    insertDom.innerHTML = insert  // 元素赋值
    documentDom.appendChild(insertDom)
    // 再添加样式
    let style = `
        #google {
            position:absolute;
            right:-136px;
            width:85px;
            text-align:center;
            line-height:40px;
            top:50%;
            transform:translate(-50%,-50%);
            border-radius:24px;
            font-size:14px;
            background:#fbbc05;
        }
        #google:hover {
            background:#d2a00e;
        }
        #google a {
            color:white;
            text-decoration:none;
            display:inline-block;
            width: 100%;
        }
    `

    let styleDom = document.createElement('style')
    styleDom.innerHTML = style
    documentDom.appendChild(styleDom)
// 打完收功
})();