hexo/node_modules/hexo-theme-butterfly/layout/includes/third-party/comments/utterances.pug

37 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
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()
}
}