ok-ready-go/js/index.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-02-07 13:44:57 +01:00
async function sayNumber(number) {
2023-02-09 13:23:28 +01:00
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]}`));
}
2023-02-07 13:44:57 +01:00
}
2023-02-09 13:23:28 +01:00
function playAudio(audio) {
return new Promise((res) => {
audio.play();
audio.onended = res;
});
2023-02-07 13:44:57 +01:00
}
2023-02-09 13:23:28 +01:00
function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
2023-02-07 13:44:57 +01:00
}
2023-02-09 13:23:28 +01:00
function PasswordForm() {
return {
formData: {
password: "",
},
submitForm() {
Alpine.store("localState").password = this.formData.password;
},
};
}
2023-02-07 13:44:57 +01:00
2023-02-09 13:23:28 +01:00
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);
},
};
}