// 请使用该文件替换“[root]\themes\butterfly\layout\includes\third-party\comments\artalk.pug” - const { server, site, option } = theme.artalk - const { use, lazyload } = theme.comments script. (() => { let artalkItem = null const option = !{JSON.stringify(option)} const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo' const destroyArtalk = () => { if (artalkItem) { artalkItem.destroy() artalkItem = null } } const artalkChangeMode = theme => artalkItem && artalkItem.setDarkMode(theme === 'dark') const initArtalk = (el = document, pageKey = location.pathname) => { artalkItem = Artalk.init({ el: el.querySelector('#artalk-wrap'), server: '!{server}', site: '!{site}', darkMode: document.documentElement.getAttribute('data-theme') === 'dark', ...option, pageKey: isShuoshuo ? pageKey : (option && option.pageKey) || pageKey, imgUploader: function(file) { token = "Bearer " + "你的token"; api = "https://lsky.pro.example/api/v1/upload" let headers = new Headers(); headers.set('Accept', 'application/json'); headers.set('Authorization', token); let formData = new FormData(); formData.append('file', file); // 发起请求,上传图片 return fetch(api, { method: 'POST', body: formData, headers: headers }).then((resp) => resp.json()) .then((resp) => resp.data.links.url) .catch((error) => { console.error('Image upload failed:', error); return null; }); }, }) if (GLOBAL_CONFIG.lightbox === 'null') return artalkItem.on('list-loaded', () => { artalkItem.ctx.get('list').getCommentNodes().forEach(comment => { const $content = comment.getRender().$content btf.loadLightbox($content.querySelectorAll('img:not([atk-emoticon])')) }) }) if (isShuoshuo) { window.shuoshuoComment.destroyArtalk = () => { destroyArtalk() if (el.children.length) { el.innerHTML = '' el.classList.add('no-comment') } } } btf.addGlobalFn('pjaxSendOnce', destroyArtalk, 'destroyArtalk') btf.addGlobalFn('themeChange', artalkChangeMode, 'artalk') } const loadArtalk = async (el, pageKey) => { if (typeof Artalk === 'object') initArtalk(el, pageKey) else { await btf.getCSS('!{theme.asset.artalk_css}') await btf.getScript('!{theme.asset.artalk_js}') initArtalk(el, pageKey) } } if (isShuoshuo) { '!{use[0]}' === 'Artalk' ? window.shuoshuoComment = { loadComment: loadArtalk } : window.loadOtherComment = loadArtalk return } if ('!{use[0]}' === 'Artalk' || !!{lazyload}) { if (!{lazyload}) btf.loadComment(document.getElementById('artalk-wrap'), loadArtalk) else setTimeout(loadArtalk, 100) } else { window.loadOtherComment = loadArtalk } })()