So, here’s a little tale. I’m trying to use Aaron Boodman’s labels.js w/ my newly reinstated search box. But oddly enough, while it seems to mostly work, for some reason, the label isn’t being hidden. This seems odd since I’m not getting any errors with the insertRule/addRule.
So, what’s going on? Jesse pointed out something pretty obvious, but that had totally escaped my attention, which is that Aaron’s code is hard-coded to append rules to the last stylesheet (document.styleSheets[document.styleSheets.length-1]
), which in my case, happens to be an alternate stylesheet. The ideal way to fix this is to add a new stylesheet, however there’s no standard way to do it.
What Jesse does for his bookmarklets that deal w/ styles is to use JS to create link/style nodes. Which is fine, except I’m lazy and I don’t want to bother with writing the branching code, so I did the easiest thing and wrote a for loop to add the style to all of the stylesheets.
for(i=0; i<document.styleSheets.length; i++) {
var s = document.styleSheets[i];
addStyleRule(s, "label", "position:absolute; visibility:hidden;");
}
[in Moz at least, you can query the styleSheet.disabled property to see which sheets are active, but, well, if you’re looping anyway…]