-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
663 lines (581 loc) · 23.8 KB
/
main.js
File metadata and controls
663 lines (581 loc) · 23.8 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
// main.js
(function () {
let timerIntervalId = null;
async function init() {
Core.init();
UI.init();
wireTabs();
wireFilters();
wireDeckControls();
wireQuestionControls();
wireTimedControls();
wireStateImportExport();
wireExamOptions();
// initial stats
UI.updateGlobalStats(Core.getGlobalStatsSummary());
UI.updateProgressMini(Core.getProgressSummary());
UI.updateLastDeckInfo(Core.state.appState.lastDeck || null);
UI.updateSelectionModeButtons(Core.state.filters.selectionMode);
UI.updateStatusButtons(Core.state.filters.status);
UI.updatePoolButtons(Core.state.filters.pool);
// initial decks
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
// load file when chosen
UI.els.fileInput.addEventListener("change", onFileChosen);
UI.els.resetProgressBtn.addEventListener("click", onResetProgress);
// Initialize drag and drop
wireDragAndDrop();
// Try to load cached dataset
await tryLoadCachedDataset();
// main mode = practice
Modes.setCurrent("practice");
// tick timer
timerIntervalId = setInterval(onTick, 1000);
}
async function tryLoadCachedDataset() {
const cached = await Core.loadQuestionsFromDB();
if (cached && cached.rawText) {
loadDatasetFromText(cached.rawText, cached.filename || "deck");
} else {
UI.showEmptyState(true); // show welcome screen
}
}
function wireDragAndDrop() {
const dropZone = UI.els.dropZone;
if (!dropZone) return;
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
document.body.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
document.body.addEventListener(eventName, () => dropZone.classList.add('drag-over'), false);
});
['dragleave', 'drop'].forEach(eventName => {
document.body.addEventListener(eventName, () => dropZone.classList.remove('drag-over'), false);
});
document.body.addEventListener('drop', handleDrop, false);
}
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
if (files && files.length > 0) {
loadFile(files[0]);
}
}
function wireTabs() {
// done in UI.init
}
function onFileChosen(e) {
const file = e.target.files[0];
if (!file) return;
loadFile(file);
// Reset file input so you can select the same file again if needed
e.target.value = "";
}
function loadFile(file) {
const reader = new FileReader();
reader.onload = async evt => {
const text = evt.target.result;
const filename = file.name || "deck";
await loadDatasetFromText(text, filename);
};
reader.readAsText(file);
}
async function loadDatasetFromText(text, filename) {
try {
const info = Core.loadQuestionsFromText(text, filename);
UI.showEmptyState(info.total === 0);
UI.updateDatasetInfo(filename, info.total);
UI.updateLastDeckInfo(Core.state.appState.lastDeck || null);
// rebuild subjects & decks
const allSubjects = Core.getAllSubjectsArray();
UI.updateSubjectFilters(
allSubjects,
Core.state.subjectsActive,
Core.isSubjectNoneActive ? Core.isSubjectNoneActive() : Core.state.subjectNoneActive
);
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
UI.updateGlobalStats(Core.getGlobalStatsSummary());
UI.updateProgressMini(Core.getProgressSummary());
Modes.setCurrent("practice");
// Switch to practice mode, but don't auto-advance
if (info.total > 0) {
const lastId = Core.state.appState.currentQuestionId;
const lastQ = lastId ? Core.state.questionById[lastId] : null;
if (lastQ) {
// Restore last question from previous session (if it exists in this deck)
Modes.practice.showQuestion(lastQ, true);
UI.showEmptyState(false);
} else {
// No previous question for this deck: show a neutral "ready" state
UI.showEmptyState(false);
UI.els.questionText.textContent = "Deck loaded. Click Next to begin practice.";
UI.els.optionsContainer.innerHTML = "";
UI.els.questionIdLabel.textContent = "";
UI.els.questionStatsInline.textContent = "";
UI.setFeedback("neutral", "Ready when you are — hit Next to see your first card.");
UI.els.explanationText.textContent = "";
UI.els.explanationBox.classList.remove("visible");
UI.els.showExplanationBtn.disabled = true;
}
} else {
// Empty deck – preserve old behaviour (show 'No questions available')
Modes.practice.showNext();
}
UI.els.bookmarkBtn.disabled = false;
UI.els.manageDecksBtn.disabled = false;
UI.els.nextBtn.disabled = false;
UI.els.showExplanationBtn.disabled = false;
} catch (err) {
console.error("Error loading questions:", err);
await UI.alert("Could not parse file. Make sure it is MedMCQA JSON or newline-separated JSON.");
}
}
async function onResetProgress() {
const confirmed = await UI.confirm("Reset all stored progress and decks in this browser?");
if (!confirmed) return;
await Core.hardReset();
UI.showEmptyState(true);
UI.renderNoQuestion();
UI.updateGlobalStats(Core.getGlobalStatsSummary());
UI.updateProgressMini(Core.getProgressSummary());
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
if (Modes.current && Modes.current.currentQuestion) {
const q = Modes.current.currentQuestion;
const stat = Core.getStatsFor(q.id);
UI.updatePerQuestionStats(stat);
UI.updateBookmarkButton(Core.isBookmarked(q.id));
}
}
function wireFilters() {
UI.els.modeSmart.addEventListener("click", () => {
Core.setSelectionMode("smart");
UI.updateSelectionModeButtons("smart");
Modes.setCurrent("practice");
// Do not advance immediately; applies from next question
});
UI.els.modeNew.addEventListener("click", () => {
Core.setSelectionMode("new");
UI.updateSelectionModeButtons("new");
Modes.setCurrent("practice");
// Do not advance immediately; applies from next question
});
UI.els.modeShuffle.addEventListener("click", () => {
Core.setSelectionMode("shuffle");
UI.updateSelectionModeButtons("shuffle");
Modes.setCurrent("practice");
// Do not advance immediately; applies from next question
});
UI.els.statusButtons.forEach(btn => {
btn.addEventListener("click", () => {
const status = btn.dataset.status;
Core.setStatusFilter(status);
UI.updateStatusButtons(status);
Modes.setCurrent("practice");
// No immediate showNext; apply on next click of Next
});
});
UI.els.poolDeck.addEventListener("click", () => {
Core.setPoolSource("deck");
UI.updatePoolButtons("deck");
const deckSummaries = Core.getAllDeckSummaries();
UI.updateActivePlaylistInfo("deck",
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
Modes.setCurrent("practice");
// No immediate showNext; apply on next click of Next
});
UI.els.poolPlaylist.addEventListener("click", () => {
Core.setPoolSource("playlist");
UI.updatePoolButtons("playlist");
const deckSummaries = Core.getAllDeckSummaries();
UI.updateActivePlaylistInfo("playlist",
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
Modes.setCurrent("practice");
// No immediate showNext; apply on next click of Next
});
UI.els.subjectFilters.addEventListener("click", e => {
const btn = e.target.closest(".filter-pill");
if (!btn) return;
const type = btn.dataset.type || null;
const subj = btn.dataset.subject || null;
const allSubjects = Core.getAllSubjectsArray();
if (type === "subject-all") {
// Explicit "All": all subjects included, None off
Core.resetSubjectFiltersToAll();
Core.setSubjectNoneActive(false);
} else if (type === "subject-none") {
// Explicit "None": exclude all by subject filter
Core.setSubjectNoneActive(true);
} else if (subj) {
const wasNone = Core.isSubjectNoneActive && Core.isSubjectNoneActive();
if (wasNone) {
// From "None" → clicking a subject should mean:
// leave None, and only this subject is active.
Core.setSubjectNoneActive(false);
Core.state.subjectsActive = new Set([subj]);
} else {
const activeSet = Core.state.subjectsActive;
const total = allSubjects.length;
const activeCount = activeSet.size;
const isActive = activeSet.has(subj);
// Preserve your old special behaviour:
// when ALL subjects are active and you click one, go to only that subject.
if (activeCount === total && isActive) {
Core.state.subjectsActive = new Set([subj]);
} else {
// Normal toggle
if (isActive) {
activeSet.delete(subj);
} else {
activeSet.add(subj);
}
// If this empties the set, we keep the old meaning:
// empty + subjectNoneActive=false = "All subjects allowed".
}
}
}
UI.updateSubjectFilters(
allSubjects,
Core.state.subjectsActive,
Core.isSubjectNoneActive ? Core.isSubjectNoneActive() : Core.state.subjectNoneActive
);
// Refresh practice selection with new filters
Modes.setCurrent("practice");
// Do not call showNext; current question stays, filters affect next
});
}
function wireDeckControls() {
UI.els.playlistSelect.addEventListener("change", () => {
const name = UI.els.playlistSelect.value;
if (!name) return;
Core.setActiveDeckName(name);
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
if (Core.state.filters.pool === "playlist") {
Modes.setCurrent("practice");
// Don't auto-advance; new deck applies on next
}
});
UI.els.createDeckBtn.addEventListener("click", () => {
const visible = UI.els.newDeckControls.style.display === "flex";
UI.els.newDeckControls.style.display = visible ? "none" : "flex";
if (!visible) UI.els.newDeckNameInput.focus();
});
UI.els.confirmCreateDeckBtn.addEventListener("click", () => {
const name = UI.els.newDeckNameInput.value.trim();
if (!name) return;
Core.ensureDeck(name);
Core.setActiveDeckName(name);
UI.els.newDeckNameInput.value = "";
UI.els.newDeckControls.style.display = "none";
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
if (Core.state.filters.pool === "playlist") {
Modes.setCurrent("practice");
// Don't auto-advance; new deck applies on next
}
});
UI.els.bookmarkBtn.addEventListener("click", () => {
const mode = Modes.current || Modes.practice;
const q = mode.currentQuestion || mode.currentQuestion?.();
const question = q || Modes.practice.currentQuestion;
if (!question) return;
Core.toggleBookmark(question.id);
UI.updateBookmarkButton(Core.isBookmarked(question.id));
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
});
UI.els.manageDecksBtn.addEventListener("click", () => {
const mode = Modes.current || Modes.practice;
const q = mode.currentQuestion || mode.currentQuestion?.();
const question = q || Modes.practice.currentQuestion;
if (!question) return;
const deckSummaries = Core.getAllDeckSummaries();
UI.showDeckManagerPanel(question.id, deckSummaries, (deckName, id) =>
Core.isInDeck(deckName, id)
);
});
UI.els.closeDeckPanelBtn.addEventListener("click", () => {
UI.hideDeckManagerPanel();
});
UI.els.deckPanelAddBtn.addEventListener("click", () => {
const mode = Modes.current || Modes.practice;
const q = mode.currentQuestion || mode.currentQuestion?.();
const question = q || Modes.practice.currentQuestion;
if (!question) return;
const name = UI.els.deckPanelNewNameInput.value.trim();
if (!name) return;
Core.ensureDeck(name);
Core.addToDeck(name, question.id);
Core.setActiveDeckName(name);
UI.els.deckPanelNewNameInput.value = "";
const deckSummaries = Core.getAllDeckSummaries();
UI.showDeckManagerPanel(question.id, deckSummaries, (deckName, id) =>
Core.isInDeck(deckName, id)
);
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateBookmarkButton(Core.isBookmarked(question.id));
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
});
UI.els.deckCheckboxes.addEventListener("change", e => {
if (e.target.tagName !== "INPUT") return;
const checkbox = e.target;
const deckName = checkbox.value;
const mode = Modes.current || Modes.practice;
const q = mode.currentQuestion || mode.currentQuestion?.();
const question = q || Modes.practice.currentQuestion;
if (!question) return;
if (checkbox.checked) Core.addToDeck(deckName, question.id);
else Core.removeFromDeck(deckName, question.id);
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateBookmarkButton(Core.isBookmarked(question.id));
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
});
}
function wireQuestionControls() {
UI.els.optionsContainer.addEventListener("click", e => {
const btn = e.target.closest(".option-btn");
if (!btn) return;
const idx = Number(btn.dataset.index);
if (Modes.current === Modes.exam) {
Modes.exam.handleAnswer(idx);
} else if (Modes.current === Modes.lite) {
Modes.lite.handleAnswer(idx);
} else {
Modes.practice.handleAnswer(idx);
}
});
UI.els.nextBtn.addEventListener("click", () => {
if (Modes.current === Modes.exam) {
Modes.exam.goNext();
} else if (Modes.current === Modes.lite) {
Modes.lite.goNext();
} else {
handlePracticeNextClick();
}
});
UI.els.prevQuestionBtn.addEventListener("click", () => {
if (Modes.current === Modes.practice) Modes.practice.goPrevious();
});
UI.els.backLatestBtn.addEventListener("click", () => {
if (Modes.current === Modes.practice) Modes.practice.goLatest();
});
UI.els.showExplanationBtn.addEventListener("click", () => {
if (Modes.current === Modes.exam) return;
if (Modes.current === Modes.lite) Modes.lite.toggleExplanation();
else Modes.practice.toggleExplanation();
});
}
function handlePracticeNextClick() {
const pool = Core.getFilteredPool();
const hasAny = pool && pool.length > 0;
if (!hasAny) {
// Deck is loaded but filters are too restrictive
if (Core.state.questions.length > 0) {
UI.setFeedback(
"neutral",
"No questions match the current filters. Adjust subjects, status, or playlist."
);
} else {
// No questions at all
UI.setFeedback(
"neutral",
"No questions loaded. Load a MedMCQA deck to begin."
);
}
// Important: do NOT call showNext(); keep current question visible
return;
}
// Normal behavior: advance to the next question from the filtered pool
Modes.practice.showNext();
}
function wireTimedControls() {
UI.els.startLiteBtn.addEventListener("click", async () => {
if (Modes.current === Modes.exam && Modes.exam.state && Modes.exam.state.active) {
await UI.alert("Finish or end the current NEET exam first.");
return;
}
const count = parseInt(UI.els.liteCountInput.value, 10) || 50;
if (Modes.lite.startSession(count)) {
Modes.setCurrent("lite");
Modes.lite.showCurrent();
}
});
UI.els.pauseLiteBtn.addEventListener("click", () => {
if (Modes.current === Modes.lite) Modes.lite.pauseOrResume();
});
UI.els.endLiteBtn.addEventListener("click", async () => {
if (!Modes.lite.state || !Modes.lite.state.active) return;
const confirmed = await UI.confirm("End Lite session now and see summary?");
if (!confirmed) return;
Modes.lite.finishSession();
});
UI.els.startExamBtn.addEventListener("click", async () => {
if (Modes.current === Modes.lite && Modes.lite.state && Modes.lite.state.active) {
await UI.alert("Finish or end the current Lite session first.");
return;
}
if (Modes.exam.startSession()) {
Modes.setCurrent("exam");
Modes.exam.showCurrent();
}
});
UI.els.endExamBtn.addEventListener("click", async () => {
if (!Modes.exam.state || !Modes.exam.state.active) return;
const confirmed = await UI.confirm("End NEET exam now and score based on current answers?");
if (!confirmed) return;
Modes.exam.finishAndScore();
});
}
function wireExamOptions() {
if (!UI.els.examUseWeightsToggle) return;
// Initialize from Core state
const useWeights = Core.getExamUseWeights();
UI.els.examUseWeightsToggle.checked = useWeights;
UI.els.examUseWeightsToggle.addEventListener("change", () => {
Core.setExamUseWeights(UI.els.examUseWeightsToggle.checked);
});
}
function wireStateImportExport() {
UI.els.exportStateBtn.addEventListener("click", () => {
const blob = new Blob([JSON.stringify(Core.state.appState, null, 2)], {
type: "application/json"
});
const now = new Date();
const y = now.getFullYear();
const m = String(now.getMonth() + 1).padStart(2, "0");
const d = String(now.getDate()).padStart(2, "0");
const filename = `medmcqa_progress_${y}${m}${d}.json`;
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
});
UI.els.importStateBtn.addEventListener("click", () => {
UI.els.importStateInput.click();
});
UI.els.importStateInput.addEventListener("change", e => {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = async evt => {
try {
const imported = JSON.parse(evt.target.result);
if (!imported || typeof imported !== "object") {
await UI.alert("Invalid progress file.");
return;
}
Core.state.appState = imported;
Core.ensurePlaylistsShape();
Core.saveAppState();
UI.updateLastDeckInfo(Core.state.appState.lastDeck || null);
const deckSummaries = Core.getAllDeckSummaries();
UI.updatePlaylistSelects(deckSummaries, Core.getActiveDeckName());
UI.updateDeckSummaryList(deckSummaries);
UI.updateActivePlaylistInfo(Core.state.filters.pool,
deckSummaries.find(d => d.name === Core.getActiveDeckName()));
UI.updateGlobalStats(Core.getGlobalStatsSummary());
UI.updateProgressMini(Core.getProgressSummary());
await UI.alert("Progress imported successfully.");
} catch (err) {
console.error("Failed to import progress:", err);
await UI.alert("Could not import progress file.");
}
};
reader.readAsText(file);
UI.els.importStateInput.value = "";
});
UI.els.exportWeakBtn.addEventListener("click", async () => {
const weakQuestions = Core.state.questions.filter(q =>
Core.isWeak(Core.getStatsFor(q.id))
);
const payload = Core.exportQuestionsAsNDJSON(weakQuestions, "medmcqa_weak");
if (!payload) {
await UI.alert("No weak questions to export.");
return;
}
triggerDownload(payload);
});
UI.els.exportBookmarkedBtn.addEventListener("click", async () => {
const deck = Core.getDeck("Bookmarks");
const set = new Set(deck.ids);
const bookmarkedQuestions = Core.state.questions.filter(q => set.has(q.id));
const payload = Core.exportQuestionsAsNDJSON(bookmarkedQuestions, "medmcqa_bookmarks");
if (!payload) {
await UI.alert("No bookmarked questions to export.");
return;
}
triggerDownload(payload);
});
UI.els.exportDeckBtn.addEventListener("click", async () => {
const name = UI.els.exportDeckSelect.value;
if (!name) {
await UI.alert("Select a deck to export.");
return;
}
const deck = Core.getDeck(name);
if (!deck || !deck.ids || deck.ids.length === 0) {
await UI.alert(`Deck "${name}" has no questions.`);
return;
}
const set = new Set(deck.ids);
const qs = Core.state.questions.filter(q => set.has(q.id));
const payload = Core.exportQuestionsAsNDJSON(
qs,
`medmcqa_deck_${name.replace(/\s+/g, "_")}`
);
if (!payload) {
await UI.alert("No questions to export.");
return;
}
triggerDownload(payload);
});
}
function triggerDownload(payload) {
const blob = new Blob([payload.text], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = payload.filename;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
function onTick() {
if (Modes.current === Modes.lite) Modes.lite.onTimerTick();
else if (Modes.current === Modes.exam) Modes.exam.onTimerTick();
}
document.addEventListener("DOMContentLoaded", init);
})();