Last active
March 7, 2025 19:42
-
-
Save Greenscreener/4422f5be36752bc720cbc7222fb73cdc to your computer and use it in GitHub Desktop.
Convert all elements with 12-hour time to 24-hour automatically (for WhatsApp Web, but could be adapted easily)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name WAWeb 24-hourifier | |
// @version 0.10 | |
// @description Convert all elements with 12-hour time to 24-hour automatically (for WhatsApp Web, but could be adapted easily) | |
// @author Greenscreener | |
// @homepage https://grsc.cz/ | |
// @match https://web.whatsapp.com/* | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/Greenscreener/4422f5be36752bc720cbc7222fb73cdc/raw/12to24.user.js | |
// @updateURL https://gist.githubusercontent.com/Greenscreener/4422f5be36752bc720cbc7222fb73cdc/raw/12to24.user.js | |
// ==/UserScript== | |
{ | |
const re = /^((?:last seen \w+ at )?)(\d\d?):(\d\d) ([ap])(?:\.\u00A0)?m\.?$/ | |
function conv12to24(str) { | |
const hr = parseInt(str.match(re)[2]) | |
const mi = parseInt(str.match(re)[3]) | |
const add = (str.match(re)[4] === "p") !== (hr === 12) // Why is 12-hour time so dumb | |
return str.match(re)[1]+((hr+12*add)%24).toString()+":"+mi.toString().padStart(2,"0") | |
} | |
setInterval(() => { | |
[ | |
...document.body.getElementsByTagName("span"), | |
...document.body.getElementsByTagName("div") | |
].filter(e => e.innerText.match(re)) | |
.forEach(e => e.innerText = conv12to24(e.innerText)) | |
}, 500) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah that one. I never clicked that button and it is empty for me unfortunately. I will try to add a fix to that as soon as someone in my contact list does a status update.