GeoGuessr Highscore Human Readable Dates

Display the date on the highscores of a map in a human readable format

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name GeoGuessr Highscore Human Readable Dates
// @namespace   gghrd
// @description Display the date on the highscores of a map in a human readable format
// @version 0.3
// @match https://www.geoguessr.com/*
// @run-at document-start
// @license MIT
// ==/UserScript==

function format(date) {
  /*
  sv-SE 2025-12-31
  en-GB 31/12/2025
  en-US 12/31/2025 💀

  year: 'numeric' | '2-digit'
  month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long'
  day: 'numeric' | '2-digit'
  */
  return date.toLocaleDateString("sv-SE", { day: "2-digit", month: "2-digit", year: "2-digit" })
}

function onMutations (mutations) {
  if (!location.pathname.includes("/maps/")) return

  for (let mutation of mutations) {
    if (mutation.type === "childList") {
      if (mutation.target.nodeName == "TBODY" && mutation.addedNodes && mutation.addedNodes.length) {
        for (let addedNode of mutation.addedNodes) {
          for (let node of addedNode.querySelectorAll("[class*=map-highscore_date]")) {
            let span = node.querySelector("span")
            span.innerText = format(new Date(span.title))
          }
        }
      }
    } else if (mutation.type === "attributes") {
      if (mutation.attributeName === "title" && mutation.target.parentNode.className.includes("map-highscore_date")) {
        let span = mutation.target
        span.innerText = format(new Date(span.title))
      }
    } else {
      console.log(mutation)
    }
  }
}

window.addEventListener("load", (event) => {
  for (let node of document.body.querySelectorAll("[class*=map-highscore_date]")) {
    let span = node.querySelector("span")
    span.innerText = format(new Date(span.title))
  }

  let observer = new MutationObserver(onMutations);

  let config = {
    subtree: true,
    childList: true,
    attributes: true,
    attributeFilter: ["title"],
  };

  observer.observe(document.body, config);
});