//disqus.com/api/3.0/forums/listPosts.json?forum=up-4ever-site&related=thread&limit=6&api_key=CFUmECe7yuSfJPnUxtTnerCNyY8C2xwgs5Vw4hiGrUmhrGrjMn0gBn2feqnCK0A4') .then(response => response.json()) .then(data => { const disqusArray = data.response.map(item => { return { 'avatar': item.author.avatar.cache, 'content': changeContent(item.message), 'nick': item.author.name, 'url': item.url, 'date': item.createdAt } }) saveToLocal.set('disqus-newest-comments', JSON.stringify(disqusArray), 30/(60*24)) generateHtml(disqusArray) }).catch(e => { const $dom = document.querySelector('#card-newest-comments .aside-list') $dom.textContent= "无法获取评论,请确认相关配置是否正确" }) } const generateHtml = array => { let result = '' if (array.length) { for (let i = 0; i < array.length; i++) { result += '
' if (true) { const name = 'src' result += `${array[i].nick}` } result += `
${array[i].content}
${array[i].nick}
` } } else { result += '没有评论' } let $dom = document.querySelector('#card-newest-comments .aside-list') $dom && ($dom.innerHTML= result) window.lazyLoadInstance && window.lazyLoadInstance.update() window.pjax && window.pjax.refresh($dom) } const newestCommentInit = () => { if (document.querySelector('#card-newest-comments .aside-list')) { const data = saveToLocal.get('disqus-newest-comments') if (data) { generateHtml(JSON.parse(data)) } else { getComment() } } } newestCommentInit() document.addEventListener('pjax:complete', newestCommentInit) })