word/quiz: report table to save user actions
[sheet.git] / word / quiz.js
index 2385455ea0ff6e3d3a641b08ba0e8a87e1bf6401..bb12a832c73b170e496dc09e25e6fb88aa0c8849 100644 (file)
@@ -58,7 +58,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);
+               this.history = [];
+               window.onbeforeunload = e => {
+                       this.stop('abort');
+               };
        }
 }