Geoguessr unrounded map stats

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

Εγκατάσταση αυτού του κώδικαΒοήθεια
Κώδικας προτεινόμενος από τον δημιιουργό

Μπορεί, επίσης, να σας αρέσει ο κώδικας Show profile details.

Εγκατάσταση αυτού του κώδικα

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Geoguessr unrounded map stats
// @version      0.2.2
// @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() {
    let mapId = location.href.split("/").pop()
    fetch(location.origin + "/api/v3/search/map?page=0&count=1&q=" + mapId)
    .then(res => res.json())
    .then(json => {
        if (json[0].id != mapId) return;
        mapSearchData = json[0];
        addDetailedLocCount();
    }).catch(err => {throw(err);});
}

function doCheck() {
    if (location.pathname.includes("/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);