This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
152 lines (139 loc) · 5.1 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function decreaseTime(para, bool) {
let time = document.querySelector(para);
if (Number(time.innerText) === 1)
return;
time.innerText = Number(time.innerText) - 1;
if (bool)
setCountdown(false, true);
}
function increaseTime(para, bool) {
let time = document.querySelector(para);
time.innerText = Number(time.innerText) + 1;
if (bool)
setCountdown(true, true);
}
function setCountdown(flag, flagHour, countDown) {
let strTime = document.querySelector('#timeCountDown');
let intTime = toIntTime(strTime.innerText);
if (intTime === 0) {
clearInterval(countDown);
let text = document.querySelector('#showSessionOrBreak');
if (text.innerText === 'Session') {
setBreak();
play();
}
else {
let timeSession = document.querySelector('#sessionTimeText');
let timeBreak = document.querySelector('#breakTimeText');
setTime(timeSession.innerText, timeBreak.innerText);
play();
}
return;
}
else if (intTime <= 11) {
strTime.style.color = '#660000';
}
if (flagHour && flag) {
intTime += 60;
}
else if (flagHour && !flag) {
intTime -= 60;
}
else if (!flagHour && flag)
++intTime;
else
--intTime;
strTime.innerText = toStrTime(intTime);
}
function toIntTime(strTime) {
let intTime;
if (strTime.length > 5) {
intTime = Number(strTime.substring(0, 2)) * 60 * 60 +
Number(strTime.substring(3, 5)) * 60 +
Number(strTime.substring(6));
}
else if (strTime.length === 4)
intTime = Number(strTime.substring(0, 1)) * 60 +
Number(strTime.substring(2));
else
intTime = Number(strTime.substring(0, 2)) * 60 +
Number(strTime.substring(3));
return intTime;
}
function toStrTime(intTime) {
if (intTime >= 3600) {
let hour = Math.trunc(intTime/3600);
let minute = Math.trunc((intTime - hour * 3600)/60);
let second = (intTime - hour * 3600)%60;
return ((hour < 10) ? '0' + hour : hour) + ':' +
((minute < 10) ? '0' + minute : minute) +
':' + ((second < 10) ? '0' + second : second);
}
else {
let minute = Math.trunc(intTime/60);
let second = intTime%60;
return ((minute < 10) ? '0' + minute : minute)
+ ':' + ((second < 10) ? '0' + second : second);
}
}
function play() {
let time = document.querySelector('#timeCountDown');
time.style.color = '#208000';
disableButtons(true);
let countdown = setInterval(function() {
document.querySelector('#pauseBtn').disabled = false;
document.querySelector('#pauseBtn').onclick = function() {
clearInterval(countdown);
document.querySelector('#playBtn').disabled = false;
document.querySelector('#pauseBtn').disabled = true;
};
document.querySelector('#stopBtn').onclick = function() {
clearInterval(countdown);
let time = document.querySelector('#timeCountDown');
let selectedTime = document.querySelector('#sessionTimeText');
time.innerText = selectedTime.innerText + ':00';
let text = document.querySelector('#showSessionOrBreak');
if (text.innerText === 'Break')
setBreak();
else {
let timeSession = document.querySelector('#sessionTimeText');
let timeBreak = document.querySelector('#breakTimeText');
setTime(timeSession.innerText, timeBreak.innerText);
}
disableButtons(false);
}
document.querySelector('#replayBtn').onclick = function() {
clearInterval(countdown);
disableButtons(false);
setTime('25', '5');
}
setCountdown(false, false, countdown);
}, 1000);
}
function disableButtons(bool) {
document.querySelector('#downLeftBtn').disabled = bool;
document.querySelector('#downRightBtn').disabled = bool;
document.querySelector('#upLeftBtn').disabled = bool;
document.querySelector('#upRightBtn').disabled = bool;
document.querySelector('#playBtn').disabled = bool;
}
function setTime(sessionTime, breakTime) {
let time = document.querySelector('#timeCountDown');
let selectedSessionTime = document.querySelector('#sessionTimeText');
let selectedBreakTime = document.querySelector('#breakTimeText');
let text = document.querySelector('#showSessionOrBreak');
selectedSessionTime.innerText = sessionTime;
selectedBreakTime.innerText = breakTime;
time.innerText = selectedSessionTime.innerText + ':00';
time.style.color = '#999999';
text.innerText = 'Session';
}
function setBreak() {
let text = document.querySelector('#showSessionOrBreak')
let time = document.querySelector('#timeCountDown');
let selectedBreakTime = document.querySelector('#breakTimeText');
text.innerText = 'Break';
time.innerText = selectedBreakTime.innerText + ':00';
time.style.color = '#999999';
}
setTime('25', '5');