avatar
Ordis
三丘丘采药,四丘丘嗷~
Github
公告
本站图片链接已更新为阿里云OSS存储,访问更快~
最新文章
最新评论
正在加载中...
网站资讯
文章数目 :
125
已运行时间 :
本站总字数 :
205.2k
本站访客数 :
本站总访问量 :
最后更新时间 :
码]') // replace code content = content.replace(/<[^>]+>/g,"") // remove html tag if (content.length > 150) { content = content.substring(0,150) + '...' } return content } const getIcon = (icon, mail) => { if (icon) return icon let defaultIcon = '?d=monsterid' let iconUrl = `https://gravatar.loli.net/avatar/${md5(mail.toLowerCase()) + defaultIcon}` 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://lean-p.imbhj.com' var settings = { "method": "GET", "headers": { "X-LC-Id": 'Q8iemLwPqGgpJFy1DEwzrV9X-MdYXbMMI', "X-LC-Key": 'bIqfkPv7EhRw1KriklzYG0Co', "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), 20/(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) })