GeoGuessr Streak Unique Counter

Count the number of unique countries/regions in an ongoing streak

  1. // ==UserScript==
  2. // @name GeoGuessr Streak Unique Counter
  3. // @namespace ggsuc
  4. // @description Count the number of unique countries/regions in an ongoing streak
  5. // @version 0.5
  6. // @match https://www.geoguessr.com/*
  7. // @run-at document-start
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. var etat_precedant = 0
  12.  
  13. window.addEventListener("locationchange", () => { etat_precedant = 0 })
  14.  
  15. window.addEventListener("load", (event) => {
  16. let bodyList = document.querySelector("body")
  17.  
  18. let observer = new MutationObserver(function (mutations) {
  19. if (location.pathname.includes("/challenge/") || location.pathname.includes("/results/") || location.pathname.includes("/game/")) {
  20. checkPage();
  21. }
  22. });
  23.  
  24. let config = {
  25. childList: true,
  26. subtree: true
  27. };
  28.  
  29. observer.observe(bodyList, config);
  30. });
  31.  
  32. function checkPage() {
  33. let id = location.pathname.split("/").pop()
  34.  
  35. if (etat_precedant != 1) {
  36. let divs = document.querySelectorAll("div[class*=streak-round-result_answerLabel]")
  37. if (divs.length == 1) {
  38. etat_precedant = 1
  39. let liste = JSON.parse(localStorage["ggsuc-"+id] || "[]")
  40.  
  41. let pays = divs[0].querySelector("span").innerText
  42. if (!liste.includes(pays)) {
  43. liste.push(pays)
  44. localStorage["ggsuc-"+id] = JSON.stringify(liste)
  45. }
  46. }
  47. }
  48.  
  49. if (etat_precedant != 2) {
  50. let div = document.querySelector("div[class*=status_streaksValue]")
  51. if (div != null) {
  52. etat_precedant = 2
  53. let liste = JSON.parse(localStorage["ggsuc-"+id] || "[]")
  54.  
  55. let div2 = div.parentElement.nextElementSibling
  56. if (div2 == null) {
  57. div2 = document.createElement("div")
  58. div2.className = "status_section__8uP8o"
  59. div.parentElement.after(div2)
  60. }
  61.  
  62. let div3 = div2.querySelector("div[class*=status_streaksValue]")
  63. if (div3 == null) {
  64. div3 = document.createElement("div")
  65. div3.className = div.className
  66. div3.addEventListener("click", (ev) => { navigator.clipboard.writeText(ev.target.parentElement.title) })
  67. div2.appendChild(div3)
  68. }
  69.  
  70. if (div3.innerText.length == 0 || div3.innerText != "🚩" + liste.length) {
  71. div3.innerText = "🚩" + liste.length
  72. div2.title = liste.join(", ")
  73. }
  74. }
  75. }
  76. }