mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
feat: 添加artalk評論 closed #933 fix: 修復 開啟 archor 後, facebook評論加載不正確的 bug fix: 修復 facebook 評論數無法加載的 bug
45 lines
1.4 KiB
Plaintext
45 lines
1.4 KiB
Plaintext
- const { server, site } = theme.artalk
|
|
|
|
script.
|
|
function addArtalkSource () {
|
|
const ele = document.createElement('link')
|
|
ele.rel = 'stylesheet'
|
|
ele.href= '!{theme.asset.artalk_css}'
|
|
document.getElementsByTagName('head')[0].appendChild(ele)
|
|
}
|
|
|
|
function loadArtalk () {
|
|
function initArtalk () {
|
|
window.artalkItem = new Artalk({
|
|
el: '#artalk-wrap',
|
|
server: '!{server}',
|
|
site: '!{site}',
|
|
pageKey: location.pathname,
|
|
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
|
|
countEl: '.artalk-count'
|
|
})
|
|
}
|
|
|
|
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200)
|
|
else {
|
|
addArtalkSource()
|
|
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk)
|
|
: setTimeout(()=>{initArtalk()},200)
|
|
}
|
|
}
|
|
|
|
document.getElementById('darkmode').addEventListener('click',()=> {
|
|
if (typeof window.artalkItem !== 'object') return
|
|
let isDark = document.documentElement.getAttribute('data-theme') === 'dark'
|
|
window.artalkItem.setDarkMode(!isDark)
|
|
})
|
|
|
|
|
|
if ('!{theme.comments.use[0]}' === 'Artalk' || !!{theme.comments.lazyload}) {
|
|
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('artalk-wrap'), loadArtalk)
|
|
else loadArtalk()
|
|
} else {
|
|
function loadOtherComment () {
|
|
loadArtalk()
|
|
}
|
|
} |