Saturday, 26 November 2011

Site-specific stylesheets in Internet Explorer

Stylish has been one of my favourite Firefox add-ons for years - having the ability to tweak the appearance of a website certainly helps when faced with small white text on a black background or perhaps where just a little too much space is wasted on padding.

So it was that a few hours ago I went looking, unsuccessfully, for an equivalent on Internet Explorer.  In the end, I found a great article on Writing a Managed Internet Explorer Extension and decided to implement the functionality myself.

After a few minutes work we have a nice proof of concept.  Following through the article, all we need to do is add a few lines of code that adds a new stylesheet to the document and we have the foundation for site-specific stylesheets:

        void _webBrowser2Events_DocumentComplete(object pDisp, ref object URL) {
            HTMLDocument document = _webBrowser2.Document;
            var css = document.createStyleSheet("", 0);
            css.cssText = "a{ color:red !important; }";
        }


Which gives us the admittedly backwards experience of forcing all links to be red...


Next up, another step closer with actual site-specific stylesheets.

0 comments:

Post a Comment