Geoguessr Random Map Button (Stable)

Adds a visible floating button to get a random Geoguessr map

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Geoguessr Random Map Button (Stable)
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds a visible floating button to get a random Geoguessr map
// @author       you
// @match        https://www.geoguessr.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    function injectButton() {
        // Avoid duplicate buttons
        if (document.getElementById('random-map-button')) return;

        const button = document.createElement('button');
        button.id = 'random-map-button';
        button.textContent = '🎲 Random Map';
        Object.assign(button.style, {
            position: 'fixed',
            top: '20px',
            right: '20px',
            padding: '10px 15px',
            fontSize: '14px',
            fontWeight: 'bold',
            backgroundColor: '#00AA88',
            color: 'white',
            border: 'none',
            borderRadius: '5px',
            cursor: 'pointer',
            zIndex: '9999',
            opacity: '1',
            display: 'block',
            boxShadow: '0 2px 5px rgba(0, 0, 0, 0.3)',
        });

        button.onclick = async () => {
            try {
                const res = await fetch('https://www.geoguessr.com/api/v3/social/maps/browse/random', {
                    credentials: 'include'
                });
                const data = await res.json();
                const mapUrl = 'https://www.geoguessr.com' + data.url;
                window.open(mapUrl, '_blank');
            } catch (err) {
                alert('Error fetching map. Are you logged in?');
                console.error(err);
            }
        };

        document.body.appendChild(button);
    }

    // Retry until body is loaded
    function waitAndInject() {
        if (document.body) {
            injectButton();
        } else {
            setTimeout(waitAndInject, 500); // retry every 0.5s
        }
    }

    waitAndInject();
})();