From f0c08a64d2906595e3229d498abccd8bbc0aa207 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Thu, 30 Sep 2021 14:33:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20[=E6=99=9A=E4=B8=8A?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E6=A8=A1=E5=BC=8F]=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD;=20=E4=BC=98=E5=8C=96=20[=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=A8=A1=E5=BC=8F]=20=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=88=E4=B8=8D=E5=86=8D=E5=88=B7=E6=96=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DarkMode.user.js | 58 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/DarkMode.user.js b/DarkMode.user.js index 6f9cf76..a57ebca 100644 --- a/DarkMode.user.js +++ b/DarkMode.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 护眼模式 -// @version 1.2.8 +// @version 1.2.9 // @author X.I.U // @description 简单有效的全网通用护眼模式(夜间模式、暗黑模式、深色模式) // @match *://*/* @@ -30,7 +30,8 @@ ['menu_autoRecognition', '智能排除自带暗黑模式的网页 (beta)', '智能排除自带暗黑模式的网页 (beta)', true], ['menu_forcedToEnable', '✅ 已强制当前网站启用护眼模式 (👆)', '❌ 未强制当前网站启用护眼模式 (👆)', []], ['menu_darkModeType', '点击切换模式', '点击切换模式', 2], - ['menu_customMode', '自定义当前模式', '自定义当前模式', true], ['menu_customMode1',,,'80|70'], ['menu_customMode2',,,'80|20|70|30'], ['menu_customMode3',,,'80'] + ['menu_customMode', '自定义当前模式', '自定义当前模式', true], ['menu_customMode1',,,'80|70'], ['menu_customMode2',,,'80|20|70|30'], ['menu_customMode3',,,'80'], + ['menu_autoSwitch', '晚上自动切换模式', '晚上自动切换模式', ''], ], menu_ID = []; for (let i=0;i 6 && hours < 19) { // 白天 + darkModeType = GM_getValue('menu_autoSwitch').split('|')[0]; + } else { // 晚上 + darkModeType = GM_getValue('menu_autoSwitch').split('|')[1]; + } + } + return parseInt(darkModeType) + } + + // 自定义当前模式 function menu_customMode() { let newMods, tip, defaults, name; - switch(menu_value('menu_darkModeType')) { + switch(getAutoSwitch()) { case 1: tip = '自定义 [模式 1],修改后立即生效 (部分网页可能需要刷新)~\n格式:亮度 (白天)|亮度 (晚上)\n默认:80|70(均为百分比 1~100,不需要 % 符号)'; defaults = '80|70'; @@ -227,7 +265,12 @@ menu_status += 1; } GM_setValue(`${Name}`, menu_status); - location.reload(); // 刷新网页 + registerMenuCommand(); // 重新注册脚本菜单 + if (document.getElementById('XIU2DarkMode')) { + document.getElementById('XIU2DarkMode').remove(); // 即时修改样式 + addStyle(); + } + //location.reload(); // 刷新网页 }; @@ -296,7 +339,10 @@ } } - switch(menu_value('menu_darkModeType')) { + + let darkModeType = getAutoSwitch(); + + switch(darkModeType) { case 1: style += style_12; break;