Greasy Fork

Greasy Fork is available in English.

快速切换百度和谷歌搜索引擎移动端

在移动端的谷歌和百度搜索之间来回跳转

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         快速切换百度和谷歌搜索引擎移动端
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  在移动端的谷歌和百度搜索之间来回跳转
// @author       我自己
// @match          *://*.baidu.com/*
// @include        *://*.google.tld/*
// @match        https://www.google.com/*
// @license MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=baidu.com
// @grant        none

// ==/UserScript==

(function() {
    'use strict';

    /********************************
    根据域名地址,判断当前应该用哪个规则
*********************************/
var domain = document.domain;
console.log(domain);
if (domain.match("baidu")){
    console.log("当前网址是百度"+ domain);
    var url = "https://www.google.com/search?q=";
    var input = document.getElementById("kw").value;
    var enginename = "谷歌";

    /****************************************
        创建一个a标签,里面是span标签,内容是“谷歌”。
    *****************************************/
    var newNode = document.createElement("a");
    newNode.setAttribute("class","se-tabitem");
    var spannode = document.createElement("span");
    newNode.appendChild(spannode);
    spannode.innerHTML="谷歌";
    //设置属性
    newNode.setAttribute("href",url+input);

    //用insertNode函数向页面插入节点
    var insertedNode  = document.querySelectorAll("div.se-tab-lists")[0];
    var referenceNode = document.querySelectorAll("a.se-tabitem")[1];
    insertedNode .insertBefore(newNode, referenceNode);
}
if (domain.match("google")){
    console.log("当前网址是谷歌"+ domain);
    var url = "https://m.baidu.com/s?word=";
    var input = document.querySelector('input[name="q"]').value;
    var enginename = "百度";

    /****************************************
        创建一个a标签,里面是span标签,内容是“谷歌”。
    *****************************************/
    var newNode = document.createElement("div");
    newNode.setAttribute("class","hdtb-mitem");
    var spannode = document.createElement("a");
    newNode.appendChild(spannode);
    spannode.innerHTML="百度";
    //设置属性
    spannode.setAttribute("href",url+input);

    //用insertNode函数向页面插入节点
    var insertedNode  = document.querySelectorAll("div.IC1Ck")[0];
    console.log(insertedNode);
    var referenceNode = document.querySelectorAll("div.hdtb-mitem")[1];
    console.log(referenceNode);
    insertedNode .insertBefore(newNode, referenceNode);
}
})();