Google disable safesearch

Set off google safesearch

ของเมื่อวันที่ 05-07-2023 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Google disable safesearch
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  Set off google safesearch
// @author       You
// @include      /^https\:\/\/[a-z]*\.(google)\.[a-z]*/search\?
// @icon         https://www.google.com/s2/favicons?domain=google.com
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    var count = 0;
    window.addEventListener("load",function(){
        run();
    });

    function disableSafesearch() {
        var safeui = document.querySelector("g-menu-item a[aria-label][href*='setprefs?sig']");
        if(safeui != null){
            if(safeui.href.match(/safeui=off$/) == null){
                window.location = safeui.href.replace(/safeui=(on|images)$/,"safeui=off");
                console.log("Google disable safesearch: done!");
            } else {
                console.log("Google disable safesearch: nothing to do!");
            }
        } else {
            safeui = document.querySelector("g-menu-item a[href*='setprefs?sig'][href$='safeui=off']");
            if(safeui != null) {
                window.location = safeui.href;
                console.log("Google disable safesearch: done!");
            } else {
                if(document.querySelector("g-menu-item a[href*='setprefs?sig'][href$='safeui=on']") != null){
                    console.log("Google disable safesearch: nothing to do!");
                } else {
                    console.log(document.querySelector("g-menu-item a[href*='setprefs?sig']"));
                    console.log("Google disable safesearch: failed!");
                }
            }
        }
    }

    function run(){
        //only few pages have safesearch settings menu
        if(document.URL.includes("tbm") == false || document.URL.match(/tbm=(isch|vid|nws)/) != null){
            if(document.querySelector("g-menu-item a[href*='setprefs?sig']") == null){
                //wait until safesearch settings menu exist
                window.setTimeout(function (){
                    run();
                },50);
                count += 1;
                if(count > 10){
                    console.log("Google disable safesearch: too fast!");
                    count = 0;
                }
            } else {
                disableSafesearch();
            }
        } else {
            console.log("Google disable safesearch: no safesearch page!");
        }
    }

})();