Pure Black Background with Visible Text and Links

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
})();