-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (70 loc) · 1.7 KB
/
script.js
File metadata and controls
79 lines (70 loc) · 1.7 KB
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
var cycleCount = 0;
var timer;
var toWork = new Audio("back_to_work_Barbossa.mp3");
var takeBreak = new Audio("break_time.mp3");
window.onload = function() {
$("start").click();
};
function getEndTime(minutes) {
var starts = new Date().getTime();
var time = starts + (1000 * 60 * minutes);
var ends = new Date(time);
return ends;
}
function getTimeRemaining(endTime) {
var timeArray = [];
var now = new Date();
var timeLeft = new Date(endTime - now);
var minutes = addZeroBefore(timeLeft.getMinutes(), 2);
var seconds = addZeroBefore(timeLeft.getSeconds(), 2);
if (minutes == "00" && seconds == "00") {
return null;
}
timeArray.push(minutes);
timeArray.push(seconds);
return timeArray;
}
function pomodoro() {
var pomodoroEnd = getEndTime(25);
$("#start").css("visibility", "hidden")
$("#task").css("visibility", "visible")
$("#timeLeft").css("visibility", "visible")
$("#task").html("Get to work!");
timer = window.setInterval(function() {
var time = getTimeRemaining(pomodoroEnd);
if (time != null) {
$("#minutes").html(time[0]);
$("#seconds").html(time[1]);
} else {
clearInterval(timer);
takeBreak.play();
pomodoro_break();
}
}, 500);
cycleCount += 1;
}
function pomodoro_break() {
if (cycleCount % 4 != 0) {
var breakEnd = getEndTime(5);
} else {
var breakEnd = getEndTime(15);
}
$("#task").html("Take a break!");
timer = window.setInterval(function() {
var time = getTimeRemaining(breakEnd);
if (time != null) {
$("#minutes").html(time[0]);
$("#seconds").html(time[1]);
} else {
clearInterval(timer);
toWork.play();
pomodoro();
}
}, 500);
}
function addZeroBefore(number) {
if(number < 10) {
number = "0" + number;
}
return number;
}