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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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