Skip to content

Commit b539206

Browse files
committed
优化 位于 Cloudflare CDN 的人机验证界面且当浏览器是深色模式时,将自动停用脚本滤镜(CF又变化了,这次是更新判断方式)
1 parent 86f2efe commit b539206

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

DarkMode.user.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 护眼模式
44
// @name:zh-TW 護眼模式
55
// @name:ru Тёмный режим
6-
// @version 1.5.7
6+
// @version 1.5.8
77
// @author X.I.U
88
// @description Simple and effective network-wide eye protection mode (night mode, dark mode, black mode)
99
// @description:zh-CN 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式)
@@ -441,8 +441,8 @@
441441
clearInterval(timer); // 取消定时器(每 5 毫秒一次的)
442442
setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 150 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜)
443443
console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor)
444-
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)) {
445-
// 如果 body 没有 CSS 背景颜色(或是在资源页 且 浏览器为白天模式),那就需要添加一个背景颜色,否则影响滤镜效果
444+
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)) {
445+
// 如果不是在 (CF CDN 的人机验证页面 且 浏览器为暗黑模式) 或 body 没有 CSS 背景颜色(或是在资源页 且 浏览器为白天模式),那就需要添加一个背景颜色,否则影响滤镜效果
446446
let style_Add2 = document.createElement('style');
447447
style_Add2.id = 'XIU2DarkMode2';
448448
document.lastElementChild.appendChild(style_Add2).textContent = style_00;
@@ -492,7 +492,7 @@
492492

493493
// Cloudflare CDN 的人机验证界面特殊处理
494494
function checkChallenge() {
495-
return (window.matchMedia('(prefers-color-scheme: dark)').matches && document.querySelector('body>script[data-cf-beacon]'))
495+
return (window.matchMedia('(prefers-color-scheme: dark)').matches && document.querySelector('head>meta[content*="https://challenges.cloudflare.com"]') && document.querySelector('body>script[nonce]'))
496496
}
497497

498498
// 获取背景颜色值

0 commit comments

Comments
 (0)