Skip to content

Instantly share code, notes, and snippets.

@anamoyee
Created January 1, 2026 04:30
Show Gist options
  • Select an option

  • Save anamoyee/46b37fe3a1b68cd4cce3153b87a58ff8 to your computer and use it in GitHub Desktop.

Select an option

Save anamoyee/46b37fe3a1b68cd4cce3153b87a58ff8 to your computer and use it in GitHub Desktop.
A crude (but working) tampermonkey/violentmonkey script to change most 12h time displays into 24h format in Google Maps (since they cant be bothered to add "English (UK)" language option...). This will probably break if they ever change the jslog ids or the general layout of the page.
// ==UserScript==
// @name Google Maps 24h Time Converter
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Convert most am/pm times to 24-hour format on Google Maps
// @author You
// @match https://www.google.com/maps/*
// @grant none
// ==/UserScript==
function convertAmPmTo24h(text) {
const ampmRegex = /\b(\d{1,2})(?::(\d{2}))?\s*(am|pm)\b/gi;
return text.replace(ampmRegex, (_, hour, minute, meridiem) => {
hour = parseInt(hour, 10);
minute = minute ? parseInt(minute, 10) : 0;
if (meridiem.toLowerCase() === 'pm' && hour !== 12) {
hour += 12;
} else if (meridiem.toLowerCase() === 'am' && hour === 12) {
hour = 0;
}
const hh = hour;
const mm = minute.toString().padStart(2, '0');
return `${hh}:${mm}`;
});
}
(function() {
'use strict';
function replace_preview(){
// previews on businesses without multiple hour categories (without a full view after click)
document.querySelectorAll('[jslog^="14925"] span:not(:has(*))').forEach(span => {
span.innerText = convertAmPmTo24h(span.innerText)
})
// for the above but user expanded the preview inline
document.querySelectorAll('[jslog^="36914"] li:not(:has(*))').forEach(li => {
li.innerText = convertAmPmTo24h(li.innerText)
})
// previews on businesses with one "hours"
document.querySelectorAll('[jslog^="36914"] span:not(:has(*))').forEach(span => {
span.innerText = convertAmPmTo24h(span.innerText)
})
}
function replace_full_view(){
document.querySelectorAll('h1.fontTitleLarge').forEach(h1 => {
h1.parentElement.parentElement.parentElement.parentElement.parentElement.querySelectorAll('div[role=main] > div:nth-child(2) table li').forEach(li => {
li.innerText = convertAmPmTo24h(li.innerText)
})
})
}
function replace_carousel() {
document.querySelectorAll('[jslog="24224"] span:not(:has(*))').forEach(span => {
span.innerText = convertAmPmTo24h(span.innerText)
})
}
function tick(){
replace_preview();
replace_full_view();
replace_carousel();
}
setInterval(tick, 25)
tick()
})();
@iansquenet
Copy link

Is there a way to get the textbox working as well to display 24-hour format?

@anamoyee
Copy link
Author

anamoyee commented Jan 3, 2026

Is there a way to get the textbox working as well to display 24-hour format?

I think that may require reimplementing the whole textbox or adding some sort of wrapper around it, but if you find a way and want to add your contribution feel free to post your version of the script here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment