-
Notifications
You must be signed in to change notification settings - Fork 0
/
pomodoro.js
111 lines (102 loc) · 3.33 KB
/
pomodoro.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
$(document).ready(function() {
//rounding and concatenation
function rounding(n) {
if(n >= 10) {
return n;
} else {
var dec = Math.floor(n / 10);
var un = n % 10;
return dec + "" + un;
}
}
//Set value clock for Work
$("#plus-work").click(function() {
if(running == false) {
$("#status").text("Work!");
$("#work-time").text(+$("#work-time").text() + 1);
var min = $("#work-time").html();
$("#min").text(rounding(min));
}
});
$("#minus-work").click(function() {
if(+$("#work-time").text() > 1 && running == false) {
$("#work-time").text(+$("#work-time").text() - 1);
$("#status").text("Work!");
var min = $("#work-time").html();
$("#min").text(rounding(min));
}
});
//Set value clock for Break
$("#plus-rest").click(function() {
if(running == false)
$("#rest-time").text(+$("#rest-time").text() + 1);
});
$("#minus-rest").click(function() {
if(+$("#rest-time").text() > 1 && running == false)
$("#rest-time").text(+$("#rest-time").text() - 1);
});
//audio
var audio = new Audio('http://www.soundjay.com/misc/sounds/bell-ringing-04.mp3');
function beep() {
audio.play();
}
//Start pomodoro function
function run() {
var min = $("#min").html();
var sec = $("#sec").html();
if(sec == 0) {
if(min > 0) {
min--;
sec = 59;
} else {
var status = $("#status").html();
$(".progress-bar").css("width", "0%");
if(status == "Work!") {
beep();
$("#status").text("Break!");
var breakMin = +$("#rest-time").html();
$("#min").text(breakMin);
$("#bar").removeClass("progress-bar-success");
$("#bar").addClass("progress-bar-danger");
return 0;
} else {
beep();
$("#status").text("Work!");
var workMin = +$("#work-time").html();
$("#min").text(workMin);
$("#bar").removeClass("progress-bar-danger");
$("#bar").addClass("progress-bar-success");
return 0;
}
}
} else {
sec--;
}
$("#min").text(rounding(min));
$("#sec").text(rounding(sec));
$(".progress-bar").css("width", moveBar(min, sec) + "%");
}
//for progress bar
function moveBar(m, n) {
var statusWork = $("#status").html();
var timeStatus;
if(statusWork == "Work!")
timeStatus = +$("#work-time").html();
else
timeStatus = +$("#rest-time").html();
var secondTime = timeStatus * 60;
return Math.ceil((100 * (secondTime - (m * 60 + n)))/secondTime);
}
var running = false;
var interval;
$('#start').click(function() {
if(running == false) {
interval = setInterval(run, 1000);
running = true;
}
});
$('#pause').click(function() {
clearInterval(interval);
running = false;
});
});