Greasy Fork

夜间模式调低对比度

夜间模式调低对比度。

当前为 2023-04-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         夜间模式调低对比度
// @author       ChatGPT    
// @version      2
// @description  夜间模式调低对比度。
// @match        *://*/*
// @run-at       document-end
// @namespace https://greasyfork.org/users/452911
// ==/UserScript==

(function() {
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        // 夜间模式已开启,修改背景色为 #FFFEFE
        document.querySelectorAll('*').forEach(function(el) {
            if (getComputedStyle(el).backgroundColor == 'rgb(255, 255, 255)') {
                el.style.backgroundColor = '#FFFEFE';
            }
        });
        // 添加黑色遮罩
        var overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.backgroundColor = '#000';
        overlay.style.top = '0';
        overlay.style.left = '0';
        overlay.style.zIndex = '999999';
        overlay.style.pointerEvents = 'none';
        overlay.style.opacity = '0.20';
        overlay.style.width = '100%';
        overlay.style.height = '100%';
        document.body.appendChild(overlay);
    }
})();