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
37 lines
1.4 KiB
Plaintext
37 lines
1.4 KiB
Plaintext
script.
|
|
function loadUtterances () {
|
|
let ele = document.createElement('script')
|
|
ele.setAttribute('id', 'utterances_comment')
|
|
ele.setAttribute('src', 'https://utteranc.es/client.js')
|
|
ele.setAttribute('repo', '!{theme.utterances.repo}')
|
|
ele.setAttribute('issue-term', '!{theme.utterances.issue_term}')
|
|
let nowTheme = document.documentElement.getAttribute('data-theme') === 'dark' ? '#{theme.utterances.dark_theme}' : '#{theme.utterances.light_theme}'
|
|
ele.setAttribute('theme', nowTheme)
|
|
ele.setAttribute('crossorigin', 'anonymous')
|
|
ele.setAttribute('async', 'true')
|
|
document.getElementById('utterances-wrap').insertAdjacentElement('afterbegin',ele)
|
|
}
|
|
|
|
function utterancesTheme (theme) {
|
|
const iframe = document.querySelector('.utterances-frame')
|
|
if (iframe) {
|
|
const theme = theme === 'dark' ? '#{theme.utterances.dark_theme}' : '#{theme.utterances.light_theme}'
|
|
const message = {
|
|
type: 'set-theme',
|
|
theme: theme
|
|
};
|
|
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
|
}
|
|
}
|
|
|
|
btf.addModeChange('utterances', utterancesTheme)
|
|
|
|
if ('!{theme.comments.use[0]}' === 'Utterances' || !!{theme.comments.lazyload}) {
|
|
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('utterances-wrap'), loadUtterances)
|
|
else loadUtterances()
|
|
} else {
|
|
function loadOtherComment () {
|
|
loadUtterances()
|
|
}
|
|
}
|