diff --git a/src/disqus.js b/src/disqus.js index d0e05f2..697877d 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -144,7 +144,7 @@ $$('disqus_thread').innerHTML = '
评论完整模式加载中...如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理,或使用 评论基础模式
' $$('dsqjs-force-dsqjs').addEventListener('click', forceDsqjs); - s.src = 'https://' + disqusjs.config.shortname + '.disqus.com/embed.js'; + s.src = `https://${disqusjs.config.shortname}.disqus.com/embed.js`; s.setAttribute('data-timestamp', + new Date()); (d.head || d.body).appendChild(s); } @@ -299,24 +299,21 @@ getComment(disqusjs.page.next); } - // 处理传入的 cursor - if (!cursor) { - // 不存在 cursor,API 中不需要带上 cursor 参数 - cursor = ''; - var getCommentError = () => { - // 不存在 cursor,出错时只需要在 #dsqjs-msg 中显示提示信息 + let getCommentError = () => { + if (!cursor) { loadError(); - } - } else { - // 带上 cursor 参数 - cursor = `&cursor=${cursor}`; - var getCommentError = () => { - // 解禁 加载更多评论 + } else { $loadMoreBtn.classList.remove('dsqjs-disabled'); // 在按钮上显示提示信息 - $loadMoreBtn.innerHTML = '加载更多评论失败,点击重试' + $loadMoreBtn.innerHTML = '加载更多评论失败,点击重试'; + // 重新在按钮上绑定 加载更多按钮 + $loadMoreBtn.addEventListener('click', getMoreComment); } - } + }; + + // 处理传入的 cursor + cursor = (!cursor) ? '' : `&cursor=${cursor}`; + // 在发起请求前禁用 加载更多评论 按钮防止重复调用 $loadMoreBtn.classList.add('dsqjs-disabled') /* @@ -536,7 +533,7 @@ children.map((comment) => { comment = processData(comment); comment.nesting = nesting + 1; - html += `
  • ${renderPostItem(comment.comment)}${childrenComments(comment)}
  • `; + html += `
  • ${renderPostItem(comment.comment)}${childrenComments(comment)}
  • `; }); html += ''; @@ -558,7 +555,7 @@ comment.nesting = 1; } comment = processData(comment); - html += `
  • ${renderPostItem(comment.comment)}${childrenComments(comment)}
  • `; + html += `
  • ${renderPostItem(comment.comment)}${childrenComments(comment)}
  • `; });