I'm currently using a dark theme in firefox. It looks really nice, but many webpages use a plain white background. The resulting contrast is a little unpleasant and sometimes hurts the eye when I switch from a dark tab to a white tab.

Is there a way to make firefox replace white backgrouns everywhere with some other color (light gray, for instance)? It could be a Stylish script, a userChrome.css hack, or anything that works (preferably as light as possible).

To make myself clear: after I achieve my objective, the background color whenever I visit the super-user site should be light-grey instead of white, and the same should happen to any other site with a white background (google sites, tech crunch, etc).

Is there a way to do that?

link|improve this question

3  
I would recommend against this, most websites use lots of different classes and CSS for text styling. What happens when you have a black background AND black text, as per styled on the web page? What OS do you use out of interest? – danixd Aug 27 '10 at 14:56
Windows 7 mostly, though a platform independent solution would be better 'cause I also use ubuntnu at work. I know it might cause some awkward behavior with some sites, and the background would have to be some light grey instead of black so the text is readable. But this thing's been bothering me to the point that I'm willing to experiment. – Bruce Connor Aug 28 '10 at 17:17
feedback

6 Answers

up vote 6 down vote accepted

I just wrote a quick Greasemonkey script that checks the computed style of the body element and changes it to black (you probably want to choose a different colour):

(function () {
    if (window.getComputedStyle(document.body, null).getPropertyValue("background-color") == "rgb(255, 255, 255)") {
        console.log("Setting new background color...");
        document.body.setAttribute("style", "background-color: #000000;");
    }
})();

The problem with these types of things is that unless websites are designed extremely well, there will be blotches of white on black.

link|improve this answer
2  
Forgive my ignorance, but where do I paste this script? (thanks for the trouble) – Bruce Connor Aug 27 '10 at 3:31
@Bruce: Install Greasemonkey, create a new user script for *, and paste this into the text editor. Save, and refresh the page. – Hello71 Aug 27 '10 at 14:43
Ok, this method works best so far. It doesn't change the background of textboxes and a couple other stuff, but other than that it's good. I guess any solution will leave a few white boxes lying around anyway. thanks – Bruce Connor Aug 28 '10 at 18:17
feedback

This is not a perfect solution but you can do this whenever you visit the sites you want to change the background.

In Firefox, go to Tools > Options > Content and click on Colours button.

Select grey for the "Background", and clear the checkboxes near "Allow pages to choose their own colours, instead of my selections above" and "Use system colours".

alt text

link|improve this answer
This one deserves a vote up for being the easiest. It works on almost every site. It forces you to change the text color though, and that makes it slightly inferior to a couple other methods. – Bruce Connor Aug 28 '10 at 17:44
@Bruce Connor: True. On the other hand, in may cases if you change the bg color, you will have to change fg color as well, to get reasonable contrast. So in practice having to change the text color may not be a big drawback. – sleske May 21 '11 at 14:19
feedback

The following Javascript will override the CSS and HTML background elements with white and the text elements with black on the current page, just paste it into your location or browser field:

javascript:(function(){var newSS,styles='* {
background-color:black !important;color:white !important}
:link,:link *{color:#99C0EB !important}
:visited,:visited *{color:#C398EB !important}';
if(document.createStyleSheet){document.createStyleSheet("javascript:'"+styles+"'");
}else{newSS=document.createElement('link');newSS.rel='stylesheet';
newSS.href='data:text/css,'+escape(styles);
document.getElementsByTagName("head")[0].appendChild(newSS);}})();
link|improve this answer
Ugh. Painful %20. – Hello71 Aug 27 '10 at 19:26
This turns all element's background black, and all elements (not just text) white. – Hello71 Aug 27 '10 at 19:28
1  
This really works well. I changed black to lightgrey, and removed the part that changes the text color, so the text is still black. And the result is actually pretty good. The only issue is that it changes the background of absolutely everything, not just what is white, so a lot of stuff get hidden (like the vote buttons here in SU). Is there a way to fix that? – Bruce Connor Aug 28 '10 at 17:54
1  
@hello71, somehow when I pasted this in my browser it changed all the spaces to %20. These have been removed. I said it changed all backgrounds black, I have edited it to now change only text backgrounds black, try again. – Dour High Arch Aug 30 '10 at 3:14
feedback

In the URL bar type about:config and navigate to this setting: browser.display.background_color

More info if you need it here.

link|improve this answer
1  
Changing this variable only works on webpages that don't specify a background color. I could only get it to work on google.com/firefox and on blank tabs. – Bruce Connor Aug 27 '10 at 0:17
1  
Firebug will allow you to change pages but you would have to do it each time you visited the site. Change only white backgrounds is kinda tough. – jer.salamon Aug 27 '10 at 0:36
1  
feedback

I discover lately this firefox addon Stylish. This will do what you want & much more !

link|improve this answer
feedback

I can't post this as a comment to Mehper C. Palavuzlar's answer, but if you use Firefox option like it's described there, it's recommended to use addon like "No Color" to quickly switch it on/off (because changing colors will cause various bugs on many sites). Alternatively, use Pentadactyl addon to be able to assign any action to any key (including any Firefox option toggling).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.