Greasy Fork 还支持 简体中文。

Geoguessr unrounded map stats

Display the exact number of played games, locations count and likes for Geoguessr maps

目前為 2023-07-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 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 map stats
// @version      0.2.0
// @description  Display the exact number of played games, locations count and likes for Geoguessr maps
// @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 lastURL = "";
let mapData = {};
let mapSearchData = {};

function checkRoundedStat() {
    let q = document.querySelectorAll("div[class*='map-stats_mapStatMetricValue__']");
    if (q == undefined || q.length < 4) return false;
    if (q[1].innerText.includes("M") || q[1].innerText.includes("K")) return true
    if (q[2].innerText.includes("+")) return true
    if (q[3].innerText.includes("K")) return true
    return false;
};

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

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

function addDetailedLocCount() {
    let divs = document.querySelectorAll("div[class*='map-stats_mapStatMetricValue__']");
    let countElt = divs[2];
    let likesElt = divs[3];
    let countValue = mapSearchData.coordinateCount.toLocaleString();
    let likesValue = mapSearchData.likes.toLocaleString();
    countElt.innerText = countValue; likesElt.innerText = likesValue;
    for (let ms of [100,200,300,400,500]) {
        setTimeout(() => {countElt.innerText = countValue; likesElt.innerText = likesValue;}, ms);
    }
};

function checkOtherStats() {
    fetch(location.href.replace("maps/", "api/v3/search/map?page=0&count=1&q="))
    .then(res => res.json())
    .then(json => {
        mapSearchData = json[0];
        addDetailedLocCount();
    }).catch(err => {throw(err);});
}

function doCheck() {
    if (location.pathname.startsWith("/maps") && location.pathname != lastURL && checkRoundedStat()) {
        checkGamesPlayedStats();
        checkOtherStats();
    } else if (location.pathname != lastURL) {
        mapData = {};
        mapSearchData = {};
    }
    location.pathname != lastURL;
};

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

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

document.addEventListener('click', tryAddDetailed, false);
document.addEventListener('load', tryAddDetailedOnRefresh(), false);
window.addEventListener('popstate', tryAddDetailed, false);