Greasy Fork 还支持 简体中文。

Geoguessr unrounded games played for popular maps

Display the exact number of played games on maps where this number has been rounded (more than 1000 games played)

目前為 2022-10-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Geoguessr unrounded games played for popular maps
// @version      0.1
// @description  Display the exact number of played games on maps where this number has been rounded (more than 1000 games played)
// @author       victheturtle#5159
// @license      MIT
// @match        https://www.geoguessr.com/*
// @grant        none
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @namespace    https://greasyfork.org/users/967692-victheturtle
// ==/UserScript==

let last_URL = "";
let map_data = {};

function checkRoundedStat() {
    let q = document.querySelectorAll(".map-stats_mapStatMetricValue__UW5ne");
    return q.length >= 2 && (q[1].innerText.includes("M") || q[1].innerText.includes("K"));
};

function addDetailedPlayed() {
    let elt = document.querySelectorAll(".map-stats_mapStatMetricValue__UW5ne")[1];
    let value = map_data.props.pageProps.map.numFinishedGames.toLocaleString();
    elt.innerText = value;
    for (let ms of [100,200,300,400,500]) {
        setTimeout(() => {elt.innerText = value;}, ms);
    }
};

function checkStats() {
    if (map_data.props != null) {
        addDetailedPlayed();
        return;
    }
    let game_url = window.location.href;
    fetch(game_url)
    .then(res => res.text())
    .then(str => {
        let parser = new DOMParser();
        let html = parser.parseFromString(str, "text/html");
        let dataHTML = html.getElementById("__NEXT_DATA__");
        map_data = JSON.parse(dataHTML.innerHTML);
        addDetailedPlayed();
    }).catch(err => {throw(err);});
};

function doCheck() {
    if (location.pathname.startsWith("/maps") && location.pathname != last_URL && checkRoundedStat()) {
        checkStats();
    } else if (location.pathname != last_URL) {
        map_data = {};
    }
    location.pathname != last_URL;
};

function tryAddDetailedPlayedOnRefresh() {
    setTimeout(doCheck, 300);
};

function tryAddDetailedPlayed() {
    for (let timeout of [250,500,1200,2000]) {
        setTimeout(doCheck, timeout);
    }
};

document.addEventListener('click', tryAddDetailedPlayed, false);
document.addEventListener('load', tryAddDetailedPlayedOnRefresh(), false);
window.addEventListener('popstate', tryAddDetailedPlayed, false);