官职徽章改回主题渲染,数据由后端 rank 字段下发
Deploy to Production / pre-check (push) Successful in 1m16s
Deploy to Production / build (push) Successful in 10m24s
Deploy to Production / deploy-edgeone (push) Successful in 3m52s
Deploy to Production / finalize (push) Successful in 28s
Deploy to Production / notify-failure (push) Skipped

上一版把九品官阶塞进官方 badge_name/badge_color 槽——但博主
徽章是独一无二的,官职应该接在它后面而不是挤占同一个槽位。
后端现下发独立字段 rank_name/rank_title/rank_count/rank_color/
rank_bg(配色沿用主题原版彩字+半透明底),本文件在
comment-rendered 事件里渲染官职徽章。
This commit is contained in:
QunLIn committed 2026-10-03 10:01:52 +08:00
1 parent 20869a3c45
commit cc85ace7c2
1 file changed
+30 -4
+30 -4
View File
@@ -624,10 +624,8 @@ var getPageKey = function() {
var processBadges = function() {
if (!linkMap && !feedMap) return;
// 评论等级(九品官阶)已迁到评论后端:artalk-cf 按全站真实评论数
// 计算并直接下发 badge_name/badge_color(官方 badge 槽渲染)。
// 原 localStorage 累计方案只统计当前浏览器见过的评论,跨设备/清缓存
// 就失真,已废弃(RANK_TABLE 保留仅作历史参考,不再注入)。
// 友链 / 友圈徽章:数据来自 window.friendLinks / window.friendFeeds
// (评论等级官职徽章已迁到 comment-rendered 处理,见下方)
document.querySelectorAll('.atk-comment-wrap').forEach(function(wrap) {
var nickEl = wrap.querySelector('.atk-nick');
@@ -692,6 +690,34 @@ var injectAllBadges = function() {
}
};
// 评论等级官职徽章——后端按全站真实评论数计算,随评论 API 下发
// rank_name/rank_title/rank_count/rank_color/rank_bg(不占用官方 badge 槽,
// 官方徽章如「博主」保留,官职徽章接在其后面)。配色沿用主题原版。
artalk.on('comment-rendered', function(node) {
try {
var data = null;
if (node && typeof node.getData === 'function') data = node.getData();
else if (node && node.comment && typeof node.comment.getData === 'function') data = node.comment.getData();
else data = node;
if (!data || !data.rank_name) return;
var el = null;
if (node && node.$el) el = node.$el;
else if (node && typeof node.getEl === 'function') el = node.getEl();
if (!el || !el.querySelector) return;
var nickEl = el.querySelector('.atk-nick');
if (!nickEl || nickEl.querySelector('.atk-rank-badge')) return;
var rb = document.createElement('span');
rb.className = 'atk-rank-badge';
rb.textContent = data.rank_name;
var tip = data.rank_title || data.rank_name;
if (data.rank_count != null) tip += ' (' + data.rank_count + '条评论)';
rb.title = tip;
rb.style.color = data.rank_color || '';
rb.style.backgroundColor = data.rank_bg || '';
nickEl.appendChild(rb);
} catch (e) { /* 徽章注入失败不影响评论 */ }
});
artalk.on('list-loaded', function() {
// Badge injection
badgesInjected = false;