Skip to content

Commit 86f2efe

Browse files
committed
优化 位于 Cloudflare CDN 的人机验证界面且当浏览器是深色模式时,将自动停用脚本滤镜(CF会自动适配为黑色背景无需再对背景颜色进行额外判断)
1 parent 1562fd9 commit 86f2efe

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

DarkMode.user.js

Lines changed: 10 additions & 5 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.6
6+
// @version 1.5.7
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 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式)
@@ -447,8 +447,8 @@
447447
style_Add2.id = 'XIU2DarkMode2';
448448
document.lastElementChild.appendChild(style_Add2).textContent = style_00;
449449

450-
} else if ((document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches) || (document.querySelector('html[class*=dark], html[data-dark-theme*=dark], html[data-theme*=dark], html[data-color-mode*=dark], body[class*=dark]')) || (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)') || (getColorValue(document.body) > 0 && getColorValue(document.body) < 898989) || (getColorValue(document.lastElementChild) > 0 && getColorValue(document.lastElementChild) < 898989) || (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgb(0, 0, 0)')) {
451-
// 如果是在资源页 且 浏览器为暗黑模式,或 html/body 元素包含 dark 标识,或底色为黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
450+
} else if (checkChallenge() || (document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches) || (document.querySelector('html[class*=dark], html[data-dark-theme*=dark], html[data-theme*=dark], html[data-color-mode*=dark], body[class*=dark]')) || (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)') || (getColorValue(document.body) > 0 && getColorValue(document.body) < 898989) || (getColorValue(document.lastElementChild) > 0 && getColorValue(document.lastElementChild) < 898989) || (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgb(0, 0, 0)')) {
451+
// 如果是在 (CF CDN 的人机验证页面 且 浏览器为暗黑模式) 或 (资源页 且 浏览器为暗黑模式),或 html/body 元素包含 dark 标识,或底色为黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
452452
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
453453
for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜
454454
if (websiteList[i] === location.host) return
@@ -463,8 +463,8 @@
463463
// 用来解决一些 CSS 加载缓慢的网站,可能会出现没有正确排除的问题,在没有找到更好的办法之前,先这样凑活着用
464464
setTimeout(function(){
465465
console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor)
466-
if ((document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches) || (document.querySelector('html[class*=dark], html[data-dark-theme*=dark], html[data-theme*=dark], html[data-color-mode*=dark], body[class*=dark]')) || (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)') || (getColorValue(document.body) > 0 && getColorValue(document.body) < 898989) || (getColorValue(document.lastElementChild) > 0 && getColorValue(document.lastElementChild) < 898989) || (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgb(0, 0, 0)')) {
467-
// 如果是在资源页 且 浏览器为暗黑模式,或 html/body 元素包含 dark 标识,或底色为黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
466+
if (checkChallenge() || (document.querySelector('head>meta[name="color-scheme"],head>link[href^="resource:"]') && window.matchMedia('(prefers-color-scheme: dark)').matches) || (document.querySelector('html[class*=dark], html[data-dark-theme*=dark], html[data-theme*=dark], html[data-color-mode*=dark], body[class*=dark]')) || (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)') || (getColorValue(document.body) > 0 && getColorValue(document.body) < 898989) || (getColorValue(document.lastElementChild) > 0 && getColorValue(document.lastElementChild) < 898989) || (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgb(0, 0, 0)')) {
467+
// 如果是在 (CF CDN 的人机验证页面 且 浏览器为暗黑模式) 或 (资源页 且 浏览器为暗黑模式),或 html/body 元素包含 dark 标识,或底色为黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
468468
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
469469
for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜
470470
if (websiteList[i] === location.host) return
@@ -490,6 +490,11 @@
490490
}
491491
}
492492

493+
// Cloudflare CDN 的人机验证界面特殊处理
494+
function checkChallenge() {
495+
return (window.matchMedia('(prefers-color-scheme: dark)').matches && document.querySelector('body>script[data-cf-beacon]'))
496+
}
497+
493498
// 获取背景颜色值
494499
function getColorValue(e) {
495500
let rgbValueArry = window.getComputedStyle(e).backgroundColor.replace(/rgba|rgb|\(|\)| /g, '').split (',')

0 commit comments

Comments
 (0)