Force google language to english & disable google safe search

Force google to use english language

目前為 2023-09-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Force google language to english & disable google safe search
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Force google to use english language
// @author       kenshin.rorona
// @match        https://www.google.com/search?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// @run-at       document-start
// @license      MIT
// credit: https://gf.qytechs.cn/en/scripts/25286-google-disable-safesearch-automatically
// ==/UserScript==

(function() {
    'use strict';
    window.addEventListener('load', function() {
        var url = window.location.href;
        var hl = window.navigator.language;
        var params = ["hl=", "safe=off"];
        for (var param of params) {
            if(url.indexOf(param) == -1){
                url += `&${param}`;
                if (param.indexOf("hl=") != -1) {
                    url += hl;
                }
            }
        }

        // TODO: test on mobile
        var switchLang = hl;
        if (url.indexOf(`hl=${hl}`) != -1) {
            switchLang = "default"
        }
        let top = 4;
        let left = 65;
        const switchBtn = document.createElement("button");
        switchBtn.innerHTML = `Switch to ${switchLang}`;
        switchBtn.style.height = 'auto';
        switchBtn.style.objectFit = 'contain';
        var uiProps = 'background-color: #073276;border-radius: 8px;border-style: none;box-sizing: border-box;color: #FFFFFF;cursor: pointer;display: inline-block;font-family: "Haas Grot Text R Web", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 14px;font-weight: 500;height: 40px;line-height: 20px;list-style: none;margin: 0;outline: none;padding: 13px 16px;text-align: center;text-decoration: none;transition: color 100ms;vertical-align: baseline;user-select: none;-webkit-user-select: none;touch-action: manipulation;'
        switchBtn.style.cssText = `position:absolute;z-index:100;z-index:99999;top:${top}%;left:${left}%;${uiProps}`;
        switchBtn.addEventListener("click", function () {
            if (url.indexOf(`hl=${hl}`) != -1) {
                // switch to default
                url  = url.replace(`hl=${hl}`, "hl=");
            } else {
                // switch to browser lang
                url  = url.replace("hl=", `hl=${hl}`);
            }
            document.location.replace(url);
        });
        document.body.prepend(switchBtn);
        if (url != window.location.href) {
            document.location.replace(url);
        }
    });
})();

QingJ © 2025

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