From 460436a2259de5955b208b0768a1208b3b7ccfdb Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20[=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E6=9A=97=E9=BB=91=E6=A8=A1=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E7=BD=91=E9=A1=B5=20(beta)]=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DarkMode.user.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index 2590e38..c01ff50 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -146,16 +146,14 @@ // 为了避免 body 还没加载导致无法检查是否设置背景颜色 let timer = setInterval(function(){ if (document.body) { - let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace('rgb(', '').replace('rgba(', '').replace(')', '').split(', '); - let grayLevel = rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2]; - console.log(grayLevel) console.log(window.getComputedStyle(document.body).backgroundColor) - - if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)') { // 如果 body 没有 CSS 背景颜色,那就需要添加一个,否则影响滤镜 - document.lastChild.appendChild(document.createElement("style")).textContent = style_00; - } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || grayLevel < 898989) { + if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)') { + // 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果 + document.lastChild.appendChild(document.createElement('style')).textContent = style_00; + } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || window.getComputedStyle(document.body).backgroundColor.replace(/rgb|rgba|\(|\)|,| /g, '') < 898989) { + // 如果是黑色 (等于0,0,0) 或深色 (小于 88,88,88),就停用本脚本滤镜 if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) - console.log('检测到当前网页自带暗黑模式,停用本脚本ing...') + console.log('检测到当前网页自带暗黑模式,停用本脚本滤镜...') document.getElementById('XIU2DarkMode').remove(); } }