-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
111 lines (85 loc) · 2.42 KB
/
app.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
//source idea for setinterval: http://jsfiddle.net/Ankit47/6wm3eky9/
let breathIn = 4;
let breathHold = 7;
let breathOut = 8;
const bri = document.getElementById('breath-in');
const brh = document.getElementById('breath-hold');
const bro = document.getElementById('breath-out');
let inB = () => {
timerBi = setInterval(bI, 1000);
};
window.onload = () => { window.setTimeout(inB(), 6000) };
//timer to set interval for countdown in miliseconds and call the function
let
timerBi,
timerBh,
timerBo;
const breathStage = ['Slowly Breath in', 'Hold the breath', 'Slowly Breath Out'];
let bFn = stage => stage.toUpperCase().toString();
//breath in
let bI = () => {
if (breathIn == -1) {
clearTimeout(timerBi);
doBreathIn();
} else {
let counter = `${breathIn}`;
bri.innerText = `${counter} \n \n ${bFn(breathStage[0])}`;
breathIn--;
}
};
let doBreathIn = () => {
bri.innerText = 'Breath hold';
bro.innerText = '___◁◁◁◁___';
brh.innerText = '_________';
console.log(bri.innerHTML);
timerBh = setInterval(bH, 1000);
};
//breath hold
let bH = () => {
if (breathHold == -1) {
clearTimeout(timerBh);
doBreathHold();
} else {
brh.innerText = `${breathHold} \n \n ${bFn(breathStage[1])}`;
breathHold--;
}
};
let doBreathHold = () => {
brh.innerText = 'Breath out';
bro.innerText = '__▷▷▷▷▷▷▷';
bri.innerText = '_________';
console.log(brh.innerHTML);
timerBo = setInterval(bO, 1000);
};
//breath out
let bO = () => {
if (breathOut == 0) {
clearTimeout(timerBo);
doBreathOut();
} else {
bro.innerText = `${breathOut} \n \n ${bFn(breathStage[2])}`;
breathOut--;
}
};
let doBreathOut = () => {
bro.innerText = 'Relax Breath';
bri.innerText = 'Observe ';
brh.innerText = '_________';
console.log(bro.innerHTML);
window.setTimeout(thodaRuko, 2 * 6000)
};
let thodaRuko = () => {
document.location.reload()
};
//clock
let displayTime = () => {
let date = new Date();
let time = date.toLocaleTimeString();
document.querySelector('.clock').textContent = time;
};
displayTime();
const createClock = setInterval(displayTime, 1000);
const bottomVisible = () =>
document.documentElement.clientHeight + window.scrollY >=
(document.documentElement.scrollHeight || document.documentElement.clientHeight);
bottomVisible();