Skip to content

Commit

Permalink
mutationobserver instead of mutationevents
Browse files Browse the repository at this point in the history
  • Loading branch information
tesu committed Jul 18, 2015
1 parent 042199c commit db23fa3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions greentext.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ function greenTextify(node) {
}
}

function onModification(event) {
searcher(event.relatedNode);
}
var greentextRegex = /^\s*(?:>|&gt;)(?:[^<.>]|>+[^>\s]+)/i;

var greentextRegex = /^\s*(?:>|&gt;)(?:[^<.>]|>+[^>]+)/i;
var obs = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
searcher(mutation.target);
});
});

window.addEventListener('load', function() {
searcher(document);
obs.observe(document, {attributes: false, childList: true, characterData: true, subtree: true});
});
document.addEventListener("DOMNodeInserted", onModification, false);
document.addEventListener("DOMCharacterDataModified", onModification, false);

//setInterval("searcher(document.getElementsByTagName('body') [0]);", 1000);
// function onModification(event) {
// searcher(event.relatedNode);
// }

// document.addEventListener("DOMNodeInserted", onModification, false);
// document.addEventListener("DOMCharacterDataModified", onModification, false);
// setInterval("searcher(document.getElementsByTagName('body') [0]);", 1000);

0 comments on commit db23fa3

Please sign in to comment.