Maysion e48e7b03c2
Some checks failed
Deploy Pages / Generate-Pages (push) Failing after 1m46s
feat: init
2025-04-20 12:29:11 +08:00

26 lines
920 B
Plaintext

- const { shortname, apikey } = theme.disqus
script.
(() => {
const getCount = async () => {
try {
const eleGroup = document.querySelectorAll('#recent-posts .disqus-count')
const cleanedLinks = Array.from(eleGroup).map(i => `thread:link=${i.href.replace(/#post-comment$/, '')}`);
const res = await fetch(`https://disqus.com/api/3.0/threads/set.json?forum=!{shortname}&api_key=!{apikey}&${cleanedLinks.join('&')}`,{
method: 'GET'
})
const result = await res.json()
eleGroup.forEach(i => {
const cleanedLink = i.href.replace(/#post-comment$/, '')
const urlData = result.response.find(data => data.link === cleanedLink) || { posts: 0 }
i.textContent = urlData.posts
})
} catch (err) {
console.error(err)
}
}
window.pjax ? getCount() : window.addEventListener('load', getCount)
})()