diff options
| author | BigCoke233 <hi@guhub.cn> | 2020-03-28 17:21:08 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2020-03-28 17:21:08 +0800 |
| commit | 7fde411bf014e0b16569ae1d9c1dcde0c6b7ec26 (patch) | |
| tree | 5fbe70bec69be5e459084c90c00374133d0cf6f2 /assets/js | |
| parent | 3d7f72862c6bfe897567a5f29f0ac46be4b2fe6d (diff) | |
:sunglasses: Add: 支持日落模式
Diffstat (limited to 'assets/js')
| -rw-r--r-- | assets/js/miracles.min.js | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/assets/js/miracles.min.js b/assets/js/miracles.min.js index 05c301a..f497979 100644 --- a/assets/js/miracles.min.js +++ b/assets/js/miracles.min.js @@ -69,32 +69,54 @@ function gotoPosition(e){ * Dark theme
*/
//toggleDark
+var theme = 0;
function Dark() {
- //Add classs to use dark theme
- $("body").toggleClass("body-dark");
+ theme++;
//Add cookie to record
- if ($("body").hasClass("body-dark")) {
- addCookie("darkTheme", "on", 9);
- $("#toggle-dark-button").html('<i class="iconfont icon-sun"></i>');
- $("#toggle-dark-mobile").html('<i class="iconfont icon-sun"></i>');
- alertSend("已切换夜间模式");
- } else {
- addCookie("darkTheme", "off", 9);
+ if(theme==2){
+ addCookie("theme", "2", 9);
$("#toggle-dark-button").html('<i class="iconfont icon-moon"></i>');
$("#toggle-dark-mobile").html('<i class="iconfont icon-moon"></i>');
- alertSend("已切换日间模式")
- }
+ $("body").removeClass("body-sepia");
+ $("body").addClass("body-dark");
+ alertSend("已切换夜间模式");
+ }
+ else if(theme==1){
+ addCookie("theme", "1", 9);
+ $("#toggle-dark-button").html('<i class="iconfont icon-sunset"></i>');
+ $("#toggle-dark-mobile").html('<i class="iconfont icon-sunset"></i>');
+ $("body").removeClass("body-dark");
+ $("body").addClass("body-sepia");
+ alertSend("已切换日落模式");
+ }
+ else {
+ addCookie("theme", "3", 9);
+ theme = 0;
+ $("#toggle-dark-button").html('<i class="iconfont icon-sun"></i>');
+ $("#toggle-dark-mobile").html('<i class="iconfont icon-sun"></i>');
+ $("body").removeClass("body-dark");
+ $("body").removeClass("body-sepia");
+ alertSend("已切换日间模式");
+ }
}
//auto dark theme
-var whetherDark = getCookie("darkTheme");
+var whatTheme = getCookie("theme");
var schemeGeter = window.matchMedia ("(prefers-color-scheme: dark)");
-if (whetherDark == "on" || schemeGeter.matches) {
+if (whatTheme == "2" || schemeGeter.matches) {
$("body").addClass("body-dark");
- $("#toggle-dark-button").html('<i class="iconfont icon-sun"></i>');
- $("#toggle-dark-mobile").html('<i class="iconfont icon-sun"></i>');
- alertSend("检测到您上次使用深色模式,已自动切换");
+ $("#toggle-dark-button").html('<i class="iconfont icon-moon"></i>');
+ $("#toggle-dark-mobile").html('<i class="iconfont icon-moon"></i>');
+ alertSend("检测到您使用深色模式,已自动切换");
+ theme="2";
}
+else if (whatTheme == "1") {
+ $("#toggle-dark-button").html('<i class="iconfont icon-sunset"></i>');
+ $("#toggle-dark-mobile").html('<i class="iconfont icon-sunset"></i>');
+ $("body").addClass("body-sepia");
+ alertSend("检测到您使用日落模式,已自动切换");
+ theme="1";
+}
//支持系统深色模式
function swDarkMode(scheme){
if(scheme.matches) {
|
