Geoguessr unrounded map stats

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

Install this script?
Author's suggested script

You may also like Show profile details.

Install this script
  1. // ==UserScript==
  2. // @name Geoguessr unrounded map stats
  3. // @version 0.2.2
  4. // @description Display the exact number of played games, locations count and likes for Geoguessr maps
  5. // @author victheturtle#5159
  6. // @license MIT
  7. // @match https://www.geoguessr.com/*
  8. // @grant none
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
  10. // @namespace https://greasyfork.org/users/967692-victheturtle
  11. // ==/UserScript==
  12.  
  13. let lastURL = "";
  14. let mapData = {};
  15. let mapSearchData = {};
  16.  
  17. function checkRoundedStat() {
  18. let q = document.querySelectorAll("div[class*='map-stats_mapStatMetricValue__']");
  19. if (q == undefined || q.length < 4) return false;
  20. if (q[1].innerText.includes("M") || q[1].innerText.includes("K")) return true
  21. if (q[2].innerText.includes("+")) return true
  22. if (q[3].innerText.includes("K")) return true
  23. return false;
  24. };
  25.  
  26. function addDetailedPlayed() {
  27. let elt = document.querySelectorAll("div[class*='map-stats_mapStatMetricValue__']")[1];
  28. let value = mapData.props.pageProps.map.numFinishedGames.toLocaleString();
  29. elt.innerText = value;
  30. for (let ms of [100,200,300,400,500]) {
  31. setTimeout(() => {elt.innerText = value;}, ms);
  32. }
  33. };
  34.  
  35. function checkGamesPlayedStats() {
  36. if (mapData.props != null) {
  37. addDetailedPlayed();
  38. return;
  39. }
  40. fetch(location.href)
  41. .then(res => res.text())
  42. .then(str => {
  43. let parser = new DOMParser();
  44. let html = parser.parseFromString(str, "text/html");
  45. let dataHTML = html.getElementById("__NEXT_DATA__");
  46. mapData = JSON.parse(dataHTML.innerHTML);
  47. addDetailedPlayed();
  48. }).catch(err => {throw(err);});
  49. };
  50.  
  51. function addDetailedLocCount() {
  52. let divs = document.querySelectorAll("div[class*='map-stats_mapStatMetricValue__']");
  53. let countElt = divs[2];
  54. let likesElt = divs[3];
  55. let countValue = mapSearchData.coordinateCount.toLocaleString();
  56. let likesValue = mapSearchData.likes.toLocaleString();
  57. countElt.innerText = countValue; likesElt.innerText = likesValue;
  58. for (let ms of [100,200,300,400,500]) {
  59. setTimeout(() => {countElt.innerText = countValue; likesElt.innerText = likesValue;}, ms);
  60. }
  61. };
  62.  
  63. function checkOtherStats() {
  64. let mapId = location.href.split("/").pop()
  65. fetch(location.origin + "/api/v3/search/map?page=0&count=1&q=" + mapId)
  66. .then(res => res.json())
  67. .then(json => {
  68. if (json[0].id != mapId) return;
  69. mapSearchData = json[0];
  70. addDetailedLocCount();
  71. }).catch(err => {throw(err);});
  72. }
  73.  
  74. function doCheck() {
  75. if (location.pathname.includes("/maps/") && location.pathname != lastURL && checkRoundedStat()) {
  76. checkGamesPlayedStats();
  77. checkOtherStats();
  78. } else if (location.pathname != lastURL) {
  79. mapData = {};
  80. mapSearchData = {};
  81. }
  82. location.pathname != lastURL;
  83. };
  84.  
  85. function tryAddDetailedOnRefresh() {
  86. setTimeout(doCheck, 300);
  87. };
  88.  
  89. function tryAddDetailed() {
  90. for (let timeout of [250,500,1200,2000]) {
  91. setTimeout(doCheck, timeout);
  92. }
  93. };
  94.  
  95. document.addEventListener('click', tryAddDetailed, false);
  96. document.addEventListener('load', tryAddDetailedOnRefresh(), false);
  97. window.addEventListener('popstate', tryAddDetailed, false);