-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
76 lines (66 loc) · 2.23 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
var fullscreen = false;
var timer;
var running = false;
var hours = 0;
var minutes = 0;
var seconds = 0;
document.onkeydown = (e) => {
if (e.key === "s" || e.keyCode == 32) { ToggleTimer(); }
else if (e.key === "r") { ClearTimer(); }
else if (e.key === "f") { ToggleFullscreen(); }
}
function DrawTime() {
document.getElementById("hour").innerText = `${hours}h`;
document.getElementById("minute").innerText = `${minutes}m`;
document.getElementById("second").innerText = `${seconds}s`;
}
function ToggleFullscreen() {
var elem = document.documentElement;
if (!fullscreen) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
document.getElementById("fullscreen-icon").innerText = "fullscreen_exit";
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
document.getElementById("fullscreen-icon").innerText = "fullscreen";
}
fullscreen = !fullscreen;
}
function ToggleTimer() {
if (!running) { StartTimer(); }
else { StopTimer(); }
running = !running;
}
function StartTimer() {
timer = setInterval(function () {
seconds++;
if (seconds == 60) { seconds = 0; minutes++; }
if (minutes == 60) { minutes = 0; hours++; }
DrawTime();
}, 1000);
document.getElementById("start-btn").innerText = "stop";
}
function StopTimer() {
clearInterval(timer);
document.getElementById("start-btn").innerText = "start";
}
function ClearTimer() {
StopTimer();
hours = 0, minutes = 0, seconds = 0;
DrawTime();
}