Detect Dark Mode Preference with JavaScript

Seemingly every website, dapp, and app offers a dark mode preference, and thank goodness. Dark mode is especially useful when I’m doing late night coding, or even worse, trading into altcoins. I’m presently working on implementing a dark theme on MetaMask and it got me to thinking: is there a way we can default to dark mode if the user’s operating system also defaults to dark mode? You can determine if the user’s operating system prefers dark mode with one quick line of code: const prefersDarkMode = window.matchMedia("(prefers-color-scheme:dark)").matches; // true This code snippet takes advantage of the CSS prefers-color-scheme media query with JavaScript’s... more →
Posted in: JavaScript

Working with Algolia’s Crawler

I’ve been using Algolia on my blog for a while now. It’s an excellent search solution for the Jamstack and I absolutely recommend it, especially for sites where the size means Lunr may not be appropriate. While I like Algolia a lot, I haven’t really dug terribly deep into it. I went through multiple iterations of my implementation here to help deal with the size of my content and so forth, but outside of that, I kept the actual search experience nice and simple. This week, I gave a talk at the Jamstack_Berlin user group on search options for the Jamstack and that’s got me thinking more about both Lunr and Algolia. One of the things... more →
Posted in: JavaScript
1 35 36 37 38 39 87