Pure Black Background Enhanced

Change websites to pure black background with customization options

目前为 2024-09-06 提交的版本。查看 最新版本

// ==UserScript==
// @name         Pure Black Background Enhanced
// @namespace    (link unavailable)
// @version      0.03
// @description  Change websites to pure black background with customization options
// @match        *://*/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @run-at       document-start
// ==/UserScript==

(function() {
  'use strict';

  // Load settings
  const cfg = {
    bgColor: GM_getValue("bgColor", "#000000"),
    textColor: GM_getValue("textColor", "#8cffb5"),
    linkColor: GM_getValue("linkColor", "#ff66ff"),
    imgBrightness: GM_getValue("imgBrightness", 0.8),
    imgContrast: GM_getValue("imgContrast", 1.2)
  };

  // CSS styles
  const css = `
    html, body {
      background-color: ${cfg.bgColor} !important;
      color: ${cfg.textColor} !important;
    }
    * {
      background-color: rgba(0, 0, 0, 0.5) !important;
      border-color: #444444 !important;
    }
    a {
      color: ${cfg.linkColor} !important;
    }
    img {
      filter: brightness(${cfg.imgBrightness}) contrast(${cfg.imgContrast});
    }
    video, .html5-video-container video {
      filter: none !important;
    }
  `;

  // Apply styles
  const style = document.createElement('style');
  style.type = 'text/css';
  style.appendChild(document.createTextNode(css));
  document.head.appendChild(style);

  // Mutation observer to handle dynamic content
  const observer = new MutationObserver(function() {
    document.documentElement.style.backgroundColor = cfg.bgColor;
    document.body.style.backgroundColor = cfg.bgColor;
  });
  observer.observe(document, { childList: true, subtree: true });

  // Menu commands for customization
  if (typeof GM_registerMenuCommand !== "undefined") {
    GM_registerMenuCommand("Customize Background Color", () => {
      const color = prompt("Enter background color:", cfg.bgColor);
      if (color) {
        GM_setValue("bgColor", color);
        location.reload();
      }
    });
    GM_registerMenuCommand("Customize Text Color", () => {
      const color = prompt("Enter text color:", cfg.textColor);
      if (color) {
        GM_setValue("textColor", color);
        location.reload();
      }
    });
    GM_registerMenuCommand("Customize Link Color", () => {
      const color = prompt("Enter link color:", cfg.linkColor);
      if (color) {
        GM_setValue("linkColor", color);
        location.reload();
      }
    });
    GM_registerMenuCommand("Customize Image Brightness", () => {
      const brightness = prompt("Enter image brightness (0-1):", cfg.imgBrightness);
      if (brightness) {
        GM_setValue("imgBrightness", parseFloat(brightness));
        location.reload();
      }
    });
    GM_registerMenuCommand("Customize Image Contrast", () => {
      const contrast = prompt("Enter image contrast (1-2):", cfg.imgContrast);
      if (contrast) {
        GM_setValue("imgContrast", parseFloat(contrast));
        location.reload();
      }
    });
  }
})();