Last active
July 19, 2016 17:28
-
-
Save TheEnigmaBlade/ebf13913a989ac93a988b3837193d3de to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Approve time ago | |
// @author Enigma | |
// @namespace reddit_approve_time_ago | |
// @include /^https?://(.+\.)?reddit.com\// | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
($(function() { | |
function s(t) { | |
if(t != 1) { | |
return "s"; | |
} | |
return ""; | |
} | |
function timeAgoStr(t) { | |
var seconds = t/1000; | |
var minutes = seconds/60; | |
var hours = minutes/60; | |
var days = hours/24; | |
var years = days/365; | |
if(seconds < 60) { | |
var v = Math.floor(seconds); | |
return v+" second"+s(v)+" ago"; | |
} | |
else if(minutes < 60) { | |
var v = Math.floor(minutes); | |
return v+" minute"+s(v)+" ago"; | |
} | |
else if(hours < 24) { | |
var v = Math.floor(hours); | |
return v+" hour"+s(v)+" ago"; | |
} | |
else if(days < 365) { | |
var v = Math.floor(days); | |
return v+" day"+s(v)+" ago"; | |
} | |
else { | |
var v = Math.floor(years); | |
return v+" year"+s(v)+" ago"; | |
} | |
} | |
var timeExtract = /approved by \w+ at (.+)/; | |
var now = new Date().getTime(); | |
var checks = $(".approval-checkmark"); | |
checks.each(function(){ | |
var $this = $(this); | |
var text = $this.attr("title"); | |
var match = text.match(timeExtract); | |
if(match !== null) { | |
var timestamp = match[1]; | |
var then = Date.parse(timestamp); | |
var dt = now - then; | |
var dtStr = timeAgoStr(dt); | |
$this.attr("title", text+" ("+dtStr+")"); | |
} | |
}); | |
}))(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment