hexo-theme-butterfly/layout/includes/third-party/comments/artalk.pug
Jerry a36c9ca6d2 feat: 在綫聊天新增facebook洽談外掛程式 closed #918
feat: 添加artalk評論 closed #933
fix: 修復 開啟 archor 後, facebook評論加載不正確的 bug
fix: 修復 facebook 評論數無法加載的 bug
2022-07-17 01:14:41 +08:00

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()
}
}