Copy Live Challenge Scores

Press 'c' to copy live challenge scores to clipboard

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Copy Live Challenge Scores
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Press 'c' to copy live challenge scores to clipboard
// @match        https://www.geoguessr.com/*
// @author       BrainyGPT
// @icon         https://www.google.com/s2/favicons?domain=geoguessr.com
// @license      MIT
// @grant        GM_setClipboard
// ==/UserScript==

(function () {
    'use strict';

    function getScoresCSV() {
        const resultRows = document.querySelectorAll('[class*="results_row"]');
        const data = [];

        resultRows.forEach(row => {
            const columns = row.querySelectorAll('div');
            let playerName = null;
            let scores = [];

            columns.forEach(col => {
                const text = col.textContent.trim();

                // Find player name
                if (!playerName && text.length > 0 && !text.match(/^\d+[,.]?\d* km$/)) {
                    const isPlayer = col.querySelector('a[href*="/user/"]');
                    if (isPlayer) {
                        playerName = text.replace(/^\d+\.\s*/, ''); // Remove ranking numbers like "1. "
                    }
                }

                // Score values like "4,691 pts"
                if (text.endsWith('pts')) {
                    const ptsOnly = text.replace(/[^\d]/g, '');
                    scores.push(ptsOnly);
                }
            });

            if (playerName && scores.length === 6) {
                data.push([playerName, ...scores]);
            }
        });

        return data.map(row => row.join(',')).join('\n');
    }

    function copyToClipboard() {
        const csv = getScoresCSV();
        if (csv && typeof GM_setClipboard === 'function') {
            GM_setClipboard(csv);
            alert('✅ GeoGuessr scores copied to clipboard!');
        } else {
            console.error('Clipboard copy failed. GM_setClipboard not available.');
        }
    }

    window.addEventListener('keydown', (e) => {
        if (e.key === 'c' && !e.ctrlKey && !e.metaKey && !e.altKey) {
            copyToClipboard();
        }
    });

    console.log("✅ GeoGuessr script ready — press 'c' to copy scores to clipboard");
})();