mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
feat: 設置了隨系統而切換淺色和深色模式後,評論和 mermaind 也會跟隨切換顏色 feat: artalk 最新評論,從 artalk 配置讀取頭像 CDN 和默認頭像 fix: 修復代碼塊在未展開時,點擊複製按鈕,無法複製的 bug improvement: 代碼和性能優化 improvement: artalk 獲取評論數,由 LoadCountWidget 改為 loadCountWidget
51 lines
1.7 KiB
Plaintext
51 lines
1.7 KiB
Plaintext
- const { server, site, option } = theme.artalk
|
|
|
|
script.
|
|
function loadArtalk () {
|
|
function initArtalk () {
|
|
window.artalkItem = new Artalk(Object.assign({
|
|
el: '#artalk-wrap',
|
|
server: '!{server}',
|
|
site: '!{site}',
|
|
pageKey: location.pathname,
|
|
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
|
|
countEl: '.artalk-count'
|
|
},!{JSON.stringify(option)}))
|
|
|
|
if (GLOBAL_CONFIG.lightbox === 'null') return
|
|
window.artalkItem.use(ctx => {
|
|
ctx.on('list-loaded', () => {
|
|
ctx.getCommentList().forEach(comment => {
|
|
const $content = comment.getRender().$content
|
|
btf.loadLightbox($content.querySelectorAll('img:not([atk-emoticon])'))
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
if (typeof window.artalkItem === 'object') setTimeout(()=>{initArtalk()},200)
|
|
else {
|
|
getCSS('!{theme.asset.artalk_css}').then(()=>{
|
|
typeof Artalk !== 'function' ? getScript('!{theme.asset.artalk_js}').then(initArtalk)
|
|
: setTimeout(()=>{initArtalk()},200)
|
|
})
|
|
}
|
|
}
|
|
|
|
function artalkChangeMode (theme) {
|
|
const artalkWrap = document.getElementById('artalk-wrap')
|
|
if (!(artalkWrap && artalkWrap.children.length)) return
|
|
const isDark = theme === 'dark'
|
|
window.artalkItem.setDarkMode(isDark)
|
|
}
|
|
|
|
btf.addModeChange('artalk', artalkChangeMode)
|
|
|
|
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()
|
|
}
|
|
} |