metamorpov/content_script.js

52 lines
716 B
JavaScript

var person;
loadReplace();
function loadReplace()
{
chrome.storage.local.get("person", function(value)
{
person = value.person;
if(person != null){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;
v = v.replace(/\by\/n\b/ig, person);
textNode.nodeValue = v;
}