2015-07-31 06:58:38 -04:00
|
|
|
var valChange = /\by\/n\b|\(y\/n\)|\[y\/n\]/ig;
|
|
|
|
|
|
|
|
|
|
chrome.extension.onMessage.addListener(function(message,sender,sendResponse){
|
|
|
|
|
//This is where the stuff you want from the background page will be
|
|
|
|
|
valChange = new RegExp(message.stuff, "ig");
|
|
|
|
|
loadReplace();
|
|
|
|
|
});
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2015-07-31 06:58:38 -04:00
|
|
|
var v = textNode.nodeValue;
|
|
|
|
|
v = v.replace(valChange, person); //replaces Y/N or other value entered regardless of the case, whether it's in a bracket or not
|
2015-02-21 22:00:28 -05:00
|
|
|
|
|
|
|
|
textNode.nodeValue = v;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 19:02:34 -04:00
|
|
|
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
|
|
|
|
|
|
|
|
|
|
var observer = new MutationObserver(function(mutations, observer) {
|
|
|
|
|
loadReplace();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// define what element should be observed by the observer
|
|
|
|
|
// and what types of mutations trigger the callback
|
|
|
|
|
observer.observe(document, {
|
|
|
|
|
subtree: true,
|
|
|
|
|
childList: true
|
|
|
|
|
//...
|
2015-07-31 06:58:38 -04:00
|
|
|
});
|