-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
94 lines (79 loc) · 2.56 KB
/
scripts.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
89
90
91
92
93
94
var time;
var currentTime;
setInterval(function() {
tick();
}, 1000);
var started = false;
var skipTheClick = false;
var audioBeep = new Audio("sound-effects/beep.mp3");
var audioAlert = new Audio("sound-effects/alert2.mp3");
var toggleFulscreenButton = document.getElementById("toggleFulscreenButton");
toggleFulscreenButton.addEventListener("click", function() {
var doc = window.document;
var docEl = doc.documentElement;
var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
requestFullScreen.call(docEl);
document.getElementById("toggleFulscreenButton").style.opacity = 0.2;
} else {
cancelFullScreen.call(doc);
document.getElementById("toggleFulscreenButton").style.opacity = 1;
}
}, false);
function skipClick() {
skipTheClick = true;
}
function clickBody() {
if (skipTheClick) {
skipTheClick = false;
return;
}
if (started) {
makeScreenLightGreen();
document.getElementById("number").innerHTML = time;
currentTime = time;
} else {
document.getElementById("formLabel").style.display = "none";
document.getElementById("formInput").style.display = "none";
document.getElementById("number").innerHTML = "";
started = true;
setTime();
}
}
function setTime() {
time = document.getElementsByName("time")[0].value;
currentTime = time;
}
function tick() {
console.log(currentTime);
if (currentTime < 0) {
return;
}
if (currentTime === 0) {
audioAlert.play();
end();
} else {
makeScreenGreen();
if (started) {
document.getElementById("number").innerHTML = currentTime;
if (currentTime < 6 && currentTime >= 0) {
audioBeep.play();
}
}
}
currentTime--;
}
function end() {
makeScreenRed();
document.getElementById("number").innerHTML = "💥";
}
function makeScreenGreen() {
document.getElementById("clickTarget").style.backgroundColor = "green";
}
function makeScreenRed() {
document.getElementById("clickTarget").style.backgroundColor = "red";
}
function makeScreenLightGreen() {
document.getElementById("clickTarget").style.backgroundColor = "greenyellow";
}