Code Monkey home page Code Monkey logo

Comments (4)

AmazingRise avatar AmazingRise commented on July 4, 2024

Hi, thanks for your feedback.
But it works well for me here.
To validate that, I've added several console.log, like this:

// From https://www.jdeal.cn/archives/Dark.html
        var night = document.cookie.replace(/(?:(?:^|.*;\s*)night\s*\=\s*([^;]*).*$)|^.*$/, "$1");
        if (night==""){
            console.log("No cookies detected.");
            if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
                console.log("Dark mode enabled by default.");
                this.toggleDarkMode();
            }
        }else{
            // If night is not empty
            if (night=="1") {
                this.toggleDarkMode();
            }
        }

When I switched my browser to dark mode, it was changed as excepted, both in Firefox and Chromium.
图片

As for wiki, thanks for your advice, I will update soon.
And I will also consider making it a variable.

from hugo-theme-diary.

jforce avatar jforce commented on July 4, 2024

Thanks Rise, just given your new update a go and working perfectly

from hugo-theme-diary.

AmazingRise avatar AmazingRise commented on July 4, 2024

OK. If you have any further questions, please feedback. Thanks.

from hugo-theme-diary.

Darthagnon avatar Darthagnon commented on July 4, 2024

Is there a way to always enable Dark Mode by default irrespective of browser-mode? Or am I misunderstanding what auto dark mode does? I've tried setting the param, but the site still initialises in light mode (I think my browser might be "light mode" with a dark theme).

from hugo-theme-diary.

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.