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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GeoGuessr Return Old Team Duels UI
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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();
    }
})();