Last active
March 24, 2023 13:54
-
-
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 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) | |
} |
Love this solution. Thank you very very much.
I just noticed that the Status Updates still use 12 hours am/pm notation.
@rob-vandenberg If you check whatsapptime.js in my repository it will contain the fix for that.
I think you misunderstood me. I was talking about the "Status" window in Whatsapp.
That's the window you see when you click on the left of the 3 icons at the top of the Whatsapp window, just above the contacts list.
The left icon that looks like a circle consisting of 3 parts. That one still shows AM/PM, also with the new code (I tried it).
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At 12:xx the time is shown wrong btw. Adding an AND operator and check for hr !=12 fixes this.
Also I made a standalone Chrome extension for this, I credited you:
https://github.com/MathijsNL/WhatsappTime