_includes/comments/disqus.html in jekyll-theme-chirpy-5.3.1 vs _includes/comments/disqus.html in jekyll-theme-chirpy-5.3.2

- old
+ new

@@ -13,11 +13,10 @@ this.page.url = '{{ page.url | absolute_url }}'; this.page.identifier = '{{ page.url }}'; }; /* Lazy loading */ - var disqus_observer = new IntersectionObserver(function (entries) { if(entries[0].isIntersecting) { (function () { var d = document, s = d.createElement('script'); s.src = 'https://{{ site.comments.disqus.shortname }}.disqus.com/embed.js'; @@ -30,25 +29,26 @@ }, { threshold: [0] }); disqus_observer.observe(document.querySelector('#disqus_thread')); /* Auto switch theme */ - function reloadDisqus() { - /* Disqus hasn't been loaded */ - if (typeof DISQUS === "undefined") { - return; - } + if (event.source === window && event.data && + event.data.direction === ModeToggle.ID) { + /* Disqus hasn't been loaded */ + if (typeof DISQUS === "undefined") { + return; + } - if (document.readyState == 'complete') { - DISQUS.reset({ reload: true, config: disqus_config }); + if (document.readyState == 'complete') { + DISQUS.reset({ reload: true, config: disqus_config }); + } } } const modeToggle = document.querySelector(".mode-toggle"); if (typeof modeToggle !== "undefined") { - /* modeToggle.addEventListener('click', reloadDisqus); // not pretty for 'color-scheme' */ - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', reloadDisqus); + window.addEventListener("message", reloadDisqus); } </script>