X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/c64bae6314f71d7c4aa3a0c27c53f54f9f7f6344..9b8d7e610cef31f15f12c1058dfd45efffac5fb0:/word/quiz.js diff --git a/word/quiz.js b/word/quiz.js index fb36be1..f47fde1 100644 --- a/word/quiz.js +++ b/word/quiz.js @@ -30,13 +30,13 @@ class WordQuiz { if (this.preset.cat !== undefined) { ids.clear(); - let children = [this.preset.cat]; + let children = this.preset.cat; for (let loop = 0; children.length && loop < 20; loop++) { for (let child of children) ids.add(child.toString()); children = children.map(cat => json[cat][3]).filter(is => is).flat() } } - if (this.preset.image) { + if (this.preset.images) { ids = ids.filter(id => json[id][2]); } if (this.preset.level !== undefined) { @@ -62,16 +62,23 @@ class WordQuiz { return selection; } - load(dataurl) { - this.preset = {}; - let input; - if (input = window.location.hash.match(/\d+/)) { - this.preset.cat = parseInt(input[0]); - } - if (window.location.hash.match(/a/)) { - this.preset.level = 3; + configure(params) { + const opts = new Map(params.map(arg => arg.split(/[:=](.*)/))); + for (let [query, val] of opts) { + if (query.match(/^\d+$/)) { + this.preset.cat = [parseInt(query)]; + } + else if (query === 'level') { + this.preset.level = parseInt(val); + } + else { + this.preset[query] = val; + } } + } + load(dataurl) { + this.configure(window.location.hash.split('#')); fetch(dataurl).then(res => res.json()).then(json => { this.words = this.dataselect(json) this.setup(); @@ -89,6 +96,7 @@ class WordQuiz { } constructor(dataurl) { + this.preset = {images: true}; this.load(dataurl); this.history = []; window.onbeforeunload = e => {