Skip to content

Commit 97242c8

Browse files
committed
优化 [排除自带暗黑模式的网页 (beta)] 功能
1 parent 40f678c commit 97242c8

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

DarkMode.user.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 护眼模式
3-
// @version 1.0.9
3+
// @version 1.0.10
44
// @author X.I.U
55
// @description 最简单的全网通用护眼模式、夜间模式、暗黑模式
66
// @match *://*/*
@@ -149,17 +149,23 @@
149149
clearInterval(timer); // 取消定时器(每 10 毫秒一次的)
150150
setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 100 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜)
151151
console.log('html:', window.getComputedStyle(document.lastChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor)
152+
/*let rgbValueArry1 = window.getComputedStyle(document.body).backgroundColor.replace(/rgba|rgb|\(|\)| /g, '').split (','),
153+
rgbValueArry2 = window.getComputedStyle(document.lastChild).backgroundColor.replace(/rgba|rgb|\(|\)| /g, '').split (','),
154+
grayLevelBody = parseInt(rgbValueArry1[0]) + parseInt(rgbValueArry1[1]) + parseInt(rgbValueArry1[2]),
155+
grayLevelHTML = parseInt(rgbValueArry2[0]) + parseInt(rgbValueArry2[1]) + parseInt(rgbValueArry2[2]);
156+
console.log('html:', window.getComputedStyle(document.lastChild).backgroundColor, rgbValueArry2, grayLevelHTML, 'body:', window.getComputedStyle(document.body).backgroundColor, grayLevelBody)*/
157+
152158
if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgba(0, 0, 0, 0)') {
153159
// 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果
154160
document.lastChild.appendChild(document.createElement('style')).textContent = style_00;
155-
} else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || window.getComputedStyle(document.body).backgroundColor.replace(/rgb|rgba|\(|\)|,| /g, '') < 898989 || window.getComputedStyle(document.lastChild).backgroundColor.replace(/rgb|rgba|\(|\)|,| /g, '') < 898989) {
161+
} else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || window.getComputedStyle(document.body).backgroundColor != 'rgba(0, 0, 0, 0)' && parseInt(window.getComputedStyle(document.body).backgroundColor.replace(/rgba|rgb|\(|\)|,| /g, '')) < 898989 || window.getComputedStyle(document.lastChild).backgroundColor != 'rgba(0, 0, 0, 0)' && parseInt(window.getComputedStyle(document.lastChild).backgroundColor.replace(/rgba|rgb|\(|\)|,| /g, '')) < 898989) {
156162
// 如果是黑色 (等于0,0,0) 或深色 (小于 88,88,88),就停用本脚本滤镜
157163
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
158164
console.log('检测到当前网页自带暗黑模式,停用本脚本滤镜...')
159165
document.getElementById('XIU2DarkMode').remove();
160166
}
161167
}
162-
}, 100);
168+
}, 150);
163169
}
164170
}, 10);
165171
}

0 commit comments

Comments
 (0)