OpenGuessr Hack Location Finder

Extract and open PanoramaIframe src in Google Maps full site when pressing Control + X + S together

目前為 2024-12-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OpenGuessr Hack Location Finder
// @namespace    https://openguessr.com/
// @version      1.4
// @description  Extract and open PanoramaIframe src in Google Maps full site when pressing Control + X + S together
// @author       YourName
// @license      MIT
// @match        https://openguessr.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Track pressed keys
    const keysPressed = new Set();

    // Event listener for keydown
    document.addEventListener('keydown', (event) => {
        keysPressed.add(event.code); // Use `event.code` for consistent detection

        // Check if ControlLeft, KeyX, and KeyS are pressed
        if (keysPressed.has('ControlLeft') && keysPressed.has('KeyX') && keysPressed.has('KeyS')) {
            // Find the iframe element by ID
            const iframe = document.querySelector('#PanoramaIframe');
            if (iframe) {
                const src = iframe.getAttribute('src');
                if (src) {
                    // Extract latitude and longitude
                    const url = new URL(src);
                    const latLng = url.searchParams.get('pb')?.split('!')[2];
                    if (latLng) {
                        const [latitude, longitude] = latLng.split(',');
                        // Open in full Google Maps
                        const mapsUrl = `https://www.google.com/maps/@${latitude},${longitude},15z`;
                        window.open(mapsUrl, '_blank');
                    } else {
                        console.error('Latitude and longitude could not be extracted');
                    }
                } else {
                    console.error('Iframe src attribute not found');
                }
            } else {
                console.error('Iframe with ID "PanoramaIframe" not found');
            }

            // Prevent default behavior
            event.preventDefault();
        }
    });

    // Event listener for keyup to clear pressed keys
    document.addEventListener('keyup', (event) => {
        keysPressed.delete(event.code); // Use `event.code`
    });
})();