GeoGuessr Highscore Human Readable Dates

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
});