Last active
January 23, 2021 20:39
-
-
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
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 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