Skip to content

Commit e1e9083

Browse files
committed
优化 [排除自带暗黑模式的网页 (beta)] 功能
1 parent 57d8446 commit e1e9083

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

DarkMode.user.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 护眼模式
3-
// @version 1.0.6
3+
// @version 1.0.7
44
// @author X.I.U
55
// @description 最简单的全网通用护眼模式、夜间模式、暗黑模式
66
// @match *://*/*
@@ -143,23 +143,24 @@
143143
style_Add.id = 'XIU2DarkMode';
144144
document.lastChild.appendChild(style_Add).textContent = style;
145145

146-
// 为了避免 body 还没加载导致无法检查是否设置背景颜色的备用措施
147-
setTimeout(function(){
146+
// 为了避免 body 还没加载导致无法检查是否设置背景颜色
147+
let timer = setInterval(function(){
148148
if (document.body) {
149-
let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace ('rgb(', '').replace ('rgba(', '').replace (')', '').split (', ');
149+
let rgbValueArry = window.getComputedStyle(document.body).backgroundColor.replace('rgb(', '').replace('rgba(', '').replace(')', '').split(', ');
150150
let grayLevel = rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2];
151151
console.log(grayLevel)
152152
console.log(window.getComputedStyle(document.body).backgroundColor)
153153

154-
if (rgbValueArry [0] + rgbValueArry [1] + rgbValueArry [2] === "000") {
154+
if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)') { // 如果 body 没有 CSS 背景颜色,那就需要添加一个,否则影响滤镜
155155
document.lastChild.appendChild(document.createElement("style")).textContent = style_00;
156-
} else if (grayLevel < 898989) {
156+
} else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || grayLevel < 898989) {
157157
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
158158
console.log('检测到当前网页自带暗黑模式,停用本脚本ing...')
159159
document.getElementById('XIU2DarkMode').remove();
160160
}
161161
}
162+
clearInterval(timer);
162163
}
163-
}, 100);
164+
}, 10);
164165
}
165166
})();

0 commit comments

Comments
 (0)