added ai评论
This commit is contained in:
1 parent
ec6f05539e
commit
0f7be7d270
152 files changed
+2323
-1277
No files matched your search
@@ -82,7 +82,89 @@ if (typeof lazyLoadInit === 'function') {
|
||||
|
||||
// 异步初始化 Artalk 并获取评论数据 (Moved to barrage.js)
|
||||
|
||||
// Global Artalk Initialization Function (Supports PJAX)
|
||||
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...');
|
||||
// Optional: Retry logic could be added here if needed, but usually bundle is loaded by now
|
||||
return;
|
||||
}
|
||||
|
||||
var isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
||||
|
||||
// Initialize Artalk
|
||||
window.artalk = Artalk.init({
|
||||
el: window.artalkConfig.el || '#Comments',
|
||||
server: window.artalkConfig.server,
|
||||
site: window.artalkConfig.site,
|
||||
pageKey: window.artalkConfig.pageKey, // Dynamic pageKey from config
|
||||
flatMode: true,
|
||||
darkMode: isDark,
|
||||
emoticons: window.artalkConfig.emoticons
|
||||
});
|
||||
|
||||
// Inject AI Comment
|
||||
window.artalk.on('list-loaded', function() {
|
||||
if (window.artalkConfig.aiComment && !document.querySelector('.atk-ai-comment')) {
|
||||
var listBody = document.querySelector('.atk-list-body') || document.querySelector('.atk-list');
|
||||
if (listBody) {
|
||||
var aiData = window.artalkConfig.aiComment;
|
||||
var aiDiv = document.createElement('div');
|
||||
aiDiv.className = 'atk-comment atk-ai-comment';
|
||||
// Initially empty content for typewriter effect
|
||||
aiDiv.innerHTML = `
|
||||
<div class="atk-avatar">
|
||||
<img src="${aiData.avatar}">
|
||||
</div>
|
||||
<div class="atk-main">
|
||||
<div class="atk-header">
|
||||
<span class="atk-nick">${aiData.name}</span>
|
||||
<span class="atk-badge">BOT</span>
|
||||
<span class="atk-date" title="${aiData.date}">${aiData.date}</span>
|
||||
</div>
|
||||
<div class="atk-body">
|
||||
<div class="atk-content">
|
||||
<p class="ai-content-text"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
listBody.prepend(aiDiv);
|
||||
|
||||
// Typewriter Effect
|
||||
const contentEl = aiDiv.querySelector('.ai-content-text');
|
||||
const text = aiData.content;
|
||||
let i = 0;
|
||||
|
||||
function type() {
|
||||
if (i < text.length) {
|
||||
contentEl.textContent += text.charAt(i);
|
||||
i++;
|
||||
// Random delay for more natural typing (20-50ms)
|
||||
setTimeout(type, Math.random() * 30 + 20);
|
||||
}
|
||||
}
|
||||
|
||||
// Start typing after a short delay
|
||||
setTimeout(type, 500);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Artalk 初始化完成后,再加载弹幕 (If available)
|
||||
if (typeof isMobile === 'function' && !isMobile() && window.loadBarrager) {
|
||||
window.loadBarrager();
|
||||
}
|
||||
};
|
||||
|
||||
async function fetchHitokoto() {
|
||||
try {
|
||||
|
||||
@@ -176,37 +176,8 @@ document.addEventListener("pjax:complete", function () {
|
||||
// 初始化代码复制
|
||||
initCodeCopy()
|
||||
// 重载评论
|
||||
if (document.querySelector("#Comments")) {
|
||||
var isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
||||
// 默认配置作为后备
|
||||
var serverUrl = 'https://artalk.usj.cc';
|
||||
var siteName = '优世界';
|
||||
var emoticons = '/emotion/OwO.json';
|
||||
|
||||
// 尝试从 window.siteConfig 获取配置
|
||||
if (window.siteConfig && window.siteConfig.artalk) {
|
||||
serverUrl = window.siteConfig.artalk.server || serverUrl;
|
||||
siteName = window.siteConfig.artalk.site || siteName;
|
||||
emoticons = window.siteConfig.artalk.emoticons || emoticons;
|
||||
}
|
||||
|
||||
// 保存实例到全局变量 window.artalk
|
||||
window.artalk = Artalk.init({
|
||||
el: '#Comments', // 绑定元素的 Selector
|
||||
server: serverUrl, // 后端地址
|
||||
site: siteName, // 你的站点名
|
||||
// 使用全局变量或 DOM 读取 pageKey
|
||||
// 必须动态获取当前页面的 pid (RelPermalink)
|
||||
pageKey: document.getElementById('data-pid')?.textContent?.trim() || location.pathname,
|
||||
flatMode: true,
|
||||
darkMode: isDark,
|
||||
emoticons: emoticons
|
||||
})
|
||||
|
||||
// Artalk 初始化完成后,再加载弹幕
|
||||
if (!isMobile() && window.loadBarrager) {
|
||||
window.loadBarrager();
|
||||
}
|
||||
if (typeof window.initArtalk === 'function') {
|
||||
window.initArtalk();
|
||||
}
|
||||
// 重载不蒜子统计
|
||||
if (typeof window.bsz_fetch === 'function') {
|
||||
|
||||
Reference in new issue
Block a user