-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
681 lines (657 loc) · 22.7 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
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
<!doctype html>
<html>
<head>
<title>
Alarm
</title>
<script src="https://epicenterprograms.github.io/standards/behavior/general.js"></script>
<!--
<script src="file:///C:/Users/Robert/Documents/GitHub/standards/behavior/general.js"></script>
-->
<script>
var S = Standards.general;
var countDown;
var time; // the number of seconds left before the alarm goes off
var colorChange;
var colorNumber = 0;
var sounds;
var nagger;
var strategy = "annoy";
var methodNumber = 1;
var timerTone,
interval1,
interval2,
interval3,
interval4,
interval5,
progress3,
progress4,
progress5;
var wastedTime = 0; ////
var startOfWastedTime;
var lifeCoach = new S.Speaker();
var idleTime = 0; // how long the website has been idle (in seconds)
var focused = true; // whether the tab that has the website is currently focused //// unused
var visits = 1; // how many times the website was visited since being loaded
var advancedSettingsSection = document.createElement("div"); // holds the advanced settings section (//// in the future)
function changeBackground(speed) {
var increment,
repeat;
if (speed.toLowerCase() == "slow") {
increment = .1;
repeat = 500;
} else if (speed.toLowerCase() == "fast") {
increment = .8;
repeat = 8;
}
clearInterval(colorChange);
if (speed.toLowerCase() == "none") {
document.body.style.backgroundImage = "";
} else {
colorChange = setInterval(function () {
if (colorNumber > 100) {
colorNumber = 0;
}
var newColor = S.colorCode(null, colorNumber, [0, 0, 255], [255, 0, 255], [255, 0, 0], [255, 255, 0], [0, 255, 0], [0, 255, 255], [0, 0, 255]);
document.body.style.backgroundImage = "repeating-linear-gradient({0}, white 100vh, {0} 200vh)".format(newColor);
// The gradient is basically an image.
colorNumber += increment;
}, repeat);
}
}
function impede(callback, tryNumber) {
if (time < 0) {
var remark = "",
number1 = Math.round(Math.random()*10),
number2 = Math.round(Math.random()*10),
number3 = Math.round(Math.random()*10),
number4 = Math.round(Math.random()*10);
tryNumber = tryNumber===undefined ? 0 : tryNumber;
if (tryNumber > 0) {
remark = "WRONG!<br>Start over!<br>";
}
S.makeDialog("{0}What is {1}×{2}+{3}×{4}?<br>(What? You wanted to stop the noise?)<br><input type='text' class='answer' placeholder='Answer'>".format(remark, number1, number2, number3, number4), ["Submit", function () {
if (Number(S.getEnd(S.getClass("answer")).value) == number1 * number2 + number3 * number4) {
if (S.getId("changeBackground").checked) {
changeBackground("slow");
} else {
changeBackground("none");
}
sounds.forEach(function (sound) {
sound.stop();
});
wastedTime += Number(S.getId("time").value);
strategy = "annoy";
callback();
} else {
tryNumber++;
impede(callback, tryNumber);
}
}]);
S.getEnd(S.getClass("answer")).addEventListener("keydown", function (event) {
if (event.key == "Enter") {
S.getClass("dialog")[0].getElementsByClassName("buttons")[0].children[0].click();
}
});
S.getEnd(S.getClass("answer")).focus();
} else {
if (S.getId("changeBackground").checked) {
changeBackground("slow");
} else {
changeBackground("none");
}
sounds.forEach(function(sound) {
sound.stop();
});
if (time > 3) {
wastedTime = 0;
startOfWastedTime = new Date().getTime();
}
callback();
}
}
S.listen("timer", "click", function() {
if (this.innerHTML.trim() == "Start eye-strain timer") {
this.innerHTML = "Stop eye-strain timer";
interval1 = setInterval(function() {
timerTone.play("ae5a5");
interval2 = setTimeout(function() {
timerTone.play("a5e5a");
}, 25000); // 25 seconds
}, 1224000); // 20.4 minutes
} else {
this.innerHTML = "Start eye-strain timer";
clearInterval(interval2);
clearInterval(interval1);
}
});
S.listen("distractionButton", "click", function () {
let initialTime;
let timeToDoStuff;
if (this.textContent.trim() == "I'm distracted") {
if (S.getId("distractionTime").value.trim() && S.getId("distractionTime").value.trim().search(/^\d+:\d+$/) > -1) {
this.textContent = "I'm back on track";
initialTime = new Date();
let time = S.getId("distractionTime").value.trim();
time = { hours: Number(time.split(":")[0]), minutes: Number(time.split(":")[1]), nextDay: false };
if (initialTime.getHours() > 12) {
if (initialTime.getHours() - 12 <= time.hours) {
if (time.hours == 12) { // if the time is during the midnight hour
time.hours = 0;
} else {
time.hours += 12;
}
} else {
nextDay = true;
}
} else if (initialTime.getHours() > time.hours) {
time.hours += 12;
}
if (time.nextDay) { // if the time goes into the next day
timeToDoStuff = new Date(initialTime.getTime() + 86400000);
timeToDoStuff = new Date(timeToDoStuff.getFullYear(), timeToDoStuff.getMonth(), timeToDoStuff.getDate(), time.hours, time.minutes);
} else {
timeToDoStuff = new Date(initialTime.getFullYear(), initialTime.getMonth(), initialTime.getDate(), time.hours, time.minutes);
}
function nag(time) {
if (time < 5000) {
time = 5000;
}
nagger = setTimeout(function () {
lifeCoach.speak("Hey, you need to quit being distracted.");
nag(time / 2);
}, time);
}
nag((timeToDoStuff.getTime() - initialTime.getTime()) / 2);
} else {
S.makeDialog("You need to provide a time for when you need to be back on track.");
}
} else {
this.textContent = "I'm distracted";
S.getId("distractionTime").value = "";
clearTimeout(nagger);
}
});
S.listen("fiveMinutes", "change", function() {
if (this.checked) {
let time = 0;
interval3 = setInterval(function() {
timerTone.play("a5a5a5a5a5sa4");
}, 300000);
progress3 = setInterval(function () {
if (time >= 300000) {
time = 3000;
} else {
time += 3000;
}
S.getId("fiveMinutesProgress").value = time / 300000;
}, 3000);
} else {
clearInterval(interval3);
clearInterval(progress3);
S.getId("fiveMinutesProgress").value = 0;
}
});
S.listen("oneMinute", "change", function() {
if (this.checked) {
let time = 0;
interval4 = setInterval(function() {
timerTone.play("a4-");
}, 60000);
progress4 = setInterval(function () {
if (time >= 60000) {
time = 600;
} else {
time += 600;
}
S.getId("oneMinuteProgress").value = time / 60000;
}, 600);
} else {
clearInterval(interval4);
clearInterval(progress4);
S.getId("oneMinuteProgress").value = 0;
}
});
S.listen("customRecurrence", "change", function() {
if (this.checked) {
let time = 0;
let recurrence = S.getId("customNumber").value || 10;
interval5 = setInterval(function() {
timerTone.play("e5sa6");
}, recurrence * 60000);
progress5 = setInterval(function () {
if (time >= recurrence * 60000) {
time = recurrence * 600;
} else {
time += recurrence * 600;
}
S.getId("customProgress").value = time / (recurrence * 60000);
}, recurrence * 600);
} else {
clearInterval(interval5);
clearInterval(progress5);
S.getId("customProgress").value = 0;
}
});
S.listen("customNumber", "dblclick", function () {
this.value = "";
clearInterval(interval5);
clearInterval(progress5);
S.getId("customProgress").value = 0;
S.getId("customRecurrence").checked = false;
});
/*
S.listen("customRecurrence2", "click", function () {
if (this.checked) {
let time = 0;
let recurrence = S.getId("customNumber").value || 10;
interval5 = setInterval(function () {
timerTone.play("e5sa6");
}, recurrence * 60000);
progress5 = setInterval(function () {
if (time >= recurrence * 60000) {
time = recurrence * 600;
} else {
time += recurrence * 600;
}
S.getId("customProgress").value = time / (recurrence * 60000);
}, recurrence * 600);
} else {
clearInterval(interval5);
clearInterval(progress5);
S.getId("customProgress").value = 0;
}
});
S.listen("customNumber", "dblclick", function () {
this.value = "";
clearInterval(interval5);
clearInterval(progress5);
S.getId("customProgress").value = 0;
S.getId("customRecurrence2").checked = false;
});
*/
S.listen("soundVolume", "change", function () {
let volume = Number(this.value) / 100;
sounds.forEach(function (sound) {
sound.change("maxVolume", volume);
});
timerTone.change("maxVolume", volume);
sounds[0].play("e5---");
});
// sets up idleness tracking
window.addEventListener("focus", function () {
focused = true;
if (idleTime >= 1200) {
lifeCoach.shush(); // stops any potential lecturing from the life coach
}
idleTime = 0;
});
window.addEventListener("blur", function () {
focused = false;
if (idleTime >= 1200) {
lifeCoach.shush();
}
idleTime = 0;
});
document.addEventListener("mousemove", function () {
if (idleTime >= 1200) {
lifeCoach.shush();
}
idleTime = 0;
});
document.addEventListener("mouseup", function () {
if (idleTime >= 1200) {
lifeCoach.shush();
}
idleTime = 0;
});
document.addEventListener("scroll", function () {
if (idleTime >= 1200) {
lifeCoach.shush();
}
idleTime = 0;
});
S.listen("changeBackground", "change", function () {
if (this.checked) {
if (time < 0) {
changeBackground("fast");
} else {
changeBackground("slow");
}
} else {
changeBackground("none");
}
});
S.onLoad(function () {
S.makeToneGenerator(true, function () {
sounds = [
new S.Sound({ "waveform": "square" }),
new S.Sound({ "waveform": "sawtooth", "frequency": 400 }),
new S.Sound({ "waveform": "sawtooth", "frequency": 420 }),
new S.Sound({ "waveform": "square", "changeWave": "sawtooth", "modulation": .5, "hertzChange": 150 }),
new S.Sound({ "waveform": "square", "changeWave": "square", "modulation": 2, "hertzChange": 100 })
];
timerTone = new S.Sound();
}, function () {
S.makeDialog("Dude, don't you even understand the whole point of this webpage?", ["Yes", function () {
S.makeDialog("You're insane. If you decide to be sensible, you can refresh the page.");
}], ["No", function () {
S.makeDialog("Would you like to learn?", ["Yes", function () {
S.makeDialog("This is a webpage which uses various tones to do things such as keep you awake, reduce your eye-strain, and/or alert you to how much time has passed. Preventing the production of tones pretty much defeats the purpose of this page. If you'd like to change your mind, you can refresh the page to get another chance to go though this.");
}], ["No", function () {
S.makeDialog("Get out.", ["Okay", function () {
window.open("", "_self").close();
}]);
}]);
}]);
});
// activates the alarm countdown
S.getId("start").addEventListener("click", function() {
if (this.innerHTML.trim() == "Start") {
this.innerHTML = "Renew";
S.getId("time").style.display = "none";
S.getId("time").value = S.getId("time").value.trim() ? Number(S.getId("time").value.trim())*60 : 400;
time = Number(S.getId("time").value);
S.getTag("h2")[0].innerHTML = "Seconds left: " + time;
document.title = time;
startOfWastedTime = new Date().getTime();
countDown = setInterval(function() {
if (time > 0 ) { // if there's still time left
time--;
S.getTag("h2")[0].innerHTML = "Seconds left: " + time;
document.title = time;
// plays warning tones when time is running out
if (time == 10) {
sounds[0].play("a4 a4 a4", { "attack": 10, "noteLength": 100, "decay": 10 });
} else if (time == 20) {
sounds[0].play("a4 a4", { "attack": 10, "noteLength": 100, "decay": 10 });
} else if (time == 30) {
sounds[0].play("a4", { "attack": 10, "noteLength": 100, "decay": 10 });
}
} else { // make the alarm play
/// annoy, wait, annoy, wait, alternate, wait, random
if (strategy == "annoy") {
sounds[1].start();
sounds[2].start();
setTimeout(function () {
sounds[1].stop();
sounds[2].stop();
}, 500);
if (time == 0) {
changeBackground("fast");
}
if (time < -8 && !sounds[3].playing) {
sounds[3].start();
}
if (time < -16 && !sounds[4].playing) {
sounds[4].start();
}
if (time == -180) { // if the alarm has been going off for 3 minutes
sounds.forEach(function (sound) {
sound.stop();
});
strategy = "wait";
}
if (time == -450) { // if the alarm has been going off another 3 minutes
sounds.forEach(function (sound) {
sound.stop();
});
strategy = "wait";
}
} else if (strategy == "wait") {
if (time == -270) { // if the alarm has been paused for 1.5 minutes
strategy = "annoy";
}
if (time == -540) { // if the alarm has been paused for another 1.5 minutes
sounds[4].start();
strategy = "alternate";
}
if (time == -810) { // if it's been another 1.5 minutes
strategy = "random";
}
} else if (strategy == "alternate") {
if (time % 5 == 0) {
if (time % 2 == 0) {
sounds[3].stop();
sounds[4].start();
} else {
sounds[4].stop();
sounds[3].start();
}
}
if (time == -720) { // if it's been another 3 minutes
sounds[4].stop();
strategy = "wait";
}
} else if (strategy == "random") {
if (time % 15 == 0) {
sounds.forEach(function (sound) {
sound.stop();
});
let primeNumbers = [2, 3, 5, 7];
let index = Math.floor(Math.random() * primeNumbers.length);
methodNumber = primeNumbers[index];
primeNumbers.splice(index, 1);
index = Math.floor(Math.random() * primeNumbers.length);
methodNumber *= primeNumbers[index];
if (methodNumber % 2 == 0 && Math.round(Math.random())) { // makes sure there aren't too many pauses
methodNumber /= 2;
primeNumbers.splice(index, 1);
index = Math.floor(Math.random() * primeNumbers.length);
methodNumber *= primeNumbers[index];
}
}
if (methodNumber % 2 != 0) {
if (methodNumber % 3 == 0) {
sounds[1].start();
sounds[2].start();
setTimeout(function () {
sounds[1].stop();
sounds[2].stop();
}, 500);
}
if (methodNumber % 5 == 0) {
sounds[3].start();
}
if (methodNumber % 7 == 0) {
sounds[4].start();
}
}
}
time--;
}
}, 1000);
} else {
impede(function() {
time = Number(S.getId("time").value);
S.getTag("h2")[0].innerHTML = "Seconds left: " + time;
document.title = time;
if (false && wastedTime > Number(S.getId("time").value)) { ////
setTimeout(function () {
lifeCoach.speak("You've wasted {0} minutes. That's right, {0} minutes.".format(Math.round(wastedTime / 60)));
}, 1500);
}
if (new Date().getTime() - startOfWastedTime > Number(S.getId("time").value) * 1000) {
setTimeout(function () {
let now = new Date();
console.info("{0}:{1} - It's been {2} minutes since you've been consistently conscious.".format(now.getHours(), now.getMinutes()>9 ? now.getMinutes() : "0"+now.getMinutes(), Math.round((now.getTime()-startOfWastedTime)/60000)));
lifeCoach.speak("You've wasted {0} minutes. That's right, {0} minutes.".format(Math.round((now.getTime()-startOfWastedTime)/60000)));
}, 1500);
}
});
}
});
S.getId("stop").addEventListener("click", function() {
if (time < 0) {
impede(function () {
clearInterval(countDown);
document.title = "Alarm";
S.getTag("h2")[0].innerHTML = "Seconds left: ∞";
S.getId("time").value = "";
S.getId("time").style.display = "inline-block";
S.getId("start").innerHTML = "Start";
});
} else {
S.makeDialog("Are you sure you want to stop the alarm?",
["Yes", function () {
clearInterval(countDown);
if (S.getId("changeBackground").checked) {
changeBackground("slow");
} else {
changeBackground("none");
}
sounds.forEach(function (sound) {
sound.stop();
});
document.title = "Alarm";
S.getTag("h2")[0].innerHTML = "Seconds left: ∞";
S.getId("time").value = "";
S.getId("time").style.display = "inline-block";
S.getId("start").innerHTML = "Start";
}],
"No"
);
}
});
// tracks idle time
let latenessTracker;
S.listen("trackLateness", "change", function () {
if (this.checked) {
latenessTracker = setInterval(function () {
idleTime += 10;
let time = new Date().getHours();
if (time > 21 || time < 8) {
if (idleTime == 1200) { // if the website has been idle for 20 minutes
lifeCoach.speak("It's been a while since I've noticed your activity; are you still awake?");
} else if (idleTime == 1500) { // if the website has been idle for 25 minutes
lifeCoach.speak("I'm going to start the countdown soon if you don't check in with me.");
} else if (idleTime == 1800) { // if the website has been idle for 30 minutes
S.getId("start").click();
lifeCoach.speak("I started the countdown.");
}
} else {
idleTime = 0;
}
}, 10000);
} else {
clearInterval(latenessTracker);
}
});
S.getId("trackLateness").click();
// says when the battery is low
if (navigator && navigator.getBattery) {
navigator.getBattery().then(function (battery) {
battery.addEventListener("levelchange", function () {
if (this.level < .2 && !this.charging) {
lifeCoach.speak("The battery is running low.");
}
});
});
}
S.getId("timer").click();
if (S.getId("changeBackground").checked) {
changeBackground("slow");
}
});
</script>
<link rel="stylesheet" href="https://epicenterprograms.github.io/standards/formatting/foundation.css">
<!--
<link rel="stylesheet" href="file:///C:/Users/Robert/Documents/GitHub/standards/formatting/foundation.css">
-->
<style>
#distractionTime {
width: 3em;
}
#customNumber {
width: 2em;
}
progress { /* Use [value] for only progress bars that show a specific value at a given time. */
border: .05rem solid darkgray;
border-radius: .25rem;
background: lightgray;
}
progress {
color: #0c0;
}
progress::-moz-progress-bar {
border-radius: .25rem;
background: lightgray;
}
progress::-webkit-progress-value {
border-radius: .25rem;
background: #0c0;
}
progress::-webkit-progress-bar {
border-radius: .25rem;
background: lightgray;
}
#advancedSettings {
margin-top: 1.5em;
}
</style>
</head>
<body>
<h1 class="main-title">
Alarm
</h1>
<main>
<h2>
Seconds left: ∞
</h2>
<input type="text" id="time" placeholder="Time to recur (minutes)">
<br>
<br>
<button id="start">
Start
</button>
<button id="stop">
Stop
</button>
<br>
<br>
<button id="timer">
Start eye-strain timer
</button>
<br>
<br>
<button id="distractionButton">
I'm distracted
</button>
I need to do something at
<input type="text" id="distractionTime" placeholder="Time">
<h4>
Volume
</h4>
<input type="range" id="soundVolume" value="60">
<br>
<br>
<div class="list">
<input type="checkbox" id="fiveMinutes">
<label for="fiveMinutes">Make a tone every 5 minutes</label><br>
<progress id="fiveMinutesProgress" value="0"></progress>
<br>
<input type="checkbox" id="oneMinute">
<label for="oneMinute">Make a tone every 1 minute</label><br>
<progress id="oneMinuteProgress" value="0"></progress>
<br>
<input type="checkbox" id="customRecurrence">
<label for="customRecurrence">Make a tone every <input type="text" id="customNumber"> minutes</label><br>
<progress id="customProgress" value="0"></progress>
<!--
<br>
<input type="checkbox" id="customRecurrence2">
<label for="customRecurrence2">Make a different tone every <input type="text" id="customNumber"> minutes</label><br>
<progress id="customProgress" value="0"></progress>
-->
</div>
<button id="advancedSettings" disabled>
Advanced settings
</button>
<br>
<div id="advancedSettingsSection">
<input type="checkbox" id="trackLateness"> <label for="tarckLateness">Track lateness</label>
<input type="checkbox" id="changeBackground" checked> <label for="changeBackground">Change background color</label>
</div>
</main>
</body>
</html>