-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (67 loc) · 2.08 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
var seconds = 0;
var interval;
pomodoro = (mins) => {
let now = new Date();
localStorage.setItem(
Date.now(),
JSON.stringify({
interval: mins,
date: now.toLocaleDateString(),
minutes: now.toLocaleTimeString(),
})
);
data();
// var x = document.getElementById("myAudio");
clearInterval(interval);
seconds = mins * 60 || 0;
interval = setInterval(function () {
seconds--;
var sec = seconds % 60;
var minutes = Math.floor(seconds / 60);
var elem = document.getElementById("myBar");
var width = Math.abs(seconds / (mins * 60) - 1) * 100;
elem.style.width = width + "%";
elem.innerHTML = Math.round(width * 100) / 100 + "%";
document.getElementById("timer").innerHTML =
minutes.toString().padStart(2, "0") +
":" +
sec.toString().padStart(2, "0");
document.title =
minutes.toString().padStart(2, "0") +
":" +
sec.toString().padStart(2, "0");
if (!seconds) {
clearInterval(interval);
// x.play();
var notification = new Notification("🚨 Time to break 😎");
}
}, 1000);
};
stop = () => {
seconds = 1;
};
data = () => {
Notification.requestPermission();
document.getElementById("data").innerHTML =
'<thead><tr><th>Interval</th><th scope="col">Date</th> <th>Time</th></tr></thead>';
for (let i = 0; i < localStorage.length; i++) {
tr = document.createElement("tr");
document.getElementById("data").appendChild(tr);
let td = document.createElement("td");
let td2 = document.createElement("td");
let td3 = document.createElement("td");
tr.appendChild(td);
tr.appendChild(td2);
tr.appendChild(td3);
var int = JSON.parse(localStorage.getItem(localStorage.key(i))).interval;
var dat = JSON.parse(localStorage.getItem(localStorage.key(i))).date;
var min = JSON.parse(localStorage.getItem(localStorage.key(i))).minutes;
td.innerHTML += int;
td2.innerHTML += dat;
td3.innerHTML += min;
}
};
cleardata = () => {
localStorage.clear();
data();
};