You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
920 B
26 lines
920 B
9 months ago
|
- 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)
|
||
|
})()
|