-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentScript.js
More file actions
37 lines (37 loc) · 1.15 KB
/
Copy pathcontentScript.js
File metadata and controls
37 lines (37 loc) · 1.15 KB
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
function forEachTextNode(func, node) {
node = node || document.body;
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType == 3) {
func(node.childNodes[i]);
} else if (node.childNodes[i].childNodes) {
arguments.callee(func, node.childNodes[i]);
}
}
}
forEachTextNode(function (node) {
var src, out, match;
src = node.textContent;
out = '';
while (true) {
if (match = src.match(/^\w+/)) {
match = match[0];
if (match.length > 2) { /* this is where the magic happens */
out += match[0] + match.substr(1, match.length - 2).split('').sort(function () {
return Math.random() * 2 - 1
}).join('') + match[match.length - 1];
} else {
out += match;
}
src = src.substr(match.length);
continue;
}
if (match = src.match(/^\W+/)) {
match = match[0];
out += match;
src = src.substr(match.length);
continue;
}
break;
}
node.textContent = out;
});