I am making a chrome extension that should replace certain words with others. The problem is it won't replace words that contain serbian latin characters like Č, Ć, Ž, Đ or Š. Here is my code:
var exprs = [
//Example
[/\bČ\b/g, "Ć"],
]
function replaceTextInNode(node) {
var value = node.nodeValue
var expr
for (expr of exprs) {
value = value.replace(expr[0], expr[1])
}
node.nodeValue = value
}
function walk(node) {
var child, next
switch (node.nodeType) {
case 1: // element
case 9: // document
case 11: // fragment
child = node.firstChild
while (child) {
next = child.nextSibling
walk(child)
child = next
}
break
case 3: // text
replaceTextInNode(node)
break
}
}
document.addEventListener("DOMContentLoaded", function(e) {
walk(document.body)
})
document.addEventListener("DOMNodeInserted", function(e) {
walk(e.target)
})
Everything is saved as UTF8
Code is based on: Javascript Regex to replace text NOT in html attributes
Thanks everyone in advance.