mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 18:40:53 +08:00
45 lines
1.3 KiB
Plaintext
45 lines
1.3 KiB
Plaintext
script.
|
|
(()=>{
|
|
const $countDom = document.getElementById('twikoo-count')
|
|
const init = () => {
|
|
twikoo.init(Object.assign({
|
|
el: '#twikoo-wrap',
|
|
envId: '!{theme.twikoo.envId}',
|
|
region: '!{theme.twikoo.region}'
|
|
}, !{JSON.stringify(theme.twikoo.option)}))
|
|
}
|
|
|
|
const getCount = () => {
|
|
twikoo.getCommentsCount({
|
|
envId: '!{theme.twikoo.envId}',
|
|
region: '!{theme.twikoo.region}',
|
|
urls: [window.location.pathname],
|
|
includeReply: false
|
|
}).then(function (res) {
|
|
$countDom.innerText = res[0].count
|
|
}).catch(function (err) {
|
|
console.error(err);
|
|
});
|
|
}
|
|
|
|
const loadTwikoo = (bool = false) => {
|
|
if (typeof twikoo === 'object') {
|
|
init()
|
|
bool && $countDom && setTimeout(getCount,0)
|
|
} else {
|
|
getScript('!{theme.CDN.twikoo}').then(()=> {
|
|
init()
|
|
bool && $countDom && setTimeout(getCount,0)
|
|
})
|
|
}
|
|
}
|
|
|
|
if ('!{theme.comments.use[0]}' === 'Twikoo' || !!{theme.comments.lazyload}) {
|
|
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
|
|
else loadTwikoo(true)
|
|
} else {
|
|
window.loadOtherComment = () => {
|
|
loadTwikoo()
|
|
}
|
|
}
|
|
})() |