/
index.html
286 lines (259 loc) Β· 6.6 KB
/
index.html
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<html>
<head>
<meta charset="UTF-8">
<script>
var clocks = [];
var pomodoroTime = 25 * 60;
var breakTime = 5 * 60;
var workClock;
var breakCredit;
var breakClock;
var state = "stopped";
var lastTime;
var pomodoros;
var pomoCount;
var audio = new Audio("alarm.mp3");
function showTime(div, time) {
time = Math.floor(time);
var sign = "";
if (time < 0) {
sign = "-";
time = Math.abs(time);
}
var seconds = time % 60;
var minutes = (Math.floor(time / 60) % 60);
var hours = Math.floor(time / 3600);
var secondsStr = ( seconds < 10 ? "0" : "" ) + seconds;
var minutesStr = ( minutes < 10 ? "0" : "" ) + minutes;
if (hours > 0) {
minutesStr = hours + ":" + minutesStr;
}
div.firstChild.nodeValue = sign + minutesStr + ":" + secondsStr;
}
function update() {
var now = new Date().getTime();
var delta = (now - lastTime) / 1000;
lastTime = now;
if (state == "working") {
workClock.time += delta;
breakCredit.time += (delta / (pomodoroTime / breakTime));
var pomos = "";
var nPomos = Math.floor(workClock.time / (pomodoroTime));
for (var i = 0; i < nPomos; i++) {
pomos = pomos + "\u{1f345}";
}
pomoCount.firstChild.nodeValue = nPomos + " pomodoro" + (nPomos != 1 ? "s" : "") + (nPomos > 0 ? "!" : "");
pomodoros.firstChild.nodeValue = (nPomos > 0 ? pomos : "-");
} else if (state == "breaking" || state == "breaking_played") {
breakClock.time += delta;
breakCredit.time -= delta;
if (state == "breaking" && breakCredit.time <= 0) {
audio.currentTime = 0;
audio.play();
state = "breaking_played";
}
}
breakCredit.div.style.color = breakCredit.time < 0 ? "red" : "black";
for (var i = 0; i < clocks.length; i++) {
var clock = clocks[i];
showTime(clock.div, clock.time);
}
}
function startWorkClock() {
state = "working";
workClock.div.style.color = "#009900";
breakClock.div.style.color = "black";
breakClock.div.style.color = "black";
audio.pause();
}
function startBreakClock() {
state = "breaking";
workClock.div.style.color = "black";
breakClock.div.style.color = "#009900";
audio.pause();
}
function pauseClocks() {
state = "paused";
workClock.div.style.color = "red";
breakClock.div.style.color = "red";
audio.pause();
}
function getQueryParams(qs) {
qs = qs.split('+').join(' ');
var params = {};
var tokens;
var re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
function main() {
var params = getQueryParams(window.location.search);
var workClockTime = params.wrk !== undefined ? Math.floor(params.wrk) : 0;
var breakCreditTime = params.cre !== undefined ? Math.floor(params.cre) : 0;
var breakClockTime = params.brk !== undefined ? Math.floor(params.brk) : 0;
var now = new Date().getTime();
lastTime = now;
pomodoros = document.getElementById("pomodoros");
pomoCount = document.getElementById("pomoCount");
workClock = { "div": document.getElementById("workClock"), "time": workClockTime };
breakCredit = { "div": document.getElementById("breakCredit"), "time": breakCreditTime };
breakClock = { "div": document.getElementById("breakClock"), "time": breakClockTime };
clocks.push(workClock);
clocks.push(breakCredit);
clocks.push(breakClock);
setInterval("update()", 100);
}
</script>
<style>
@font-face {
font-family: 'Raleway';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway-Regular'), url("raleway.woff2") format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}
body {
background-color: #e0e0e0;
}
.header {
font-family: 'Raleway', sans-serif;
color: #404040;
width: 50%;
margin: 0 auto;
font-size: 1.2vw;
}
.header h1 {
color: #303030;
text-align: center;
}
.pomodoros {
width: 100%;
float: left;
text-align: center;
font-size: 2.5vw;
}
.pomoCount {
width: 100%;
float: left;
text-align: center;
font-size: 0.75vw;
}
.panel {
font-family: 'Deja Vu Sans Mono', 'Bistream Vera Sans', sans-serif;
margin-top: 50px;
width: 33%;
float: left;
text-align: center;
}
.panel h2 {
font-family: 'Raleway', sans-serif;
font-size: 2vw;
color: #303030;
text-align: center;
}
.clock {
font-size: 3vw;
}
button {
background: #4163a8;
color: white;
font-size: 1.5vw;
padding-left: 1.5vw;
padding-right: 1.5vw;
padding-top: 1.5vw;
padding-bottom: 1.5vw;
border: 0px;
}
button:hover {
background: #5173b8;
}
.buttons {
float: left;
width: 100%;
margin-top: 50px;
text-align: center;
}
.footer {
font-family: 'Raleway', sans-serif;
font-size: 1vw;
float: left;
width: 100%;
margin-top: 50px;
text-align: center;
}
a {
text-decoration: none;
color: #3030ff;
}
a:visited {
text-decoration: none;
color: #3030ff;
}
@media (max-width: 999px) {
.header {
width: 80%;
font-size: 4vw;
}
p {
font-size: 4vw;
}
.panel h2 {
font-size: 4vw;
}
.clock {
font-size: 6vw;
}
.pomoCount {
font-size: 1vw;
}
.pomodoros {
font-size: 4vw;
}
button {
font-size: 4vw;
padding-left: 3vw;
padding-right: 3vw;
padding-top: 5vw;
padding-bottom: 5vw;
}
}
</style>
</head>
<body onload="main();">
<div class="header">
<h1>Adaptive Pomodoro Clock</h1>
<p>This is an experiment of an alternative "pomodoro" time tracking scheme,
designed to avoid breaking your flow. It won't interrupt you with a break time
when you complete one pomodoro (25 minutes), instead it will accumulate time
for a longer break later.</p>
</div>
<div class="pomodoros" id="pomodoros"> </div>
<div class="pomoCount" id="pomoCount"> </div>
<div class="panel">
<h2>Work clock</h2>
<div class="clock" id="workClock"> </div>
</div>
<div class="panel">
<h2>Break credit</h2>
<div class="clock" id="breakCredit"> </div>
</div>
<div class="panel">
<h2>Break clock</h2>
<div class="clock" id="breakClock"> </div>
</div>
<div class="panel">
<button onclick="startWorkClock();">Work!</button>
</div>
<div class="panel">
<button onclick="pauseClocks();">Pause</button>
</div>
<div class="panel">
<button onclick="startBreakClock();">Break!</button>
</div>
<div class="footer">
<p>by <a href="http://hisham.hm/">hisham.hm</a> (<a href="http://twitter.com/hisham_hm/">@hisham_hm</a> on Twitter) - <a href="http://github.com/hishamhm/adaptive-pomodoro">source</a></p>
</div>
</body>
</html>