Files
walk-to-wank/Source/content_script.js
Amrit Panesar d79a13a3b3 First Commit!
This should work out nicely
2014-06-06 09:37:24 -07:00

44 lines
701 B
JavaScript

walk(document.body);
function walk(node)
{
// I stole this function from here:
// http://is.gd/mwZp7E
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);
child = next;
}
break;
case 3: // Text node
handleText(node);
break;
}
}
function handleText(textNode)
{
var v = textNode.nodeValue;
// Deal with the easy case
v = v.replace(/\b(W|w)alk/g, function(match, p1, p2, offset, string) {
w = String.fromCharCode(p1.charCodeAt(0));
return w + "ank";
});
textNode.nodeValue = v;
}