No White Background Color

Save your eyes by changing white background color

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @author      Tommy Reynolds <[email protected]>
// @description Save your eyes by changing white background color
// @grant	none
// @include	https?://*
// @name	No White Background Color
// @namespace	www.MegaCoder.com
// @run-at	document-end
// @version	1.0.2
// ==/UserScript==
// ============================================================================
// No White Background Color (NWBC) Script for GreaseMonkey
// Modified by [email protected]
// Modified by Wellen
// Originally by Howard Smith
// ---------------------------------------------------------------------------
// This was originally by Howard Smith and seems to be the best script which
// works on the most websites for getting the eyeball burning white background
// color most sites seem to use, to be a less harsh color of the users
// choice. Firstly I have no intention of taking the credit for this script as
// it is Howard's work from many years ago, but as I couldn't find it online
// easily I wanted to make sure it wasn't lost to the Internet ether so I
// thought I should post it here.
// ---------------------------------------------------------------------------
// I found it on:
//	http://superuser.com/questions/181214/change-the-white-background-in-webpages-to-another-color
// Must also thanks user The Bahamunt for not only posting it there, but for
// digging it out from an old computer! Hope everyone finds it useful and
// enjoys not having their eyes burnt at night!
// ---------------------------------------------------------------------------
// wellen
// ===========================================================================

(function()	{
	function noWhiteBackgroundColor()	{
		function changeBackgroundColor( x )	{
			// auto change colors too close to white
			var backgroundColorRGB =
				window.getComputedStyle( x, null ).backgroundColor;
			if(  backgroundColorRGB != "transparent" )	{
				// convert hex color to rgb color to compare
				var RGBValuesArray = backgroundColorRGB.match( /\d+/g );
				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 color you wish to
				// suppress white backgrounds with:
				// Default grey provided:
				// ===========================================================

				var red_needed	 = 230;
				var green_needed = 230;
				var blue_needed  = 230;

				if(
					red   >= 220							&&
					green >= 220							&&
					blue  >= 220
				)	{
					// This color is just too bright for this world
					if(
						red   >= 250						&&
						red   <= 255						&&
						green >= 250						&&
						green <= 255						&&
						blue  >= 250						&&
						blue  <= 255
					)	{
						red_needed	 += 0;
						green_needed += 0;
						blue_needed  += 0;
					} else if(
						red   >= 240						&&
						red   <= 255						&&
						green >= 240						&&
						green <= 255						&&
						blue  >= 240						&&
						blue  <= 255
					)	{
						red_needed	 += 6;
						green_needed += 3;
						blue_needed  += 0;
					} else if(
						red   >= 230						&&
						red   <= 255						&&
						green >= 230						&&
						green <= 255						&&
						blue  >= 230						&&
						blue  <= 255
					)	{
						red_needed	 += 10;
						green_needed += 5;
						blue_needed  += 0;
					} else if(
						red  >= 220							&&
						red  <= 255							&&
						green >= 220						&&
						green <= 255						&&
						blue  >= 220						&&
						blue  <= 255
					)	{
						red_needed   += 14;
						green_needed += 7;
						blue_needed  += 0;
					}
					// the background-color you want
					x.style.backgroundColor =
						"rgb( "			+
						red_needed		+
						", "			+
						green_needed	+
						", "			+
						blue_needed		+
						")";
				}
			}
		}
		// Check and possibly change background color on each element
		var allElements = document.getElementsByTagName( "*" );
		for( var i = 0; i < allElements.length; i++ )	{
			changeBackgroundColor( allElements[ i ] );
		}
	}
	window.addEventListener(
		"DOMContentLoaded",
		noWhiteBackgroundColor,
		false
	);
})();

// vim: nonu noet sw=4 ts=4 ai sm