Giter Club home page Giter Club logo

Comments (2)

xzhuz avatar xzhuz commented on June 15, 2024

可以,后期可以看看,这个功能还是很好的。
之前有根据时间来自动设置夜间模式,但是这个功能当时有点小缺陷,不是特别好,所以后面直接改成手动控制了

from halo-theme-xue.

zwc456baby avatar zwc456baby commented on June 15, 2024

自己动手,丰衣足食

修改 source/js/_plugins/night-mode.js 文件记录:

修改后经过测试是可以的~~~ 而且不影响手动开关夜间模式的功能。

// 首先定义一个key:
var userSelectNightModeId = 'userSelectNightMode';
 
// 在 clickNightMode 方法中增加一行,原有的不要动
//这里的目的是记录用户已经手动选择过夜间模式了
//如果用户点击 switch,手动开关了夜间模式,就不要自动跟随系统的夜间模式了
hanUtils.setLocalStorage(userSelectNightModeId, true);
 
    autoNightMode: function () {
        // 如果用户手动选择过夜间模式,则不要自动跟随系统的夜间模式,而是继续用之前的模式
        // 如果用户未手动选择过,则自动跟随系统的夜间模式
        if(hanUtils.getLocalStorage(userSelectNightModeId)){
            // 根据当前时间判断是否是晚上
            // 如果当前是晚上,由于各种设置会不一样,这里干脆写死, 并且开启了自动夜晚模式
            nightMode.changeNightMode(hanUtils.getLocalStorage(nightModeId));
        }else{
            nightMode.changeNightMode(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
        }
    }

from halo-theme-xue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.