- const {envId} = theme.twikoo
script(pjax).
(async () => {
document.querySelector('#comments-page').textContent = `#{__("loading")}`
const emojiReg = /]+>/g
let cache = utils.saveToLocal.get('twikoo-recent-comments')
if (cache) {
setHtml(document.querySelector('#comments-page'), cache)
return
}
let ls = []
await fetch('!{envId}', {
method: "POST",
body: JSON.stringify({
"event": "GET_RECENT_COMMENTS",
"includeReply": true,
"pageSize": !{limit}
}),
headers: {'Content-Type': 'application/json'}
}).then(res => res.json()).then(async ({data}) => {
for (const i of data) {
if (i.avatar === undefined) i.avatar = '!{avatar}/avatar/d615d5793929e8c7d70eab5f00f7f5f1?d=mp'
let title = ''
if (i.url) {
await fetch(i.url).then(res => res.text()).then(html => {
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
title = doc.querySelector('title').innerText
}).catch(() => {
title = i.url
})
}
if (title.indexOf('|') > 0) {
title = title.split('|')[0]
}
ls.push({
avatar: i.avatar,
nick: i.nick,
title: title,
content: i.comment,
url: i.url + '#' + i.id,
time: i.created
})
}
setHtml(document.querySelector('#comments-page'), ls)
utils.saveToLocal.set('twikoo-recent-comments', ls, !{cache})
});
function setHtml(el, data) {
el.innerHTML = data.map(i => `