修复流畅性
This commit is contained in:
1 parent
3a7bddb881
commit
9ab38b6e6a
11 files changed
+175
-82
No files matched your search
@@ -1,19 +1,40 @@
|
||||
// Global Artalk Initialization Function (Supports PJAX)
|
||||
window.loadScriptOnce = window.loadScriptOnce || function(src, globalName, callback) {
|
||||
if (globalName && window[globalName]) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var existing = document.querySelector('script[data-dynamic-src="' + src + '"]');
|
||||
if (existing) {
|
||||
existing.addEventListener('load', callback, { once: true });
|
||||
return;
|
||||
}
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = src;
|
||||
script.defer = true;
|
||||
script.dataset.dynamicSrc = src;
|
||||
script.onload = callback;
|
||||
document.head.appendChild(script);
|
||||
};
|
||||
|
||||
window.initArtalk = function() {
|
||||
if (!document.querySelector("#Comments")) return;
|
||||
|
||||
|
||||
// Check if configuration exists
|
||||
if (!window.artalkConfig) {
|
||||
console.warn('window.artalkConfig is not defined. Skipping Artalk init.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if Artalk library is loaded
|
||||
if (typeof Artalk === 'undefined') {
|
||||
console.warn('Artalk library is not loaded yet. Waiting for bundle...');
|
||||
var artalkUrl = window.optionalAssetUrls && window.optionalAssetUrls.artalk;
|
||||
if (!artalkUrl) return;
|
||||
window.loadScriptOnce(artalkUrl, 'Artalk', window.initArtalk);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// Logic for caching Artalk configuration to speed up rendering
|
||||
// 1. Manual Refresh (F5): Request from server and save to localStorage
|
||||
@@ -195,19 +216,11 @@ window.initArtalk = function() {
|
||||
|
||||
// Force hide "No Comment" if AI comment exists
|
||||
if (window.artalkConfig.aiComment) {
|
||||
var checkNoComment = setInterval(function() {
|
||||
var noComment = document.querySelector('.atk-list-no-comment');
|
||||
var aiComment = document.querySelector('.atk-ai-comment');
|
||||
if (aiComment && noComment && noComment.style.display !== 'none') {
|
||||
noComment.style.display = 'none';
|
||||
}
|
||||
if (!document.querySelector('#Comments')) {
|
||||
clearInterval(checkNoComment);
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// Clear interval after 10 seconds to save resources
|
||||
setTimeout(function() { clearInterval(checkNoComment); }, 10000);
|
||||
var noComment = document.querySelector('.atk-list-no-comment');
|
||||
var aiComment = document.querySelector('.atk-ai-comment');
|
||||
if (aiComment && noComment) {
|
||||
noComment.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user