none
How to implement custom content filtering like AdBlock?

    Question

  • I want to filter some DOM nodes, e.g. with ID="banner" like firefox plugin AdBlock does.
    Is there any trident parser event on node insertion into document?
    Or maybe just before the node rendering occurs?
    Or maybe custom behaviors should do the trick?

    I believe that filtering nodes on DownloadComplete or DocumentComplete events is not an option because of page flickering. Can we just "not display" filtered nodes rather than displaying and then hiding them?

    Saturday, December 18, 2010 8:55 AM

Answers

All replies

  • document.getElementById('banner').style.display='none';

    or in a userStylesheet

    #banner{display:none!important}


    Rob^_^
    Sunday, December 19, 2010 12:19 AM
  • I saw the Adblock IE sources it rescans document.all nodes on DownloadComplete event and does for IHTMLDOMNode n the n.parentNode.removeChild(n).

    Actually the problem isn't to hide node, but when to hide so it isn't displayed.

    Sunday, December 19, 2010 1:08 AM
  • I want to do exacly the same thing. I asked similar question on stackoverflow (http://stackoverflow.com/questions/4224498/) but I still don't know.

    Bigger problem is for scripts because in adblock when script matches the filter it isn't loaded and executed. But in IE removing script after DocumentComplete do nothing so adverts generated by this script are still visible.

     

    I'd appreciate if someone would answer this question!

    Monday, December 20, 2010 9:51 AM
  • I suspect the answer lies in building your own pluggable protocol handler.

    http://msdn.microsoft.com/en-us/library/aa767916(VS.85).aspx

    Monday, December 20, 2010 5:09 PM
  • I believe we don't want to mess with streams of bytes like proxies do. Instead we should work with DOM document node which is parsed but doesn't rendered yet.
    Monday, December 20, 2010 8:16 PM
  • I know of no way to interpose yourself between the parser and the renderer.  
    Monday, December 20, 2010 10:05 PM
  • Can You tell what exactly should I use from this site?

    I see I can write my own custom pluggable protocol like in examples here and here . But this won't give me what I want. I want to filter image, flashes, script, etc. And here I can only manage link with "new_protocl:url" pattern.

    In the site you gave a link there is also something called "Pluggable MIME Filters" but from what I understand It's not what I'm looking for because

      "pluggable MIME filters are only invoked by Internet Explorer for the resource specified by the URL. The MIME filter will not be invoked for other resources (such as images on an HTML page) that are associated with the resource specified by the URL."

    So how witting my own pluggable protocol handler would be useful for implementing something like AdBlock?

    Tuesday, January 11, 2011 12:18 PM