Bookmarklet: Black and white
A few days ago I wrote a bookmarklet to hide unwanted elements on a page. Today I have one to “fix” the colors on any page, so everything is black-on-white. Here it is, tested in IE7 and Firefox. Note that it doesn’t actually make most pages easier to read (for example all links will become the same color as regular text), but if someone tries yellow on red, or light grey on slightly lighter grey, now you have a weapon.
And here’s the readable version:
It builds upon what I learned when writing my dynamic CSS library. It’s a really simple process, complicated by browser quirks and inconsistencies. First it makes sure the page has a stylesheet, and adds one if not. Then it adds a rule at the end of the last stylesheet.
The if is needed because IE and Firefox use different functions for adding rules (IE uses addRule and Firefox uses insertRule).
The timeout is needed because of a Firefox quirk: if you add a stylesheet, it’s not immediately available. Setting the timeout forces Firefox to do whatever it needs to do before the rule is added.
For all the complaining some people do about working around IE’s problems, this is one script that’s much harder in Firefox.