-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
50 lines (41 loc) · 1.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aria Live Announcer</title>
<script defer type="module">
import { AriaLiveAnnouncer } from './dist/index.js';
// Enable debugging
AriaLiveAnnouncer.__DEBUG__ = true;
// Random words
const words = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig', 'grape', 'honeydew', 'kiwi', 'lemon', 'mango', 'nectarine', 'orange', 'papaya', 'quince', 'raspberry', 'strawberry', 'tangerine', 'ugli', 'victoria', 'watermelon', 'xigua', 'yam', 'zucchini', 'apricot', 'blackberry', 'cantaloupe', 'dragonfruit', 'elderflower', 'feijoa'];
// Generate a random sentence from the words
function generateRandomSentence(wordCount = 10) {
let sentence = [];
for (let i = 0; i < wordCount; i++) {
// Select a random word from the array and add it to the sentence
const randomIndex = Math.floor(Math.random() * words.length);
sentence.push(words[randomIndex]);
}
// Join the words into a sentence
return sentence.join(' ') + '.';
}
const announcer = new AriaLiveAnnouncer({ politeness: 'polite', processingTime: 1000 });
setTimeout(() => {
announcer.destroy();
setTimeout(() => {
announcer.init();
}, 5000);
}, 5000);
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#button').addEventListener('click', () => {
announcer.announce(generateRandomSentence(1));
});
});
</script>
</head>
<body>
<button type="button" id="button">Announce some random text !</button>
</body>
</html>