Created
August 28, 2014 17:24
-
-
Save anonymous/dca9be0cde7a03fc6f7b to your computer and use it in GitHub Desktop.
Fixed timestamps in ps2tracker.net
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
<script type="text/javascript"> | |
(function() { | |
"use strict"; | |
/* From https://github.com/dperini/ContentLoaded/blob/master/src/contentloaded.js | |
* Author: Diego Perini (diego.perini at gmail.com) | |
* License: MIT | |
*/ | |
function contentLoaded(win, fn) { | |
var done = false, top = true, | |
doc = win.document, root = doc.documentElement, | |
add = doc.addEventListener ? 'addEventListener' : 'attachEvent', | |
rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent', | |
pre = doc.addEventListener ? '' : 'on', | |
init = function(e) { | |
if (e.type == 'readystatechange' && doc.readyState != 'complete') return; | |
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false); | |
if (!done && (done = true)) fn.call(win, e.type || e); | |
}, | |
poll = function() { | |
try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; } | |
init('poll'); | |
}; | |
if (doc.readyState == 'complete') fn.call(win, 'lazy'); | |
else { | |
if (doc.createEventObject && root.doScroll) { | |
try { top = !win.frameElement; } catch(e) { } | |
if (top) poll(); | |
} | |
doc[add](pre + 'DOMContentLoaded', init, false); | |
doc[add](pre + 'readystatechange', init, false); | |
win[add](pre + 'load', init, false); | |
} | |
} | |
function utcnow() { | |
var now = new Date(); | |
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); | |
return now_utc; | |
} | |
// The following function is under MIT License - http://www.opensource.org/licenses/mit-license.php | |
// Adapted from https://github.com/rmm5t/jquery-timeago/blob/master/jquery.timeago.js | |
function prettyTimeDiff(then, now) { | |
var diff = now - then; | |
var seconds = Math.abs(diff) / 1000; | |
var minutes = seconds / 60; | |
var hours = minutes / 60; | |
var days = hours / 24; | |
var years = days / 365; | |
var words; | |
true && seconds < 60 && (words = seconds + 'seconds') || | |
seconds < 120 && (words = '1 minute') || | |
minutes < 60 && (words = Math.round(minutes) + ' minutes') || | |
hours < 24 && (words = Math.round(hours) + ' hours') || | |
days < 2 && (words = '1 day') || | |
days < 31 && (words = Math.round(days) + ' days') || | |
days < 365 && (words = Math.round(days / 30) + ' months') || | |
years < 2 && (words = '1 year') || | |
(words = Math.round(years) + ' years'); | |
return words + ' ago'; | |
} | |
function relTime() { | |
var now = utcnow(); | |
var elements = document.querySelectorAll('span.posttime'); | |
var d, item, dstring; | |
for(var i = 0; i < elements.length; i++) { | |
item = elements[i]; | |
dstring = item.getAttribute('data-ms'); | |
d = new Date(dstring); | |
item.innerHTML = prettyTimeDiff(now, d); | |
item.setAttribute('title', dstring); | |
} | |
} | |
contentLoaded(window, relTime); | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment