git.shiar.nl
/
sheet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
latin: group aliases similar to termcol ea
[sheet.git]
/
word
/
quiz.js
diff --git
a/word/quiz.js
b/word/quiz.js
index 187aea7e76d72aa2aa3410e8117679cf1e7822f2..d32368bb01bdaae2160c64798384e7fe29138418 100644
(file)
--- a/
word/quiz.js
+++ b/
word/quiz.js
@@
-8,21
+8,30
@@
Array.prototype.shuffle = function () {
class WordQuiz {
dataselect(json) {
class WordQuiz {
dataselect(json) {
+ this.data = json;
+ this.cats = {}; // category lookup
+ for (let i in json) {
+ let cat = json[i][3];
+ if (this.cats[cat]) {
+ this.cats[cat].push(i);
+ }
+ else {
+ this.cats[cat] = [i];
+ }
+ }
+ return this.datafilter(json);
+ }
+
+ datafilter(json) {
// find viable rows from json data
let rows = Object.values(json);
// find viable rows from json data
let rows = Object.values(json);
- if (this.preset.cat !== undefined) {
- let cats = {}; // category lookup
- for (let i in json) {
- let cat = json[i][3];
- if (!cats[cat]) cats[cat] = [];
- cats[cat].push(i)
- }
+ if (this.preset.cat !== undefined) {
rows = [];
rows = [];
- let children = cats[this.preset.cat];
+ let children =
this.
cats[this.preset.cat];
for (let loop = 0; children.length && loop < 20; loop++) {
rows.push(...children);
for (let loop = 0; children.length && loop < 20; loop++) {
rows.push(...children);
- children = children.map(cat => cats[cat]).filter(is => is).flat();
+ children = children.map(cat =>
this.
cats[cat]).filter(is => is).flat();
}
rows = rows.map(row => json[row]).filter(row => row[2]);
}
}
rows = rows.map(row => json[row]).filter(row => row[2]);
}
@@
-49,7
+58,7
@@
class WordQuiz {
this.preset.cat = input[0];
}
if (window.location.hash.match(/a/)) {
this.preset.cat = input[0];
}
if (window.location.hash.match(/a/)) {
- this.preset.level =
2
;
+ this.preset.level =
3
;
}
fetch(dataurl).then(res => res.json()).then(json => {
}
fetch(dataurl).then(res => res.json()).then(json => {
@@
-58,7
+67,21
@@
class WordQuiz {
});
}
});
}
+ log(...args) {
+ this.history.push([new Date().toISOString(), ...args]);
+ }
+
+ stop(...args) {
+ this.log(...args);
+ window.onbeforeunload = null;
+ fetch('/word/report', {method: 'POST', body: JSON.stringify(this.history)});
+ }
+
constructor(dataurl) {
this.load(dataurl);
constructor(dataurl) {
this.load(dataurl);
+ this.history = [];
+ window.onbeforeunload = e => {
+ this.stop('abort');
+ };
}
}
}
}