added 代码折叠 修复bug
This commit is contained in:
1 parent
c115c7c0fb
commit
33a6ce2d85
4 files changed
+212
-35
No files matched your search
@@ -88,27 +88,38 @@ async function processFiles(dir) {
|
||||
window.artalk.on('list-loaded', function() {
|
||||
// 检查是否有 AI 评论数据
|
||||
if (window.artalkConfig.aiComment && !document.querySelector('.atk-ai-comment')) {
|
||||
// 创建 DOM 结构
|
||||
var aiDiv = document.createElement('div');
|
||||
aiDiv.className = 'atk-comment atk-ai-comment';
|
||||
aiDiv.innerHTML = `...`; // 填充 HTML
|
||||
var listBody = document.querySelector('.atk-list-body') || document.querySelector('.atk-list');
|
||||
|
||||
if (listBody) {
|
||||
// 避免同时出现“此时无声胜有声”
|
||||
var noComment = document.querySelector('.atk-list-no-comment');
|
||||
if (noComment) noComment.style.display = 'none';
|
||||
|
||||
// 插入到列表头部
|
||||
var listBody = document.querySelector('.atk-list-body');
|
||||
if (listBody) listBody.prepend(aiDiv);
|
||||
|
||||
// 简单的打字机效果
|
||||
const contentEl = aiDiv.querySelector('.ai-content-text');
|
||||
const text = window.artalkConfig.aiComment.content;
|
||||
let i = 0;
|
||||
function type() {
|
||||
if (i < text.length) {
|
||||
contentEl.textContent += text.charAt(i);
|
||||
i++;
|
||||
setTimeout(type, Math.random() * 30 + 20);
|
||||
}
|
||||
// 创建 DOM 结构
|
||||
var aiDiv = document.createElement('div');
|
||||
aiDiv.className = 'atk-comment atk-ai-comment';
|
||||
aiDiv.innerHTML = `...`; // 填充 HTML
|
||||
|
||||
// 插入到列表头部
|
||||
listBody.prepend(aiDiv);
|
||||
|
||||
// ... (打字机效果)
|
||||
}
|
||||
setTimeout(type, 500);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## 4. 适配 PJAX
|
||||
|
||||
由于博客使用了 PJAX,页面切换时需要重新初始化 Artalk。我们将初始化逻辑封装在 `initArtalk` 函数中,并在 `pjax:complete` 事件中调用。
|
||||
|
||||
```javascript
|
||||
// mypjax.js
|
||||
document.addEventListener("pjax:complete", function () {
|
||||
// ...
|
||||
// 重载评论
|
||||
if (typeof window.initArtalk === 'function') {
|
||||
window.initArtalk();
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user