yufan.me/themes/spectre/layout/_plugin/comment/disqus_click/main.ejs
2024-06-14 02:15:18 +08:00

50 lines
1.9 KiB
Plaintext

<div id="disqus_thread"></div>
<!-- add animation -->
<style>
</style>
<div class="btn_click_load">
<button class="btn btn-primary disqus_click_btn"><%= __('post.comments_load_button') %></button>
</div>
<script type="text/javascript">
var disqus_config = function () {
this.page.url = '<%= page.permalink %>'; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = '<%= page.permalink %>'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
</script>
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://disqus.com/next/config.json', true);
xhr.timeout = 4000;
xhr.send();
xhr.onload = function() {
if(this.status == 200||this.status == 304){
var d = document;
var s = d.createElement('script');
s.src = '//<%= theme.comment.shortname %>.disqus.com/embed.js';
s.setAttribute('data-timestamp', + new Date());
(d.head || d.body).appendChild(s);
document.querySelector(".disqus_click_btn").setAttribute("style", "display:none");
}
};
xhr.ontimeout = function(e) {
document.querySelector(".disqus_click_btn").setAttribute("style", "display:block");
};
xhr.onerror = function(e) {
document.querySelector(".disqus_click_btn").setAttribute("style", "display:block");
};
document.querySelector(".disqus_click_btn").onclick=function() { //click to load comments
(function() { // DON'T EDIT BELOW THIS LINE
var d = document;
var s = d.createElement('script');
s.src = '//<%= theme.comment.shortname %>.disqus.com/embed.js';
s.setAttribute('data-timestamp', + new Date());
(d.head || d.body).appendChild(s);
})();
document.querySelector(".disqus_click_btn").setAttribute("style", "display:none");
};
</script>