From 4a27ef430df54e7e6a978f5ca633984d93a89d18 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Sat, 19 Jun 2021 13:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DarkMode.user.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index 6fc7eca..2355f03 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 护眼模式 -// @version 1.0.3 +// @version 1.0.4 // @author X.I.U // @description 最简单的全网通用护眼模式、夜间模式、暗黑模式 // @match *://*/* @@ -98,7 +98,7 @@ style_Add = document.createElement('style'), hours = new Date().getHours(), style = ``, - style_00 = `body {background-color: #ffffff;}`, + style_00 = `html {background-color: #ffffff;}`, style_11 = `html {filter: brightness(80%) !important;}`, style_11_firefox = `html {filter: brightness(80%) !important; background-image: url();}`, style_12 = `html {filter: brightness(70%) !important;}`, @@ -111,11 +111,12 @@ style_31_firefox = `html {filter: invert(80%) !important;} img, video {filter: invert(1) !important; background-image: url();}`; // 判断网页是否没有设置背景颜色(没有背景颜色会导致滤镜对背景颜色无效) - if (document.body) { + /*if (document.body) { + console.log(window.getComputedStyle(document.body).backgroundColor) rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace ('rgb(', '').replace ('rgba(', '').replace (')', '').split (', '); grayLevel = rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2]; if (grayLevel === "000") style += style_00 - } + }*/ // Firefox 浏览器需要特殊对待 if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { @@ -161,18 +162,18 @@ } // 为了避免 body 还没加载导致无法检查是否设置背景颜色的备用措施 - if (!grayLevel) { - let timer2 = setInterval(function(){ - if (document.body) { - let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace ('rgb(', '').replace ('rgba(', '').replace (')', '').split (', '), - style_Add1 = document.createElement('style'); - if (rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2] === "000") { - style_Add1.innerHTML = style_00; - document.head.appendChild(style_Add1); - } - clearInterval(timer2); + //if (!grayLevel) { + setTimeout(function(){ + if (document.body) { + console.log(window.getComputedStyle(document.body).backgroundColor) + let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace ('rgb(', '').replace ('rgba(', '').replace (')', '').split (', '), + style_Add1 = document.createElement('style'); + if (rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2] === "000") { + style_Add1.innerHTML = style_00; + document.head.appendChild(style_Add1); } - }, 1); - } + } + }, 100); + //} } })(); \ No newline at end of file