Pure Black Background with Visible Text and Links

Apply a pure black background to any website, ensure text visibility, and differentiate links

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Pure Black Background with Visible Text and Links
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Apply a pure black background to any website, ensure text visibility, and differentiate links
// @author       Patrick Gomes
// @match        *://*/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Apply pure black background and ensure text visibility
    const applyStyles = () => {
        $('*').each(function() {
            const color = $(this).css('color');
            if (color) {
                const rgb = color.match(/\d+/g);
                if (rgb) {
                    const brightness = (parseInt(rgb[0]) * 299 + parseInt(rgb[1]) * 587 + parseInt(rgb[2]) * 114) / 1000;
                    if (brightness < 128) {
                        $(this).css('color', '#FFFFFF');
                    }
                }
            }
            $(this).css('background-color', '#000000');
        });

        // Style links and visited links
        $('a:link').css('color', '#1E90FF'); // DodgerBlue for unvisited links
        $('a:visited').css('color', '#551A8B'); // Purple for visited links
    };

    // Initial style application
    applyStyles();

    // Observe for dynamically loaded content
    const observer = new MutationObserver(applyStyles);
    observer.observe(document.body, { childList: true, subtree: true });
})();