友链卡片固定在评论列表上方(不再被新评论挤到中间):整条评论用class隐藏,卡片插入atk-list-body首位
Deploy to Production / pre-check (push) Successful in 53s
Deploy to Production / build (push) Canceled after 1m2s
Deploy to Production / deploy-edgeone (push) Canceled after 0s
Deploy to Production / finalize (push) Canceled after 0s
Deploy to Production / notify-failure (push) Canceled after 0s

This commit is contained in:
zqlit committed 2026-10-03 17:20:04 +08:00
1 parent ab94c25273
commit c952620fd6
2 files changed
+28 -12

No files matched your search

+21 -5
View File
@@ -723,10 +723,14 @@ artalk.on('comment-rendered', function(node) {
var content = String(d2.content || '').trim().replace(/\/+$/, '').toLowerCase();
if (content !== 'https://usj.cc/link-apply') return;
// 幂等 + 自愈:class 每次渲染都补一次(隐藏原评论内容的 CSS 规则依赖它),
// 已有卡片就直接返回,避免 Artalk 重渲染时出现第二张卡片
// 幂等 + 自愈:class 每次渲染都补一次(CSS 靠它隐藏整条评论),
// 卡片始终挂在评论列表"上方"(.atk-list-body 的第一个子节点),
// 这样发新评论/切换排序都不会把卡片夹到评论中间。
el2.classList.add('atk-fl-apply');
if (el2.querySelector('.atk-fl-card')) return;
var listBody = document.querySelector('.atk-list-body') || document.querySelector('.atk-list');
var oldHolder = document.querySelector('.atk-fl-card-wrap');
if (oldHolder && listBody && oldHolder.parentNode === listBody && oldHolder.isConnected) return;
if (oldHolder && oldHolder.parentNode) oldHolder.parentNode.removeChild(oldHolder);
el2.style.cursor = 'pointer';
el2.title = '点击申请友链';
@@ -785,9 +789,21 @@ artalk.on('comment-rendered', function(node) {
var nickRow = card.querySelector('span > span');
nickRow.appendChild(bw);
}
// 卡片直接挂在评论节点(.atk-comment)下:宽度与评论输入框一致
// 卡片包一层容器挂到列表上方(宽度与评论区一致,且不受列表排序/新增影响)
if (contentEl) contentEl.innerHTML = '';
commentEl.appendChild(card);
var holder = document.createElement('div');
holder.className = 'atk-fl-card-wrap';
holder.appendChild(card);
if (listBody) {
if (listBody.firstChild) listBody.insertBefore(holder, listBody.firstChild);
else listBody.appendChild(holder);
} else {
commentEl.appendChild(holder);
}
// 点击卡片即打开申请弹窗(原来挂在 el2 上,现在卡片已移出评论节点)
holder.addEventListener('click', function () {
if (window.flApplyOpenModal) window.flApplyOpenModal();
});
// ── 打字机效果(PJAX 安全:卡片被移除/替换时定时器自动停止) ──
// 注意:不要用 prefers-reduced-motion 跳过打字 —— Windows 关闭"动画效果"