I recently replaced my old computer and needed to set up Firefox again. One of the main things I wished to reinstate was a Greasemonkey script which changed the background colour of any website.
I was therefore a little annoyed that I couldn't find the one I'd used before. Long story short - here is the one from my old PC.
This script is not my own work
All credit must go to Howard Smith. This was originally posted on Userscripts.org which now appears to be unavailable.
Simply create a new user script in Greasemonkey and paste the following in:
(function () {
function noWhiteBackgroundColor() {
function changeBackgroundColor(x) { // Auto change colors too close to white
var backgroundColorRGB = window.getComputedStyle(x, null).backgroundColor; // Get background-color
if(backgroundColorRGB != "transparent") { // Convert hexadecimal color to RGB color to compare
var RGBValuesArray = backgroundColorRGB.match(/\d+/g); // Get RGB values
var red = RGBValuesArray[0];
var green = RGBValuesArray[1];
var blue = RGBValuesArray[2];
// ============================================================================
// Set the base colors you require:
// Use: http://www.colorpicker.com
// to find the RGB values of the base colour you wish to
// suppress white backgrounds with:
// Default gray provided:
// ============================================================================
var red_needed = 220;
var green_needed = 220;
var blue_needed = 255;
if (red>=220 && green>=220 && blue>=220) { // White range detection
if (red>=250 && red<=255 && green>=250 && green<=255 && blue>=250 && blue<=255) {
red_needed += 0;
green_needed += 0; }
else if (red>=240 && red<=255 && green>=240 && green<=255 && blue>=240 && blue<=255) {
red_needed += 6;
green_needed += 3; }
else if (red>=230 && red<=255 && green>=230 && green<=255 && blue>=230 && blue<=255) {
red_needed += 10;
green_needed += 5; }
else if (red>=220 && red<=255 && green>=220 && green<=255 && blue>=220 && blue<=255) {
red_needed += 14;
green_needed += 7; }
x.style.backgroundColor = "rgb( " + red_needed + ", " + green_needed + ", " + blue_needed + ")"; // The background-color you want
}
}
}
var allElements=document.getElementsByTagName("*"); // Get all elements on a page
for(var i=0; i<allElements.length; i++) {
changeBackgroundColor(allElements[i]);}
}
window.addEventListener("DOMContentLoaded",noWhiteBackgroundColor, false);
})();
I have been using this for almost two years and cannot think of any websites which it has failed to change the white background.
Various addons can do sort of do this - e.g. https://addons.mozilla.org/En-us/firefox/addon/blank-your-monitor-easy-readin/
– Wilf – 2016-01-10T18:02:23.8905I 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 – 2010-08-27T14:56:54.147
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. – Malabarba – 2010-08-28T17:17:17.640