加载中...
return iconUrl } const generateHtml = array => { let result = '' if (array.length) { for (let i = 0; i < array.length; i++) { result += '
' if (true) { const name = 'data-lazy-src' result += `${array[i].nick}` } result += `
${array[i].content}
${array[i].nick} /
` } } else { result += '没有评论' } let $dom = document.querySelector('#card-newest-comments .aside-list') $dom.innerHTML= result window.lazyLoadInstance && window.lazyLoadInstance.update() window.pjax && window.pjax.refresh($dom) } const getComment = () => { const serverURL = 'https://uoaDTvEN.api.lncldglobal.com' var settings = { "method": "GET", "headers": { "X-LC-Id": 'uoaDTvEN4KnsU5xM1f2l1T12-MdYXbMMI', "X-LC-Key": 'f2158LsoEVzRzMS8EG7rvFSs', "Content-Type": "application/json" }, } fetch(`${serverURL}/1.1/classes/Comment?limit=6&order=-createdAt`,settings) .then(response => response.json()) .then(data => { const valineArray = data.results.map(function (e) { return { 'avatar': getIcon(e.QQAvatar, e.mail), 'content': changeContent(e.comment), 'nick': e.nick, 'url': e.url + '#' + e.objectId, 'date': e.updatedAt, } }) saveToLocal.set('valine-newest-comments', JSON.stringify(valineArray), 10/(60*24)) generateHtml(valineArray) }).catch(e => { const $dom = document.querySelector('#card-newest-comments .aside-list') $dom.innerHTML= "无法获取评论,请确认相关配置是否正确" }) } const newestCommentInit = () => { if (document.querySelector('#card-newest-comments .aside-list')) { const data = saveToLocal.get('valine-newest-comments') if (data) { generateHtml(JSON.parse(data)) } else { getComment() } } } newestCommentInit() document.addEventListener('pjax:complete', newestCommentInit) })