Skip to content

Commit 9ca2977

Browse files
committed
新增 [自定义模式颜色]
1 parent 660d7b2 commit 9ca2977

1 file changed

Lines changed: 54 additions & 12 deletions

File tree

DarkMode.user.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 护眼模式
3-
// @version 1.1.3
3+
// @version 1.1.4
44
// @author X.I.U
55
// @description 简单有效的全网通用护眼模式、夜间模式、暗黑模式
66
// @match *://*/*
@@ -25,7 +25,10 @@
2525
var menu_ALL = [
2626
['menu_runDuringTheDay', '白天保持开启 (比晚上亮一点点)', '白天保持开启', true],
2727
['menu_autoRecognition', '排除自带暗黑模式的网页 (beta)', '排除自带暗黑模式的网页 (beta)', true],
28-
['menu_darkModeType', '点击切换模式', '点击切换模式', 1]
28+
['menu_darkModeType', '点击切换模式', '点击切换模式', 1],
29+
['menu_customMode1', '自定义模式 1', '自定义模式 1', '80|70'],
30+
['menu_customMode2', '自定义模式 2', '自定义模式 2', '80|20|70|30'],
31+
['menu_customMode3', '自定义模式 3', '自定义模式 3', '80']
2932
], menu_ID = [], websiteList = ['rarbgprx.org','fitgirl-repacks.site','masquerade.site','www.gamersky.com'];
3033
for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值
3134
if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])};
@@ -49,6 +52,15 @@
4952
GM_setValue('menu_darkModeType', menu_ALL[i][3]);
5053
}
5154
menu_ID[i] = GM_registerMenuCommand(`🔄 [ ${menu_ALL[i][3]} ] ${menu_ALL[i][1]}`, function(){menu_toggle(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
55+
} else if (menu_ALL[i][0] === 'menu_customMode1') {
56+
GM_setValue('menu_customMode1', menu_ALL[i][3]);
57+
menu_ID[i] = GM_registerMenuCommand(`1️⃣ ${menu_ALL[i][1]}`, function(){menu_customMode(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
58+
} else if (menu_ALL[i][0] === 'menu_customMode2') {
59+
GM_setValue('menu_customMode2', menu_ALL[i][3]);
60+
menu_ID[i] = GM_registerMenuCommand(`2️⃣ ${menu_ALL[i][1]}`, function(){menu_customMode(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
61+
} else if (menu_ALL[i][0] === 'menu_customMode3') {
62+
GM_setValue('menu_customMode3', menu_ALL[i][3]);
63+
menu_ID[i] = GM_registerMenuCommand(`3️⃣ ${menu_ALL[i][1]}`, function(){menu_customMode(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`)});
5264
} else {
5365
menu_ID[i] = GM_registerMenuCommand(`🌝 [ ${menu_ALL[i][3]?'√':'×'} ] ${menu_ALL[i][1]}`, function(){menu_switch(`${menu_ALL[i][3]}`,`${menu_ALL[i][0]}`,`${menu_ALL[i][2]}`)});
5466
}
@@ -57,6 +69,33 @@
5769
}
5870

5971

72+
function menu_customMode(menu_status, Name) {
73+
let newMods, tip, defaults;
74+
switch(Name) {
75+
case 'menu_customMode1':
76+
tip = '自定义 [模式 1],刷新网页后生效~\n格式:亮度 (白天)|亮度 (晚上)\n默认:80|70(均为百分比 1~100,不需要 % 符号)'
77+
defaults = '80|70'
78+
break;
79+
case 'menu_customMode2':
80+
tip = '自定义 [模式 2],刷新网页后生效~\n格式:亮度 (白天)|暖色 (白天)|亮度 (晚上)|暖色 (晚上)\n默认:80|20|70|30(均为百分比 1~100,不需要 % 符号)'
81+
defaults = '80|20|70|30'
82+
break;
83+
case 'menu_customMode3':
84+
tip = '自定义 [模式 3],刷新网页后生效~\n格式:反色\n默认:80(均为百分比 50~100,不需要 % 符号)'
85+
defaults = '80'
86+
break;
87+
}
88+
newMods = prompt(tip, GM_getValue(`${Name}`));
89+
if (newMods === '') {
90+
GM_setValue(`${Name}`, defaults);
91+
registerMenuCommand(); // 重新注册脚本菜单
92+
} else if (newMods != null) {
93+
GM_setValue(`${Name}`, newMods);
94+
registerMenuCommand(); // 重新注册脚本菜单
95+
}
96+
}
97+
98+
6099
// 切换暗黑模式
61100
function menu_toggle(menu_status, Name) {
62101
menu_status = parseInt(menu_status)
@@ -97,18 +136,21 @@
97136
function addStyle() {
98137
let remove = false, style_Add = document.createElement('style'),
99138
hours = new Date().getHours(),
139+
style_10 = GM_getValue('menu_customMode1').split('|'),
140+
style_20 = GM_getValue('menu_customMode2').split('|'),
141+
style_30 = GM_getValue('menu_customMode3').split('|'),
100142
style = ``,
101143
style_00 = `html, body {background-color: #ffffff;}`,
102-
style_11 = `html {filter: brightness(80%) !important;}`,
103-
style_11_firefox = `html {filter: brightness(80%) !important; background-image: url();}`,
104-
style_12 = `html {filter: brightness(70%) !important;}`,
105-
style_12_firefox = `html {filter: brightness(70%) !important; background-image: url();}`,
106-
style_21 = `html {filter: brightness(80%) sepia(20%) !important;}`,
107-
style_21_firefox = `html {filter: brightness(80%) sepia(20%) !important; background-image: url();}`,
108-
style_22 = `html {filter: brightness(70%) sepia(30%) !important;}`,
109-
style_22_firefox = `html {filter: brightness(70%) sepia(30%) !important; background-image: url();}`,
110-
style_31 = `html {filter: invert(80%) !important;} img, video {filter: invert(1) !important;}`,
111-
style_31_firefox = `html {filter: invert(80%) !important; background-image: url();} img, video {filter: invert(1) !important;}`;
144+
style_11 = `html {filter: brightness(${style_10[0]}%) !important;}`,
145+
style_11_firefox = `html {filter: brightness(${style_10[0]}%) !important; background-image: url();}`,
146+
style_12 = `html {filter: brightness(${style_10[1]}%) !important;}`,
147+
style_12_firefox = `html {filter: brightness(${style_10[1]}%) !important; background-image: url();}`,
148+
style_21 = `html {filter: brightness(${style_20[0]}%) sepia(${style_20[1]}%) !important;}`,
149+
style_21_firefox = `html {filter: brightness(${style_20[0]}%) sepia(${style_20[1]}%) !important; background-image: url();}`,
150+
style_22 = `html {filter: brightness(${style_20[2]}%) sepia(${style_20[3]}%) !important;}`,
151+
style_22_firefox = `html {filter: brightness(${style_20[2]}%) sepia(${style_20[3]}%) !important; background-image: url();}`,
152+
style_31 = `html {filter: invert(${style_30[0]}%) !important;} img, video {filter: invert(1) !important;}`,
153+
style_31_firefox = `html {filter: invert(${style_30[0]}%) !important; background-image: url();} img, video {filter: invert(1) !important;}`;
112154

113155
// Firefox 浏览器需要特殊对待
114156
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {

0 commit comments

Comments
 (0)