logo和配置修改

This commit is contained in:
谢宇宁
2026-09-23 16:50:34 +07:00
parent bef9f8b4ed
commit 0db8087765
163 changed files with 393 additions and 20366 deletions
+24 -704
View File
@@ -120,239 +120,18 @@
})();
(function () {
// detail.js 同步执行早于 defer 的 request.js,需等 HttpRequest 就绪后再绑定
function toast(message, type) {
if (typeof window.showToast === "function") {
window.showToast(message, type);
return;
}
window.alert(message);
}
// 付费剧集:不再站内解锁,统一引导下载 APP
var lockedEpisodes = document.querySelectorAll("[data-episode-locked]");
if (!lockedEpisodes.length) return;
function bindLikeActions() {
var likeBtns = document.querySelectorAll("[data-detail-like]");
if (!likeBtns.length) return;
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
if (!bindLikeActions._retried) {
bindLikeActions._retried = true;
window.addEventListener("load", bindLikeActions, { once: true });
lockedEpisodes.forEach(function (el) {
el.addEventListener("click", function (e) {
e.preventDefault();
if (typeof window.openDownloadApp === "function") {
window.openDownloadApp();
}
return;
}
if (bindLikeActions._bound) return;
bindLikeActions._bound = true;
function applyLikeUI(isLike, countLike) {
var liked = Number(isLike) === 1;
likeBtns.forEach(function (btn) {
btn.classList.toggle("detail-action--active", liked);
btn.classList.toggle("detail-h5-top-btn--active", liked);
btn.classList.toggle("detail-h5-like--active", liked);
btn.classList.toggle("play-h5-side-item--active", liked);
btn.setAttribute("data-liked", liked ? "1" : "2");
btn.setAttribute("aria-pressed", liked ? "true" : "false");
if (countLike != null) {
btn.setAttribute("data-count-like", String(countLike));
}
var label = btn.querySelector("[data-detail-like-label]");
if (label) {
if (btn.getAttribute("data-like-label-mode") === "state") {
label.textContent = liked ? "已点赞" : "点赞";
} else {
var n = countLike != null ? countLike : btn.getAttribute("data-count-like");
label.textContent = String(n == null || n === "" ? 0 : n);
}
}
var h5Icon = btn.querySelector("[data-h5-like-icon]");
if (h5Icon) {
h5Icon.src = liked
? "/static/images/h5_liked.svg"
: "/static/images/like.svg";
}
});
}
likeBtns.forEach(function (btn) {
btn.addEventListener("click", function () {
if (btn.getAttribute("data-liking") === "1") return;
var playletId = Number(btn.getAttribute("data-playlet-id") || 0);
if (!playletId) return;
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
var countNow = Number(btn.getAttribute("data-count-like") || 0);
if (Number.isNaN(countNow)) countNow = 0;
var nextLike = !likedNow;
var nextCount = Math.max(0, countNow + (nextLike ? 1 : -1));
likeBtns.forEach(function (item) {
item.setAttribute("data-liking", "1");
item.disabled = true;
});
applyLikeUI(nextLike ? 1 : 2, nextCount);
window.HttpRequest.post("/api/playlet/like/set", {
id: playletId,
isLike: nextLike,
})
.then(function (res) {
if (!res || res.code !== 200) {
if (res && res.code === 401) {
var loginOpen = document.querySelector(
"[data-login-dialog-open]"
);
if (loginOpen) loginOpen.click();
}
throw new Error((res && (res.tip || res.msg)) || "操作失败");
}
var data = res.data || {};
applyLikeUI(
data.isLike != null ? data.isLike : nextLike ? 1 : 2,
data.countLike != null ? data.countLike : nextCount
);
})
.catch(function (err) {
applyLikeUI(likedNow ? 1 : 2, countNow);
toast((err && err.message) || "操作失败,请稍后重试", "error");
})
.finally(function () {
likeBtns.forEach(function (item) {
item.removeAttribute("data-liking");
item.disabled = false;
});
});
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", bindLikeActions, { once: true });
} else {
bindLikeActions();
}
})();
(function () {
function toast(message, type) {
if (typeof window.showToast === "function") {
window.showToast(message, type);
return;
}
window.alert(message);
}
function bindCollectActions() {
var collectBtns = document.querySelectorAll("[data-detail-collect]");
if (!collectBtns.length) return;
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
if (!bindCollectActions._retried) {
bindCollectActions._retried = true;
window.addEventListener("load", bindCollectActions, { once: true });
}
return;
}
if (bindCollectActions._bound) return;
bindCollectActions._bound = true;
function applyCollectUI(isCollect, countCollect) {
var collected = Number(isCollect) === 1;
collectBtns.forEach(function (btn) {
btn.classList.toggle("detail-action--active", collected);
btn.classList.toggle("detail-h5-collect--active", collected);
btn.classList.toggle("detail-h5-top-btn--active", collected);
btn.classList.toggle("play-h5-side-item--active", collected);
btn.classList.toggle("is-collected", collected);
btn.setAttribute("data-collected", collected ? "1" : "2");
btn.setAttribute("aria-pressed", collected ? "true" : "false");
if (countCollect != null) {
btn.setAttribute("data-count-collect", String(countCollect));
}
var label = btn.querySelector("[data-detail-collect-label]");
if (label) {
if (btn.classList.contains("detail-h5-collect")) {
var n = countCollect != null
? countCollect
: btn.getAttribute("data-count-collect");
label.textContent = String(n == null || n === "" ? 0 : n);
} else {
label.textContent = collected ? "已收藏" : "收藏";
}
}
var h5Icon = btn.querySelector("[data-h5-collect-icon]");
if (h5Icon) {
if (btn.classList.contains("detail-h5-top-btn")) {
h5Icon.src = collected
? "/static/images/h5_collected.svg?v=2"
: "/static/images/collect.svg";
} else if (btn.classList.contains("play-h5-side-item")) {
h5Icon.src = collected
? "/static/images/h5_collected.svg?v=2"
: "/static/images/collect.svg";
} else {
h5Icon.src = collected
? "/static/images/h5_detail_collected.svg"
: "/static/images/h5_detail_collect.svg";
}
}
});
}
collectBtns.forEach(function (btn) {
btn.addEventListener("click", function () {
if (btn.getAttribute("data-collecting") === "1") return;
var playletId = Number(btn.getAttribute("data-playlet-id") || 0);
if (!playletId) return;
var collectedNow = Number(btn.getAttribute("data-collected") || 2) === 1;
var countNow = Number(btn.getAttribute("data-count-collect") || 0);
if (Number.isNaN(countNow)) countNow = 0;
var nextCollect = !collectedNow;
var nextCount = Math.max(0, countNow + (nextCollect ? 1 : -1));
collectBtns.forEach(function (item) {
item.setAttribute("data-collecting", "1");
item.disabled = true;
});
applyCollectUI(nextCollect ? 1 : 2, nextCount);
window.HttpRequest.post("/api/playlet/collect/set", {
id: playletId,
isCollect: nextCollect,
})
.then(function (res) {
if (!res || res.code !== 200) {
if (res && res.code === 401) {
var loginOpen = document.querySelector(
"[data-login-dialog-open]"
);
if (loginOpen) loginOpen.click();
}
throw new Error((res && (res.tip || res.msg)) || "操作失败");
}
var data = res.data || {};
applyCollectUI(
data.isCollect != null ? data.isCollect : nextCollect ? 1 : 2,
data.countCollect != null ? data.countCollect : nextCount
);
})
.catch(function (err) {
applyCollectUI(collectedNow ? 1 : 2, countNow);
toast((err && err.message) || "操作失败,请稍后重试", "error");
})
.finally(function () {
collectBtns.forEach(function (item) {
item.removeAttribute("data-collecting");
item.disabled = false;
});
});
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", bindCollectActions, { once: true });
} else {
bindCollectActions();
}
});
})();
(function () {
@@ -593,15 +372,6 @@
return formatCommentTime(raw);
}
function formatCompactCount(n) {
n = Number(n);
if (!n || n < 0 || Number.isNaN(n)) return "0";
if (n < 10000) return String(n);
var v = n / 10000;
if (v >= 10) return Math.floor(v) + "w";
return (Math.round(v * 10) / 10) + "w";
}
function avatarURL(url) {
url = String(url || "").trim();
return url || DEFAULT_AVATAR;
@@ -614,10 +384,7 @@
}
function renderDetailComment(item, playPcMode) {
var liked = Number(item.isLike) === 1;
var avatar = avatarURL(item.userAvatar);
var commentId = item.id;
var parentsId = Number(item.parentsId || 0) || Number(commentId);
var avatarHtml = item.userAvatar
? '<img class="detail-comment-avatar lazy" src="' +
PLACEHOLDER +
@@ -627,9 +394,6 @@
escapeHtml((item.userName || "匿名用户") + "的头像") +
'" />'
: '<img class="detail-comment-avatar" src="' + DEFAULT_AVATAR + '" alt="匿名用户头像" />';
var likeIcon = liked
? "/static/images/like_solid.svg"
: "/static/images/like_hollow.svg";
var textHtml = escapeHtml(item.text || "");
if (item.replyUserName) {
textHtml =
@@ -691,11 +455,7 @@
}
return (
'<div class="detail-comment" data-comment-id="' +
escapeHtml(commentId) +
'" data-parents-id="' +
escapeHtml(parentsId) +
'" data-user-name="' +
escapeHtml(item.userName || "匿名用户") +
escapeHtml(item.id) +
'">' +
avatarHtml +
'<div class="detail-comment-body">' +
@@ -709,27 +469,6 @@
'<span class="detail-comment-time">' +
escapeHtml(formatCommentTime(item.createdAt)) +
"</span>" +
'<button class="detail-comment-like' +
(liked ? " detail-comment-like--active" : "") +
'" type="button" aria-label="点赞" data-comment-like="' +
escapeHtml(commentId) +
'" data-liked="' +
(liked ? "1" : "2") +
'">' +
'<img src="' +
likeIcon +
'" alt="点赞" />' +
'<span data-like-count>' +
escapeHtml(item.countLike == null ? 0 : item.countLike) +
"</span>" +
"</button>" +
'<button class="detail-comment-reply-label" type="button" data-comment-reply="' +
escapeHtml(commentId) +
'" data-parents-id="' +
escapeHtml(parentsId) +
'" data-reply-name="' +
escapeHtml(item.userName || "匿名用户") +
'">回复</button>' +
"</div>" +
repliesHtml +
"</div></div>"
@@ -737,10 +476,8 @@
}
function renderPlayComment(item) {
var liked = Number(item.isLike) === 1;
var avatar = avatarURL(item.userAvatar);
var commentId = item.id;
var parentsId = Number(item.parentsId || 0) || Number(commentId);
var children = Array.isArray(item.children) ? item.children : [];
var replyCount = Number(item.commentCount || children.length || 0);
var avatarHtml = item.userAvatar
@@ -752,9 +489,6 @@
escapeHtml((item.userName || "匿名用户") + "的头像") +
'" />'
: '<img class="play-comment-avatar" src="' + DEFAULT_AVATAR + '" alt="匿名用户头像" />';
var likeIcon = liked
? "/static/images/h5_liked.svg"
: "/static/images/like_hollow.svg";
var textHtml = escapeHtml(item.text || "");
if (item.replyUserName) {
textHtml =
@@ -807,10 +541,6 @@
return (
'<div class="play-comment-item" data-comment-id="' +
escapeHtml(commentId) +
'" data-parents-id="' +
escapeHtml(parentsId) +
'" data-user-name="' +
escapeHtml(item.userName || "匿名用户") +
'">' +
avatarHtml +
'<div class="play-comment-body">' +
@@ -825,30 +555,7 @@
'<span class="play-comment-time">' +
escapeHtml(formatRelativeTime(item.createdAt)) +
"</span>" +
'<button class="play-comment-reply-action" type="button" data-comment-reply="' +
escapeHtml(commentId) +
'" data-parents-id="' +
escapeHtml(parentsId) +
'" data-reply-name="' +
escapeHtml(item.userName || "匿名用户") +
'">回复</button>' +
"</div>" +
'<button class="play-comment-like' +
(liked ? " play-comment-like--active" : "") +
'" type="button" aria-label="点赞" data-comment-like="' +
escapeHtml(commentId) +
'" data-liked="' +
(liked ? "1" : "2") +
'" data-like-raw="' +
escapeHtml(item.countLike == null ? 0 : item.countLike) +
'">' +
'<img src="' +
likeIcon +
'" alt="点赞" />' +
'<span data-like-count>' +
escapeHtml(formatCompactCount(item.countLike)) +
"</span>" +
"</button>" +
"</div>" +
repliesHtml +
"</div></div>"
@@ -887,18 +594,12 @@
var scope = sheetRoot || section;
var listEl = section.querySelector("[data-comment-list]");
var moreBtn = section.querySelector("[data-comment-more]");
var composerInput =
scope.querySelector(".play-comment-composer-input") ||
scope.querySelector(".detail-comment-composer-input");
var composerCount = scope.querySelector(".detail-comment-composer-count");
var titleEl = section.querySelector("[data-comment-title]");
var sendBtn = scope.querySelector("[data-comment-send]");
var sortBtns = scope.querySelectorAll("[data-comment-sort]");
var sheetTitle = sheetRoot
? sheetRoot.querySelector("[data-play-comment-title]")
: document.querySelector("[data-play-comment-title]");
var sideCount = document.querySelector("[data-play-comment-count]");
var iconSend = !!(sendBtn && sendBtn.classList.contains("play-comment-composer-emoji"));
if (section.getAttribute("data-comment-inited") === "1") return;
section.setAttribute("data-comment-inited", "1");
@@ -910,169 +611,11 @@
var page = 0;
var total = 0;
var loading = false;
var sending = false;
var replyTarget = null; // { parentsId, replyCommentId, replyName }
var inlineSending = false;
function getObjectId() {
return Number(section.getAttribute("data-comment-object-id") || 0);
}
function clearReplyTarget() {
replyTarget = null;
if (!scope) return;
var boxes = scope.querySelectorAll("[data-comment-inline-composer]");
Array.prototype.forEach.call(boxes, function (el) {
el.remove();
});
}
function setReplyTarget(parentsId, replyCommentId, replyName, anchorEl) {
parentsId = Number(parentsId || 0);
replyCommentId = Number(replyCommentId || 0);
if (!parentsId || !replyCommentId || !anchorEl) return;
var root =
anchorEl.closest(commentItemSelector()) ||
anchorEl.closest("[data-comment-id]");
if (!root || !scope.contains(root)) return;
// 再次点击同一条:关闭内联输入框
var existingOnRoot = root.querySelector("[data-comment-inline-composer]");
if (
existingOnRoot &&
replyTarget &&
replyTarget.replyCommentId === replyCommentId
) {
clearReplyTarget();
return;
}
clearReplyTarget();
replyTarget = {
parentsId: parentsId,
replyCommentId: replyCommentId,
replyName: replyName || "用户",
};
var meta =
root.querySelector(".detail-comment-meta") ||
root.querySelector(".play-comment-meta");
var body =
root.querySelector(".detail-comment-body") ||
root.querySelector(".play-comment-body") ||
root;
var box = document.createElement("div");
box.className = sheetMode
? "play-comment-inline-composer"
: "detail-comment-inline-composer";
box.setAttribute("data-comment-inline-composer", "");
var placeholder = "回复 @" + replyTarget.replyName + "…";
if (sheetMode) {
box.innerHTML =
'<div class="play-comment-reply-hint" data-comment-reply-hint>' +
"<span>回复 @" +
escapeHtml(replyTarget.replyName) +
"</span>" +
'<button type="button" data-comment-reply-cancel>取消</button>' +
"</div>" +
'<div class="play-comment-inline-row">' +
'<input class="play-comment-inline-input" type="text" maxlength="200" placeholder="' +
escapeHtml(placeholder) +
'" data-comment-inline-input autocomplete="off" />' +
'<button class="play-comment-inline-send" type="button" data-comment-inline-send>发送</button>' +
"</div>";
} else {
box.innerHTML =
'<div class="detail-comment-reply-hint" data-comment-reply-hint>' +
"<span>回复 @" +
escapeHtml(replyTarget.replyName) +
"</span>" +
'<button type="button" data-comment-reply-cancel>取消</button>' +
"</div>" +
'<textarea class="detail-comment-inline-input" maxlength="200" rows="2" placeholder="' +
escapeHtml(placeholder) +
'" data-comment-inline-input></textarea>' +
'<div class="detail-comment-inline-footer">' +
'<button class="detail-comment-inline-send" type="button" data-comment-inline-send>发表回复</button>' +
"</div>";
}
if (meta && meta.parentNode === body) {
if (meta.nextSibling) {
body.insertBefore(box, meta.nextSibling);
} else {
body.appendChild(box);
}
} else {
body.appendChild(box);
}
var inlineInput = box.querySelector("[data-comment-inline-input]");
if (inlineInput) {
inlineInput.focus();
}
}
function sendInlineReply(box) {
if (!box || inlineSending || !replyTarget) return;
var objectId = getObjectId();
if (!objectId) return;
var input = box.querySelector("[data-comment-inline-input]");
var btn = box.querySelector("[data-comment-inline-send]");
if (!input) return;
var text = String(input.value || "").trim();
if (!text) {
toast("请输入评论内容", "error");
return;
}
if (Array.from(text).length > 200) {
toast("评论最多 200 字", "error");
return;
}
inlineSending = true;
if (btn) {
btn.disabled = true;
btn.classList.add("is-loading");
}
input.disabled = true;
var payload = {
objectId: objectId,
objectType: objectType,
text: text,
parentsId: replyTarget.parentsId,
replyCommentId:
replyTarget.replyCommentId > 0
? replyTarget.replyCommentId
: replyTarget.parentsId,
};
window.HttpRequest.post("/api/comment/send", payload)
.then(function (res) {
if (!res || res.code !== 200) {
if (res && res.code === 401) {
var loginOpen = document.querySelector(
"[data-login-dialog-open]"
);
if (loginOpen) loginOpen.click();
}
throw new Error((res && (res.tip || res.msg)) || "发表失败");
}
clearReplyTarget();
toast("发布成功,评论审核后才会展示", "success");
})
.catch(function (err) {
toast((err && err.message) || "发表失败,请稍后重试", "error");
})
.finally(function () {
inlineSending = false;
if (btn) {
btn.disabled = false;
btn.classList.remove("is-loading");
}
if (input) input.disabled = false;
});
}
function commentItemSelector() {
return sheetMode ? ".play-comment-item" : ".detail-comment";
}
@@ -1089,32 +632,6 @@
}
}
function applyLikeUI(btn, isLike, countLike) {
var liked = Number(isLike) === 1;
btn.classList.toggle("detail-comment-like--active", liked);
btn.classList.toggle("play-comment-like--active", liked);
btn.setAttribute("data-liked", liked ? "1" : "2");
var img = btn.querySelector("img");
if (img) {
if (sheetMode) {
img.src = liked
? "/static/images/h5_liked.svg"
: "/static/images/like_hollow.svg";
} else {
img.src = liked
? "/static/images/like_solid.svg"
: "/static/images/like_hollow.svg";
}
}
var countEl = btn.querySelector("[data-like-count]");
if (countEl && countLike != null) {
btn.setAttribute("data-like-raw", String(countLike));
countEl.textContent = sheetMode
? formatCompactCount(countLike)
: String(countLike);
}
}
function syncSortActive() {
sortBtns.forEach(function (item) {
var active = Number(item.getAttribute("data-comment-sort")) === sortOrder;
@@ -1140,7 +657,6 @@
var emptyClass = sheetMode
? "section-empty play-comment-empty"
: "section-empty";
clearReplyTarget();
listEl.innerHTML =
'<div class="' +
emptyClass +
@@ -1179,7 +695,6 @@
updateTitleCount();
if (replace) {
clearReplyTarget();
if (!rows.length) {
showEmpty("暂无评论");
return;
@@ -1225,15 +740,6 @@
});
}
if (composerInput && composerCount) {
var syncCount = function () {
composerCount.textContent =
Array.from(composerInput.value).length + " / 200";
};
composerInput.addEventListener("input", syncCount);
syncCount();
}
syncSortActive();
sortBtns.forEach(function (btn) {
@@ -1251,149 +757,27 @@
});
});
if (sendBtn && composerInput) {
var sendBtnDefaultText = sendBtn.textContent || "发表评论";
sendBtn.addEventListener("click", function () {
var objectId = getObjectId();
if (sending || !objectId) return;
var text = String(composerInput.value || "").trim();
if (!text) {
toast("请输入评论内容", "error");
return;
}
if (Array.from(text).length > 200) {
toast("评论最多 200 字", "error");
return;
}
sending = true;
sendBtn.disabled = true;
sendBtn.classList.add("is-loading");
if (!iconSend) sendBtn.textContent = "发表中";
composerInput.disabled = true;
var payload = {
objectId: objectId,
objectType: objectType,
text: text,
parentsId: 0,
replyCommentId: 0,
};
window.HttpRequest.post("/api/comment/send", payload)
.then(function (res) {
if (!res || res.code !== 200) {
if (res && res.code === 401) {
var loginOpen = document.querySelector(
"[data-login-dialog-open]"
);
if (loginOpen) loginOpen.click();
}
throw new Error((res && (res.tip || res.msg)) || "发表失败");
}
composerInput.value = "";
if (composerCount) composerCount.textContent = "0 / 200";
toast("发布成功,评论审核后才会展示", "success");
// 与 PC 一致:发表后不强制刷新列表(审核后才可见)
})
.catch(function (err) {
toast((err && err.message) || "发表失败,请稍后重试", "error");
})
.finally(function () {
sending = false;
sendBtn.disabled = false;
sendBtn.classList.remove("is-loading");
if (!iconSend) sendBtn.textContent = sendBtnDefaultText;
composerInput.disabled = false;
});
});
if (sheetMode) {
composerInput.addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault();
sendBtn.click();
}
});
}
}
if (scope) {
scope.addEventListener("click", function (e) {
var cancel =
e.target && e.target.closest
? e.target.closest("[data-comment-reply-cancel]")
: null;
if (cancel) {
e.preventDefault();
clearReplyTarget();
return;
}
var inlineSend =
e.target && e.target.closest
? e.target.closest("[data-comment-inline-send]")
: null;
if (inlineSend && scope.contains(inlineSend)) {
e.preventDefault();
var box = inlineSend.closest("[data-comment-inline-composer]");
sendInlineReply(box);
return;
}
var repliesToggle =
e.target && e.target.closest
? e.target.closest("[data-comment-replies-toggle]")
: null;
if (repliesToggle && scope.contains(repliesToggle)) {
e.preventDefault();
var repliesBox = repliesToggle.closest(".detail-comment-replies");
if (!repliesBox) return;
var expanded = repliesToggle.getAttribute("aria-expanded") === "true";
expanded = !expanded;
repliesToggle.setAttribute("aria-expanded", expanded ? "true" : "false");
repliesToggle.textContent = replyToggleLabel(
expanded,
repliesToggle.getAttribute("data-reply-count")
);
var hiddenItems = repliesBox.querySelectorAll("[data-reply-collapsed-item]");
Array.prototype.forEach.call(hiddenItems, function (el) {
el.hidden = !expanded;
});
return;
}
var replyBtn =
e.target && e.target.closest
? e.target.closest("[data-comment-reply]")
: null;
if (!replyBtn || !scope.contains(replyBtn)) return;
if (!repliesToggle || !scope.contains(repliesToggle)) return;
e.preventDefault();
var replyCommentId = Number(replyBtn.getAttribute("data-comment-reply") || 0);
var parentsId = Number(replyBtn.getAttribute("data-parents-id") || 0);
var replyName = replyBtn.getAttribute("data-reply-name") || "用户";
if (!parentsId) {
var root =
replyBtn.closest("[data-parents-id]") ||
replyBtn.closest("[data-comment-id]");
if (root) {
parentsId = Number(
root.getAttribute("data-parents-id") ||
root.getAttribute("data-comment-id") ||
0
);
}
}
if (!replyCommentId) return;
if (!parentsId) parentsId = replyCommentId;
setReplyTarget(parentsId, replyCommentId, replyName, replyBtn);
});
scope.addEventListener("keydown", function (e) {
if (e.key !== "Enter") return;
var input =
e.target && e.target.closest
? e.target.closest("[data-comment-inline-input]")
: null;
if (!input || !scope.contains(input)) return;
if (input.tagName === "TEXTAREA" && !e.ctrlKey && !e.metaKey) return;
e.preventDefault();
var box = input.closest("[data-comment-inline-composer]");
sendInlineReply(box);
var repliesBox = repliesToggle.closest(".detail-comment-replies");
if (!repliesBox) return;
var expanded = repliesToggle.getAttribute("aria-expanded") === "true";
expanded = !expanded;
repliesToggle.setAttribute("aria-expanded", expanded ? "true" : "false");
repliesToggle.textContent = replyToggleLabel(
expanded,
repliesToggle.getAttribute("data-reply-count")
);
var hiddenItems = repliesBox.querySelectorAll("[data-reply-collapsed-item]");
Array.prototype.forEach.call(hiddenItems, function (el) {
el.hidden = !expanded;
});
});
}
@@ -1403,70 +787,6 @@
});
}
if (listEl) {
listEl.addEventListener("click", function (e) {
var btn =
e.target && e.target.closest
? e.target.closest("[data-comment-like]")
: null;
if (!btn || !listEl.contains(btn)) return;
var commentId = Number(btn.getAttribute("data-comment-like") || 0);
if (!commentId) return;
if (btn.getAttribute("data-liking") === "1") return;
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
var nextLike = !likedNow;
var rawAttr = btn.getAttribute("data-like-raw");
var countEl = btn.querySelector("[data-like-count]");
var prevCount = Number(
rawAttr != null
? rawAttr
: countEl && countEl.textContent
? countEl.textContent
: 0
);
if (Number.isNaN(prevCount)) prevCount = 0;
btn.setAttribute("data-liking", "1");
btn.disabled = true;
applyLikeUI(
btn,
nextLike ? 1 : 2,
Math.max(0, prevCount + (nextLike ? 1 : -1))
);
window.HttpRequest.post("/api/comment/like/set", {
commentId: commentId,
isLike: nextLike,
})
.then(function (res) {
if (!res || res.code !== 200) {
if (res && res.code === 401) {
var loginOpen = document.querySelector(
"[data-login-dialog-open]"
);
if (loginOpen) loginOpen.click();
}
throw new Error((res && (res.tip || res.msg)) || "操作失败");
}
var data = res.data || {};
applyLikeUI(
btn,
data.isLike != null ? data.isLike : nextLike ? 1 : 2,
data.countLike != null ? data.countLike : null
);
})
.catch(function (err) {
applyLikeUI(btn, likedNow ? 1 : 2, prevCount);
toast((err && err.message) || "操作失败,请稍后重试", "error");
})
.finally(function () {
btn.removeAttribute("data-liking");
btn.disabled = false;
});
});
}
if (!listEl || !getObjectId()) {
if (listEl) showEmpty("暂无评论");
return;