GeoGuessr Return Old Team Duels UI

This script returns the old GeoGuessr Team Duels UI but only when on the teams page.

目前为 2025-05-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         GeoGuessr Return Old Team Duels UI
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  This script returns the old GeoGuessr Team Duels UI but only when on the teams page.
// @author       AaronThug
// @match        https://www.geoguessr.com/*
// @icon         https://www.geoguessr.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fteam-duels.52be0df6.webp&w=64&q=75
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
    const modifiedButtons = new Set();
    let observerActive = false;
    const playButtonLabels = {
        'English': 'Play',
        'Deutsch': 'Spielen',
        'Español': 'Jugar',
        'Français': 'Jouer',
        'Italiano': 'Gioca',
        'Nederlands': 'Spelen',
        'Português': 'Jogar',
        'Svenska': 'Spela',
        'Türkçe': 'Oyna',
        '日本語': 'プレイ',
        'Polski': 'Graj'
    };
    function modifyPlayButton() {
        if (!window.location.href.includes('/multiplayer/teams')) {
            return;
        }
        const playButtons = document.querySelectorAll('button.button_button__aR6_e.button_variantPrimary__u3WzI');
        playButtons.forEach(button => {
            if (modifiedButtons.has(button)) {
                return;
            }
            const buttonText = button.querySelector('.button_label__ERkjz');
            if (buttonText && Object.values(playButtonLabels).includes(buttonText.textContent)) {
                modifiedButtons.add(button);
                const newButton = button.cloneNode(true);
                button.parentNode.replaceChild(newButton, button);
                newButton.addEventListener('click', handlePlayButtonClick, true);
                modifiedButtons.add(newButton);
            }
        });
    }
    function handlePlayButtonClick(e) {
        e.preventDefault();
        e.stopPropagation();
        const avatarContainer = document.querySelector('#planet-anchor-container > div.team-section_avatarContainer__bHGNz');
        if (!avatarContainer) {
            redirectToDefault();
            return;
        }
        const friendContainer = avatarContainer.querySelector('div > div.team-avatars_friendContainer__29kpm');
        if (!friendContainer) {
            redirectToDefault();
            return;
        }
        const canvas = friendContainer.querySelector('canvas.team-avatars_friend__ITCMj');
        if (!canvas) {
            redirectToDefault();
            return;
        }
        const userId = canvas.id.split('_local')[0];
        if (!userId) {
            redirectToDefault();
            return;
        }
        window.location.href = `https://www.geoguessr.com/matchmaking?id=${userId}`;
    }
    function redirectToDefault() {
        window.location.href = 'https://www.geoguessr.com/multiplayer/teams';
    }
    function setupObserver() {
        if (observerActive) {
            return;
        }
        observerActive = true;
        const observer = new MutationObserver(function(mutations) {
            if (!window.location.href.includes('/multiplayer/teams')) {
                return;
            }
            const hasNewNodes = mutations.some(mutation =>
                mutation.type === 'childList' && mutation.addedNodes.length > 0
            );
            if (hasNewNodes) {
                modifyPlayButton();
            }
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }
    function init() {
        modifyPlayButton();
        setupObserver();
    }
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();