Deny google precise location question

Block google precise location question popup ("See results closer to you?") by automatically telling it no

คุณจะต้องติดตั้งส่วนขยาย เช่น 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         Deny google precise location question
// @version      2024-03-08
// @description  Block google precise location question popup ("See results closer to you?") by automatically telling it no
// @match        *://*.google.com/*
// @license      MIT
// @namespace https://greasyfork.org/users/1272292
// ==/UserScript==


var interval = 2; // ms, how often the loop should run
var maxTime = 5000; // ms, max time to try to run the loop for

var startTime = new Date().getTime();
var checkTimer = setInterval(TimeLoop, interval);
checkTimer();

function TimeLoop() {
    const warning = document.getElementsByClassName("cMeQ8e b9SLDc"); //class of the popup
    if (warning[0] !== undefined){ //see if it exists yet
        if (warning[0].innerText == ("To get the closest results, let Google use your device's precise location.")) {
            document.querySelector('[jsaction="click:O6N1Pb"]').click(); //click the 'Not now' button
            clearInterval(checkTimer); //kill the timer once complete
        }
    }
    if (new Date().getTime() - startTime > maxTime) {
        clearInterval(checkTimer); //kill the timer if the popup hasnt shown after maxTime milliseconds
    }
}