Implement a switch for switching between light and dark mode

This commit is contained in:
Philipp Oppermann
2021-10-17 14:18:08 +02:00
parent 9d7c0ead07
commit 96ab77fd1e
3 changed files with 72 additions and 0 deletions

View File

@@ -61,3 +61,27 @@ function toc_scroll_position(container) {
current_toc_item.classList.add("active");
}
}
function toggle_lights() {
var body = document.querySelector("body");
var comment_form = document.querySelector("iframe.giscus-frame");
if (body != null) {
if (body.classList.contains("dark")) {
body.classList.replace("dark", "light");
if (comment_form != null) {
comment_form.contentWindow.postMessage({
giscus: { setConfig: { theme: 'light' } }
}, "https://giscus.app")
}
} else {
body.classList.remove("light");
body.classList.add("dark");
if (comment_form != null) {
comment_form.contentWindow.postMessage({
giscus: { setConfig: { theme: 'dark' } }
}, "https://giscus.app")
}
}
console.log(body)
}
}