From 4d2bf9a7cdb421556c33edb95a1175261598bb55 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Wed, 23 Jun 2021 09:43:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E4=B8=AA=E5=88=AB?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6=E5=A4=AA=E6=85=A2=E7=9A=84?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E6=BB=A4=E9=95=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DarkMode.user.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index 6d1ca54..e28dc9a 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 护眼模式 -// @version 1.1.0 +// @version 1.1.1 // @author X.I.U // @description 简单有效的全网通用护眼模式、夜间模式、暗黑模式 // @match *://*/* @@ -141,7 +141,17 @@ break; } style_Add.id = 'XIU2DarkMode'; - document.lastChild.appendChild(style_Add).textContent = style; + //console.log(document,document.lastChild,document.querySelector('html')) + if (document.lastChild) { + document.lastChild.appendChild(style_Add).textContent = style; + } else { // 发现个别网站速度太慢的话,就会出现脚本运行太早,连 html 标签都还没加载。。。 + let timer1 = setInterval(function(){ // 每 5 毫秒检查一下 html 是否已存在 + if (document.lastChild) { + clearInterval(timer1); // 取消定时器 + document.lastChild.appendChild(style_Add).textContent = style; + } + }, 5); + } // 为了避免 body 还没加载导致无法检查是否设置背景颜色 let timer = setInterval(function(){ // 每 10 毫秒检查一下 body 是否已存在