metamorpov/content_script.js

52 lines
716 B
JavaScript
Raw Normal View History

2015-02-21 22:00:28 -05:00
var person;
loadReplace();
function loadReplace()
{
chrome.storage.local.get("person", function(value)
{
person = value.person;
2015-02-27 05:46:57 -05:00
if(person != null){walk(document.body);}
2015-02-21 22:00:28 -05:00
}
)
}
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;
2015-03-05 02:32:46 -05:00
v = v.replace(/\by\/n\b/ig, person);
2015-02-21 22:00:28 -05:00
textNode.nodeValue = v;
}