GeoGuessr Return Old Team Duels UI

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

目前為 2025-05-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         GeoGuessr Return Old Team Duels UI
// @namespace    http://tampermonkey.net/
// @version      1.2
// @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
// @require https://update.greasyfork.org/scripts/460322/1408713/Geoguessr%20Styles%20Scan.js
// ==/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'
    };
    
    async function initClassNames() {
        await scanStyles();
    }
    
    async function modifyPlayButton() {
        if (!window.location.href.includes('/multiplayer/teams')) {
            return;
        }
        
        const buttonClass = cn("button_button__");
        const buttonVariantClass = cn("button_variantPrimary__");
        const buttonLabelClass = cn("button_label__");
        
        if (!buttonClass || !buttonVariantClass || !buttonLabelClass) {
            setTimeout(modifyPlayButton, 1000);
            return;
        }
        
        const playButtons = document.querySelectorAll(`button.${buttonClass}.${buttonVariantClass}`);
        playButtons.forEach(button => {
            if (modifiedButtons.has(button)) {
                return;
            }
            const buttonText = button.querySelector(`.${buttonLabelClass}`);
            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 teamSectionAvatarContainerClass = cn("team-section_avatarContainer__");
        const teamAvatarsFriendContainerClass = cn("team-avatars_friendContainer__");
        const teamAvatarsFriendClass = cn("team-avatars_friend__");
        
        if (!teamSectionAvatarContainerClass || !teamAvatarsFriendContainerClass || !teamAvatarsFriendClass) {
            redirectToDefault();
            return;
        }
        
        const avatarContainer = document.querySelector(`#planet-anchor-container > div.${teamSectionAvatarContainerClass}`);
        if (!avatarContainer) {
            redirectToDefault();
            return;
        }
        const friendContainer = avatarContainer.querySelector(`div > div.${teamAvatarsFriendContainerClass}`);
        if (!friendContainer) {
            redirectToDefault();
            return;
        }
        const canvas = friendContainer.querySelector(`canvas.${teamAvatarsFriendClass}`);
        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
        });
    }
    
    async function init() {
        await initClassNames();
        modifyPlayButton();
        setupObserver();
    }
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();