From b53920677c8e4d32614077ee8b49cbf2a58acc23 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Wed, 22 Apr 2026 19:00:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BD=8D=E4=BA=8E=20Cloud?= =?UTF-8?q?flare=20CDN=20=E7=9A=84=E4=BA=BA=E6=9C=BA=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=B8=94=E5=BD=93=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E6=98=AF=E6=B7=B1=E8=89=B2=E6=A8=A1=E5=BC=8F=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E8=87=AA=E5=8A=A8=E5=81=9C=E7=94=A8=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=BB=A4=E9=95=9C(CF=E5=8F=88=E5=8F=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E8=BF=99=E6=AC=A1=E6=98=AF=E6=9B=B4=E6=96=B0=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=96=B9=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DarkMode.user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index 33e868d..bc83ea2 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -3,7 +3,7 @@ // @name:zh-CN 护眼模式 // @name:zh-TW 護眼模式 // @name:ru Тёмный режим -// @version 1.5.7 +// @version 1.5.8 // @author X.I.U // @description Simple and effective network-wide eye protection mode (night mode, dark mode, black mode) // @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) @@ -441,8 +441,8 @@ clearInterval(timer); // 取消定时器(每 5 毫秒一次的) setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 150 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜) console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) - if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgba(0, 0, 0, 0)' && !(document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - // 如果 body 没有 CSS 背景颜色(或是在资源页 且 浏览器为白天模式),那就需要添加一个背景颜色,否则影响滤镜效果 + if (!(checkChallenge()) && window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgba(0, 0, 0, 0)' && !(document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches)) { + // 如果不是在 (CF CDN 的人机验证页面 且 浏览器为暗黑模式) 或 body 没有 CSS 背景颜色(或是在资源页 且 浏览器为白天模式),那就需要添加一个背景颜色,否则影响滤镜效果 let style_Add2 = document.createElement('style'); style_Add2.id = 'XIU2DarkMode2'; document.lastElementChild.appendChild(style_Add2).textContent = style_00; @@ -492,7 +492,7 @@ // Cloudflare CDN 的人机验证界面特殊处理 function checkChallenge() { - return (window.matchMedia('(prefers-color-scheme: dark)').matches && document.querySelector('body>script[data-cf-beacon]')) + return (window.matchMedia('(prefers-color-scheme: dark)').matches && document.querySelector('head>meta[content*="https://challenges.cloudflare.com"]') && document.querySelector('body>script[nonce]')) } // 获取背景颜色值