forked from XilkyTofu/bilibili_translate_chrome_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
39 lines (31 loc) · 828 Bytes
/
main.js
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
function replaceText(fromString, toString){
getTextNodes().forEach(function(node){
node.nodeValue = node.nodeValue.replace(new RegExp(quote(fromString), 'g'), toString);
});
function getTextNodes(){
var node_list = [];
(function scan(node){
if(node.childNodes.length)
for(var i = 0; i < node.childNodes.length; i++) {
scan(node.childNodes[i]);
}
else if(node.nodeType == Node.TEXT_NODE) {
node_list.push(node);
}
})(document);
return node_list;
}
function quote(str){
return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
}
(function main(){
for (let key in dictionary) {
replaceText(key, dictionary[key]);
}
})();
setTimeout(function () {
for (let key in dictionary) {
replaceText(key, dictionary[key]);
}
}, 3000);