Auto switch Disqus theme

This commit is contained in:
Cotes Chung 2021-09-14 20:45:17 +08:00
parent 2acf14ecf0
commit 7ef88c8b8f

View file

@ -29,5 +29,26 @@
}
}, { threshold: [0] });
disqus_observer.observe(document.querySelector("#disqus_thread"));
disqus_observer.observe(document.querySelector('#disqus_thread'));
/* Auto switch theme */
function reloadDisqus() {
/* Disqus hasn't been loaded */
if (typeof DISQUS === "undefined") {
return;
}
if (document.readyState == 'complete') {
DISQUS.reset({ reload: true, config: disqus_config });
}
}
const modeToggle = document.querySelector(".mode-toggle");
if (modeToggle !== null) {
modeToggle.addEventListener('click', reloadDisqus);
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reloadDisqus);
}
</script>