From 1d31de479637ea5cb96c46834b259c354f01642c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BD=9E?= <1617530133@qq.com> Date: Sat, 7 Nov 2026 11:17:50 +0800 Subject: [PATCH] feat: gate homepage entry buttons by login state --- index.html | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index c38fd3f..ebb3fdd 100644 --- a/index.html +++ b/index.html @@ -1146,8 +1146,7 @@ if (lightboxItem && lightboxItem.skillId) params.set("skill", lightboxItem.skillId); if (lightboxIndustry.name) params.set("industry", lightboxIndustry.name); const target = "/generate" + (params.toString() ? "?" + params.toString() : ""); - const loggedIn = !!localStorage.getItem("access_token"); - window.location.href = loggedIn ? target : "/login/?redirect=" + encodeURIComponent(target); + goEntry(target); } function closeLightbox() { @@ -1366,6 +1365,34 @@ window.clearTimeout(resizeTimer); resizeTimer = window.setTimeout(measure, 120); }); + + function isLoggedIn() { + return !!localStorage.getItem("access_token"); + } + + function goEntry(target) { + const dest = target || "/generate"; + if (isLoggedIn()) { + window.location.href = dest; + return; + } + const params = new URLSearchParams({ v: "20261107", redirect: dest }); + window.location.href = "/login/?" + params.toString(); + } + + document.querySelectorAll("a.pill--login, a.pill--signup").forEach(function (link) { + link.addEventListener("click", function (event) { + event.preventDefault(); + goEntry("/generate"); + }); + }); + + document.querySelectorAll('a[href="/generate"]').forEach(function (link) { + link.addEventListener("click", function (event) { + event.preventDefault(); + goEntry(link.getAttribute("href") || "/generate"); + }); + }); })();