Last active
December 14, 2015 14:09
-
-
Save jaymzcd/5098772 to your computer and use it in GitHub Desktop.
Charlies code for demo
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
| //test | |
| //Set an Interval on the function to run every 10 secs | |
| setInterval(function() { | |
| //Get actual date | |
| var date = new Date(); | |
| //console.log(date); | |
| var reDate = /(\d+)\/(\d+)\/(\d+)/; | |
| var days; | |
| //Make comment date into actual date format | |
| data = jQuery('a[title]').filter(function(){ | |
| var a = jQuery(this); | |
| return a.text() && a.text().length!=0 || a.attr('title').match(reDate) | |
| }); | |
| //getTimeDiff(a); | |
| //if ((a.text() && a.text().length===0) || !a.attr('title').match(reDate) ){return 0} | |
| //workout how long it has been between the post time and the actual time | |
| data.each(function () { | |
| var a = jQuery(this); | |
| var d = new Date(a.attr('title').replace(reDate, "$3/$2/$1")); | |
| console.log(d, 'd'); | |
| var time_diff = date - d; | |
| var secs = time_diff/1000; | |
| var minutes = secs / 60; | |
| var hours = (minutes / 60); | |
| console.log(date, 'date'); | |
| if(time_diff<1000) { | |
| a.text('less than 1 second'); | |
| }else if(time_diff<6000) { | |
| a.text('less than a minute'); | |
| }else if(time_diff<3600000) { | |
| if (minutes > 1) { | |
| a.text(parseInt(minutes) + ' minutes'); | |
| }else{ | |
| a.text(parseInt(minutes) + ' minute'); | |
| } | |
| }else if(time_diff<86400000) { | |
| if (hours > 1) { | |
| a.text(parseInt(hours) + ' hours'); | |
| }else{ | |
| a.text(parseInt(hours) + ' hour'); | |
| } | |
| }else if(time_diff>86400000) { | |
| msToDay(hours); | |
| if (days > 1) { | |
| a.text(parseInt(days) + ' days'); | |
| }else{ | |
| a.text(parseInt(days) + ' day'); | |
| } | |
| } | |
| }); | |
| //How many Days in milliseconds | |
| function msToDay(hours) { | |
| days = hours / 24; | |
| days = days % 24; | |
| days = parseInt(days); | |
| return days; | |
| } | |
| }, 10000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment