Greasy Fork 还支持 简体中文。

AnyGuessr - Universal Geoguessr-alike game cheat

Get the location in any GeoGuessr-alike game

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AnyGuessr - Universal Geoguessr-alike game cheat
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Get the location in any GeoGuessr-alike game
// @author       daijro
// @license      MIT
// @include      *
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @grant        GM_xmlhttpRequest
// ==/UserScript==

let globalCoordinates = {
    lat: 0,
    lng: 0
};

let globalPanoID = undefined;

// Function to fetch the country name using Nominatim API (OpenStreetMap)
async function findCountry({ lat, lon }) {
    let data = null;
    try {
        const response = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json`);
        data = await response.json();
    } catch (e) {
        console.error("Error fetching country data:", e);
        data = { address: { country: "Unknown" }}; // default to unknown if error occurs
    }
    return data?.address?.country ?? "Unknown";
}

// Override XMLHttpRequest open to intercept API calls and extract coordinates
var originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
    if (method.toUpperCase() === 'POST' &&
        (url.startsWith('https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/GetMetadata') ||
         url.startsWith('https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/SingleImageSearch'))) {

        this.addEventListener('load', async function () {
            let interceptedResult = this.responseText;
            const pattern = /-?\d+\.\d+,-?\d+\.\d+/g;
            let match = interceptedResult.match(pattern)[0];
            let split = match.split(",");

            let lat = Number.parseFloat(split[0]);
            let lng = Number.parseFloat(split[1]);

            globalCoordinates.lat = lat;
            globalCoordinates.lng = lng;
            console.log(`Coordinates: ${JSON.stringify(globalCoordinates)}`);

            // Call function to fetch country name
            const country = await findCountry({ lat, lon: lng });
            console.log(`Detected Country: ${country}`);
        });
    }
    return originalOpen.apply(this, arguments);
};