-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
38 lines (37 loc) · 1.07 KB
/
build.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
var vocab = [];
var _vocab_responses = [];
var _vocab_waiters = [];
var _vocab_started = false;
function _vocab_complete() {
return vocab.length > 0;
}
function GetVocab(cb) {
if (_vocab_complete()) {
if (cb) cb(vocab);
return;
}
if (cb) _vocab_waiters.push(cb);
if (_vocab_started)
return;
_vocab_started = true;
Array(40).fill().map((_, i) => i).forEach((num) => {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", () => {
try {
_vocab_responses[num] = JSON.parse(xhr.responseText);
} catch (e) {
console.log(`failed to parse ${num}`);
console.log(xhr.responseText);
return;
}
if (_vocab_responses.filter((e) => e).length != 40)
return;
vocab = [].concat.apply([], _vocab_responses);
_vocab_waiters.forEach((xb) => xb(vocab));
_vocab_waiters = [];
});
xhr.open("GET", `dict/${num+1}.json`);
xhr.send();
});
}
GetVocab();