|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 护眼模式 |
3 | | -// @version 1.0.9 |
| 3 | +// @version 1.0.10 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 最简单的全网通用护眼模式、夜间模式、暗黑模式 |
6 | 6 | // @match *://*/* |
|
149 | 149 | clearInterval(timer); // 取消定时器(每 10 毫秒一次的) |
150 | 150 | setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 100 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜) |
151 | 151 | 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 | + |
152 | 158 | if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgba(0, 0, 0, 0)') { |
153 | 159 | // 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果 |
154 | 160 | 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) { |
156 | 162 | // 如果是黑色 (等于0,0,0) 或深色 (小于 88,88,88),就停用本脚本滤镜 |
157 | 163 | if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) |
158 | 164 | console.log('检测到当前网页自带暗黑模式,停用本脚本滤镜...') |
159 | 165 | document.getElementById('XIU2DarkMode').remove(); |
160 | 166 | } |
161 | 167 | } |
162 | | - }, 100); |
| 168 | + }, 150); |
163 | 169 | } |
164 | 170 | }, 10); |
165 | 171 | } |
|
0 commit comments