Implement a switch for switching between light and dark mode

This commit is contained in:
Philipp Oppermann
2020-12-28 20:47:17 +01:00
parent eb767523a5
commit 300a6f452a
5 changed files with 81 additions and 3 deletions

View File

@@ -61,3 +61,29 @@ 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.utterances-frame");
if (body != null) {
if (body.classList.contains("dark")) {
body.classList.replace("dark", "light");
if (comment_form != null) {
comment_form.contentWindow.postMessage(
{ type: "set-theme", theme: "github-light" },
"https://utteranc.es/"
)
}
} else {
body.classList.remove("light");
body.classList.add("dark");
if (comment_form != null) {
comment_form.contentWindow.postMessage(
{ type: "set-theme", theme: "github-dark" },
"https://utteranc.es/"
)
}
}
console.log(body)
}
}