I'm working on a user script for opera, and opera doesn't support DOMSubtreeModified, Is there any alternative method for subtree modified?
NOTE: I'm looking a solution only in javascript. (not jquery or any javascript library)
Thanks.
I'm working on a user script for opera, and opera doesn't support DOMSubtreeModified, Is there any alternative method for subtree modified?
NOTE: I'm looking a solution only in javascript. (not jquery or any javascript library)
Thanks.
Share Improve this question asked Nov 17, 2011 at 12:04 Okan KocyigitOkan Kocyigit 13.4k18 gold badges72 silver badges131 bronze badges 1- 4 What percentage of your users actually use Opera? Consider the question: is it really worth it? – Matt Ball Commented Nov 17, 2011 at 12:07
1 Answer
Reset to default 8Target the nodes you really care about, then use an interval timer to check for changes.
The key is choosing the nodes of interest, for example given:
<div id="content"><p class="author"> ... </p>
...
</div>
Maybe you want the "author" nodes.
You would scan for these using querySelectorAll("#content p.author")
inside a timer.
Something like this pseudo code:
setInterval (MyNodeCheckFunc, 500);
function MyNodeCheckFunc ()
{
var newNodeList = [];
this.oldNodeList = this.oldNodeList || [];
var targetNodes = document.querySelectorAll ('VALID CSS-STYLE SELECTOR');
if (targetNodes && targetNodes.length > 0)
{
/*--- Found target node(s). Go through each and act if they
are new.
*/
for (var J = targetNodes.length - 1; J >= 0; --J)
{
var targNode = targetNodes[J];
newNodeList.push (targNode);
if (! targNode.weHaveProcessed)
{
targNode.weHaveProcessed = true;
//// DO STUFF FOR NEW NODE.
}
}
}
/*/// HERE, COMPARE newNodeList TO oldNodeList.
1) If an item is in oldNodeList, but not in newNodeList,
do any DELETED NODE action.
2) If an item is in a different order from oldNodeList
to newNodeList, do any MOVED NODE action.
*/
this.oldNodeList = newNodeList;
}