Greasy Fork is available in English.

Geoguessr Random Map Button (Stable)

Adds a visible floating button to get a random Geoguessr map

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
})();