Index

joshstock.in / 0fe4f18

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
15814 Jan 2023 23:375aaa26aWebsite rewriteJosh Stockin1210G

Blob @ joshstock.in / site / static / js / theme.js

application/javascript668 bytesdownload raw
1function updateTheme() {
2 if (localStorage.getItem("theme") == null) {
3 if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
4 console.log("Prefers dark");
5 localStorage.setItem("theme", "dark")
6 } else {
7 localStorage.setItem("theme", "")
8 }
9 }
10 let themeName = localStorage.getItem("theme");
11
12 document.querySelector("html").classList.value = themeName;
13}
14
15function toggleDarkMode() {
16 localStorage.setItem("theme", localStorage.getItem("theme") == "" ? "dark" : "");
17 updateTheme();
18}
19
20updateTheme();
21document.addEventListener('DOMContentLoaded', updateTheme);
22