-
Notifications
You must be signed in to change notification settings - Fork 1
/
ago.min.js
1 lines (1 loc) · 878 Bytes
/
ago.min.js
1
function Ago(a,b){a instanceof Array||(b=a,a=void 0),a=a||document.querySelectorAll("time"),b=b||{};var c={interval:1e4,units:[["minute",60],["hour",3600],["day",86400],["week",604800],["month",2592e3],["year",31536e3]],date:function(a){return new Date(a.getAttribute("datetime"))},format:function(a,b){if(!b)return"just now";var c=0>a?" ahead":" ago";return Math.abs(a)+" "+b+c},plural:{minute:"minutes",hour:"hours",day:"days",week:"weeks",month:"months",year:"years"}};for(var d in c)b[d]=b[d]||c[d];var e=function(a){var c=b.date(a),d=((new Date).getTime()-c.getTime())/1e3,e=Math.floor(Math.abs(d)),f=null,g=null;for(var h in b.units){var i=b.units[h][1];if(!(e>=i))break;f=b.units[h][0],g=i}null!==g&&(e=Math.floor(e/g),1!=e&&(f=b.plural[f])),a.textContent=b.format(0>d?-e:e,f)},f=function(){for(var b=0;b<a.length;b++)e(a[b])};f(),setInterval(function(){f()},b.interval)}