|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 护眼模式 |
3 | | -// @version 1.1.3 |
| 3 | +// @version 1.1.4 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 简单有效的全网通用护眼模式、夜间模式、暗黑模式 |
6 | 6 | // @match *://*/* |
|
25 | 25 | var menu_ALL = [ |
26 | 26 | ['menu_runDuringTheDay', '白天保持开启 (比晚上亮一点点)', '白天保持开启', true], |
27 | 27 | ['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'] |
29 | 32 | ], menu_ID = [], websiteList = ['rarbgprx.org','fitgirl-repacks.site','masquerade.site','www.gamersky.com']; |
30 | 33 | for (let i=0;i<menu_ALL.length;i++){ // 如果读取到的值为 null 就写入默认值 |
31 | 34 | if (GM_getValue(menu_ALL[i][0]) == null){GM_setValue(menu_ALL[i][0], menu_ALL[i][3])}; |
|
49 | 52 | GM_setValue('menu_darkModeType', menu_ALL[i][3]); |
50 | 53 | } |
51 | 54 | 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]}`)}); |
52 | 64 | } else { |
53 | 65 | 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]}`)}); |
54 | 66 | } |
|
57 | 69 | } |
58 | 70 |
|
59 | 71 |
|
| 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 | + |
60 | 99 | // 切换暗黑模式 |
61 | 100 | function menu_toggle(menu_status, Name) { |
62 | 101 | menu_status = parseInt(menu_status) |
|
97 | 136 | function addStyle() { |
98 | 137 | let remove = false, style_Add = document.createElement('style'), |
99 | 138 | 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('|'), |
100 | 142 | style = ``, |
101 | 143 | 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;}`; |
112 | 154 |
|
113 | 155 | // Firefox 浏览器需要特殊对待 |
114 | 156 | if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { |
|
0 commit comments