fix(comment): disqus doesn't follow theme mode switching
This commit is contained in:
parent
e50343b06b
commit
b0d5956f5a
1 changed files with 10 additions and 10 deletions
|
@ -15,7 +15,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Lazy loading */
|
/* Lazy loading */
|
||||||
|
|
||||||
var disqus_observer = new IntersectionObserver(function (entries) {
|
var disqus_observer = new IntersectionObserver(function (entries) {
|
||||||
if(entries[0].isIntersecting) {
|
if(entries[0].isIntersecting) {
|
||||||
(function () {
|
(function () {
|
||||||
|
@ -32,23 +31,24 @@
|
||||||
disqus_observer.observe(document.querySelector('#disqus_thread'));
|
disqus_observer.observe(document.querySelector('#disqus_thread'));
|
||||||
|
|
||||||
/* Auto switch theme */
|
/* Auto switch theme */
|
||||||
|
|
||||||
function reloadDisqus() {
|
function reloadDisqus() {
|
||||||
/* Disqus hasn't been loaded */
|
if (event.source === window && event.data &&
|
||||||
if (typeof DISQUS === "undefined") {
|
event.data.direction === ModeToggle.ID) {
|
||||||
return;
|
/* Disqus hasn't been loaded */
|
||||||
}
|
if (typeof DISQUS === "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (document.readyState == 'complete') {
|
if (document.readyState == 'complete') {
|
||||||
DISQUS.reset({ reload: true, config: disqus_config });
|
DISQUS.reset({ reload: true, config: disqus_config });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const modeToggle = document.querySelector(".mode-toggle");
|
const modeToggle = document.querySelector(".mode-toggle");
|
||||||
|
|
||||||
if (typeof modeToggle !== "undefined") {
|
if (typeof modeToggle !== "undefined") {
|
||||||
/* modeToggle.addEventListener('click', reloadDisqus); // not pretty for 'color-scheme' */
|
window.addEventListener("message", reloadDisqus);
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reloadDisqus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue