-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcountdown.js
48 lines (37 loc) · 1.55 KB
/
countdown.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
function timer(page, duration, containerClass, buildingID, langCancel) {
var timer = duration, hours, minutes, seconds;
var countdown = function () {
// console.log(page);
var container;
if (page === "overview") {
container = document.getElementsByClassName(containerClass)[0];
} else {
container = document.getElementsByClassName(containerClass)[0].querySelector("div");
}
hours = parseInt(timer / 3600, 10);
minutes = parseInt(timer / 60, 10) - (60 * hours);
seconds = parseInt(timer % 60, 10);
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
var pageLink;
if (buildingID > 100) {
pageLink = "research";
} else {
pageLink = "building";
}
if (page === "overview") {
container.innerHTML = hours + ":" + minutes + ":" + seconds;
} else {
container.innerHTML = "<div class='row'><div class='col-md-12'>" + hours + ":" + minutes + ":" + seconds + "</div><div class='col-md-12'><a href=\"game.php?page=" + pageLink + "&cancel=" + buildingID + "\">" + langCancel + "</a></div></div>";
}
if (--timer <= 0) {
container.textContent = "done";
window.setTimeout(function () {
window.location.href = "game.php?page=" + page;
}, 2000);
}
setTimeout(countdown, 1000);
};
countdown();
}