word/quiz: decode uri-encoded location hash
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 17 Jan 2023 18:21:55 +0000 (19:21 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 9 Feb 2023 17:54:07 +0000 (18:54 +0100)
Separator # not recognised in correct browsers like chrome.

word/quiz.js

index 5283628407e51fbe84ff5cc54ea02f1c7e88c623..dce5f7a43ace9c973c726432f70d651112cbea69 100644 (file)
@@ -6,6 +6,12 @@ Array.prototype.shuffle = function () {
        return this;
 };
 
+function hashparams() {
+       // location.hash is not encoded in firefox
+       const encodedhash = (window.location.href.split('#'))[1] || '';
+       return decodeURIComponent(encodedhash).split('#');
+}
+
 class Words {
        constructor(data, root = undefined) {
                this.data = data;
@@ -111,7 +117,7 @@ class WordQuiz {
                return selection;
        }
 
-       configure(params = window.location.hash.split('#')) {
+       configure(params = hashparams()) {
                const opts = new Map(params.map(arg => arg.split(/[:=](.*)/)));
                for (let [query, val] of opts) {
                        if (query.match(/^\d+$/)) {