-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkarr2000.js
More file actions
38 lines (34 loc) · 899 Bytes
/
Copy pathkarr2000.js
File metadata and controls
38 lines (34 loc) · 899 Bytes
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
$(function() {
// Get custom data from local storage
chrome.storage.sync.get('karrData', function(data) {
if (data != undefined) {
// TODO : replace matching elements in DOM
walk(document.body, data.karrData);
}
});
});
function walk(node, replacements) {
var child, next;
switch (node.nodeType){
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while (child) {
next = child.nextSibling;
walk(child, replacements);
child = next;
}
break;
case 3: // Text node
handleText(node, replacements);
break;
}
}
function handleText(textNode, replacements) {
var v = textNode.nodeValue;
replacements.forEach(function(replacement) {
v = v.replace(new RegExp(replacement.match, 'i'), replacement.substitute);
textNode.nodeValue = v;
});
}