最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What Can I Use Instead of DOMSubtreeModified? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

Target 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;
}
发布评论

评论列表(0)

  1. 暂无评论