It's playable

This commit is contained in:
Lynn
2022-01-14 00:16:27 +01:00
parent 4a08467237
commit 687f2acc22
6 changed files with 69 additions and 23 deletions

View File

@@ -24,3 +24,24 @@ export function resetRng(): void {
export function pick<T>(array: Array<T>): T {
return array[Math.floor(array.length * random())];
}
// https://a11y-guidelines.orange.com/en/web/components-examples/make-a-screen-reader-talk/
export function speak(
text: string,
priority: "polite" | "assertive" = "assertive"
) {
var el = document.createElement("div");
var id = "speak-" + Date.now();
el.setAttribute("id", id);
el.setAttribute("aria-live", priority || "polite");
el.classList.add("sr-only");
document.body.appendChild(el);
window.setTimeout(function () {
document.getElementById(id)!.innerHTML = text;
}, 100);
window.setTimeout(function () {
document.body.removeChild(document.getElementById(id)!);
}, 1000);
}