Universal Dark Mode 2 (Chrome-like)

Chrome-like dark mode with adjusted colors for better readability.

Skript installieren?
Vom Ersteller vorgeschlagenes Skript

Ihnen könnte auch Universal Dark Mode 3 (Gray-Blue) gefallen.

Skript installieren

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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 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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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        Universal Dark Mode 2 (Chrome-like)
// @match       *://*/*
// @grant       none
// @version     1.5
// @author      almahmud & gpt
// @homepageURL    https://github.com/almahmudbd/universal-dark-mode
// @description Chrome-like dark mode with adjusted colors for better readability.
// @license     GPL-2.0
// @run-at      document-start
// @namespace https://greatest.deepsurf.us/users/1238578
// ==/UserScript==

const setDarkModeCookie = (value) => {
    document.cookie = `darkMode=${value}; path=/; max-age=2592000`; // 1 month expiration
};

const getDarkModeCookie = () => {
    const match = document.cookie.match(/darkMode=([^;]+)/);
    return match ? match[1] === 'true' : false; // Default to false
};

const isDarkMode = getDarkModeCookie();

// Set a base background color to prevent flash
document.documentElement.style.backgroundColor = "#263238"; // Dark grey-blue color for background

const applyDarkModeStyles = () => {
    const elements = document.querySelectorAll("*");
    elements.forEach((element) => {
        const computedStyle = window.getComputedStyle(element);
        const backgroundColor = computedStyle.backgroundColor;

        // Apply dark background to all elements except images and videos
        if (!backgroundColor.includes("rgba") && !backgroundColor.includes("transparent")) {
            element.style.backgroundColor = "#263238";
        }

        // Change text color to white
        element.style.color = "#ffffff"; 
    });
};

// Apply dark mode immediately if cookie is set
if (isDarkMode) {
    applyDarkModeStyles();
}

// Adjust colors function
const adjustColors = () => {
    const elements = document.querySelectorAll("*");
    elements.forEach((element) => {
        const computedStyle = window.getComputedStyle(element);
        
        if (computedStyle.backgroundColor !== "rgba(0, 0, 0, 0)" && 
            computedStyle.backgroundColor !== "transparent") {
            element.style.backgroundColor = "#263238"; // Dark grey-blue for background
        }
        
        element.style.color = "#ffffff"; // White text color
    });
};

// Adjust colors when the document is ready
document.onreadystatechange = () => {
    if (isDarkMode) {
        adjustColors();
    }
};

// Observe changes in the DOM
new MutationObserver(adjustColors).observe(document.body, { subtree: true, childList: true });