Skip to content

Commit 10c35bc

Browse files
committed
优化 代码
1 parent 4eeed97 commit 10c35bc

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

DarkMode.user.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 护眼模式
3-
// @version 1.1.2
3+
// @version 1.1.3
44
// @author X.I.U
55
// @description 简单有效的全网通用护眼模式、夜间模式、暗黑模式
66
// @match *://*/*
@@ -26,7 +26,7 @@
2626
['menu_runDuringTheDay', '白天保持开启 (比晚上亮一点点)', '白天保持开启', true],
2727
['menu_autoRecognition', '排除自带暗黑模式的网页 (beta)', '排除自带暗黑模式的网页 (beta)', true],
2828
['menu_darkModeType', '点击切换模式', '点击切换模式', 1]
29-
], menu_ID = [], websiteList = ['rarbgprx.org','fitgirl-repacks.site','masquerade.site'];
29+
], menu_ID = [], websiteList = ['rarbgprx.org','fitgirl-repacks.site','masquerade.site','www.gamersky.com'];
3030
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
3131
if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
3232
}
@@ -98,7 +98,7 @@
9898
let remove = false, style_Add = document.createElement('style'),
9999
hours = new Date().getHours(),
100100
style = ``,
101-
style_00 = `html {background-color: #ffffff;}`,
101+
style_00 = `html, body {background-color: #ffffff;}`,
102102
style_11 = `html {filter: brightness(80%) !important;}`,
103103
style_11_firefox = `html {filter: brightness(80%) !important; background-image: url();}`,
104104
style_12 = `html {filter: brightness(70%) !important;}`,
@@ -108,7 +108,7 @@
108108
style_22 = `html {filter: brightness(70%) sepia(30%) !important;}`,
109109
style_22_firefox = `html {filter: brightness(70%) sepia(30%) !important; background-image: url();}`,
110110
style_31 = `html {filter: invert(80%) !important;} img, video {filter: invert(1) !important;}`,
111-
style_31_firefox = `html {filter: invert(80%) !important;} img, video {filter: invert(1) !important; background-image: url();}`;
111+
style_31_firefox = `html {filter: invert(80%) !important; background-image: url();} img, video {filter: invert(1) !important;}`;
112112

113113
// Firefox 浏览器需要特殊对待
114114
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
@@ -141,6 +141,7 @@
141141
break;
142142
}
143143
style_Add.id = 'XIU2DarkMode';
144+
style_Add.type = 'text/css';
144145
//console.log(document,document.lastChild,document.querySelector('html'))
145146
if (document.lastChild) {
146147
document.lastChild.appendChild(style_Add).textContent = style;
@@ -212,6 +213,16 @@
212213
}
213214
}
214215
}, 3000);*/
216+
217+
// 解决远景论坛会清理掉前面插入的 CSS 样式的问题
218+
if (location.hostname === 'bbs.pcbeta.com') {
219+
let timer1 = setInterval(function(){
220+
if (!document.getElementById('XIU2DarkMode')) {
221+
document.lastChild.appendChild(style_Add).textContent = style;
222+
clearInterval(timer1);
223+
}
224+
}, 10);
225+
}
215226
}
216227

217228
// 获取背景颜色值

0 commit comments

Comments
 (0)