-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
23 lines (22 loc) · 728 Bytes
/
content.js
File metadata and controls
23 lines (22 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const speakButtonHTML = `[<a id="tts_btn">speak</a>]`;
const btns = document.querySelectorAll(".bz_comment_number");
btns.forEach((btn) => {
btn.innerHTML += speakButtonHTML;
});
document.querySelectorAll("#tts_btn").forEach((btn) => {
btn.addEventListener("click", (event) => {
const textElement =
event.target.parentElement.parentElement.parentElement.querySelector(
".bz_comment_text",
);
const selectedText = textElement.innerText;
highlight(textElement);
chrome.runtime.sendMessage({ action: "speak", text: selectedText });
});
});
function highlight(element) {
element.style.backgroundColor = "yellow";
setTimeout(() => {
element.style.backgroundColor = "";
}, 300);
}