-
Notifications
You must be signed in to change notification settings - Fork 0
/
mightygumball.js
42 lines (37 loc) · 1.29 KB
/
mightygumball.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
/**
* Created By: Adrienne Cabouet
* Date: 7/10/13
* Time: 1:11 PM
*/
var lastReportTime = 0;
window.onload = function () {
setInterval(handleRefresh, 3000);
function handleRefresh() {
var url="http://gumball.wickedlysmart.com?callback=updateSales" +
"&lastreporttime=" + lastReportTime +
"&random=" + (new Date()).getTime();
var newScriptElement = document.createElement("script");
newScriptElement.setAttribute("src", url);
newScriptElement.setAttribute("id", "jsonp");
var oldScriptElement = document.getElementById("jsonp");
var head = document.getElementsByTagName("head")[0];
if (oldScriptElement == null) {
head.appendChild(newScriptElement);
} else {
head.replaceChild(newScriptElement, oldScriptElement);
}
}
};
function updateSales(sales) {
var salesDiv = document.getElementById("sales");
for (var i = 0; i < sales.length; i++) {
var sale = sales[i];
var div = document.createElement("div");
div.setAttribute("class", "saleItem");
div.innerHTML = sale.name + " sold " + sale.sales + " gumballs";
salesDiv.appendChild(div);
}
if (sales.length > 0) {
lastReportTime = sales[sales.length-1].time;
}
}