Skip to content

Instantly share code, notes, and snippets.

@dannyedel
Last active January 23, 2021 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyedel/6522654 to your computer and use it in GitHub Desktop.
Save dannyedel/6522654 to your computer and use it in GitHub Desktop.
GreaseMonkey script to change Timestamps in github to the user's timezone and locale settings
// ==UserScript==
// @name github-relative-dates-timezone.js
// @namespace http://danny-edel.de/
// @include https://github.com/*
// @version 2
// ==/UserScript==
/** Walk through all <time> Tags and
* use toLocaleString() to render them to a
* user-friendly format.
*/
function updateGithubTimestamps() {
var githubTimes = document.getElementsByClassName('js-relative-date');
for(var i=0; i<githubTimes.length; i++) {
var time = githubTimes[i];
// parse the time from the 'datetime' attribute
var datetimeStringOld = time.getAttribute('datetime');
// dateSeconds: seconds since 1970-01-01 00:00:00 zulu
var dateSeconds = Date.parse(datetimeStringOld);
// build a date object with the (timezone-agnostic) timepoint
var date = new Date(dateSeconds);
// format the date according to locale's rules
var localString = date.toLocaleString();
// write it to the 'title' attribute (gets shown upon mouseover)
time.setAttribute('title', localString);
}
}
var timerVar = setInterval( function(){ updateGithubTimestamps() }, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment