72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
|
async function sayNumber(number) {
|
||
|
console.log(number);
|
||
|
number = number.toString();
|
||
|
number = number.replace(/[^0-9]/, "");
|
||
|
for (let i = 0; i < number.length; i++) {
|
||
|
await playAudio(document.getElementById(`sound-${number[i]}`));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function playAudio(audio) {
|
||
|
return new Promise((res) => {
|
||
|
audio.play();
|
||
|
audio.onended = res;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function uuidv4() {
|
||
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
||
|
(
|
||
|
c ^
|
||
|
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
|
||
|
).toString(16)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function PasswordForm() {
|
||
|
return {
|
||
|
formData: {
|
||
|
password: "",
|
||
|
},
|
||
|
submitForm() {
|
||
|
Alpine.store("localState").password = this.formData.password;
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function Timer() {
|
||
|
return {
|
||
|
time: 0,
|
||
|
over: false,
|
||
|
init() {
|
||
|
setInterval(() => {
|
||
|
const startedAt = Alpine.store("localState").startedAt;
|
||
|
const resultTime = Alpine.store("localState").time;
|
||
|
|
||
|
let time;
|
||
|
if (!startedAt && !resultTime) {
|
||
|
time = 0;
|
||
|
this.over = false;
|
||
|
} else if (resultTime) {
|
||
|
time = resultTime / 1000;
|
||
|
this.over = true;
|
||
|
} else {
|
||
|
this.over = false;
|
||
|
time = (new Date().getTime() - startedAt) / 1000;
|
||
|
}
|
||
|
|
||
|
this.time = time.toFixed(2);
|
||
|
}, 10);
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
|
||
|
const event = new Event('wasm-loaded');
|
||
|
wasm_bindgen('lib/crypto_helper_bg.wasm').then(() => {
|
||
|
document.dispatchEvent(event);
|
||
|
});
|
||
|
|
||
|
document.addEventListener("alpine:init", () => {
|
||
|
document.getElementsByClassName("hide-after-init").item(0).outerHTML = ""
|
||
|
document.getElementsByClassName("hide-before-init").item(0).classList.remove("hide-before-init")
|
||
|
});
|