OLED Pure Black Background

Change websites' background to pure black for OLED screens

As of 2024-08-25. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         OLED Pure Black Background
// @namespace    (link unavailable)
// @version      1.0
// @description  Change websites' background to pure black for OLED screens
// @author       Patrick Gomes
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
  'use strict';

  // Apply styles globally to make the background pure black and text readable
  const css = `
    html, body {
      background-color: #000000 !important;
    }
    * {
      background-color: transparent !important;
      color: #b0c4de !important; /* LightSteelBlue for text */
      border-color: #444444 !important; /* Dark gray borders to replace any potentially invisible borders */
    }
    a {
      color: #ff0000 !important; /* Red for links */
    }
    img, video {
      filter: brightness(0.8) contrast(1.2); /* Adjust brightness and contrast of images and videos */
    }
  `;

  // Create a style element and add it to the document head
  const style = document.createElement('style');
  style.type = 'text/css';
  style.appendChild(document.createTextNode(css));
  document.head.appendChild(style);

  // Observe any changes in the DOM to ensure the styles are consistently applied
  const observer = new MutationObserver(function() {
    document.documentElement.style.backgroundColor = '#000000';
    document.body.style.backgroundColor = '#000000';
  });
  observer.observe(document, { childList: true, subtree: true });

})();