调整UI
This commit is contained in:
@@ -75,21 +75,6 @@
|
||||
var displayedIndex = -1;
|
||||
var loadGeneration = 0;
|
||||
|
||||
function emitTrack(item, eventType) {
|
||||
if (!item || eventType === "close") return;
|
||||
if (window.tracker && typeof window.tracker.externalAd === "function") {
|
||||
window.tracker.externalAd(item, eventType);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
document.dispatchEvent(new CustomEvent("external-ad:track", {
|
||||
detail: { element: item, eventType: eventType },
|
||||
}));
|
||||
} catch (error) {
|
||||
// 埋点不可用时不影响广告展示与关闭。
|
||||
}
|
||||
}
|
||||
|
||||
function hideAllItems() {
|
||||
items.forEach(function (item) {
|
||||
item.hidden = true;
|
||||
@@ -118,7 +103,6 @@
|
||||
var item = displayedIndex >= 0 ? items[displayedIndex] : null;
|
||||
if (item && !item.__dialogAdShowTracked) {
|
||||
item.__dialogAdShowTracked = true;
|
||||
emitTrack(item, "show");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,18 +223,13 @@
|
||||
if (!item || item.hidden || !mask.contains(item)) return;
|
||||
var index = items.indexOf(item);
|
||||
if (index < 0 || index !== displayedIndex) return;
|
||||
if (event.target.closest("[data-dialog-ad-link]")) {
|
||||
emitTrack(item, "click");
|
||||
}
|
||||
if (event.target.closest("[data-dialog-ad-close]")) {
|
||||
emitTrack(item, "close");
|
||||
showItem(index + 1);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Escape" && mask.classList.contains("is-open") && displayedIndex >= 0) {
|
||||
emitTrack(items[displayedIndex], "close");
|
||||
showNextItem();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,10 +37,6 @@
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
if (window.AuthAPI && typeof window.AuthAPI.toast === "function") {
|
||||
window.AuthAPI.toast(message, type || "info");
|
||||
return;
|
||||
}
|
||||
window.alert(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
(function () {
|
||||
var form = document.querySelector("[data-login-page-form]");
|
||||
var password = document.querySelector("[data-login-page-password]");
|
||||
var toggle = document.querySelector("[data-login-page-toggle]");
|
||||
var toggleIcon = document.querySelector("[data-login-page-toggle-icon]");
|
||||
var submitBtn = document.querySelector("[data-login-page-submit]") || (form && form.querySelector('button[type="submit"]'));
|
||||
var root = form || document;
|
||||
|
||||
if (toggle && password && toggleIcon) {
|
||||
toggle.addEventListener("click", function () {
|
||||
var show = password.getAttribute("type") === "password";
|
||||
password.setAttribute("type", show ? "text" : "password");
|
||||
toggleIcon.setAttribute("src", show ? "/static/images/eye-off.svg" : "/static/images/eye.svg");
|
||||
toggle.setAttribute("aria-label", show ? "隐藏密码" : "显示密码");
|
||||
});
|
||||
}
|
||||
|
||||
function clearFieldError(name) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.remove("is-error");
|
||||
if (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllErrors() {
|
||||
root.querySelectorAll("[data-field]").forEach(function (el) {
|
||||
el.classList.remove("is-error");
|
||||
});
|
||||
root.querySelectorAll("[data-field-error]").forEach(function (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
});
|
||||
}
|
||||
|
||||
function setFieldError(name, message) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.add("is-error");
|
||||
if (err) {
|
||||
err.hidden = false;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = message || "";
|
||||
}
|
||||
}
|
||||
|
||||
function isLen4to16(value) {
|
||||
var len = String(value || "").length;
|
||||
return len >= 4 && len <= 16;
|
||||
}
|
||||
|
||||
function validateForm() {
|
||||
clearAllErrors();
|
||||
var fd = new FormData(form);
|
||||
var account = String(fd.get("account") || "").trim();
|
||||
var pwd = String(fd.get("password") || "");
|
||||
var valid = true;
|
||||
|
||||
if (!account) {
|
||||
setFieldError("account", "请输入账号");
|
||||
valid = false;
|
||||
} else if (
|
||||
!(window.AuthAPI && AuthAPI.isValidLoginAccount
|
||||
? AuthAPI.isValidLoginAccount(account)
|
||||
: isLen4to16(account) || account.indexOf("@") >= 0)
|
||||
) {
|
||||
setFieldError("account", "账号需为 4–16 位,或合法邮箱");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd) {
|
||||
setFieldError("password", "请输入密码");
|
||||
valid = false;
|
||||
} else if (!isLen4to16(pwd)) {
|
||||
setFieldError("password", "密码需为 4–16 位");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return null;
|
||||
return { account: account, password: pwd };
|
||||
}
|
||||
|
||||
function mapServerError(err) {
|
||||
var tip = (err && err.message) || "登录失败,请稍后重试";
|
||||
if (/账号|账户|用户|不存在|邮箱/.test(tip) && !/密码/.test(tip)) {
|
||||
setFieldError("account", tip);
|
||||
return;
|
||||
}
|
||||
setFieldError("password", tip);
|
||||
}
|
||||
|
||||
function setSubmitting(loading) {
|
||||
if (!submitBtn) return;
|
||||
submitBtn.disabled = !!loading;
|
||||
submitBtn.classList.toggle("is-loading", !!loading);
|
||||
submitBtn.textContent = loading ? "登录中…" : "登录";
|
||||
}
|
||||
|
||||
if (form) {
|
||||
form.querySelectorAll("input").forEach(function (input) {
|
||||
input.addEventListener("input", function () {
|
||||
var name = input.getAttribute("name");
|
||||
if (name) clearFieldError(name);
|
||||
});
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
if (!window.AuthAPI || !window.HttpRequest) {
|
||||
setFieldError("password", "认证脚本未加载,请刷新页面");
|
||||
return;
|
||||
}
|
||||
if (submitBtn && submitBtn.classList.contains("is-loading")) return;
|
||||
|
||||
var payload = validateForm();
|
||||
if (!payload) return;
|
||||
|
||||
setSubmitting(true);
|
||||
AuthAPI.login(payload)
|
||||
.then(function (res) {
|
||||
AuthAPI.toast((res && res.tip) || "登录成功", "success");
|
||||
window.setTimeout(function () {
|
||||
window.location.href = "/";
|
||||
}, 400);
|
||||
})
|
||||
.catch(function (err) {
|
||||
setSubmitting(false);
|
||||
mapServerError(err);
|
||||
AuthAPI.toast((err && err.message) || "登录失败", "error");
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
@@ -1,252 +0,0 @@
|
||||
(function () {
|
||||
var root = document.querySelector("[data-login-pop]");
|
||||
if (!root) return;
|
||||
|
||||
var form = root.querySelector("[data-login-form]");
|
||||
var password = root.querySelector("[data-login-password]");
|
||||
var toggle = root.querySelector("[data-login-toggle]");
|
||||
var toggleIcon = root.querySelector("[data-login-toggle-icon]");
|
||||
var title = root.querySelector("[data-login-title]");
|
||||
var description = root.querySelector("[data-login-desc]");
|
||||
var submitBtn = root.querySelector("[data-login-submit]") || (form && form.querySelector('button[type="submit"]'));
|
||||
var previousOverflow = "";
|
||||
var switchAccountMode = false;
|
||||
|
||||
function closeRegister() {
|
||||
if (typeof window.closeRegisterPop === "function") {
|
||||
window.closeRegisterPop();
|
||||
return;
|
||||
}
|
||||
var register = document.querySelector("[data-register-pop]");
|
||||
if (register) register.classList.remove("is-open");
|
||||
}
|
||||
|
||||
function closeUserMenu() {
|
||||
var menu = document.querySelector("[data-user-menu].is-open");
|
||||
if (menu) {
|
||||
menu.classList.remove("is-open");
|
||||
var t = menu.querySelector("[data-user-menu-toggle]");
|
||||
if (t) t.setAttribute("aria-expanded", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function clearFieldError(name) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.remove("is-error");
|
||||
if (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllErrors() {
|
||||
root.querySelectorAll("[data-field]").forEach(function (el) {
|
||||
el.classList.remove("is-error");
|
||||
});
|
||||
root.querySelectorAll("[data-field-error]").forEach(function (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
});
|
||||
}
|
||||
|
||||
function setFieldError(name, message) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.add("is-error");
|
||||
if (err) {
|
||||
err.hidden = false;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = message || "";
|
||||
}
|
||||
}
|
||||
|
||||
function isLen4to16(value) {
|
||||
var len = String(value || "").length;
|
||||
return len >= 4 && len <= 16;
|
||||
}
|
||||
|
||||
function validateForm() {
|
||||
clearAllErrors();
|
||||
var fd = new FormData(form);
|
||||
var account = String(fd.get("account") || "").trim();
|
||||
var pwd = String(fd.get("password") || "");
|
||||
var valid = true;
|
||||
|
||||
if (!account) {
|
||||
setFieldError("account", "请输入账号");
|
||||
valid = false;
|
||||
} else if (
|
||||
!(window.AuthAPI && AuthAPI.isValidLoginAccount
|
||||
? AuthAPI.isValidLoginAccount(account)
|
||||
: isLen4to16(account) || account.indexOf("@") >= 0)
|
||||
) {
|
||||
setFieldError("account", "账号需为 4–16 位,或合法邮箱");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd) {
|
||||
setFieldError("password", "请输入密码");
|
||||
valid = false;
|
||||
} else if (!isLen4to16(pwd)) {
|
||||
setFieldError("password", "密码需为 4–16 位");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return null;
|
||||
return { account: account, password: pwd };
|
||||
}
|
||||
|
||||
function mapServerError(err) {
|
||||
var tip = (err && err.message) || "登录失败,请稍后重试";
|
||||
if (/账号|账户|用户|不存在|邮箱/.test(tip) && !/密码/.test(tip)) {
|
||||
setFieldError("account", tip);
|
||||
return;
|
||||
}
|
||||
setFieldError("password", tip);
|
||||
}
|
||||
|
||||
function isMobile() {
|
||||
return window.matchMedia && window.matchMedia("(max-width: 768px)").matches;
|
||||
}
|
||||
|
||||
function open(input) {
|
||||
var event = input && typeof input.preventDefault === "function" ? input : null;
|
||||
var options = event ? {} : input || {};
|
||||
if (isMobile() && !options.forcePopup) {
|
||||
if (event) event.preventDefault();
|
||||
window.location.href = "/login";
|
||||
return;
|
||||
}
|
||||
if (event) event.preventDefault();
|
||||
switchAccountMode = !!options.switchAccount;
|
||||
closeRegister();
|
||||
closeUserMenu();
|
||||
clearAllErrors();
|
||||
if (options.resetForm && form) form.reset();
|
||||
if (password) password.setAttribute("type", "password");
|
||||
if (toggle) toggle.setAttribute("aria-label", "显示密码");
|
||||
if (toggleIcon) {
|
||||
toggleIcon.setAttribute("src", "/static/images/eye.svg");
|
||||
toggleIcon.setAttribute("data-src", "/static/images/eye.svg");
|
||||
}
|
||||
if (title) title.textContent = switchAccountMode ? "切换账号" : "登录黄果短剧";
|
||||
if (description) {
|
||||
description.textContent = switchAccountMode
|
||||
? "请输入其他账号和密码完成切换"
|
||||
: "登录后可收藏作品、解锁付费剧集并查看观看历史";
|
||||
}
|
||||
root.classList.add("is-open");
|
||||
previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
var first = root.querySelector(".login-pop__input");
|
||||
if (first) {
|
||||
window.setTimeout(function () {
|
||||
first.focus();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
root.classList.remove("is-open");
|
||||
document.body.style.overflow = previousOverflow;
|
||||
clearAllErrors();
|
||||
switchAccountMode = false;
|
||||
}
|
||||
|
||||
window.openLoginPop = open;
|
||||
window.openAccountSwitchLogin = function () {
|
||||
open({ forcePopup: true, switchAccount: true, resetForm: true });
|
||||
};
|
||||
window.closeLoginPop = close;
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var opener = event.target.closest("[data-login-open]");
|
||||
if (opener) {
|
||||
open(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// PC:拦截站内 /login 链接,改为打开弹窗;H5 放行跳转登录页
|
||||
var loginLink = event.target.closest('a[href="/login"], a[href="/login/"], a[href="#login"]');
|
||||
if (loginLink && !isMobile()) {
|
||||
open(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!root.classList.contains("is-open")) return;
|
||||
if (event.target.closest("[data-login-close]")) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
if (toggle && password && toggleIcon) {
|
||||
toggle.addEventListener("click", function () {
|
||||
var show = password.getAttribute("type") === "password";
|
||||
password.setAttribute("type", show ? "text" : "password");
|
||||
toggleIcon.setAttribute("src", show ? "/static/images/eye-off.svg" : "/static/images/eye.svg");
|
||||
toggle.setAttribute("aria-label", show ? "隐藏密码" : "显示密码");
|
||||
});
|
||||
}
|
||||
|
||||
function setSubmitting(loading) {
|
||||
if (!submitBtn) return;
|
||||
submitBtn.disabled = !!loading;
|
||||
submitBtn.classList.toggle("is-loading", !!loading);
|
||||
submitBtn.textContent = loading ? "登录中…" : "登录";
|
||||
}
|
||||
|
||||
if (form) {
|
||||
form.querySelectorAll("input").forEach(function (input) {
|
||||
input.addEventListener("input", function () {
|
||||
var name = input.getAttribute("name");
|
||||
if (name) clearFieldError(name);
|
||||
});
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
if (!window.AuthAPI || !window.HttpRequest) {
|
||||
setFieldError("password", "认证脚本未加载,请刷新页面");
|
||||
return;
|
||||
}
|
||||
if (submitBtn && submitBtn.classList.contains("is-loading")) return;
|
||||
|
||||
var payload = validateForm();
|
||||
if (!payload) return;
|
||||
|
||||
setSubmitting(true);
|
||||
AuthAPI.login(payload)
|
||||
.then(function (res) {
|
||||
AuthAPI.toast((res && res.tip) || "登录成功", "success");
|
||||
window.setTimeout(function () {
|
||||
close();
|
||||
window.location.reload();
|
||||
}, 400);
|
||||
})
|
||||
.catch(function (err) {
|
||||
setSubmitting(false);
|
||||
mapServerError(err);
|
||||
AuthAPI.toast((err && err.message) || "登录失败", "error");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Escape" && root.classList.contains("is-open")) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
var params = new URLSearchParams(window.location.search || "");
|
||||
if (params.get("auth") === "login") {
|
||||
params.delete("auth");
|
||||
var qs = params.toString();
|
||||
window.history.replaceState(null, "", window.location.pathname + (qs ? "?" + qs : "") + window.location.hash);
|
||||
open();
|
||||
}
|
||||
} catch (e) {}
|
||||
})();
|
||||
+1
-782
@@ -452,7 +452,6 @@
|
||||
}
|
||||
|
||||
var playDp = null;
|
||||
var lastWatchReportKey = "";
|
||||
var currentPlayMode = "main";
|
||||
var mainBadgePC = "";
|
||||
var mainBadgeH5 = "";
|
||||
@@ -515,32 +514,6 @@
|
||||
if (label) label.textContent = mainCtaLabel || "立即播放";
|
||||
}
|
||||
|
||||
function toIntAttr(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function reportChapterWatch() {
|
||||
var root = document.querySelector("[data-play-player]");
|
||||
if (!root) return;
|
||||
var chapterId = toIntAttr(root.getAttribute("data-chapter-id"), 0);
|
||||
var playletId = toIntAttr(root.getAttribute("data-playlet-id"), 0);
|
||||
if (chapterId <= 0) return;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
if (!window.CookieUtil.isLoggedIn()) return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") return;
|
||||
var key = String(playletId || 0) + ":" + chapterId;
|
||||
if (key === lastWatchReportKey) return;
|
||||
lastWatchReportKey = key;
|
||||
var body = { chapterId: chapterId };
|
||||
if (playletId > 0) body.playletId = playletId;
|
||||
window.HttpRequest.post("/api/playlet/chapter/watch/report", body)
|
||||
.catch(function () {
|
||||
lastWatchReportKey = "";
|
||||
});
|
||||
}
|
||||
|
||||
function hidePosterOverlay() {
|
||||
var root = document.querySelector("[data-play-player]");
|
||||
if (root) root.classList.add("is-playing");
|
||||
@@ -571,20 +544,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function ensureComposerAvatarDecrypt() {
|
||||
var avatar = document.querySelector(".play-composer__avatar-img.lazy[data-src]");
|
||||
if (!avatar) return;
|
||||
if (typeof window.loadLazyNode === "function") {
|
||||
window.loadLazyNode(avatar);
|
||||
return;
|
||||
}
|
||||
if (typeof window.refreshAvatarDecrypt === "function") {
|
||||
window.refreshAvatarDecrypt(avatar.parentNode || document);
|
||||
} else if (typeof window.initLazyImages === "function") {
|
||||
window.initLazyImages(avatar.parentNode || document, { eager: true });
|
||||
}
|
||||
}
|
||||
|
||||
function initDPlayer(initialURL) {
|
||||
if (typeof window.DPlayer === "undefined") return null;
|
||||
var container = document.querySelector(".dplayer-video");
|
||||
@@ -624,9 +583,6 @@
|
||||
playDp.on("play", function () {
|
||||
patchVideoInlinePlayback(playDp);
|
||||
hidePosterOverlay();
|
||||
if (currentPlayMode === "main") {
|
||||
reportChapterWatch();
|
||||
}
|
||||
});
|
||||
}
|
||||
return playDp;
|
||||
@@ -669,9 +625,6 @@
|
||||
var root = playerRoot();
|
||||
if (!root) return;
|
||||
var next = mode === "preview" ? "preview" : "main";
|
||||
if (window.tracker && typeof window.tracker.prepareDramaModeChange === "function") {
|
||||
window.tracker.prepareDramaModeChange(next);
|
||||
}
|
||||
currentPlayMode = next;
|
||||
root.setAttribute("data-play-mode", next);
|
||||
root.classList.toggle("play-player--preview", next === "preview");
|
||||
@@ -782,7 +735,6 @@
|
||||
}
|
||||
|
||||
function bootPlayer() {
|
||||
ensureComposerAvatarDecrypt();
|
||||
var root = playerRoot();
|
||||
if (!root) return;
|
||||
|
||||
@@ -888,7 +840,7 @@
|
||||
|
||||
Array.prototype.forEach.call(openers, function (btn) {
|
||||
btn.addEventListener("click", function () {
|
||||
// 预告片模式不弹充值;属性被临时移除时也不弹。
|
||||
// 预告片模式不弹下载提示;属性被临时移除时也不弹。
|
||||
if (!btn.hasAttribute("data-play-coin-open")) return;
|
||||
if (isPreviewPlayingSurface()) return;
|
||||
open();
|
||||
@@ -906,123 +858,6 @@
|
||||
});
|
||||
})();
|
||||
|
||||
// 金币解锁:POST /api/playlet/chapter/unlock → upstream /api/app/playlet/chapter/unlock
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function openRecharge() {
|
||||
var opener = document.querySelector("[data-play-coin-open]");
|
||||
if (opener) {
|
||||
opener.click();
|
||||
return;
|
||||
}
|
||||
if (typeof window.openRechargeModal === "function") {
|
||||
window.openRechargeModal();
|
||||
return;
|
||||
}
|
||||
window.location.href = "/recharge";
|
||||
}
|
||||
|
||||
function reloadAfterUnlockTracking() {
|
||||
var tracking = Promise.resolve();
|
||||
if (window.tracker && typeof window.tracker.dramaUnlock === "function") {
|
||||
tracking = Promise.resolve(window.tracker.dramaUnlock()).catch(function () {
|
||||
// 埋点失败不影响解锁结果。
|
||||
});
|
||||
if (typeof window.tracker.flush === "function") {
|
||||
[50, 200, 500, 700].forEach(function (delay) {
|
||||
window.setTimeout(function () {
|
||||
Promise.resolve(window.tracker.flush()).catch(function () {
|
||||
// 埋点失败不影响解锁结果。
|
||||
});
|
||||
}, delay);
|
||||
});
|
||||
}
|
||||
}
|
||||
var deadline = new Promise(function (resolve) {
|
||||
window.setTimeout(resolve, 800);
|
||||
});
|
||||
return Promise.race([tracking, deadline]).then(function () {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-play-unlock]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
if (btn.disabled || btn.getAttribute("data-unlocking") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("解锁服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var chapterId = toInt(btn.getAttribute("data-chapter-id"), 0);
|
||||
var playletId = toInt(btn.getAttribute("data-playlet-id"), 0);
|
||||
if (chapterId <= 0 || playletId <= 0) {
|
||||
toast("缺少剧集信息", "error");
|
||||
return;
|
||||
}
|
||||
var payload = { chapterId: chapterId, playletId: playletId };
|
||||
btn.setAttribute("data-unlocking", "1");
|
||||
btn.disabled = true;
|
||||
window.HttpRequest.post("/api/playlet/chapter/unlock", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
var code = res && Number(res.code);
|
||||
if (code === 401 || code === 1000) {
|
||||
var login = document.querySelector("[data-login-open]");
|
||||
if (login) login.click();
|
||||
return;
|
||||
}
|
||||
// 常见余额不足码,转充值
|
||||
if (code === 400 || /金币|余额|不足/.test(String((res && (res.tip || res.msg)) || ""))) {
|
||||
openRecharge();
|
||||
return;
|
||||
}
|
||||
throw new Error((res && (res.tip || res.msg)) || "解锁失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
if (data.balance != null && window.CookieUtil && typeof window.CookieUtil.setAuthSession === "function") {
|
||||
window.CookieUtil.setAuthSession({ recharge: data.balance });
|
||||
if (typeof window.syncHeaderUser === "function") window.syncHeaderUser();
|
||||
}
|
||||
toast("购买成功", "success");
|
||||
return reloadAfterUnlockTracking();
|
||||
})
|
||||
.catch(function (err) {
|
||||
toast((err && err.message) || "解锁失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-unlocking");
|
||||
btn.disabled = false;
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
(function () {
|
||||
var btn = document.querySelector("[data-guess-refresh]");
|
||||
var grid = document.querySelector("[data-guess-grid]");
|
||||
@@ -1350,622 +1185,6 @@
|
||||
});
|
||||
})();
|
||||
|
||||
// 剧集点赞:POST /api/playlet/chapter/like/set → upstream /api/app/playlet/chapter/like/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatLikeCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyChapterLikeUI(btn, isLike, countLike) {
|
||||
if (!btn) return;
|
||||
var liked = Number(isLike) === 1;
|
||||
btn.classList.toggle("is-active", liked);
|
||||
btn.setAttribute("data-liked", liked ? "1" : "2");
|
||||
btn.setAttribute("aria-label", liked ? "取消点赞" : "点赞");
|
||||
var label = btn.querySelector("[data-chapter-like-label]");
|
||||
if (label) label.textContent = liked ? "已点赞" : "点赞";
|
||||
var countEl = btn.querySelector("[data-chapter-like-count]");
|
||||
if (countLike != null) {
|
||||
btn.setAttribute("data-like-raw", String(countLike));
|
||||
if (countEl) countEl.textContent = formatLikeCount(countLike);
|
||||
}
|
||||
if (countEl) countEl.hidden = liked;
|
||||
}
|
||||
|
||||
function toggleChapterLike(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-liking") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("点赞服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var chapterId = toInt(btn.getAttribute("data-chapter-id"), 0);
|
||||
if (chapterId <= 0) {
|
||||
toast("缺少剧集 ID", "error");
|
||||
return;
|
||||
}
|
||||
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
|
||||
var nextLike = !likedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-like-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextLike ? 1 : -1));
|
||||
btn.setAttribute("data-liking", "1");
|
||||
btn.disabled = true;
|
||||
applyChapterLikeUI(btn, nextLike ? 1 : 2, nextCount);
|
||||
var payload = { chapterId: chapterId, isLike: nextLike };
|
||||
window.HttpRequest.post("/api/playlet/chapter/like/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyChapterLikeUI(
|
||||
btn,
|
||||
data.isLike != null ? data.isLike : nextLike ? 1 : 2,
|
||||
data.countLike != null ? data.countLike : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyChapterLikeUI(btn, likedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-liking");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-chapter-like]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
toggleChapterLike(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 短剧点赞:POST /api/playlet/like/set → upstream /api/app/playlet/like/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatLikeCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyPlayletLikeUI(btn, isLike, countLike) {
|
||||
if (!btn) return;
|
||||
var liked = Number(isLike) === 1;
|
||||
btn.classList.toggle("is-active", liked);
|
||||
btn.setAttribute("data-liked", liked ? "1" : "2");
|
||||
btn.setAttribute("aria-label", liked ? "取消点赞" : "点赞");
|
||||
var label = btn.querySelector("[data-playlet-like-label]");
|
||||
if (label) label.textContent = liked ? "已点赞" : "点赞";
|
||||
var countEl = btn.querySelector("[data-playlet-like-count]");
|
||||
if (countLike != null) {
|
||||
btn.setAttribute("data-like-raw", String(countLike));
|
||||
if (countEl) countEl.textContent = formatLikeCount(countLike);
|
||||
}
|
||||
if (countEl) countEl.hidden = liked;
|
||||
}
|
||||
|
||||
function togglePlayletLike(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-liking") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("点赞服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var playletId = toInt(btn.getAttribute("data-playlet-id"), 0);
|
||||
if (playletId <= 0) {
|
||||
toast("缺少短剧 ID", "error");
|
||||
return;
|
||||
}
|
||||
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
|
||||
var nextLike = !likedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-like-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextLike ? 1 : -1));
|
||||
btn.setAttribute("data-liking", "1");
|
||||
btn.disabled = true;
|
||||
applyPlayletLikeUI(btn, nextLike ? 1 : 2, nextCount);
|
||||
var payload = { id: playletId, isLike: nextLike };
|
||||
window.HttpRequest.post("/api/playlet/like/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyPlayletLikeUI(
|
||||
btn,
|
||||
data.isLike != null ? data.isLike : nextLike ? 1 : 2,
|
||||
data.countLike != null ? data.countLike : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyPlayletLikeUI(btn, likedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-liking");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-playlet-like]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
togglePlayletLike(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 视频点赞:POST /api/video/like/set → upstream /api/app/video/like/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatLikeCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyVideoLikeUI(btn, isLike, countLike) {
|
||||
if (!btn) return;
|
||||
var liked = Number(isLike) === 1;
|
||||
btn.classList.toggle("is-active", liked);
|
||||
btn.setAttribute("data-liked", liked ? "1" : "2");
|
||||
btn.setAttribute("aria-label", liked ? "取消点赞" : "点赞");
|
||||
var label = btn.querySelector("[data-video-like-label]");
|
||||
if (label) label.textContent = liked ? "已点赞" : "点赞";
|
||||
var countEl = btn.querySelector("[data-video-like-count]");
|
||||
if (countLike != null) {
|
||||
btn.setAttribute("data-like-raw", String(countLike));
|
||||
if (countEl) countEl.textContent = formatLikeCount(countLike);
|
||||
}
|
||||
if (countEl) countEl.hidden = liked;
|
||||
}
|
||||
|
||||
function toggleVideoLike(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-liking") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("点赞服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var videoId = toInt(btn.getAttribute("data-video-id"), 0);
|
||||
if (videoId <= 0) {
|
||||
toast("缺少视频 ID", "error");
|
||||
return;
|
||||
}
|
||||
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
|
||||
var nextLike = !likedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-like-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextLike ? 1 : -1));
|
||||
btn.setAttribute("data-liking", "1");
|
||||
btn.disabled = true;
|
||||
applyVideoLikeUI(btn, nextLike ? 1 : 2, nextCount);
|
||||
var payload = { id: videoId, isLike: nextLike };
|
||||
window.HttpRequest.post("/api/video/like/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyVideoLikeUI(
|
||||
btn,
|
||||
data.isLike != null ? data.isLike : nextLike ? 1 : 2,
|
||||
data.countLike != null ? data.countLike : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyVideoLikeUI(btn, likedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-liking");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-video-like]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
toggleVideoLike(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 视频收藏:POST /api/video/collect/set → upstream /api/app/video/collect/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyVideoCollectUI(btn, isCollect, countCollect) {
|
||||
if (!btn) return;
|
||||
var collected = Number(isCollect) === 1;
|
||||
btn.classList.toggle("is-active", collected);
|
||||
btn.setAttribute("data-collected", collected ? "1" : "2");
|
||||
btn.setAttribute("aria-label", collected ? "取消收藏" : "收藏");
|
||||
var label = btn.querySelector("[data-video-collect-label]");
|
||||
if (label) label.textContent = collected ? "已收藏" : "收藏";
|
||||
var countEl = btn.querySelector("[data-video-collect-count]");
|
||||
if (countCollect != null) {
|
||||
btn.setAttribute("data-collect-raw", String(countCollect));
|
||||
if (countEl) countEl.textContent = formatCount(countCollect);
|
||||
}
|
||||
if (countEl) countEl.hidden = collected;
|
||||
}
|
||||
|
||||
function toggleVideoCollect(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-collecting") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("收藏服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var videoId = toInt(btn.getAttribute("data-video-id"), 0);
|
||||
if (videoId <= 0) {
|
||||
toast("缺少视频 ID", "error");
|
||||
return;
|
||||
}
|
||||
var collectedNow = Number(btn.getAttribute("data-collected") || 2) === 1;
|
||||
var nextCollect = !collectedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-collect-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextCollect ? 1 : -1));
|
||||
btn.setAttribute("data-collecting", "1");
|
||||
btn.disabled = true;
|
||||
applyVideoCollectUI(btn, nextCollect ? 1 : 2, nextCount);
|
||||
var payload = { id: videoId, isCollect: nextCollect };
|
||||
window.HttpRequest.post("/api/video/collect/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyVideoCollectUI(
|
||||
btn,
|
||||
data.isCollect != null ? data.isCollect : nextCollect ? 1 : 2,
|
||||
data.countCollect != null ? data.countCollect : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyVideoCollectUI(btn, collectedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-collecting");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-video-collect]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
toggleVideoCollect(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 剧集收藏:POST /api/playlet/chapter/collect/set → upstream /api/app/playlet/chapter/collect/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatLikeCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyChapterCollectUI(btn, isCollect, countCollect) {
|
||||
if (!btn) return;
|
||||
var collected = Number(isCollect) === 1;
|
||||
btn.classList.toggle("is-active", collected);
|
||||
btn.setAttribute("data-collected", collected ? "1" : "2");
|
||||
btn.setAttribute("aria-label", collected ? "取消收藏" : "收藏");
|
||||
var label = btn.querySelector("[data-chapter-collect-label]");
|
||||
if (label) label.textContent = collected ? "已收藏" : "收藏";
|
||||
var countEl = btn.querySelector("[data-chapter-collect-count]");
|
||||
if (countCollect != null) {
|
||||
btn.setAttribute("data-collect-raw", String(countCollect));
|
||||
if (countEl) countEl.textContent = formatLikeCount(countCollect);
|
||||
}
|
||||
if (countEl) countEl.hidden = collected;
|
||||
}
|
||||
|
||||
function toggleChapterCollect(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-collecting") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("收藏服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var chapterId = toInt(btn.getAttribute("data-chapter-id"), 0);
|
||||
if (chapterId <= 0) {
|
||||
toast("缺少剧集 ID", "error");
|
||||
return;
|
||||
}
|
||||
var collectedNow = Number(btn.getAttribute("data-collected") || 2) === 1;
|
||||
var nextCollect = !collectedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-collect-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextCollect ? 1 : -1));
|
||||
btn.setAttribute("data-collecting", "1");
|
||||
btn.disabled = true;
|
||||
applyChapterCollectUI(btn, nextCollect ? 1 : 2, nextCount);
|
||||
var payload = { chapterId: chapterId, isCollect: nextCollect };
|
||||
window.HttpRequest.post("/api/playlet/chapter/collect/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyChapterCollectUI(
|
||||
btn,
|
||||
data.isCollect != null ? data.isCollect : nextCollect ? 1 : 2,
|
||||
data.countCollect != null ? data.countCollect : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyChapterCollectUI(btn, collectedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-collecting");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-chapter-collect]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
toggleChapterCollect(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 短剧收藏:POST /api/playlet/collect/set → upstream /api/app/playlet/collect/set
|
||||
(function () {
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
var n = parseInt(v, 10);
|
||||
return isNaN(n) ? fallback || 0 : n;
|
||||
}
|
||||
|
||||
function formatLikeCount(n) {
|
||||
var v = Number(n) || 0;
|
||||
if (v <= 0) return "0";
|
||||
if (v < 10000) return String(v);
|
||||
var wan = v / 10000;
|
||||
if (wan >= 100) return Math.round(wan) + " 万";
|
||||
return wan.toFixed(1) + " 万";
|
||||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
var composer = document.querySelector("[data-play-composer]");
|
||||
if (composer && composer.getAttribute("data-logged-in") === "1") return true;
|
||||
if (window.CookieUtil && typeof window.CookieUtil.isLoggedIn === "function") {
|
||||
return !!window.CookieUtil.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyPlayletCollectUI(btn, isCollect, countCollect) {
|
||||
if (!btn) return;
|
||||
var collected = Number(isCollect) === 1;
|
||||
btn.classList.toggle("is-active", collected);
|
||||
btn.setAttribute("data-collected", collected ? "1" : "2");
|
||||
btn.setAttribute("aria-label", collected ? "取消收藏" : "收藏");
|
||||
var label = btn.querySelector("[data-playlet-collect-label]");
|
||||
if (label) label.textContent = collected ? "已收藏" : "收藏";
|
||||
var countEl = btn.querySelector("[data-playlet-collect-count]");
|
||||
if (countCollect != null) {
|
||||
btn.setAttribute("data-collect-raw", String(countCollect));
|
||||
if (countEl) countEl.textContent = formatLikeCount(countCollect);
|
||||
var stats = document.querySelectorAll("[data-playlet-collect-stat]");
|
||||
Array.prototype.forEach.call(stats, function (el) {
|
||||
el.textContent = formatLikeCount(countCollect);
|
||||
});
|
||||
}
|
||||
if (countEl) countEl.hidden = collected;
|
||||
}
|
||||
|
||||
function togglePlayletCollect(btn) {
|
||||
if (!btn || btn.disabled || btn.getAttribute("data-collecting") === "1") return;
|
||||
if (!isLoggedIn()) {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("收藏服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var playletId = toInt(btn.getAttribute("data-playlet-id"), 0);
|
||||
if (playletId <= 0) {
|
||||
toast("缺少短剧 ID", "error");
|
||||
return;
|
||||
}
|
||||
var collectedNow = Number(btn.getAttribute("data-collected") || 2) === 1;
|
||||
var nextCollect = !collectedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-collect-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextCollect ? 1 : -1));
|
||||
btn.setAttribute("data-collecting", "1");
|
||||
btn.disabled = true;
|
||||
applyPlayletCollectUI(btn, nextCollect ? 1 : 2, nextCount);
|
||||
var payload = { id: playletId, isCollect: nextCollect };
|
||||
window.HttpRequest.post("/api/playlet/collect/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "操作失败");
|
||||
}
|
||||
var data = res.data || {};
|
||||
applyPlayletCollectUI(
|
||||
btn,
|
||||
data.isCollect != null ? data.isCollect : nextCollect ? 1 : 2,
|
||||
data.countCollect != null ? data.countCollect : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyPlayletCollectUI(btn, collectedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-collecting");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var btn = window.domClosest(event.target, "[data-playlet-collect]");
|
||||
if (!btn) return;
|
||||
event.preventDefault();
|
||||
togglePlayletCollect(btn);
|
||||
});
|
||||
})();
|
||||
|
||||
// 简介展开:PC 超过 1 行、H5 超过 2 行才显示展开按钮
|
||||
(function () {
|
||||
var root = document.querySelector("[data-play-synopsis]");
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
// 播放页评论:只读列表 + 「查看更多评论」追加翻页
|
||||
(function () {
|
||||
var root = document.querySelector("[data-play-composer]");
|
||||
if (!root) return;
|
||||
var commentsRoot = document.querySelector("[data-play-comments]");
|
||||
if (!commentsRoot) return;
|
||||
|
||||
var commentsRoot = document.querySelector("[data-play-comments]") || root.closest(".play-comments");
|
||||
var input = root.querySelector("[data-comment-input]");
|
||||
var countEl = root.querySelector("[data-comment-count]");
|
||||
var sendBtn = root.querySelector("[data-comment-send]");
|
||||
var listEl = document.querySelector("[data-comment-list]");
|
||||
var totalEl = document.querySelector("[data-comment-total-label]");
|
||||
var moreBtn = document.querySelector("[data-comment-more]");
|
||||
var sending = false;
|
||||
var inlineSending = false;
|
||||
var loadingMore = false;
|
||||
var MAX_LEN = 200;
|
||||
var PAGE_SIZE = 4;
|
||||
var replyTarget = null;
|
||||
|
||||
function toast(message, type) {
|
||||
if (typeof window.showToast === "function") {
|
||||
window.showToast(message, type);
|
||||
return;
|
||||
}
|
||||
if (window.AuthAPI && typeof window.AuthAPI.toast === "function") {
|
||||
window.AuthAPI.toast(message, type || "info");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function toInt(v, fallback) {
|
||||
@@ -43,14 +32,14 @@
|
||||
function getPageSize() {
|
||||
return Math.max(
|
||||
1,
|
||||
toInt(commentsRoot && commentsRoot.getAttribute("data-comment-size"), PAGE_SIZE)
|
||||
toInt(commentsRoot.getAttribute("data-comment-size"), PAGE_SIZE)
|
||||
);
|
||||
}
|
||||
|
||||
function getPage() {
|
||||
return Math.max(
|
||||
1,
|
||||
toInt(commentsRoot && commentsRoot.getAttribute("data-comment-page"), 1)
|
||||
toInt(commentsRoot.getAttribute("data-comment-page"), 1)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -60,7 +49,6 @@
|
||||
}
|
||||
|
||||
function setPagerState(page, loaded, total) {
|
||||
if (!commentsRoot) return;
|
||||
if (page != null) commentsRoot.setAttribute("data-comment-page", String(page));
|
||||
if (loaded != null) commentsRoot.setAttribute("data-comment-loaded", String(loaded));
|
||||
if (total != null) commentsRoot.setAttribute("data-comment-total", String(total));
|
||||
@@ -80,12 +68,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function syncCount() {
|
||||
if (!input || !countEl) return;
|
||||
var len = Array.from(input.value || "").length;
|
||||
countEl.textContent = len + " / " + MAX_LEN;
|
||||
}
|
||||
|
||||
function formatTime(raw) {
|
||||
var s = String(raw || "").trim();
|
||||
if (!s) return "刚刚";
|
||||
@@ -111,7 +93,6 @@
|
||||
var text = escapeHtml(item.text || "");
|
||||
var time = escapeHtml(formatTime(item.createdAt));
|
||||
var like = toInt(item.countLike, 0);
|
||||
var liked = Number(item.isLike) === 1;
|
||||
var avatarHtml = avatar
|
||||
? '<img class="play-comment__avatar lazy" src="/static/images/placeholder.png?v=2" data-src="' +
|
||||
escapeHtml(avatar) +
|
||||
@@ -135,7 +116,6 @@
|
||||
})
|
||||
.join("");
|
||||
var commentId = escapeHtml(item.id || "");
|
||||
var rawName = String(item.userName || "匿名用户");
|
||||
return (
|
||||
'<li class="play-comment" data-comment-id="' +
|
||||
commentId +
|
||||
@@ -155,27 +135,12 @@
|
||||
"</p>" +
|
||||
replies +
|
||||
'<div class="play-comment__actions">' +
|
||||
'<button class="play-comment__action' +
|
||||
(liked ? " is-active" : "") +
|
||||
'" type="button" aria-label="点赞" data-comment-like="' +
|
||||
commentId +
|
||||
'" data-liked="' +
|
||||
(liked ? "1" : "2") +
|
||||
'" data-like-raw="' +
|
||||
escapeHtml(like) +
|
||||
'">' +
|
||||
'<span class="play-comment__action">' +
|
||||
'<img class="icon" src="/static/images/placeholder.png?v=2" data-src="/static/images/heart.svg" alt="" loading="lazy" decoding="async">' +
|
||||
'<span data-like-count>' +
|
||||
"<span>" +
|
||||
escapeHtml(like) +
|
||||
"</span>" +
|
||||
"</button>" +
|
||||
'<button class="play-comment__action" type="button" data-comment-reply data-comment-id="' +
|
||||
commentId +
|
||||
'" data-parents-id="' +
|
||||
commentId +
|
||||
'" data-reply-name="' +
|
||||
escapeHtml(rawName) +
|
||||
'">回复</button>' +
|
||||
"</span>" +
|
||||
"</div></div></li>"
|
||||
);
|
||||
}
|
||||
@@ -195,26 +160,6 @@
|
||||
totalEl.textContent = n > 0 ? n + " 条" : "暂无评论";
|
||||
}
|
||||
|
||||
function renderList(list, totalCount) {
|
||||
if (!listEl) return;
|
||||
list = Array.isArray(list) ? list : [];
|
||||
clearReplyTarget();
|
||||
if (!list.length) {
|
||||
listEl.innerHTML =
|
||||
'<li class="play-comment play-comment--empty"><p class="play-comment__text">暂无评论</p></li>';
|
||||
} else {
|
||||
listEl.innerHTML = list.map(renderCommentItem).join("");
|
||||
if (typeof window.initLazyImages === "function") {
|
||||
window.initLazyImages(listEl);
|
||||
}
|
||||
}
|
||||
var total = typeof totalCount === "number" ? totalCount : toInt(commentsRoot && commentsRoot.getAttribute("data-comment-total"), 0);
|
||||
if (typeof totalCount === "number") {
|
||||
updateTotal(totalCount);
|
||||
}
|
||||
setPagerState(1, list.length, total);
|
||||
}
|
||||
|
||||
// 下一页追加到现有列表底部,不替换已展示评论。
|
||||
function appendList(list, totalCount) {
|
||||
if (!listEl) return;
|
||||
@@ -222,7 +167,7 @@
|
||||
var total =
|
||||
typeof totalCount === "number"
|
||||
? totalCount
|
||||
: toInt(commentsRoot && commentsRoot.getAttribute("data-comment-total"), 0);
|
||||
: toInt(commentsRoot.getAttribute("data-comment-total"), 0);
|
||||
if (typeof totalCount === "number") {
|
||||
updateTotal(totalCount);
|
||||
}
|
||||
@@ -264,8 +209,8 @@
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.get !== "function") {
|
||||
return Promise.reject(new Error("评论服务未就绪"));
|
||||
}
|
||||
var objectId = toInt(root.getAttribute("data-object-id"), 0);
|
||||
var objectType = toInt(root.getAttribute("data-object-type"), 10);
|
||||
var objectId = toInt(commentsRoot.getAttribute("data-object-id"), 0);
|
||||
var objectType = toInt(commentsRoot.getAttribute("data-object-type"), 10);
|
||||
if (objectId <= 0) return Promise.reject(new Error("缺少评论对象"));
|
||||
var pageSize = getPageSize();
|
||||
return window.HttpRequest.get("/api/comment/list", {
|
||||
@@ -284,14 +229,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
function refreshList() {
|
||||
return fetchCommentPage(1)
|
||||
.then(function (data) {
|
||||
renderList(data.list || [], toInt(data.totalCount, 0));
|
||||
})
|
||||
.catch(function () {});
|
||||
}
|
||||
|
||||
function loadMoreComments() {
|
||||
if (loadingMore || !moreBtn) return;
|
||||
var nextPage = getPage() + 1;
|
||||
@@ -301,9 +238,7 @@
|
||||
.then(function (data) {
|
||||
var list = data.list || [];
|
||||
var total = toInt(data.totalCount, 0);
|
||||
if (commentsRoot) {
|
||||
commentsRoot.setAttribute("data-comment-page", String(nextPage));
|
||||
}
|
||||
commentsRoot.setAttribute("data-comment-page", String(nextPage));
|
||||
// 只追加,绝不 renderList 整表替换
|
||||
appendList(list, total);
|
||||
})
|
||||
@@ -316,284 +251,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
function removeInlineComposer() {
|
||||
if (!listEl) return;
|
||||
listEl.querySelectorAll("[data-comment-inline-composer]").forEach(function (el) {
|
||||
el.remove();
|
||||
});
|
||||
}
|
||||
|
||||
function clearReplyTarget() {
|
||||
replyTarget = null;
|
||||
removeInlineComposer();
|
||||
}
|
||||
|
||||
function applyLikeUI(btn, isLike, countLike) {
|
||||
if (!btn) return;
|
||||
var liked = Number(isLike) === 1;
|
||||
btn.classList.toggle("is-active", liked);
|
||||
btn.setAttribute("data-liked", liked ? "1" : "2");
|
||||
if (countLike != null) {
|
||||
btn.setAttribute("data-like-raw", String(countLike));
|
||||
var countEl = btn.querySelector("[data-like-count]");
|
||||
if (countEl) countEl.textContent = String(countLike);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleCommentLike(btn) {
|
||||
if (!btn || btn.getAttribute("data-liking") === "1") return;
|
||||
if (root.getAttribute("data-logged-in") !== "1") {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("点赞服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var commentId = toInt(btn.getAttribute("data-comment-like"), 0);
|
||||
if (commentId <= 0) return;
|
||||
var likedNow = Number(btn.getAttribute("data-liked") || 2) === 1;
|
||||
var nextLike = !likedNow;
|
||||
var prevCount = toInt(btn.getAttribute("data-like-raw"), 0);
|
||||
var nextCount = Math.max(0, prevCount + (nextLike ? 1 : -1));
|
||||
btn.setAttribute("data-liking", "1");
|
||||
btn.disabled = true;
|
||||
applyLikeUI(btn, nextLike ? 1 : 2, nextCount);
|
||||
var payload = { commentId: commentId, isLike: nextLike };
|
||||
window.HttpRequest.post("/api/comment/like/set", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
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 : nextCount
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
applyLikeUI(btn, likedNow ? 1 : 2, prevCount);
|
||||
toast((err && err.message) || "操作失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
btn.removeAttribute("data-liking");
|
||||
btn.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
function openInlineComposer(commentEl, target) {
|
||||
if (!commentEl || !target) return;
|
||||
removeInlineComposer();
|
||||
replyTarget = target;
|
||||
var body = commentEl.querySelector(".play-comment__body") || commentEl;
|
||||
var actions = body.querySelector(".play-comment__actions");
|
||||
var box = document.createElement("div");
|
||||
box.className = "play-comment__inline";
|
||||
box.setAttribute("data-comment-inline-composer", "");
|
||||
var name = target.replyName || "用户";
|
||||
box.innerHTML =
|
||||
'<div class="play-comment__inline-hint">' +
|
||||
"<span>回复 @" +
|
||||
escapeHtml(name) +
|
||||
"</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(name) +
|
||||
'…" data-comment-inline-input autocomplete="off" />' +
|
||||
'<button class="play-comment__inline-send" type="button" data-comment-inline-send>发送</button>' +
|
||||
"</div>";
|
||||
if (actions && actions.parentNode === body) {
|
||||
if (actions.nextSibling) body.insertBefore(box, actions.nextSibling);
|
||||
else body.appendChild(box);
|
||||
} else {
|
||||
body.appendChild(box);
|
||||
}
|
||||
var inlineInput = box.querySelector("[data-comment-inline-input]");
|
||||
if (inlineInput) inlineInput.focus();
|
||||
}
|
||||
|
||||
function setSending(on) {
|
||||
sending = !!on;
|
||||
if (sendBtn) sendBtn.disabled = !!on;
|
||||
if (input) input.disabled = !!on;
|
||||
}
|
||||
|
||||
function submitTopComment() {
|
||||
if (sending) return;
|
||||
if (root.getAttribute("data-logged-in") !== "1") {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("评论服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var text = String((input && input.value) || "").trim();
|
||||
if (!text) {
|
||||
toast("请输入评论内容", "error");
|
||||
return;
|
||||
}
|
||||
if (Array.from(text).length > MAX_LEN) {
|
||||
toast("评论最多 200 字", "error");
|
||||
return;
|
||||
}
|
||||
var objectId = toInt(root.getAttribute("data-object-id"), 0);
|
||||
var objectType = toInt(root.getAttribute("data-object-type"), 10);
|
||||
if (objectId <= 0) {
|
||||
toast("缺少评论对象", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = {
|
||||
objectId: objectId,
|
||||
objectType: objectType,
|
||||
text: text,
|
||||
parentsId: 0,
|
||||
replyCommentId: 0,
|
||||
};
|
||||
setSending(true);
|
||||
window.HttpRequest.post("/api/comment/send", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "发表失败");
|
||||
}
|
||||
if (input) input.value = "";
|
||||
syncCount();
|
||||
clearReplyTarget();
|
||||
toast("发布成功,评论审核后才会展示", "success");
|
||||
return refreshList();
|
||||
})
|
||||
.catch(function (err) {
|
||||
toast((err && err.message) || "发表失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
setSending(false);
|
||||
});
|
||||
}
|
||||
|
||||
function sendInlineReply(box) {
|
||||
if (!box || inlineSending || !replyTarget) return;
|
||||
if (!window.HttpRequest || typeof window.HttpRequest.post !== "function") {
|
||||
toast("评论服务未就绪", "error");
|
||||
return;
|
||||
}
|
||||
var inlineInput = box.querySelector("[data-comment-inline-input]");
|
||||
var btn = box.querySelector("[data-comment-inline-send]");
|
||||
if (!inlineInput) return;
|
||||
var text = String(inlineInput.value || "").trim();
|
||||
if (!text) {
|
||||
toast("请输入评论内容", "error");
|
||||
return;
|
||||
}
|
||||
if (Array.from(text).length > MAX_LEN) {
|
||||
toast("评论最多 200 字", "error");
|
||||
return;
|
||||
}
|
||||
var objectId = toInt(root.getAttribute("data-object-id"), 0);
|
||||
var objectType = toInt(root.getAttribute("data-object-type"), 10);
|
||||
if (objectId <= 0) {
|
||||
toast("缺少评论对象", "error");
|
||||
return;
|
||||
}
|
||||
inlineSending = true;
|
||||
if (btn) btn.disabled = true;
|
||||
inlineInput.disabled = true;
|
||||
var payload = {
|
||||
objectId: objectId,
|
||||
objectType: objectType,
|
||||
text: text,
|
||||
parentsId: toInt(replyTarget.parentsId, 0),
|
||||
replyCommentId: toInt(
|
||||
replyTarget.replyCommentId || replyTarget.parentsId,
|
||||
0
|
||||
),
|
||||
};
|
||||
window.HttpRequest.post("/api/comment/send", payload)
|
||||
.then(function (res) {
|
||||
if (!res || Number(res.code) !== 200) {
|
||||
throw new Error((res && (res.tip || res.msg)) || "发表失败");
|
||||
}
|
||||
clearReplyTarget();
|
||||
toast("发布成功,评论审核后才会展示", "success");
|
||||
return refreshList();
|
||||
})
|
||||
.catch(function (err) {
|
||||
toast((err && err.message) || "发表失败,请稍后重试", "error");
|
||||
})
|
||||
.finally(function () {
|
||||
inlineSending = false;
|
||||
if (btn) btn.disabled = false;
|
||||
if (inlineInput) inlineInput.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
if (input) {
|
||||
input.addEventListener("input", syncCount);
|
||||
input.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
submitTopComment();
|
||||
}
|
||||
});
|
||||
syncCount();
|
||||
}
|
||||
if (sendBtn) {
|
||||
sendBtn.addEventListener("click", submitTopComment);
|
||||
}
|
||||
if (moreBtn) {
|
||||
moreBtn.addEventListener("click", function (event) {
|
||||
event.preventDefault();
|
||||
loadMoreComments();
|
||||
});
|
||||
}
|
||||
if (listEl) {
|
||||
listEl.addEventListener("click", function (event) {
|
||||
var likeBtn = window.domClosest(event.target, "[data-comment-like]");
|
||||
if (likeBtn && listEl.contains(likeBtn)) {
|
||||
event.preventDefault();
|
||||
toggleCommentLike(likeBtn);
|
||||
return;
|
||||
}
|
||||
var cancelBtn = window.domClosest(event.target, "[data-comment-reply-cancel]");
|
||||
if (cancelBtn && listEl.contains(cancelBtn)) {
|
||||
clearReplyTarget();
|
||||
return;
|
||||
}
|
||||
var sendInlineBtn = window.domClosest(event.target, "[data-comment-inline-send]");
|
||||
if (sendInlineBtn && listEl.contains(sendInlineBtn)) {
|
||||
var box = sendInlineBtn.closest("[data-comment-inline-composer]");
|
||||
sendInlineReply(box);
|
||||
return;
|
||||
}
|
||||
var replyBtn = window.domClosest(event.target, "[data-comment-reply]");
|
||||
if (!replyBtn || !listEl.contains(replyBtn)) return;
|
||||
if (root.getAttribute("data-logged-in") !== "1") {
|
||||
var loginBtn = document.querySelector("[data-login-open]");
|
||||
if (loginBtn) loginBtn.click();
|
||||
return;
|
||||
}
|
||||
var parentsId = toInt(replyBtn.getAttribute("data-parents-id"), 0);
|
||||
var commentId = toInt(replyBtn.getAttribute("data-comment-id"), parentsId);
|
||||
if (parentsId <= 0) return;
|
||||
var commentEl = replyBtn.closest(".play-comment");
|
||||
openInlineComposer(commentEl, {
|
||||
parentsId: parentsId,
|
||||
replyCommentId: commentId,
|
||||
replyName: replyBtn.getAttribute("data-reply-name") || "用户",
|
||||
});
|
||||
});
|
||||
listEl.addEventListener("keydown", function (event) {
|
||||
if (event.key !== "Enter" || event.shiftKey) return;
|
||||
var inlineInput = window.domClosest(event.target, "[data-comment-inline-input]");
|
||||
if (!inlineInput || !listEl.contains(inlineInput)) return;
|
||||
event.preventDefault();
|
||||
var box = inlineInput.closest("[data-comment-inline-composer]");
|
||||
sendInlineReply(box);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
(function () {
|
||||
var form = document.querySelector("[data-register-page-form]");
|
||||
var password = document.querySelector("[data-register-page-password]");
|
||||
var confirm = document.querySelector("[data-register-page-password-confirm]");
|
||||
var submitBtn = document.querySelector("[data-register-page-submit]") || (form && form.querySelector('button[type="submit"]'));
|
||||
var root = form || document;
|
||||
|
||||
function bindToggle(key, input) {
|
||||
var btn = document.querySelector('[data-register-page-toggle="' + key + '"]');
|
||||
var icon = document.querySelector('[data-register-page-toggle-icon="' + key + '"]');
|
||||
if (!btn || !input || !icon) return;
|
||||
btn.addEventListener("click", function () {
|
||||
var show = input.getAttribute("type") === "password";
|
||||
input.setAttribute("type", show ? "text" : "password");
|
||||
icon.setAttribute("src", show ? "/static/images/eye-off.svg" : "/static/images/eye.svg");
|
||||
btn.setAttribute("aria-label", show ? "隐藏密码" : "显示密码");
|
||||
});
|
||||
}
|
||||
|
||||
bindToggle("password", password);
|
||||
bindToggle("confirm", confirm);
|
||||
|
||||
function clearFieldError(name) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.remove("is-error");
|
||||
if (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllErrors() {
|
||||
root.querySelectorAll("[data-field]").forEach(function (el) {
|
||||
el.classList.remove("is-error");
|
||||
});
|
||||
root.querySelectorAll("[data-field-error]").forEach(function (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
});
|
||||
}
|
||||
|
||||
function setFieldError(name, message) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.add("is-error");
|
||||
if (err) {
|
||||
err.hidden = false;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = message || "";
|
||||
}
|
||||
}
|
||||
|
||||
function isAccountNo(value) {
|
||||
return /^[A-Za-z0-9]{6,20}$/.test(String(value || ""));
|
||||
}
|
||||
|
||||
function isPassword(value) {
|
||||
var pwd = String(value || "");
|
||||
if (pwd.length < 8) return false;
|
||||
return /[A-Za-z]/.test(pwd) && /[0-9]/.test(pwd);
|
||||
}
|
||||
|
||||
function validateForm() {
|
||||
clearAllErrors();
|
||||
var fd = new FormData(form);
|
||||
var account = String(fd.get("account") || "").trim();
|
||||
var pwd = String(fd.get("password") || "");
|
||||
var pwd2 = String(fd.get("passwordConfirm") || "");
|
||||
var agree = form.querySelector('input[name="agree"]');
|
||||
var valid = true;
|
||||
|
||||
if (!account) {
|
||||
setFieldError("account", "请输入账号");
|
||||
valid = false;
|
||||
} else if (!isAccountNo(account)) {
|
||||
setFieldError("account", "账号需为 6 到 20 位字母或数字");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd) {
|
||||
setFieldError("password", "请输入密码");
|
||||
valid = false;
|
||||
} else if (!isPassword(pwd)) {
|
||||
setFieldError("password", "密码需 8 位以上,且同时包含字母与数字");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd2) {
|
||||
setFieldError("passwordConfirm", "请再次输入密码");
|
||||
valid = false;
|
||||
} else if (pwd2 !== pwd) {
|
||||
setFieldError("passwordConfirm", "两次输入的密码不一致");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (agree && !agree.checked) {
|
||||
setFieldError("agree", "请先同意用户条款与隐私政策");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return null;
|
||||
return { accountNo: account, password: pwd };
|
||||
}
|
||||
|
||||
function mapServerError(err) {
|
||||
var tip = (err && err.message) || "注册失败,请稍后重试";
|
||||
var code = err && err.code;
|
||||
if (code === 5005 || /已存在|重复|占用/.test(tip)) {
|
||||
setFieldError("account", tip);
|
||||
return;
|
||||
}
|
||||
if (/密码|password/i.test(tip)) {
|
||||
setFieldError("password", tip);
|
||||
return;
|
||||
}
|
||||
setFieldError("account", tip);
|
||||
}
|
||||
|
||||
function setSubmitting(loading) {
|
||||
if (!submitBtn) return;
|
||||
submitBtn.disabled = !!loading;
|
||||
submitBtn.classList.toggle("is-loading", !!loading);
|
||||
submitBtn.textContent = loading ? "注册中…" : "注册";
|
||||
}
|
||||
|
||||
if (form) {
|
||||
form.querySelectorAll("input").forEach(function (input) {
|
||||
input.addEventListener("input", function () {
|
||||
var name = input.getAttribute("name");
|
||||
if (name === "agree") clearFieldError("agree");
|
||||
else if (name) clearFieldError(name);
|
||||
});
|
||||
if (input.type === "checkbox") {
|
||||
input.addEventListener("change", function () {
|
||||
clearFieldError("agree");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
if (!window.AuthAPI || !window.HttpRequest) {
|
||||
setFieldError("account", "认证脚本未加载,请刷新页面");
|
||||
return;
|
||||
}
|
||||
if (submitBtn && submitBtn.classList.contains("is-loading")) return;
|
||||
|
||||
var payload = validateForm();
|
||||
if (!payload) return;
|
||||
|
||||
setSubmitting(true);
|
||||
AuthAPI.register(payload)
|
||||
.then(function (res) {
|
||||
AuthAPI.toast((res && res.tip) || "注册成功", "success");
|
||||
window.setTimeout(function () {
|
||||
window.location.href = "/";
|
||||
}, 400);
|
||||
})
|
||||
.catch(function (err) {
|
||||
setSubmitting(false);
|
||||
mapServerError(err);
|
||||
AuthAPI.toast((err && err.message) || "注册失败", "error");
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
@@ -1,256 +0,0 @@
|
||||
(function () {
|
||||
var root = document.querySelector("[data-register-pop]");
|
||||
if (!root) return;
|
||||
|
||||
var form = root.querySelector("[data-register-form]");
|
||||
var password = root.querySelector("[data-register-password]");
|
||||
var confirm = root.querySelector("[data-register-password-confirm]");
|
||||
var submitBtn = root.querySelector("[data-register-submit]") || (form && form.querySelector('button[type="submit"]'));
|
||||
var previousOverflow = "";
|
||||
|
||||
function closeLogin() {
|
||||
if (typeof window.closeLoginPop === "function") {
|
||||
window.closeLoginPop();
|
||||
return;
|
||||
}
|
||||
var login = document.querySelector("[data-login-pop]");
|
||||
if (login) login.classList.remove("is-open");
|
||||
}
|
||||
|
||||
function closeUserMenu() {
|
||||
var menu = document.querySelector("[data-user-menu].is-open");
|
||||
if (menu) {
|
||||
menu.classList.remove("is-open");
|
||||
var t = menu.querySelector("[data-user-menu-toggle]");
|
||||
if (t) t.setAttribute("aria-expanded", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function clearFieldError(name) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.remove("is-error");
|
||||
if (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllErrors() {
|
||||
root.querySelectorAll("[data-field]").forEach(function (el) {
|
||||
el.classList.remove("is-error");
|
||||
});
|
||||
root.querySelectorAll("[data-field-error]").forEach(function (err) {
|
||||
err.hidden = true;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = "";
|
||||
});
|
||||
}
|
||||
|
||||
function setFieldError(name, message) {
|
||||
var field = root.querySelector('[data-field="' + name + '"]');
|
||||
var err = root.querySelector('[data-field-error="' + name + '"]');
|
||||
if (field) field.classList.add("is-error");
|
||||
if (err) {
|
||||
err.hidden = false;
|
||||
var text = err.querySelector("[data-field-error-text]");
|
||||
if (text) text.textContent = message || "";
|
||||
}
|
||||
}
|
||||
|
||||
function isAccountNo(value) {
|
||||
return /^[A-Za-z0-9]{6,20}$/.test(String(value || ""));
|
||||
}
|
||||
|
||||
function isPassword(value) {
|
||||
var pwd = String(value || "");
|
||||
if (pwd.length < 8) return false;
|
||||
return /[A-Za-z]/.test(pwd) && /[0-9]/.test(pwd);
|
||||
}
|
||||
|
||||
function bindingMessage(message, fallback) {
|
||||
return String(message || fallback || "").replace(/注册/g, "绑定");
|
||||
}
|
||||
|
||||
function validateForm() {
|
||||
clearAllErrors();
|
||||
var fd = new FormData(form);
|
||||
var account = String(fd.get("account") || "").trim();
|
||||
var pwd = String(fd.get("password") || "");
|
||||
var pwd2 = String(fd.get("passwordConfirm") || "");
|
||||
var agree = form.querySelector('input[name="agree"]');
|
||||
var valid = true;
|
||||
|
||||
if (!account) {
|
||||
setFieldError("account", "请输入账号");
|
||||
valid = false;
|
||||
} else if (!isAccountNo(account)) {
|
||||
setFieldError("account", "账号需为 6 到 20 位字母或数字");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd) {
|
||||
setFieldError("password", "请输入密码");
|
||||
valid = false;
|
||||
} else if (!isPassword(pwd)) {
|
||||
setFieldError("password", "密码需 8 位以上,且同时包含字母与数字");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!pwd2) {
|
||||
setFieldError("passwordConfirm", "请再次输入密码");
|
||||
valid = false;
|
||||
} else if (pwd2 !== pwd) {
|
||||
setFieldError("passwordConfirm", "两次输入的密码不一致");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (agree && !agree.checked) {
|
||||
setFieldError("agree", "请先同意用户条款与隐私政策");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return null;
|
||||
return { accountNo: account, password: pwd };
|
||||
}
|
||||
|
||||
function mapServerError(err) {
|
||||
var tip = bindingMessage(err && err.message, "绑定失败,请稍后重试");
|
||||
var code = err && err.code;
|
||||
if (code === 5005 || /已存在|重复|占用/.test(tip)) {
|
||||
setFieldError("account", tip);
|
||||
return;
|
||||
}
|
||||
if (/密码|password/i.test(tip)) {
|
||||
setFieldError("password", tip);
|
||||
return;
|
||||
}
|
||||
setFieldError("account", tip);
|
||||
}
|
||||
|
||||
function open(event) {
|
||||
if (event) event.preventDefault();
|
||||
closeLogin();
|
||||
closeUserMenu();
|
||||
clearAllErrors();
|
||||
root.classList.add("is-open");
|
||||
previousOverflow = document.body.style.overflow;
|
||||
document.body.style.overflow = "hidden";
|
||||
var first = root.querySelector(".register-pop__input");
|
||||
if (first) {
|
||||
window.setTimeout(function () {
|
||||
first.focus();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
root.classList.remove("is-open");
|
||||
document.body.style.overflow = previousOverflow;
|
||||
clearAllErrors();
|
||||
}
|
||||
|
||||
window.openRegisterPop = open;
|
||||
window.closeRegisterPop = close;
|
||||
|
||||
function bindToggle(key, input) {
|
||||
var btn = root.querySelector('[data-register-toggle="' + key + '"]');
|
||||
var icon = root.querySelector('[data-register-toggle-icon="' + key + '"]');
|
||||
if (!btn || !input || !icon) return;
|
||||
btn.addEventListener("click", function () {
|
||||
var show = input.getAttribute("type") === "password";
|
||||
input.setAttribute("type", show ? "text" : "password");
|
||||
icon.setAttribute("src", show ? "/static/images/eye-off.svg" : "/static/images/eye.svg");
|
||||
btn.setAttribute("aria-label", show ? "隐藏密码" : "显示密码");
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("click", function (event) {
|
||||
var opener = event.target.closest("[data-register-open]");
|
||||
if (opener) {
|
||||
open(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// 站内注册入口统一使用绑定账号弹窗
|
||||
var registerLink = event.target.closest('a[href="/register"], a[href="/register/"], a[href="#register"]');
|
||||
if (registerLink) {
|
||||
open(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!root.classList.contains("is-open")) return;
|
||||
if (event.target.closest("[data-register-close]")) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
bindToggle("password", password);
|
||||
bindToggle("confirm", confirm);
|
||||
|
||||
function setSubmitting(loading) {
|
||||
if (!submitBtn) return;
|
||||
submitBtn.disabled = !!loading;
|
||||
submitBtn.classList.toggle("is-loading", !!loading);
|
||||
submitBtn.textContent = loading ? "绑定中…" : "绑定";
|
||||
}
|
||||
|
||||
if (form) {
|
||||
form.querySelectorAll("input").forEach(function (input) {
|
||||
input.addEventListener("input", function () {
|
||||
var name = input.getAttribute("name");
|
||||
if (name === "agree") clearFieldError("agree");
|
||||
else if (name) clearFieldError(name);
|
||||
});
|
||||
if (input.type === "checkbox") {
|
||||
input.addEventListener("change", function () {
|
||||
clearFieldError("agree");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
if (!window.AuthAPI || !window.HttpRequest) {
|
||||
setFieldError("account", "认证脚本未加载,请刷新页面");
|
||||
return;
|
||||
}
|
||||
if (submitBtn && submitBtn.classList.contains("is-loading")) return;
|
||||
|
||||
var payload = validateForm();
|
||||
if (!payload) return;
|
||||
|
||||
setSubmitting(true);
|
||||
AuthAPI.register(payload)
|
||||
.then(function (res) {
|
||||
AuthAPI.toast(bindingMessage(res && res.tip, "绑定成功"), "success");
|
||||
window.setTimeout(function () {
|
||||
close();
|
||||
window.location.reload();
|
||||
}, 400);
|
||||
})
|
||||
.catch(function (err) {
|
||||
setSubmitting(false);
|
||||
mapServerError(err);
|
||||
AuthAPI.toast(bindingMessage(err && err.message, "绑定失败"), "error");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Escape" && root.classList.contains("is-open")) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
var params = new URLSearchParams(window.location.search || "");
|
||||
if (params.get("auth") === "register") {
|
||||
params.delete("auth");
|
||||
var qs = params.toString();
|
||||
window.history.replaceState(null, "", window.location.pathname + (qs ? "?" + qs : "") + window.location.hash);
|
||||
open();
|
||||
}
|
||||
} catch (e) {}
|
||||
})();
|
||||
Reference in New Issue
Block a user