|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 护眼模式 |
3 | | -// @version 1.2.7 |
| 3 | +// @version 1.2.8 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) |
6 | 6 | // @match *://*/* |
|
29 | 29 | ['menu_darkModeAuto', '护眼模式跟随浏览器', '护眼模式跟随浏览器', false], |
30 | 30 | ['menu_autoRecognition', '智能排除自带暗黑模式的网页 (beta)', '智能排除自带暗黑模式的网页 (beta)', true], |
31 | 31 | ['menu_forcedToEnable', '✅ 已强制当前网站启用护眼模式 (👆)', '❌ 未强制当前网站启用护眼模式 (👆)', []], |
32 | | - ['menu_darkModeType', '点击切换模式', '点击切换模式', 1], |
| 32 | + ['menu_darkModeType', '点击切换模式', '点击切换模式', 2], |
33 | 33 | ['menu_customMode', '自定义当前模式', '自定义当前模式', true], ['menu_customMode1',,,'80|70'], ['menu_customMode2',,,'80|20|70|30'], ['menu_customMode3',,,'80'] |
34 | 34 | ], menu_ID = []; |
35 | 35 | for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值 |
|
309 | 309 | } |
310 | 310 | style_Add.id = 'XIU2DarkMode'; |
311 | 311 | style_Add.type = 'text/css'; |
312 | | - //console.log(document,document.lastChild,document.querySelector('html')) |
313 | | - if (document.lastChild) { |
314 | | - document.lastChild.appendChild(style_Add).textContent = style; |
| 312 | + console.log(document,document.lastElementChild,document.querySelector('html')) |
| 313 | + if (document.lastElementChild) { |
| 314 | + document.lastElementChild.appendChild(style_Add).textContent = style; |
315 | 315 | } else { // 发现个别网站速度太慢的话,就会出现脚本运行太早,连 html 标签都还没加载。。。 |
316 | 316 | let timer1 = setInterval(function(){ // 每 5 毫秒检查一下 html 是否已存在 |
317 | | - if (document.lastChild) { |
| 317 | + if (document.lastElementChild) { |
318 | 318 | clearInterval(timer1); // 取消定时器 |
319 | | - document.lastChild.appendChild(style_Add).textContent = style; |
| 319 | + document.lastElementChild.appendChild(style_Add).textContent = style; |
320 | 320 | } |
321 | 321 | }); |
322 | 322 | } |
|
331 | 331 | if (document.body) { |
332 | 332 | clearInterval(timer); // 取消定时器(每 5 毫秒一次的) |
333 | 333 | setTimeout(function(){ // 为了避免太快 body 的 CSS 还没加载上,先延迟 150 毫秒(缺点就是可能会出现短暂一闪而过的暗黑滤镜) |
334 | | - console.log('[护眼模式] html:', window.getComputedStyle(document.lastChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
335 | | - if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgba(0, 0, 0, 0)') { |
| 334 | + console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
| 335 | + if (window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastElementChild).backgroundColor === 'rgba(0, 0, 0, 0)') { |
336 | 336 | // 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果 |
337 | 337 | let style_Add2 = document.createElement('style'); |
338 | 338 | style_Add2.id = 'XIU2DarkMode2'; |
339 | | - document.lastChild.appendChild(style_Add2).textContent = style_00; |
340 | | - } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || getColorValue(document.body) > 0 && getColorValue(document.body) < 898989 || getColorValue(document.lastChild) > 0 && getColorValue(document.lastChild) < 898989 || window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgb(0, 0, 0)') { |
| 339 | + document.lastElementChild.appendChild(style_Add2).textContent = style_00; |
| 340 | + } else if (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)') { |
341 | 341 | // 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜 |
342 | 342 | if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) |
343 | 343 | for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜 |
|
352 | 352 |
|
353 | 353 | // 用来解决一些 CSS 加载缓慢的网站,可能会出现没有正确排除的问题,在没有找到更好的办法之前,先这样凑活着用 |
354 | 354 | setTimeout(function(){ |
355 | | - console.log('[护眼模式] html:', window.getComputedStyle(document.lastChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
356 | | - if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || getColorValue(document.body) > 0 && getColorValue(document.body) < 898989 || getColorValue(document.lastChild) > 0 && getColorValue(document.lastChild) < 898989 || window.getComputedStyle(document.body).backgroundColor === 'rgba(0, 0, 0, 0)' && window.getComputedStyle(document.lastChild).backgroundColor === 'rgb(0, 0, 0)') { |
| 355 | + console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
| 356 | + if (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)') { |
357 | 357 | // 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜 |
358 | 358 | if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) |
359 | 359 | for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜 |
|
371 | 371 |
|
372 | 372 | // 用来解决一些 CSS 加载缓慢的网站,可能会出现没有正确排除的问题,在没有找到更好的办法之前,先这样凑活着用 |
373 | 373 | /*setTimeout(function(){ |
374 | | - console.log('[护眼模式] html:', window.getComputedStyle(document.lastChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
375 | | - if (window.getComputedStyle(document.body).backgroundColor === 'rgb(0, 0, 0)' || getColorValue(document.body) > 0 && getColorValue(document.body) < 898989 || getColorValue(document.lastChild) > 0 && getColorValue(document.lastChild) < 898989) { |
| 374 | + console.log('[护眼模式] html:', window.getComputedStyle(document.lastElementChild).backgroundColor, 'body:', window.getComputedStyle(document.body).backgroundColor) |
| 375 | + if (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) { |
376 | 376 | // 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜 |
377 | 377 | if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta) |
378 | 378 | for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜 |
|
390 | 390 | if (location.hostname === 'bbs.pcbeta.com') { |
391 | 391 | let timer1 = setInterval(function(){ |
392 | 392 | if (!document.getElementById('XIU2DarkMode')) { |
393 | | - document.lastChild.appendChild(style_Add).textContent = style; |
| 393 | + document.lastElementChild.appendChild(style_Add).textContent = style; |
394 | 394 | clearInterval(timer1); |
395 | 395 | } |
396 | 396 | }); |
|
0 commit comments