Greasy Fork

Greasy Fork is available in English.

把google搜索伪装成百度搜索

用google搜索,很多人看到屏幕后会问你怎么上google的,所以把google的logo换成百度,他们就不会问那么多问题了!

目前为 2019-04-26 提交的版本,查看 最新版本

// ==UserScript==
// @name 把google搜索伪装成百度搜索
// @namespace win.somereason.web.utils
// @version 2019.04.26.1
// @description 用google搜索,很多人看到屏幕后会问你怎么上google的,所以把google的logo换成百度,他们就不会问那么多问题了!
// @author somereason
// @license MIT
// @date 2018-10-05
// @match *://www.google.com/search*
// @match *://www.google.com.hk/search*
// @match *://www.google.com.tw/search*
// @grant none
// ==/UserScript==
//


(function () {

    //伪装搜索结果页面logo
    var logo = document.getElementById("logo");
    var logoArr;
    //应对样式的变更,尝试用不同方式获取logo
    if (logo === null) {
        logoArr = document.getElementsByClassName("logo");
        if (logoArr.length > 0)
            logo = logoArr[0];
    }
    if (logo === null) {
        logoArr = document.getElementsByClassName("logocont");
        if (logoArr.length > 0)
            logo = logoArr[0];
    }
    if (logo === null) { //logo获取失败
        console.log("oops,google又改样式了.请静待更新");
    } else {
        var imgSize = getImgSize(logo);
        logo.innerHTML = '<a href="https://www.baidu.com" data-hveid="7"><img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_86d58ae1.png" alt="Baidu" data-atf="3" height="' + imgSize.height + 'px" width="' + imgSize.width + 'px"></a>';
        document.title = document.title.replace(/Google\s/g, "百度");
    }

    //伪装favicon
    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
    link.type = 'image/x-icon';
    link.rel = 'shortcut icon';
    link.href = 'https://www.baidu.com/favicon.ico';
    document.getElementsByTagName('head')[0].appendChild(link);

    /**
     * 获取图片的大小
     * @param elLogo
     */
    function getImgSize(elLogo) {
        var elImg = elLogo.querySelector("img");
        if (elImg === null) {
            return {height: 30, width: 92}
        } else {
            return {height: elImg.height, width: elImg.width}
        }
    }
})();