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.
35 lines
1.0 KiB
35 lines
1.0 KiB
9 months ago
|
- const { server, site } = theme.artalk
|
||
|
|
||
|
script.
|
||
|
(() => {
|
||
|
const getArtalkCount = async() => {
|
||
|
try {
|
||
|
const eleGroup = document.querySelectorAll('#recent-posts .artalk-count')
|
||
|
const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-page-key'))
|
||
|
|
||
|
const headerList = {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||
|
'Origin': window.location.origin
|
||
|
},
|
||
|
body: new URLSearchParams({
|
||
|
'site_name': '!{site}',
|
||
|
'type':'page_comment',
|
||
|
'page_keys': keyArray
|
||
|
})
|
||
|
}
|
||
|
|
||
|
const res = await fetch('!{server}/api/stat', headerList)
|
||
|
const result = await res.json()
|
||
|
|
||
|
keyArray.forEach((key, index) => {
|
||
|
eleGroup[index].textContent = result.data[key] || 0
|
||
|
})
|
||
|
} catch (err) {
|
||
|
console.error(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.pjax ? getArtalkCount() : window.addEventListener('load', getArtalkCount)
|
||
|
})()
|