Skip to content

Instantly share code, notes, and snippets.

@yannbertrand
Last active December 6, 2025 16:52
Show Gist options
  • Select an option

  • Save yannbertrand/f95ea36799722f789e836690cfdac5c8 to your computer and use it in GitHub Desktop.

Select an option

Save yannbertrand/f95ea36799722f789e836690cfdac5c8 to your computer and use it in GitHub Desktop.
Replace GitHub relative datetimes with absolute ones
// 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);
}
});
}
// ==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);
@yannbertrand
Copy link
Author

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