logo和配置修改
This commit is contained in:
@@ -93,142 +93,12 @@
|
||||
});
|
||||
}
|
||||
|
||||
var DEFAULT_AVATAR = "/static/images/avatar.png";
|
||||
var PLACEHOLDER = "/static/images/placeholder.png?v=2";
|
||||
|
||||
function usableAvatar(url) {
|
||||
var u = String(url || "").trim();
|
||||
if (!u) return "";
|
||||
if (/^https?:\/\//i.test(u) || u.indexOf("/static/") === 0) return u;
|
||||
return "";
|
||||
}
|
||||
|
||||
function setAvatarImg(img, url) {
|
||||
if (!img) return;
|
||||
var src = usableAvatar(url);
|
||||
img.removeAttribute("data-decrypted");
|
||||
if (src && typeof shouldDecryptImage === "function" && shouldDecryptImage(src)) {
|
||||
img.classList.add("lazy");
|
||||
img.src = PLACEHOLDER;
|
||||
img.setAttribute("data-src", src);
|
||||
} else {
|
||||
img.classList.remove("lazy");
|
||||
img.removeAttribute("data-src");
|
||||
img.src = src || DEFAULT_AVATAR;
|
||||
}
|
||||
}
|
||||
|
||||
function refreshDecrypt(root) {
|
||||
if (typeof window.initLazyImages === "function") {
|
||||
window.initLazyImages(root || document);
|
||||
}
|
||||
}
|
||||
|
||||
/** 用 cookie 登录态同步 header-account */
|
||||
function parseExpireTime(value) {
|
||||
if (value == null || value === "") return NaN;
|
||||
if (typeof value === "number") {
|
||||
return value < 1e12 ? value * 1000 : value;
|
||||
}
|
||||
var text = String(value).trim();
|
||||
if (!text) return NaN;
|
||||
if (/^\d+$/.test(text)) {
|
||||
var num = Number(text);
|
||||
return num < 1e12 ? num * 1000 : num;
|
||||
}
|
||||
return Date.parse(text);
|
||||
}
|
||||
|
||||
// vipType≠0 且 currentVipExpire 未过期(与 91ly 一致)
|
||||
function isVipActive(user) {
|
||||
if (!user) return false;
|
||||
var type = Number(user.vipType);
|
||||
if (!type || type === 0) return false;
|
||||
var expireMs = parseExpireTime(user.currentVipExpire);
|
||||
if (!isFinite(expireMs) || expireMs <= 0) return false;
|
||||
return expireMs > Date.now();
|
||||
}
|
||||
|
||||
function syncHeaderVip(session) {
|
||||
var active = isVipActive(session);
|
||||
document.querySelectorAll("[data-header-vip], [data-header-vip-sep]").forEach(function (el) {
|
||||
el.hidden = !active;
|
||||
});
|
||||
}
|
||||
|
||||
function syncHeaderAccount() {
|
||||
var account = document.querySelector("[data-header-account]");
|
||||
if (!account || !window.CookieUtil) return;
|
||||
|
||||
// 有 token 即展示个人信息(含游客)
|
||||
var loggedIn = CookieUtil.isLoggedIn();
|
||||
var session = loggedIn ? CookieUtil.getAuthSession() : null;
|
||||
var nameEl = account.querySelector("[data-header-username]");
|
||||
|
||||
if (loggedIn && session) {
|
||||
var displayName =
|
||||
session.nickName || session.accountNo || session.email || "用户";
|
||||
var avatar = usableAvatar(session.avatar);
|
||||
|
||||
account.href = "/user-center/";
|
||||
account.removeAttribute("data-login-dialog-open");
|
||||
|
||||
var guest = account.querySelector("[data-header-guest-avatar]");
|
||||
if (guest) guest.remove();
|
||||
|
||||
var photo = account.querySelector("[data-header-avatar]");
|
||||
if (!photo) {
|
||||
photo = document.createElement("img");
|
||||
photo.className = "account-avatar-photo";
|
||||
photo.setAttribute("data-header-avatar", "");
|
||||
photo.alt = displayName + "的头像";
|
||||
account.insertBefore(photo, nameEl || account.firstChild);
|
||||
}
|
||||
setAvatarImg(photo, avatar);
|
||||
|
||||
if (nameEl) {
|
||||
nameEl.textContent = displayName;
|
||||
nameEl.classList.add("account-label--logged");
|
||||
}
|
||||
|
||||
refreshDecrypt(account.parentElement || document);
|
||||
syncHeaderVip(session);
|
||||
return;
|
||||
}
|
||||
|
||||
account.href = "#login";
|
||||
account.setAttribute("data-login-dialog-open", "");
|
||||
|
||||
var loggedPhoto = account.querySelector("[data-header-avatar]");
|
||||
if (loggedPhoto) loggedPhoto.remove();
|
||||
if (!account.querySelector("[data-header-guest-avatar]")) {
|
||||
var wrap = document.createElement("div");
|
||||
wrap.className = "account-avatar";
|
||||
wrap.setAttribute("data-header-guest-avatar", "");
|
||||
wrap.innerHTML =
|
||||
'<img class="account-avatar-ring" src="' +
|
||||
DEFAULT_AVATAR +
|
||||
'" alt="未登录用户头像" />' +
|
||||
'<div class="account-avatar-body"></div>' +
|
||||
'<div class="account-avatar-head"></div>';
|
||||
account.insertBefore(wrap, nameEl || account.firstChild);
|
||||
}
|
||||
if (nameEl) {
|
||||
nameEl.textContent = "未登录";
|
||||
nameEl.classList.remove("account-label--logged");
|
||||
}
|
||||
|
||||
syncHeaderVip(null);
|
||||
}
|
||||
|
||||
syncHeaderAccount();
|
||||
window.syncHeaderAccount = syncHeaderAccount;
|
||||
document.addEventListener("auth:login", function () {
|
||||
syncHeaderAccount();
|
||||
});
|
||||
document.addEventListener("auth:logout", function () {
|
||||
syncHeaderAccount();
|
||||
});
|
||||
|
||||
document.addEventListener(
|
||||
"click",
|
||||
|
||||
Reference in New Issue
Block a user