Skip to content

Commit 8ba568c

Browse files
committed
优化 代码
1 parent 7f8a140 commit 8ba568c

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

Autopage.user.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,12 +2580,12 @@
25802580

25812581
// [Discuz! 论坛] 隐藏帖子内的 [下一页] 按钮
25822582
function hidePgbtn() {
2583-
document.lastChild.appendChild(document.createElement('style')).textContent = '.pgbtn {display: none;}';
2583+
document.lastElementChild.appendChild(document.createElement('style')).textContent = '.pgbtn {display: none;}';
25842584
}
25852585
// [Discuz! 论坛] 图片模式列表样式预处理
25862586
function waterfallStyle() {
25872587
let width = document.querySelector('#waterfall > li:first-child').style.width;
2588-
document.lastChild.appendChild(document.createElement('style')).textContent = `#waterfall {height: auto !important; width: 100% !important;} #waterfall > li {width: ${width} !important; float: left !important; position: inherit !important; left: auto !important; top: auto !important;}`;
2588+
document.lastElementChild.appendChild(document.createElement('style')).textContent = `#waterfall {height: auto !important; width: 100% !important;} #waterfall > li {width: ${width} !important; float: left !important; position: inherit !important; left: auto !important; top: auto !important;}`;
25892589
}
25902590
// [Discuz! 论坛] 的插入前函数(加载图片,仅部分论坛)
25912591
function discuz_thread_functionBefore(pageElems) {
@@ -3634,7 +3634,7 @@
36343634
responseType: type,
36353635
overrideMimeType: mimeType,
36363636
headers: {
3637-
"Referer": location.href,
3637+
'Referer': location.href,
36383638
'Content-Type': (method === 'POST') ? 'application/x-www-form-urlencoded':''
36393639
},
36403640
timeout: 5000,
@@ -3738,7 +3738,7 @@
37383738
method: 'GET',
37393739
overrideMimeType: mimeType,
37403740
headers: {
3741-
"Referer": location.href
3741+
'Referer': location.href
37423742
},
37433743
timeout: 5000,
37443744
onload: function (response) {

DarkMode.user.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 护眼模式
3-
// @version 1.2.7
3+
// @version 1.2.8
44
// @author X.I.U
55
// @description 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式)
66
// @match *://*/*
@@ -29,7 +29,7 @@
2929
['menu_darkModeAuto', '护眼模式跟随浏览器', '护眼模式跟随浏览器', false],
3030
['menu_autoRecognition', '智能排除自带暗黑模式的网页 (beta)', '智能排除自带暗黑模式的网页 (beta)', true],
3131
['menu_forcedToEnable', '✅ 已强制当前网站启用护眼模式 (👆)', '❌ 未强制当前网站启用护眼模式 (👆)', []],
32-
['menu_darkModeType', '点击切换模式', '点击切换模式', 1],
32+
['menu_darkModeType', '点击切换模式', '点击切换模式', 2],
3333
['menu_customMode', '自定义当前模式', '自定义当前模式', true], ['menu_customMode1',,,'80|70'], ['menu_customMode2',,,'80|20|70|30'], ['menu_customMode3',,,'80']
3434
], menu_ID = [];
3535
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
@@ -309,14 +309,14 @@
309309
}
310310
style_Add.id = 'XIU2DarkMode';
311311
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;
315315
} else { // 发现个别网站速度太慢的话,就会出现脚本运行太早,连 html 标签都还没加载。。。
316316
let timer1 = setInterval(function(){ // 每 5 毫秒检查一下 html 是否已存在
317-
if (document.lastChild) {
317+
if (document.lastElementChild) {
318318
clearInterval(timer1); // 取消定时器
319-
document.lastChild.appendChild(style_Add).textContent = style;
319+
document.lastElementChild.appendChild(style_Add).textContent = style;
320320
}
321321
});
322322
}
@@ -331,13 +331,13 @@
331331
if (document.body) {
332332
clearInterval(timer); // 取消定时器(每 5 毫秒一次的)
333333
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)') {
336336
// 如果 body 没有 CSS 背景颜色,那就需要添加一个背景颜色,否则影响滤镜效果
337337
let style_Add2 = document.createElement('style');
338338
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)') {
341341
// 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
342342
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
343343
for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜
@@ -352,8 +352,8 @@
352352

353353
// 用来解决一些 CSS 加载缓慢的网站,可能会出现没有正确排除的问题,在没有找到更好的办法之前,先这样凑活着用
354354
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)') {
357357
// 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
358358
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
359359
for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜
@@ -371,8 +371,8 @@
371371

372372
// 用来解决一些 CSS 加载缓慢的网站,可能会出现没有正确排除的问题,在没有找到更好的办法之前,先这样凑活着用
373373
/*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) {
376376
// 如果是黑色 (等于0,0,0) 或深色 (小于 89,89,89),就停用本脚本滤镜
377377
if (menu_value('menu_autoRecognition')) { // 排除自带暗黑模式的网页 (beta)
378378
for (let i=0;i<websiteList.length;i++){ // 这些网站强制启用护眼模式滤镜
@@ -390,7 +390,7 @@
390390
if (location.hostname === 'bbs.pcbeta.com') {
391391
let timer1 = setInterval(function(){
392392
if (!document.getElementById('XIU2DarkMode')) {
393-
document.lastChild.appendChild(style_Add).textContent = style;
393+
document.lastElementChild.appendChild(style_Add).textContent = style;
394394
clearInterval(timer1);
395395
}
396396
});

0 commit comments

Comments
 (0)