-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instant update index, close tab on correct answer
Fixes #201
- Loading branch information
Neale Pickett
committed
Apr 8, 2024
1 parent
c9bd05c
commit afae394
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ async function formSubmitHandler(event) { | |
try { | ||
message = await window.app.puzzle.SubmitAnswer(proposed) | ||
common.Toast(message) | ||
common.StateUpdateChannel.postMessage({}) | ||
document.dispatchEvent(new CustomEvent("answerCorrect")) | ||
} | ||
catch (err) { | ||
common.Toast(err) | ||
|
@@ -233,6 +235,16 @@ async function loadPuzzle(category, points) { | |
return puzzle | ||
} | ||
|
||
const confettiPromise = import("https://cdn.jsdelivr.net/npm/[email protected]/+esm") | ||
async function CorrectAnswer() { | ||
setInterval(window.close, 3 * common.Second) | ||
|
||
let confetti = await confettiPromise | ||
confetti.default({ | ||
disableForReducedMotion: true, | ||
}) | ||
} | ||
|
||
async function init() { | ||
window.app = {} | ||
window.setanswer = (str => SetAnswer(str)) | ||
|
@@ -250,6 +262,9 @@ async function init() { | |
// Workspaces may trigger a "this is the answer" event | ||
document.addEventListener("setAnswer", e => SetAnswer(e.detail.value)) | ||
|
||
// Celebrate on correct answer | ||
document.addEventListener("answerCorrect", e => CorrectAnswer()) | ||
|
||
// Make all links absolute, because we're going to be changing the base URL | ||
for (let e of document.querySelectorAll("[href]")) { | ||
e.href = new URL(e.href, common.BaseURL) | ||
|