More work on polls and themes

This commit is contained in:
Daisuke
2020-04-21 20:53:40 -05:00
parent f59049c3c2
commit 2c7a8e1da4
4 changed files with 62 additions and 2 deletions

View File

@ -424,6 +424,11 @@ function newPosts() {
};
window.setInterval(function() {
var timestamp;
$('.postAge').each(function(a){
timestamp = $(this).attr('id');
$(this).html(timeSince(timestamp)+' ago');
});
newPosts();
}, 25000);
@ -477,3 +482,37 @@ function themecheck(name){
$('#customtheme').css("display","none");
}
};
function timeSince(date) {
/* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */
var seconds = Math.floor((new Date() - (date*1000)) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval >= 1) {
return interval + " years";
}
interval = Math.floor(seconds / 2592000);
if (interval >= 1) {
return interval + " months";
}
interval = Math.floor(seconds / 604800);
if (interval >= 1) {
return interval + " weeks";
}
interval = Math.floor(seconds / 86400);
if (interval >= 1) {
return interval + " days";
}
interval = Math.floor(seconds / 3600);
if (interval >= 1) {
return interval + " hours";
}
interval = Math.floor(seconds / 60);
if (interval >= 1) {
return interval + " minutes";
}
return Math.floor(seconds) + " seconds";
}