-
Notifications
You must be signed in to change notification settings - Fork 0
/
script1.js
366 lines (333 loc) · 10.7 KB
/
script1.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
var listItemArray = [];
var listItemArrayStrike = []
var arrayIndex = 0;
var newItem = 0;
var htmlString = "";
var taskDeleteType = false;
var toggleCountDown = false;
var endBell = true;
var warningBell = true;
var warningBellPlayed = true;
var drawTimerUpdate;
var showSettings = false;
var drawTimer;
var timePickerResult;
var countDownHour = "00";
var countDownMinutes = "00";
var legalInfo = false;
var timerStarted = false;
var timerEnded = false;
var timerPaused = false;
var buttonModified = false;
var toggleFont = false;
var timerView = false;
var listView = false;
var endDate;
var startDate;
var fullScreen = document.getElementById("fullscreenBody");
var n1 = true;
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth(),
day = date.getUTCDate(),
months = [ "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var loader = document.getElementById('loader'),
border = document.getElementById('border'),
α = 0,
π = Math.PI,
t = 0;
var settingsTimeUpdate = setInterval(updateRemainingTime, 100);
document.getElementById("daymonth").innerHTML = months[month] + " " + day;
document.getElementById("year").innerHTML = year;
function pauseTimer() {
if (timerPaused) {
document.getElementById("pauseButton").value = "Pause Timer"
} else {
document.getElementById("pauseButton").value = "Restart Timer"
}
timerPaused = !timerPaused
}
function openFullscreen() {
if (fullScreen.requestFullscreen) {
fullScreen.requestFullscreen();
} else if (fullScreen.mozRequestFullScreen) { /* Firefox */
fullScreen.mozRequestFullScreen();
} else if (fullScreen.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
fullScreen.webkitRequestFullscreen();
} else if (fullScreen.msRequestFullscreen) { /* IE/Edge */
fullScreen.msRequestFullscreen();
}
}
function toggleSansFont () {
if (toggleFont) {
document.getElementById('fullscreenBody').style.fontFamily = "Courier"
} else {
document.getElementById('fullscreenBody').style.fontFamily = "Verdana"
}
toggleFont = !toggleFont
}
function hidelegalinfo() {
if(legalInfo) {
document.getElementById("legalinfo").style.display = "none";
document.getElementById("settingsHide").style.display = "block";
document.getElementById("hidelegalbutton").value = "Show legal information";
} else {
document.getElementById("legalinfo").style.display = "block";
document.getElementById("settingsHide").style.display = "none";
document.getElementById("hidelegalbutton").value = "Show Settings";
}
legalInfo = !legalInfo;
};
if ((screen.width < 800) || (screen.height < 600)) {
alert ("This application is designed for use on a Laptop and is not optimised for mobile devices");
};
function startTimer() {
if (timerStarted || startDate.toLocaleTimeString() >= endDate.toLocaleTimeString()) {
if (startDate.toLocaleTimeString() >= endDate.toLocaleTimeString() || document.getElementById("timePicker").value == "00:00" ) {
document.getElementById("messageText").innerHTML = "Please pick a time in the future";
}
clearTimer ()
return;
}
warningBellPlayed = true;
timerPaused = true;
pauseTimer();
n1 = true;
timerEnded = false;
document.getElementById("messageText").innerHTML = "";
openFullscreen();
changeSettings();
document.getElementById("startButton").value = "Stop Timer";
timerStarted = true;
timePickerTime ();
startDate = new Date()
endDate = new Date()
endDate.setHours( countDownHour );
endDate.setMinutes( countDownMinutes );
endDate.setSeconds (0);
warningBellPlayed = false;
draw()
}
function timePickerTime () {
timePickerResult = document.getElementById("timePicker").value
countDownMinutes = Number(timePickerResult.substring(3));
countDownHour = Number(timePickerResult.substring(0,2));
startDate = new Date()
endDate = new Date()
if (toggleCountDown) {
endDate.setHours( countDownHour );
endDate.setMinutes( countDownMinutes );
endDate.setSeconds (0);
} else {
endDate.setHours( startDate.getHours() + countDownHour );
endDate.setMinutes( startDate.getMinutes() + countDownMinutes );
}
}
function draw() {
if (toggleCountDown) {
t = endDate.getTime() - startDate.getTime()
t /= 360
} else {
t = countDownHour * 60 * 180
t += countDownMinutes * 180
}
if (!timerPaused) {
α++;
}
α %= 361;
var r = ( α * π / 180 )
, x = Math.sin( r ) * 200
, y = Math.cos( r ) * - 200
, mid = ( α > 180 ) ? 1 : 0
, anim = 'M 0 0 v -200 A 200 200 1 '
+ mid + ' 1 '
+ x + ' '
+ y + ' z';
loader.setAttribute( 'd', anim );
border.setAttribute( 'd', anim );
if ( α == 360) {
if (endBell) {
playEndBell()
}
document.getElementById("timeremaining").style.opacity = 0;
setTimeout(function(){
document.getElementById("timeremaining").innerHTML = "Finished";
document.getElementById("timeremaining").style.opacity = 1;
},500);
clearTimeout(drawTimer);
clearInterval(drawTimerUpdate);
α = 359.99;
var r = ( α * π / 180 )
, x = Math.sin( r ) * 200
, y = Math.cos( r ) * - 200
, mid = ( α > 180 ) ? 1 : 0
, anim = 'M 0 0 v -200 A 200 200 1 '
+ mid + ' 1 '
+ x + ' '
+ y + ' z';
loader.setAttribute( 'd', anim );
border.setAttribute( 'd', anim );
α = 0
clearTimer ()
} else {
drawTimer = setTimeout(draw, t); // Redraw
updateRemainingTime ();
}
};
function clearTimer () {
timerEnded = true;
timerStarted = false;
if (toggleCountDown) {
date = new Date()
document.getElementById("timePicker").value = (date.getHours()).toLocaleString(undefined, {minimumIntegerDigits: 2}) + ":" + (date.getMinutes()).toLocaleString(undefined, {minimumIntegerDigits: 2})
} else {
document.getElementById("timePicker").value = '00:00'
}
clearTimeout(drawTimer);
clearInterval(drawTimerUpdate);
document.getElementById("startButton").value = "Start Timer"
}
function playEndBell() {
new Audio('endbell.mp3').play();
}
function updateRemainingTime () {
timePickerTime ()
if (!timerStarted) {
document.getElementById("htmlHour").innerHTML = endDate.toLocaleTimeString();
}
var timeR
timeR = t / 180
timeR *= 60
timeR = 360 / timeR
timeR = (360-α) / timeR
timeR /= 60
var s;
if(Math.ceil(timeR) > 1 || t == 0 ) {s = "s"}else{s = ""}
if (timerStarted) {
var createString = "Time Remaining: " + Math.ceil(timeR) + " Minute" + s;
if (createString != document.getElementById("timeremaining").innerHTML) {
document.getElementById("timeremaining").style.opacity = 0;
}
setTimeout(function(){
if (createString != document.getElementById("timeremaining").innerHTML) {
document.getElementById("timeremaining").innerHTML = createString
document.getElementById("timeremaining").style.opacity = 1;
}
},500);
}
if (timeR == document.getElementById("warningTime").value && warningBell && !warningBellPlayed) {
warningBellPlayed = true;
playWarningBell()
}
}
function clearDraw() {
clearTimeout(drawTimer);
clearInterval(drawTimerUpdate);
α = 0;
var r = ( α * π / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( α > 180 ) ? 1 : 0
, anim = 'M 0 0 v -125 A 125 125 1 '
+ mid + ' 1 '
+ x + ' '
+ y + ' z';
loader.setAttribute( 'd', anim );
border.setAttribute( 'd', anim );
}
function updateTimer () {
t = document.getElementById("finishTimeInput").value
}
function changeSettings() {
if (showSettings) {
document.getElementById("settings").style.display = "none";
} else {
document.getElementById("settings").style.display = "block";
}
showSettings = !showSettings;
};
function toggleTimer() {
if (toggleCountDown) {
document.getElementById('endSpecificTime').checked = false;
document.getElementById('specificTime').checked = true;
document.getElementById("timePicker").value = '00:00'
document.getElementById("pauseButton").style.display = "inline";
} else {
document.getElementById("pauseButton").style.display = "none";
document.getElementById('specificTime').checked = false;
document.getElementById('endSpecificTime').checked = true;
date = new Date()
document.getElementById("timePicker").value = (date.getHours()).toLocaleString(undefined, {minimumIntegerDigits: 2}) + ":" + (date.getMinutes()).toLocaleString(undefined, {minimumIntegerDigits: 2})
}
toggleCountDown = !toggleCountDown;
}
function addNewListItem () {
listItemArray.push (document.getElementById("newListItemInput").value);
listItemArrayStrike.push ("");
generateHtml ();
buttonModified = false;
}
function toggleEndBell() {
endBell = !endBell
}
function toggleTimerView() {
if (!timerView) {
document.getElementById("right").style.width = "0vw"
document.getElementById("left").style.width = "100vw"
} else {
document.getElementById("right").style.width = "53vw"
document.getElementById("left").style.width = "43vw"
}
timerView = !timerView
}
function toggleListView() {
if (!listView) {
document.getElementById("right").style.height = "auto"
document.getElementById("right").style.width = "100vw"
document.getElementById("left").style.width = "100vw"
document.getElementById("left").style.height = "auto"
document.getElementById("listDiv").style.display = "none"
} else {
document.getElementById("right").style.width = "53vw"
document.getElementById("left").style.width = "43vw"
document.getElementById("left").style.height = "100vw"
document.getElementById("right").style.height = "100vw"
document.getElementById("listDiv").style.display = "block"
}
listView = !listView
}
function toggleWarningBell() {
warningBell = !warningBell
}
function playWarningBell() {
new Audio('warningbell.mp3').play();
}
function generateHtml () {
arrayIndex = 0;
htmlString = "";
while (arrayIndex < listItemArray.length) {
newItem = "<li " + "class='" + listItemArrayStrike[arrayIndex] + "' onclick='removeListItem(" + arrayIndex + ")';>" + listItemArray[arrayIndex] + "</li>";
htmlString = htmlString + newItem;
arrayIndex = arrayIndex + 1;
}
document.getElementById("toDoList").innerHTML = htmlString;
}
function removeListItem (i) {
if(taskDeleteType){
listItemArrayStrike[i] = "strike";
generateHtml ();
} else {
listItemArray.splice(i,1);
listItemArrayStrike.splice(i,1);
generateHtml ();
}
}
function modifyButton () {
if (!buttonModified) {
document.getElementById("newListItemInput").value = "";
buttonModified = true;
}
}
function deleteOrStrike(){
taskDeleteType = !taskDeleteType
}