-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (77 loc) · 3.2 KB
/
script.js
File metadata and controls
95 lines (77 loc) · 3.2 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const burger=document.querySelector(".burger");
const navManu = document.querySelector(".nav-manu");
burger.addEventListener("click", () =>{
burger.classList.toggle("active");
navManu.classList.toggle("active");
})
document.querySelectorAll(".nav-link").forEach(n=>
n.addEventListener("click",()=>{
burger.classList.remove("active");
navManu.classList.remove("active");
}))
const accordionItems = document.querySelectorAll("[data-accordion] > details");
const siblings = (el) => {
if (el.parentNode === null) return [];
return Array.prototype.filter.call(el.parentNode.children, function (child) {
return child !== el;
});
};
accordionItems.forEach((el) => {
el.addEventListener("click", () => {
const others = siblings(el);
others.forEach((sibling) => {
sibling.removeAttribute("open");
});
});
});
// const textToRead = document.getElementById('text-to-read');
// const speakButton = document.getElementById('speak-button');
// const stopButton = document.getElementById('stop-button');
// const resumeButton = document.getElementById('resume-button');
// let utterance = null;
// speakButton.addEventListener('click', () => {
// const text = textToRead.textContent;
// if (text && window.speechSynthesis) {
// utterance = new SpeechSynthesisUtterance(text);
// speechSynthesis.speak(utterance);
// }
// });
// stopButton.addEventListener('click', () => {
// if (utterance && speechSynthesis) {
// speechSynthesis.cancel();
// }
// });
// resumeButton.addEventListener('click', () => {
// if (utterance && speechSynthesis) {
// speechSynthesis.resume();
// }
// });
// 2
const playButtons = document.querySelectorAll('.playButton');
const stopButtons = document.querySelectorAll('.stopButton');
const paragraphs = document.querySelectorAll('.paragraph p');
const speechSynthesisUtterances = {};
playButtons.forEach((playButton) => {
playButton.addEventListener('click', () => {
const paragraphId = playButton.getAttribute('data-paragraph');
const paragraph = document.getElementById(paragraphId);
if (paragraph && paragraph.textContent.trim() !== '') {
speechSynthesisUtterances[paragraphId] = new SpeechSynthesisUtterance(paragraph.textContent);
speechSynthesis.speak(speechSynthesisUtterances[paragraphId]);
}
});
});
stopButtons.forEach((stopButton) => {
stopButton.addEventListener('click', () => {
const paragraphId = stopButton.getAttribute('data-paragraph');
if (speechSynthesisUtterances[paragraphId]) {
speechSynthesisUtterances[paragraphId].onend = () => {
delete speechSynthesisUtterances[paragraphId];
};
speechSynthesisUtterances[paragraphId].onpause = () => {
delete speechSynthesisUtterances[paragraphId];
};
speechSynthesis.cancel();
}
});
});