Free Google

always set the google searach region to Ghana

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
/// ==UserScript==
// @name         Free Google
// @namespace    Free Google
// @version      1.0.0
// @description  always set the google searach region to Ghana
// @author       DumbGPT
// @match        *://*.google.com/*
// @match        *://*.google.co.kr/*
// @match        *://*.google.co.jp/*
// @match        *://*.google.co.uk/*
// @match        *://*.google.de/*
// @match        *://*.google.fr/*
// @match        *://*.google.*/*
// @run-at       document-start
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_cookie
// @grant        GM_addValueChangeListener
// @grant        window.onurlchange
// ==/UserScript==
(function() {
    'use strict';
    
 
    const CHECK_INTERVAL = 1000;
    

    function isGooglePage() {
        return window.location.hostname.includes('google.');
    }
    

    function modifyURL() {
        if (!isGooglePage()) return;
        
        let currentURL = window.location.href;
        let url = new URL(currentURL);
        
 
        const hasGlParam = url.searchParams.has('gl') && url.searchParams.get('gl') === 'GH';
        const hasSafeParam = url.searchParams.has('safe') && url.searchParams.get('safe') === 'off';
        
        if (hasGlParam && hasSafeParam) {
            return; 
        }
        
        url.searchParams.set('gl', 'GH');
        url.searchParams.set('safe', 'off');
        
        if (url.pathname.includes('/search')) {
            url.searchParams.set('pws', '0'); 
        }
        
      
        const newURL = url.toString();
        if (currentURL !== newURL) {
            window.location.replace(newURL);
        }
    }
    
    function setCookies() {
        if (!isGooglePage()) return;
        
        document.cookie = "PREF=gl=GH:safe=off; expires=Fri, 31 Dec 2030 23:59:59 GMT; path=/; domain=.google.com";
        document.cookie = "NID=; path=/; domain=.google.com";
        
        const domain = window.location.hostname;
        document.cookie = `PREF=gl=GH:safe=off; expires=Fri, 31 Dec 2030 23:59:59 GMT; path=/; domain=${domain}`;
        
        try {
            localStorage.setItem('google_settings_gl', 'GH');
            localStorage.setItem('google_settings_safe', 'off');
        } catch (e) {
            console.log('로컬 스토리지 접근 오류:', e);
        }
    }
    
    function modifyPreferencesPage() {
        if (!isGooglePage()) return;
        
        if (window.location.href.includes('/preferences') || window.location.href.includes('/setprefs')) {

            const regionSelects = document.querySelectorAll('select[name="cr"], select[name="gl"]');
            regionSelects.forEach(select => {

                for (let i = 0; i < select.options.length; i++) {
                    if (select.options[i].value === 'countryGH' || select.options[i].value === 'GH') {
                        select.selectedIndex = i;
                        select.dispatchEvent(new Event('change', { bubbles: true }));
                        break;
                    }
                }
            });
            
            const safeSearchInputs = document.querySelectorAll('input[name="safe"]');
            safeSearchInputs.forEach(input => {
                if (input.value === 'off') {
                    input.checked = true;
                    input.dispatchEvent(new Event('change', { bubbles: true }));
                }
            });
            
            setTimeout(() => {
                const saveButtons = document.querySelectorAll('input[type="submit"], button[type="submit"]');
                saveButtons.forEach(button => {
                    if (button.value === '저장' || button.innerText === '저장' || 
                        button.value === 'Save' || button.innerText === 'Save') {
                        button.click();
                    }
                });
            }, 1000);
        }
    }
    
    if (window.onurlchange === null) {
        window.addEventListener('urlchange', () => {
            modifyURL();
            setCookies();
            setTimeout(modifyPreferencesPage, 1000);
        });
    }
    
    function main() {
        modifyURL();
        setCookies();
        setTimeout(modifyPreferencesPage, 1000);
    }
    
    main();
    
    setInterval(main, CHECK_INTERVAL);
    
    const observer = new MutationObserver(() => {
        modifyPreferencesPage();
    });
    
    window.addEventListener('load', () => {
        observer.observe(document.body, { childList: true, subtree: true });
    });
})();