-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
140 lines (118 loc) · 3.73 KB
/
script.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
$("#text_input").keyup(function(e){
if(e.keyCode == 13){
submit();
}
});
var missed = [];
var clicked = 1;
function select(cell) {
let cells = document.querySelectorAll("td");
for (let i = 0; i < cells.length; ++i) {
cells[i].style.backgroundColor = "#f9f9f9";
}
cell.style.backgroundColor = "#008aff";
clicked = cell.innerHTML;
// now add pronunciations
txt = "<ul>\n";
for (var i = parseInt(clicked)-1; i < 1500; i += 20) {
txt += "\t<li>" + w2024[i][0].split("|")[0];
txt += "<a onclick=\"word_url=w2024[" + i + "][1];audio();\">▶️</button></li>\n";
}
txt += "</ul>\n";
document.getElementById("pron").innerHTML = txt;
missed = [];
}
var w2024_l = w2024.length;
var word_url = "";
var word = "";
var word_idx;
var used_idx = [];
var correct = 0;
var total = 0;
function audio(){
let a = new Audio(word_url);
a.play();
}
function test(){
audio("https://www.ahdictionary.com/application/resources/wavs/T0070900.wav");
console.log(w2024[0])
}
function chk_word(){
for(let i = 0; i < used_idx.length; i++){
if(word_idx == used_idx[i]){
return false;
}
}
return true;
}
function start(){
//test();
var rem = document.getElementsByClassName("toggle1");
for (var i = 0; i < rem.length; i++) {
rem[i].style.display = "none";
}
$("#text_input").val("");
/* had to change the way 'toggle2' was toggled (shown below) bcz the new CSS messed it up somehow
original was just $("#toggle2").show(); and toggle2 used to be an id rather than a class */
var elem = document.getElementsByClassName("toggle2");
for (var i = 0; i < elem.length; i++) {
elem[i].style.display = "block";
}
if (used_idx.length == 75) {
var hide = document.getElementsByClassName("toggle2");
var show = document.getElementsByClassName("toggle3");
for (var i = 0; i < hide.length; i++) {
hide[i].style.display = "none";
}
for (var i = 0; i < show.length; i++) {
show[i].style.display = "block";
}
document.getElementById("msg-set").innerHTML += clicked.toString() + "!";
document.getElementById("msg-right").innerHTML += correct.toString() + " of them right!"
// ok now add list of wrong words
var miss_txt = "";
missed.sort((a,b) => a.localeCompare(b, undefined, {sensitivity: 'base'}));
missed.forEach(
function app(s) {
miss_txt += "<li>" + s + "</li>\n";
}
);
document.getElementById("end_wrong").innerHTML = miss_txt;
return;
}
do {
word_idx = Math.floor(Math.random() * 75) * 20 + parseInt(clicked) - 1;
} while (!chk_word());
used_idx.push(word_idx);
word = w2024[word_idx][0];
word_url = w2024[word_idx][1];
audio();
}
function submit(){
let typed = $("#text_input").val();
const arr = word.split("|");
var b = false;
arr.forEach(function check(s) {
if (typed === s) {
b = true;
}
});
if(b == true){
correct++;
$("#correct").append("<br><b>" + word + "</b>");
}else{
$("#incorrect").append("<br><b>" + word + "</b> (You entered: " + typed + ")");
missed.push(word);
}
total++;
let percent = Math.round(correct / total * 100);
$("#stats").text(correct.toString() + " out of " + total.toString() + " correct (" + percent.toString() + "%)");
start();
}
var buttons = document.querySelectorAll(".insert");
var field = document.getElementById("text_input");
buttons.forEach( function(button) {
button.addEventListener('click', function() {
field.value = field.value + button.value;
})
});