Как насчёт функции для особо ленивых?) Вот набросал код.
В HTML-верх:
<!-- Зачитать сообщение | Зачитать все сообщения --> <script type="text/javascript"> let synth = window.speechSynthesis; function readMessage(event) { let postContent = event.currentTarget.parentElement.parentElement.parentElement.getElementsByClassName("post-content")[0]; let utterThis = new SpeechSynthesisUtterance(postContent.innerText); synth.speak(utterThis); } function readAllMessages() { for (const post of posts) { let postContent = post.getElementsByClassName("post-content")[0]; let author = post.getElementsByClassName("pa-author")[0].getElementsByTagName("a")[0].innerText; let utterThis = new SpeechSynthesisUtterance(author + "пишет: " + postContent.innerText); synth.speak(utterThis); } } const posts = document.getElementsByClassName("post"); document.addEventListener("DOMContentLoaded", function () { const post = posts[0]; const header = post.getElementsByTagName("h3")[0].getElementsByTagName("span")[0]; let speaklink = document.createElement("a"); speaklink.innerHTML = "Зачитать всё"; speaklink.style.cursor = "pointer"; speaklink.style.float = "right"; speaklink.style.margin = "0px 25px 0px 0px"; speaklink.addEventListener("click", readAllMessages); header.childNodes[1].after(speaklink); for (const post of posts) { const header = post.getElementsByTagName("h3")[0].getElementsByTagName("span")[0]; let speaklink = document.createElement("a"); speaklink.innerHTML = "Зачитать"; speaklink.style.cursor = "pointer"; speaklink.style.float = "right"; speaklink.addEventListener("click", readMessage); header.childNodes[1].after(speaklink); } }); </script> <!-- Сделано GulgDev -->
Отредактировано Еремей (2021-07-19 10:19:28)
- Подпись автора
[script]UserLogin ? "Привет, " + GroupUserTitle.toLowerCase() + " " + UserName + "!" : "Привет, гость! <a href=\"/login.php\" rel=\"nofollow\">Войди</a> или <a href=\"/register.php\" rel=\"nofollow\">зарегистрируйся</a>."[/script]