-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.js
32 lines (29 loc) · 913 Bytes
/
translate.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
function translate(inputText) {
inputText = inputText.split(" ");
for (i = 0; i < inputText.length; ++i) {
inputText[i] = inputText[i].replace(/[a-z]+/, "chicken");
if (/[A-Z]/.test(inputText[i].charAt(0))) {
inputText[i] = inputText[i].replace(/([A-Z)|[a-z])+/, "Chicken");
}
}
inputText = inputText.join(" ");
return inputText;
}
function chickenify(node) {
var treeWalker = document.createTreeWalker(node,
NodeFilter.SHOW_TEXT,
null,
false);
while(treeWalker.nextNode()) {
var current = treeWalker.currentNode;
current.textContent = translate(current.textContent);
}
}
chrome.runtime.sendMessage({name: "isEnabled"}, function(response) {
if (response.isEnabled === true) {
chickenify(document.body);
document.body.addEventListener('DOMNodeInserted', function(event) {
chickenify(event.target);
});
}
});