-
Notifications
You must be signed in to change notification settings - Fork 0
/
mwe.js
112 lines (107 loc) · 4.51 KB
/
mwe.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
var totSeconds = 0;
var timerInterval;
var timeLeftInMilliseconds;
var endTime;
function changeTimerToTotSeconds() {
var backup = totSeconds;
var seconds = totSeconds % 60;
totSeconds -= totSeconds % 60;
totSeconds /= 60;
var minutes = totSeconds % 60;
totSeconds -= totSeconds % 60;
totSeconds /= 60;
var hours = totSeconds;
var hoursString = hours.toString();
var minutesString = minutes.toString();
var secondsString = seconds.toString();
if(hoursString.length === 1) hoursString = "0" + hoursString;
if(minutesString.length === 1) minutesString = "0" + minutesString;
if(secondsString.length === 1) secondsString = "0" + secondsString;
var timeToDisplay = hoursString + ":" + minutesString + ":" + secondsString;
document.getElementById("timeLeft").innerText = timeToDisplay;
document.title = timeToDisplay + " -- MWE: Make work easier by Be kind for 2020 (bkf2020)";
totSeconds = backup;
}
function updateTotSeconds() {
timeLeftInMilliseconds = endTime - Date.now();
totSeconds = Math.ceil(timeLeftInMilliseconds / 1000);
if(totSeconds >= 0) {
changeTimerToTotSeconds();
} else {
clearInterval(timerInterval);
document.getElementById("timesUp").load();
document.getElementById("timesUp").play();
document.getElementById("startpause").onclick = stopWorking;
document.getElementById("startpause").innerText = "Continue";
}
}
function stopWorking() {
document.getElementById("timesUp").pause();
var message = "Enter: 'I sincerely promise that I finished the task' if you finished.\n";
message += "Otherwise, type anything else.";
var response = window.prompt(message);
if(response === "I sincerely promise that I finished the task") {
clearInterval(timerInterval);
document.getElementById("startpause").style.display = "inline";
document.getElementById("startpause").onclick = startWorking;
document.getElementById("startpause").innerText = "Start working";
var hours = document.getElementById("hour").value;
var minutes = document.getElementById("minute").value;
var seconds = document.getElementById("second").value;
hours = Number(hours);
minutes = Number(minutes);
seconds = Number(seconds);
totSeconds = 3600 * hours + 60 * minutes + seconds;
changeTimerToTotSeconds();
document.title = "MWE: Make work easier by Be kind for 2020 (bkf2020)";
} else if(totSeconds < 0) {
message = "Choose one of the following punishments:\n";
message += "- Do burpees for one minute\n";
message += "- Do 30 pushups\n";
message += "- Run 1 mile\n";
message += "- Explain to someone why you didn't finish the task\n";
message += "- Take a cold shower\n";
message += "- Put hot sauce in your water bottle\n\n";
message += "Enter: 'I sincerely promise that I finished the punishment' to continue.\n";
response = window.prompt(message);
while(response !== "I sincerely promise that I finished the punishment") {
response = window.prompt(message);
}
document.getElementById("startpause").style.display = "inline";
document.getElementById("startpause").onclick = startWorking;
document.getElementById("startpause").innerText = "Start working";
var hours = document.getElementById("hour").value;
var minutes = document.getElementById("minute").value;
var seconds = document.getElementById("second").value;
hours = Number(hours);
minutes = Number(minutes);
seconds = Number(seconds);
totSeconds = 3600 * hours + 60 * minutes + seconds;
changeTimerToTotSeconds();
document.title = "MWE: Make work easier by Be kind for 2020 (bkf2020)";
}
endTime = Date.now() + timeLeftInMilliseconds;
}
function startWorking() {
var hours = document.getElementById("hour").value;
var minutes = document.getElementById("minute").value;
var seconds = document.getElementById("second").value;
if(0 <= hours && hours <= 99 && 0 <= minutes && minutes <= 99 && 0 <= seconds && seconds <= 99) {
document.getElementById("startpause").onclick = stopWorking;
document.getElementById("startpause").innerText = "Stop working";
document.getElementById("taskName").innerText = document.getElementById("tname").value;
hours = Number(hours);
minutes = Number(minutes);
seconds = Number(seconds);
totSeconds = 3600 * hours + 60 * minutes + seconds;
timeLeftInMilliseconds = totSeconds * 1000;
endTime = Date.now() + timeLeftInMilliseconds;
changeTimerToTotSeconds();
timerInterval = setInterval(updateTotSeconds, 100);
} else {
var message = "Invalid time! You can have at least 0 hours,";
message += " 0 mintues, and 0 seconds and at most 99 hours,";
message += " 99 minutes and 99 seconds!";
alert(message);
}
}