Skip to content

Instantly share code, notes, and snippets.

@Greenscreener
Last active March 24, 2023 13:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Greenscreener/4422f5be36752bc720cbc7222fb73cdc to your computer and use it in GitHub Desktop.
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)
// ==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)
}
@Greenscreener
Copy link
Author

Yeah, same problem here. To be perfectly honest, I expect whatsapp will fix this sooner than I actually receive a status from someone...
image

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