-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithubabsolutetime.js
58 lines (49 loc) · 2.11 KB
/
githubabsolutetime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name GitHub absolute time
// @namespace nl.topicus
// @version 0.4
// @description renders the absolute time instead of the relative time
// @match https://github.com/*
// @copyright 2012+, Hielke Hoeve
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
function GitHubAbsolutePad(n)
{
return n < 10 ? '0' + n : n
}
function GitHubAbsoluteTimeLocalTime(date) {
var localOffset = date.getTimezoneOffset() * (60*1000);
var localTime = date.getTime();
return new Date(localTime - localOffset);
}
function GitHubAbsoluteTimeRender()
{
console.log("Absolute time rendered on GitHub page: "+new Date());
//timeline view: by default render all times in date and time format
$('.commit-group time').each(function()
{
GitHubAbsoluteTimeRenderDateTimeString(this);
});
//timeline view: rerender all times where no commit time is present in time format
$('.commit-group .authorship > time:last-child, .commit-group .committer time').each(function()
{
GitHubAbsoluteTimeRenderTimeString(this);
});
//file browser, details of a commit, last commit box when showing the folder contents, last commit box when showing the history of a file
$('.tree-browser time, .full-commit time, .commit-tease time, .file-history-tease time').each(function()
{
GitHubAbsoluteTimeRenderDateTimeString(this);
});
setTimeout(GitHubAbsoluteTimeRender, 30000);
}
function GitHubAbsoluteTimeRenderTimeString(element)
{
var date = GitHubAbsoluteTimeLocalTime(new Date($(element).attr('datetime')));
$(element).text(GitHubAbsolutePad(date.getUTCHours())+":"+GitHubAbsolutePad(date.getUTCMinutes()));
}
function GitHubAbsoluteTimeRenderDateTimeString(element)
{
var date = GitHubAbsoluteTimeLocalTime(new Date($(element).attr('datetime')));
$(element).text(GitHubAbsolutePad(date.getUTCDate())+"-"+GitHubAbsolutePad(date.getUTCMonth()+1)+"-"+date.getUTCFullYear()+" "+GitHubAbsolutePad(date.getUTCHours())+":"+GitHubAbsolutePad(date.getUTCMinutes()));
}
GitHubAbsoluteTimeRender();