lewis-geek / hexo-theme-Aath

Hexo 主题
https://lewis-geek.github.io/hexo-theme-unit-test/
GNU Affero General Public License v3.0
151 stars 20 forks source link

每篇文章底部都会显示“Loading comments box needs to over the wall ” #81

Closed liofire closed 6 years ago

liofire commented 6 years ago

请问这个怎么该?

lewis-geek commented 6 years ago

当你在配置中添加 disqus_shortname 后会显示 disqus 评论框,因为在国内这个服务被墙掉了,所以在加载前会判断当前用户有没有翻墙,避免页面一直在加载状态,如果你的网络环境在墙内就会一直显示这个提示。

<% if(config['disqus_shortname']) { %>
    <!-- disqus 评论框 start -->
    <div class="comment">
        <div id="disqus_thread" class="disqus-thread">
          <i><%= __('over_the_wall') %></i>
        </div>
    </div>
    <!-- disqus 评论框 end -->
<% } %>

isAgent(getDisqus)

// determine user agent in China function isAgent(cb) { var url = '//graph.facebook.com/feed?callback=h'; var xhr = new XMLHttpRequest(); var called = false; xhr.open('GET', url); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { called = true; cb(true); } }; xhr.send(); // timeout 1s, this facebook API is very fast. setTimeout(function() { if (!called) { xhr.abort(); cb(false) } }, 1000); }

function getDisqus(isAgent) { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq) }