-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
88 lines (77 loc) · 2.04 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
$(document).ready(function() {
var jsonstring = "";
var htmlToWrite ="";
var toWrite = "";
var pulldata = function() {
$.ajax({
type: "GET",
cache: false,
dataType: "JSON",
url: "http://neapolitan.herokuapp.com/",
success: function(data) {
jsonstring = data;
massageData(jsonstring);
},
error: function (errorT) {
alert(errorT);
}
});
};
function massageData(twstring) {
twstring.statuses.forEach(function(statuses) {
if (typeof statuses.entities.media !== 'undefined') {
toWrite += "<div class='col-md-6 col-sm-6 col-xs-12'>" +
"<div class='thumbnail'>" + "<div id='outer'>" +
"<img src='" + statuses.entities.media[0].media_url + "'></div>" +
"<div class='caption'>" +
"<p>" + rtime(statuses.created_at) + "</p>" +
"<h4>" + statuses.user.name + "</h4>" +
"</div></div></div>";
}
});
$("#content").append(
toWrite
);
}
pulldata();
rtime = function(dateString) {
var rightNow = new Date();
var then = new Date(dateString);
var diff = rightNow - then;
var second = 1000;
var minute = second * 60;
var hour = minute * 60;
var day = hour * 24;
var week = day * 7;
if (isNaN(diff) || diff < 0) {
return "";
}
if (diff < second * 2) {
return "right now";
}
if (diff < minute) {
return Math.floor(diff / second) + " seconds ago";
}
if (diff < minute * 2) {
return "about 1 minute ago";
}
if (diff < hour) {
return Math.floor(diff / minute) + " minutes ago";
}
if (diff < hour * 2) {
return "about 1 hour ago";
}
if (diff < day) {
return Math.floor(diff / hour) + " hours ago";
}
if (diff > day && diff < day * 2) {
return "yesterday";
}
if (diff < day * 365) {
return Math.floor(diff / day) + " days ago";
}
else {
return "over a year ago";
}
}; // timeAgo()
});