mirror of
https://github.com/lbr77/blog-astro.git
synced 2026-04-08 16:11:56 +00:00
test
This commit is contained in:
@@ -2,41 +2,56 @@
|
||||
var TWIKOO_SRC =
|
||||
'https://cdn.jsdelivr.net/npm/twikoo@1.6.44/dist/twikoo.min.js'
|
||||
var TARGET_SELECTOR = '#tcomment'
|
||||
var state = { loading: false }
|
||||
var SCRIPT_ID = 'twikoo-cdn-script'
|
||||
|
||||
function renderTwikoo() {
|
||||
var container = document.querySelector(TARGET_SELECTOR)
|
||||
if (!container || !window.twikoo) return
|
||||
|
||||
container.innerHTML = ''
|
||||
window.twikoo.init({
|
||||
envId: 'https://twikoo.hk.nvme0n1p.dev/',
|
||||
el: TARGET_SELECTOR,
|
||||
})
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (window.twikoo) {
|
||||
renderTwikoo()
|
||||
return
|
||||
function ensureScript() {
|
||||
var existing = document.getElementById(SCRIPT_ID)
|
||||
|
||||
if (existing) {
|
||||
if (existing.dataset.failed === 'true') {
|
||||
existing.remove()
|
||||
} else {
|
||||
if (!window.twikoo) {
|
||||
existing.addEventListener('load', renderTwikoo, { once: true })
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (state.loading) return
|
||||
state.loading = true
|
||||
|
||||
var script = document.createElement('script')
|
||||
script.id = SCRIPT_ID
|
||||
script.src = TWIKOO_SRC
|
||||
script.async = true
|
||||
script.onload = function () {
|
||||
state.loading = false
|
||||
script.dataset.loaded = 'true'
|
||||
renderTwikoo()
|
||||
}
|
||||
script.onerror = function (err) {
|
||||
state.loading = false
|
||||
script.dataset.failed = 'true'
|
||||
console.error('Failed to load Twikoo:', err)
|
||||
}
|
||||
document.head.appendChild(script)
|
||||
}
|
||||
|
||||
function init() {
|
||||
ensureScript()
|
||||
|
||||
if (window.twikoo) {
|
||||
renderTwikoo()
|
||||
}
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user