A browser add-on replaces some words on a website. This part works! Now I want to skip a specific area on the site. How can I skip/exclude anything within “” or “”?
The pages structure is this:
<html>
<body id="chat">
[...]
<div id="chatBar">
<ul class="chat_bar_list">
[...]
</ul>
</div>
[...]
</body>
</html>
This part does the replacement-job:
function replaceText (node) {
if (node.nodeType === Node.TEXT_NODE) {
// My try to skip specific area here (doesn't work)
//if (document.getElementById("chatBar")) {
// return;
//}
let content = node.textContent;
for (let [word, emoji] of langMap) {
const regex = regexs.get(word);
content = content.replace(regex, emoji);
}
node.textContent = content;
}
else {
// This node contains more than just text, call replaceText() on each
// of its children.
for (let i = 0; i < node.childNodes.length; i++) {
replaceText(node.childNodes[i]);
}
}
}
replaceText(document.body);