-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
252 lines (238 loc) · 10.4 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
<!DOCTYPE>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quizlez(nupar)</title>
<script src="https://code.responsivevoice.org/responsivevoice.js?key=auvTMQpf"></script>
<link href="https://fonts.cdnfonts.com/css/product-sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"rel="stylesheet">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id="progress"></div>
<div id="menu">
<div style="display:flex;position:relative;margin-bottom:3rem">
<p style="color:white;margin:0rem;">Quizlez</p>
<p style="color:gray;margin:0rem;">nupar</p>
</div>
<div>
<input id="input" placeholder=">Enter list of vocab" size="30">
</div>
<div>
<input type="text" id="separation" placeholder=">Separation Character" size="30">
</div>
<div>
<button id="submit" class="button">[Submit]</button>
</div>
</div>
<div id="testing" style="display: none;">
<p class="number"></p>
<div>
<input id="ans" type="text" placeholder=">Type your response here" size="23">
</div>
<div style="display:flex;justify-content: space-between;margin-top:3rem">
<button onclick="playSound()">[Play]</button>
<button onclick="checkAns()">[Submit]</button>
</div>
</div>
<div id="result" style="display: none;">
<p class="number"></p>
<div id="result2">
<p id="resultText"></p>
</div>
<div style="display:flex;justify-content:center;margin-top: 3rem;">
<button onclick="nextWord()" id="ok">[OK]</button>
</div>
</div>
<div id="end" style="display: none;width: 100%;">
<div style="position:absolute; bottom:0px; left:0px;width: 100%;">
<p id="finalResultText" style="position: absolute;left:1vw;bottom:0vh;margin:0vw;"></p>
<span id="scrollDown" class="material-icons" style="display: flex;justify-content: center;margin-bottom:10px">keyboard_double_arrow_down</span>
<div style="position:absolute;width: 100%;display: flex;justify-content: space-evenly;">
<button onclick='showList("all")' id="all"> ALL </button>
<button onclick='showList("correct")' id="correct">CORRECT</button>
<button onclick='showList("incorrect")' id="incorrect">INCORRECT</button>
</div>
<div id="listContainer" style="position:absolute;width: 100%;top:5vw;display: flex;justify-content: center;"></div>
</div>
</div>
<div id="tools" style="display:none;position:fixed;right:1vh;top:2vh;">
<button onclick="restart()" style="font-size:4vh;">[Restart]</button>
<button onclick="menu()" style="font-size:4vh;">[ Menu ]</button>
</div>
<script>
var vocab = []
var currentWord = -1
var separation = ""
var correct = []
var incorrect = []
document.getElementById("submit").addEventListener('click',function() {
responsiveVoice.setDefaultVoice("Chinese Female");
separation = document.getElementById('separation').value
vocab = document.getElementById("input").value.split(separation)
for(let i=vocab.length-1;i>=0;i--)
{
vocab[i] = vocab[i].trim()
if (vocab[i] == '')
{
vocab.splice(i, 1);
// console.log(vocab)
}
}
shuffle(vocab)
console.log(vocab)
document.getElementById("menu").style.display = "none"
document.getElementById("tools").style.display = "flex"
nextWord()
})
document.getElementById("ans").addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
checkAns();
}
});
function nextWord() {
if(document.getElementById("incorrectInput") != null)
{
correctIncorrectInput = document.getElementById("incorrectInput").value.trim()
if(vocab[currentWord] != correctIncorrectInput)
{
console.log("return")
return
}
document.getElementById("incorrectInput").remove()
}
currentWord+=1
var progress = (currentWord)/vocab.length*100
document.getElementById("progress").style.width = progress+"%"
nums = document.getElementsByClassName("number")
nums[0].innerHTML = (currentWord+1)
nums[1].innerHTML = (currentWord+1)
if(currentWord<vocab.length)
{
console.log("words left")
document.getElementById("testing").style.display = "block"
document.getElementById("ans").focus()
document.getElementById("result").style.display = "none"
document.getElementById("ans").value = ""
playSound()
} else {
console.log("no words left")
document.getElementById("end").style.display = "block"
document.getElementById("scrollDown").style.display = "flex"
document.getElementById("result").style.display = "none"
document.getElementById("finalResultText").innerHTML = correct.length+"/"+vocab.length
document.getElementById("finalResultText").style.fontSize = "35vw"
document.body.style.transitionDelay = "0.5s"
document.body.style.background = "rgb(20,20,20)"
document.body.style.transitionDelay = "0s"
showList("all")
}
}
function playSound() {
responsiveVoice.speak(vocab[currentWord])
}
function checkAns() {
document.getElementById("testing").style.display = "none"
document.getElementById("result").style.display = "block"
if(vocab[currentWord] == document.getElementById("ans").value)
{
document.getElementById("ok").focus()
document.getElementById("resultText").innerHTML = "Correct!"
correct.push(vocab[currentWord])
} else {
document.getElementById("resultText").innerHTML = "Wrong, the correct word is: "+vocab[currentWord]
incorrect.push(vocab[currentWord]+" ("+document.getElementById("ans").value+")")
inputElement = document.createElement('input')
inputElement.id = "incorrectInput"
inputElement.style.display = "flex"
inputElement.style.justifyContent = "center"
inputElement.placeholder = ">Enter correct answer"
document.getElementById("result2").appendChild(inputElement)
document.getElementById("incorrectInput").focus()
}
}
document.getElementById("ok").addEventListener("keypress", function(event) {
if (event.key === "Enter") {
console.log("enter pressed")
event.preventDefault();
nextWord();
}
});
function restart() {
if(document.getElementById("incorrectInput") != null)
{
document.getElementById("incorrectInput").remove()
}
document.body.style.background = "black"
currentWord = -1
correct = []
incorrect = []
shuffle(vocab)
console.log(vocab)
document.getElementById("end").style.display = "none"
document.getElementById("ans").value = ""
nextWord()
}
function menu() {
if(document.getElementById("incorrectInput") != null)
{
document.getElementById("incorrectInput").remove()
}
document.getElementById("testing").style.display = "none"
document.getElementById("result").style.display = "none"
document.body.style.background = "black"
document.getElementById("progress").style.width = 0+"vw"
vocab = []
currentWord = -1
separation = ""
correct = []
incorrect = []
document.getElementById("end").style.display = "none"
document.getElementById("tools").style.display = "none"
document.getElementById("menu").style.display = "block"
document.getElementById("input").value = ""
document.getElementById("separation").value = ""
}
function shuffle(array) { //Fisher-Yates Shuffle
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function showList(type) {
document.getElementById("listContainer").innerHTML = ""
if(type=="all")
{
var words = correct.concat(incorrect)
}else if(type=="correct"){
var words = correct
}else{
var words = incorrect
}
const tableElement = document.createElement('table');
words.forEach(word => {
const row = document.createElement('tr');
const cell = document.createElement('td');
cell.innerText = word;
row.appendChild(cell);
tableElement.appendChild(row);
});
tableElement.id = "table"
tableElement.style.margin = "5vw"
tableElement.style.fontSize = "3vw"
document.getElementById("listContainer").appendChild(tableElement);
}
window.onscroll = function (e)
{
if(document.getElementById("scrollDown").style.display!="none")
{
document.getElementById("all").focus()
}
document.getElementById("scrollDown").style.display = "none"
}
</script>
</body>
</html>