优化 [排除自带暗黑模式的网页 (beta)] 功能

This commit is contained in:
xiu2
2021-06-22 18:07:33 +08:00
parent 40f678c341
commit 97242c8a49
+9 -3
View File
@@ -1,6 +1,6 @@
// ==UserScript==
// @name 护眼模式
// @version 1.0.9
// @version 1.0.10
// @author X.I.U
// @description 最简单的全网通用护眼模式、夜间模式、暗黑模式
// @match *://*/*
@@ -149,17 +149,23 @@
clearInterval(timer); // 取消定时器(每 10 毫秒一次的)
setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 100 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜)
console.log('html:', window.getComputedStyle(document.lastChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor)
/*let rgbValueArry1 = window.getComputedStyle(document.body).backgroundColor.replace(/rgba|rgb|\(|\)| /g, '').split (','),
rgbValueArry2 = window.getComputedStyle(document.lastChild).backgroundColor.replace(/rgba|rgb|\(|\)| /g, '').split (','),
grayLevelBody = parseInt(rgbValueArry1[0]) + parseInt(rgbValueArry1[1]) + parseInt(rgbValueArry1[2]),
grayLevelHTML = parseInt(rgbValueArry2[0]) + parseInt(rgbValueArry2[1]) + parseInt(rgbValueArry2[2]);
console.log('html:', window.getComputedStyle(document.lastChild).backgroundColor, rgbValueArry2, grayLevelHTML, 'body:', window.getComputedStyle(document.body).backgroundColor, grayLevelBody)*/
if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgba(0, 0, 0, 0)') {
// 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果
document.lastChild.appendChild(document.createElement('style')).textContent = style_00;
} 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) {
} 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) {
// 如果是黑色 (等于0,0,0) 或深色 (小于 88,88,88),就停用本脚本滤镜
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
console.log('检测到当前网页自带暗黑模式,停用本脚本滤镜...')
document.getElementById('XIU2DarkMode').remove();
}
}
}, 100);
}, 150);
}
}, 10);
}