mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Implement a switch for switching between light and dark mode
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user