It's playable
This commit is contained in:
21
src/util.ts
21
src/util.ts
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user