Last active
December 6, 2025 16:52
-
-
Save yannbertrand/f95ea36799722f789e836690cfdac5c8 to your computer and use it in GitHub Desktop.
Replace GitHub relative datetimes with absolute ones
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
| // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#datestyle | |
| const PREFERRED_LOCALE = undefined; // Keeps browser pref | |
| const PERFERRED_FORMAT = { | |
| dateStyle: 'short', | |
| timeStyle: 'medium', | |
| }; | |
| const rts = document.querySelectorAll('relative-time'); | |
| if (rts.length > 0) { | |
| rts.forEach((rt) => { | |
| if (rt.style.whiteSpace !== 'wrap') { | |
| rt.style.whiteSpace = 'wrap'; | |
| const absolute = new Date(rt.getAttribute('datetime')); | |
| const dateString = new Intl.DateTimeFormat(PREFERRED_LOCALE, PERFERRED_FORMAT).format(absolute).replace(',', '') | |
| const newRt = document.createElement('span'); | |
| newRt.textContent = dateString; | |
| newRt.setAttribute('title', absolute.toLocaleString(PREFERRED_LOCALE)) | |
| newRt.setAttribute('data-rgh-heat', rt.getAttribute('data-rgh-heat')) | |
| const parent = rt.parentNode; | |
| parent.innerHTML = ''; | |
| parent.appendChild(newRt); | |
| } | |
| }); | |
| } |
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 GitHub replace datetime | |
| // @version 1 | |
| // @grant none | |
| // ==/UserScript== | |
| // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#datestyle | |
| const PREFERRED_LOCALE = undefined; // Keeps browser pref | |
| const PERFERRED_FORMAT = { | |
| dateStyle: 'short', | |
| timeStyle: 'medium', | |
| }; | |
| function replaceRelativeTimes() { | |
| let i=0; | |
| const interval = setInterval(() => { | |
| if (i++ === 20) { | |
| clearInterval(interval); | |
| } | |
| const rts = document.querySelectorAll('relative-time'); | |
| if (rts.length > 0) { | |
| rts.forEach((rt) => { | |
| const rts = document.querySelectorAll('relative-time'); | |
| if (rts.length > 0) { | |
| rts.forEach((rt) => { | |
| if (rt.style.whiteSpace !== 'wrap') { | |
| rt.style.whiteSpace = 'wrap'; | |
| const absolute = new Date(rt.getAttribute('datetime')); | |
| const dateString = new Intl.DateTimeFormat(PREFERRED_LOCALE, PERFERRED_FORMAT).format(absolute).replace(',', '') | |
| const newRt = document.createElement('span'); | |
| newRt.textContent = dateString; | |
| newRt.setAttribute('title', absolute.toLocaleString(PREFERRED_LOCALE)) | |
| newRt.setAttribute('data-rgh-heat', rt.getAttribute('data-rgh-heat')) | |
| const parent = rt.parentNode; | |
| parent.innerHTML = ''; | |
| parent.appendChild(newRt); | |
| } | |
| }); | |
| } | |
| }); | |
| } | |
| }, 100) | |
| } | |
| replaceRelativeTimes() | |
| let currentUrl = location.href; | |
| setInterval(() => { | |
| if (location.href !== currentUrl) { | |
| currentUrl = location.href; | |
| replaceRelativeTimes(); | |
| } | |
| }, 1000); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context: https://github.com/orgs/community/discussions/5972#discussioncomment-6690428