Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

跟随深色模式切换 #75

Closed
eallion opened this issue May 23, 2022 · 1 comment
Closed

跟随深色模式切换 #75

eallion opened this issue May 23, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@eallion
Copy link

eallion commented May 23, 2022

当 DisqusJS 加载完以后,切换网站的深色(或浅色)样式,评论样式不能跟随适配。我发现我也提过这样的 Issue,现在解决了,分享一下。每个网站切换深色模式的方法不一样,所以感觉不太适合提 PR。

  1. 监听样式切换事件
let event = new Event('themeChanged');
document.dispatchEvent(event);
  1. 重载 DisqusJS
<script>
    var disqus_config = function () {
        this.page.url = ' '; // Replace PAGE_URL with your page's canonical URL variable
        this.page.identifier = ' '; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
    };

    (function () {
        var d = document,
            s = d.createElement('script');
        s.src = 'https://eallion.disqus.com/embed.js'; // Replace SITE_URL with your site's URL
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();

    // Disqus theme switching
    document.addEventListener('themeChanged', function (e) {
        if (document.readyState == 'complete') {
            DISQUS.reset({
                reload: true,
                config: disqus_config
            });
        }
    });
</script>

ref: https://help.disqus.com/en/articles/1717163-using-disqus-on-ajax-sites

@eallion
Copy link
Author

eallion commented May 23, 2022

#40 #60

@SukkaW SukkaW added the enhancement New feature or request label May 23, 2022
@eallion eallion closed this as completed Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants