64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
|
(() => {
|
||
|
if (!document.getElementById('post-comment')) return
|
||
|
const init = () => {
|
||
|
twikoo.init(Object.assign({
|
||
|
el: '#twikoo-wrap',
|
||
|
envId: GLOBAL_CONFIG.source.twikoo.twikooUrl,
|
||
|
region: '',
|
||
|
path: location.pathname.replace(/\/page\/\d$/, ""),
|
||
|
onCommentLoaded: function () {
|
||
|
btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
|
||
|
typeof hljs === 'object' && hljs.highlightAll()
|
||
|
typeof Prism === 'object' && Prism.highlightAll()
|
||
|
$("input").focus(function () {
|
||
|
heo_intype = true;
|
||
|
});
|
||
|
$("textarea").focus(function () {
|
||
|
heo_intype = true;
|
||
|
});
|
||
|
$("input").focusout(function () {
|
||
|
heo_intype = false;
|
||
|
});
|
||
|
$("textarea").focusout(function () {
|
||
|
heo_intype = false;
|
||
|
});
|
||
|
}
|
||
|
}, null))
|
||
|
}
|
||
|
|
||
|
const getCount = () => {
|
||
|
twikoo.getCommentsCount({
|
||
|
envId: GLOBAL_CONFIG.source.twikoo.twikooUrl,
|
||
|
region: '',
|
||
|
urls: [window.location.pathname],
|
||
|
includeReply: true
|
||
|
}).then(function (res) {
|
||
|
document.getElementById('twikoo-count').innerText = res[0].count
|
||
|
}).catch(function (err) {
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const runFn = () => {
|
||
|
init()
|
||
|
true && getCount()
|
||
|
}
|
||
|
|
||
|
const loadTwikoo = () => {
|
||
|
if (typeof twikoo === 'object') {
|
||
|
setTimeout(runFn, 0)
|
||
|
return
|
||
|
}
|
||
|
getScript(GLOBAL_CONFIG.source.twikoo.js).then(runFn)
|
||
|
}
|
||
|
|
||
|
if ('Twikoo' === 'Twikoo' || !GLOBAL_CONFIG.source.comments.lazyload) {
|
||
|
if (GLOBAL_CONFIG.source.comments.lazyload) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
|
||
|
else loadTwikoo()
|
||
|
} else {
|
||
|
window.loadOtherComment = () => {
|
||
|
loadTwikoo()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
})()
|