96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
(function premiumUi() {
|
|
const ready = (fn) => {
|
|
if (document.readyState === "loading") {
|
|
document.addEventListener("DOMContentLoaded", fn, { once: true });
|
|
} else {
|
|
fn();
|
|
}
|
|
};
|
|
|
|
ready(() => {
|
|
document.documentElement.classList.add("premium-ui");
|
|
syncActivePanelState();
|
|
enhanceMetricCards();
|
|
addRevealStagger();
|
|
bindPanelPulse();
|
|
observeDynamicCards();
|
|
});
|
|
|
|
function addRevealStagger(root = document) {
|
|
const groups = [
|
|
".overviewCard",
|
|
".configRail",
|
|
".panel.active",
|
|
".card[data-panel]",
|
|
".stat",
|
|
".chartBlock",
|
|
];
|
|
let index = 0;
|
|
root.querySelectorAll(groups.join(",")).forEach((el) => {
|
|
if (el.dataset.premiumReveal === "1") return;
|
|
el.dataset.premiumReveal = "1";
|
|
el.style.setProperty("--stagger", String(Math.min(index, 10)));
|
|
el.classList.add("premiumReveal");
|
|
index += 1;
|
|
});
|
|
}
|
|
|
|
function bindPanelPulse() {
|
|
document.querySelectorAll(".tabBtn[data-target]").forEach((btn) => {
|
|
if (btn.dataset.premiumTabBound === "1") return;
|
|
btn.dataset.premiumTabBound = "1";
|
|
btn.addEventListener("click", () => {
|
|
syncActivePanelState(btn.dataset.target);
|
|
window.requestAnimationFrame(() => {
|
|
const panel = findPanelByTarget(btn.dataset.target);
|
|
if (!panel) return;
|
|
panel.classList.remove("isPremiumPulse");
|
|
void panel.offsetWidth;
|
|
panel.classList.add("isPremiumPulse");
|
|
setTimeout(() => panel.classList.remove("isPremiumPulse"), 420);
|
|
addRevealStagger(panel);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function findPanelByTarget(target) {
|
|
if (!target) return null;
|
|
try {
|
|
if (window.CSS && typeof window.CSS.escape === "function") {
|
|
return document.querySelector(`.panel[data-panel="${window.CSS.escape(target)}"]`);
|
|
}
|
|
} catch (_) {}
|
|
return Array.from(document.querySelectorAll(".panel[data-panel]"))
|
|
.find((panel) => panel.dataset.panel === target) || null;
|
|
}
|
|
|
|
function syncActivePanelState(target) {
|
|
const activeTarget = target
|
|
|| document.querySelector(".tabBtn.active[data-target]")?.dataset.target
|
|
|| "device";
|
|
document.documentElement.dataset.premiumPanel = activeTarget;
|
|
}
|
|
|
|
function enhanceMetricCards() {
|
|
const tones = ["run", "device", "gift", "log"];
|
|
document.querySelectorAll(".overviewCard").forEach((card, index) => {
|
|
if (card.querySelector(".premiumMetricIcon")) return;
|
|
const icon = document.createElement("span");
|
|
icon.className = "premiumMetricIcon";
|
|
icon.dataset.tone = tones[index] || "default";
|
|
icon.setAttribute("aria-hidden", "true");
|
|
card.insertBefore(icon, card.firstElementChild);
|
|
});
|
|
}
|
|
|
|
function observeDynamicCards() {
|
|
if (!("MutationObserver" in window)) return;
|
|
const observer = new MutationObserver((records) => {
|
|
if (!records.some((record) => record.addedNodes && record.addedNodes.length)) return;
|
|
addRevealStagger();
|
|
});
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
}
|
|
})();
|