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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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