From e1e908301dd5dfda147ac76d4fff144a09a01b60 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:03:41 +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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index ee25976..2590e38 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 护眼模式 -// @version 1.0.6 +// @version 1.0.7 // @author X.I.U // @description 最简单的全网通用护眼模式、夜间模式、暗黑模式 // @match *://*/* @@ -143,23 +143,24 @@ style_Add.id = 'XIU2DarkMode'; document.lastChild.appendChild(style_Add).textContent = style; - // 为了避免 body 还没加载导致无法检查是否设置背景颜色的备用措施 - setTimeout(function(){ + // 为了避免 body 还没加载导致无法检查是否设置背景颜色 + let timer = setInterval(function(){ if (document.body) { - let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace ('rgb(', '').replace ('rgba(', '').replace (')', '').split (', '); + 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 (rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2] === "000") { + if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)') { // 如果 body 没有 CSS 背景颜色,那就需要添加一个,否则影响滤镜 document.lastChild.appendChild(document.createElement("style")).textContent = style_00; - } else if (grayLevel < 898989) { + } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || grayLevel < 898989) { if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) console.log('检测到当前网页自带暗黑模式,停用本脚本ing...') document.getElementById('XIU2DarkMode').remove(); } } + clearInterval(timer); } - }, 100); + }, 10); } })(); \ No newline at end of file