-
Notifications
You must be signed in to change notification settings - Fork 1
/
support.js
108 lines (97 loc) · 2.92 KB
/
support.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
//set minutes
var mins = 15;
//calculate the seconds
var secs = mins * 60;
var timer = "";
var audio = new Audio("./videoplayback.mp3");
//countdown function is evoked when page is loaded
function countdown() {
if (document.getElementById("min").value > 0) {
document.getElementById("writing").disabled = false;
timer = setTimeout("Decrement()", 60);
mins = document.getElementById("min").value;
secs = mins * 60;
document.getElementById("startimer").disabled = true;
document.getElementById("min").disabled = true;
} else {
alert("Timer cannot be 0");
}
}
function getFormattedTime(n) {
return n.toString().padStart(2, '0');
}
//Decrement function decrement the value.
function Decrement() {
if (document.getElementById) {
var time = document.getElementById("Time");
//if less than a minute remaining
//Display only seconds value.
if (secs < 59 && secs >= 0) {
time.innerHTML = "Timer - 0:" + getFormattedTime(secs);
}
//Display both minutes and seconds
//getminutes and getseconds is used to
//get minutes and seconds
else if (secs >= 0) {
time.innerHTML = "Timer - " + getFormattedTime(getminutes()) + ":" + getFormattedTime(getseconds());
}
//when less than a minute remaining
//colour of the minutes and seconds
//changes to red
if (mins < 1) {
time.style.color = "red";
}
//if seconds becomes zero,
//then page alert time up
if (mins < 0 || secs < 0) {
// alert('time up');
audio.play();
document.getElementById("writing").disabled = true;
document.getElementById("pause").style.display = "block";
document.getElementById("startimer").disabled = false;
document.getElementById("min").disabled = false;
time.innerHTML = "Time Up 💔";
time.style.color = "red";
}
//if seconds > 0 then seconds is decremented
else {
secs--;
setTimeout("Decrement()", 1000);
}
}
}
function getminutes() {
//minutes is seconds divided by 60, rounded down
mins = Math.floor(secs / 60);
return mins;
}
function getseconds() {
//take minutes remaining (as seconds) away
//from total seconds remaining
return secs - Math.round(mins * 60);
}
function pauseAudio() {
audio.pause();
}
function cleartextarea() {
document.getElementById("writing").innerHTML = "";
}
document
.getElementById("writing")
.addEventListener("keyup", function countWord() {
let res = [];
let str = this.value.replace(/[\t\n\r\.\?\!]/gm, " ").split(" ");
str.map((s) => {
let trimStr = s.trim();
if (trimStr.length > 0) {
res.push(trimStr);
}
});
document.querySelector("#word_count").innerText =
"Total Word Count - " + res.length;
});
function resettextbox() {
document.querySelector("#word_count").innerText = "Total Word Count - 0";
document.getElementById("writing").value = "";
document.getElementById("writing").disabled = false;
}