訪客功能、Yuzumi主頁導向

This commit is contained in:
Sahik committed 2026-11-22 19:45:40 +08:00
1 parent 2c69114f9e
commit f24d6fe0f9
22 files changed
+563 -87

No files matched your search

+155 -11
View File
@@ -21,7 +21,10 @@ const state = {
cardBust: Date.now(),
resendTimer: null,
resetTimer: null,
zhiMode: null, // null = 沒開 / "checkin" = 簽到那一下 / "more" = 繼續吱吱
guest: null, // 訪客紀錄 {code, clicks},只存在這個瀏覽器(localStorage),伺服器不記
guestOn: false, // 現在是訪客吱吱的畫面(沒登入)
installPrompt: null, // Android Chrome 的安裝事件
zhiMode: null, // null = 沒開 / "checkin" = 簽到那一下 / "guest" = 訪客那一下 / "more" = 繼續吱吱
zhiBusy: false, // 影片播放中:不接受點擊(簽到和繼續吱吱都一樣)
zhiSkipped: false, // 今天還沒簽到,但使用者按了「等等再吱」
zhiPending: 0, // 還沒送到伺服器的點擊次數
@@ -208,6 +211,7 @@ function bindAuth() {
try {
const r = await api("POST", "/api/auth/verify", { email: state.email, code, lang: state.lang });
state.me = r.user;
state.guestOn = false;
clearInterval(state.resendTimer);
showCodeStep(false);
$("email").value = "";
@@ -241,10 +245,12 @@ function bindAuth() {
await route();
});
$("guest-login").addEventListener("click", () => {
openMenu();
$("email").focus();
});
for (const id of ["guest-login", "done-login"]) {
$(id).addEventListener("click", () => {
openMenu();
$("email").focus();
});
}
}
// ---------- 簽到 ----------
@@ -268,6 +274,9 @@ function cardSrc(d) { return `${d.card_url}?v=${state.cardBust}&c=${d.clicks}`;
function renderToday(justChecked) {
const d = state.today;
state.guestOn = false;
$("share-btn").hidden = false;
$("done-login").hidden = true;
if (!d.checked_in) {
showCheckinPart("checkin-ready");
$("ready-stats").textContent = d.total_days || d.clicks ? statsText(d) : "";
@@ -282,6 +291,7 @@ function renderToday(justChecked) {
$("download-btn").href = src;
$("download-btn").setAttribute("download", `zhiwu-${d.day}.png`);
$("done-stats").textContent = statsText(d);
updateInstallHint();
}
startResetCountdown();
}
@@ -328,8 +338,129 @@ async function refreshToday() {
function showGuest() {
clearInterval(state.resetTimer);
$("next-reset").hidden = true;
if (state.guestOn) { // 正在看訪客小卡(例如換了語言)
if (state.zhiMode !== "more") renderGuestCard(false);
return;
}
closeStage();
showCheckinPart("checkin-guest");
const g = loadGuest();
$("guest-stats").hidden = !g;
if (g) $("guest-stats").textContent = guestStatsText(g);
}
// ---------- 訪客吱吱 ----------
// 不用登入。代號(訪客 #XXXX)和吱吱次數只存在這個瀏覽器,伺服器什麼都不記;
// 小卡由伺服器照網址上的代號和次數即時畫出來,沒有 UID、沒有分享連結。
const GUEST_KEY = "zhiwu_guest";
const GUEST_CHARS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; // 去掉容易看錯的 0 O 1 I
function loadGuest() {
if (state.guest) return state.guest;
try {
const g = JSON.parse(localStorage.getItem(GUEST_KEY));
if (g && /^[A-Z0-9]{4}$/.test(g.code) && Number.isInteger(g.clicks) && g.clicks >= 0) state.guest = g;
} catch { /* 沒有紀錄或壞掉了:當作新訪客 */ }
return state.guest;
}
function ensureGuest() {
if (loadGuest()) return state.guest;
const rnd = crypto.getRandomValues(new Uint8Array(4));
state.guest = { code: [...rnd].map((b) => GUEST_CHARS[b % GUEST_CHARS.length]).join(""), clicks: 0 };
saveGuest();
return state.guest;
}
function saveGuest() {
try { localStorage.setItem(GUEST_KEY, JSON.stringify(state.guest)); } catch { /* 無痕模式存不了就只留在這次 */ }
}
function addGuestClick() {
state.guest.clicks = Math.min(state.guest.clicks + 1, 9999999);
saveGuest();
}
function guestStatsText(g) {
return `${t("guest.name", { code: g.code })} · ${t("checkin.clicks", { n: fmtNum(g.clicks) })}`;
}
function guestCardSrc(g) {
return `/card/guest.png?code=${g.code}&n=${g.clicks}&lang=${state.lang}`;
}
function renderGuestCard(just) {
const g = state.guest;
showCheckinPart("checkin-done");
$("checkin-msg").textContent = t(just ? "guest.success" : "guest.card");
const src = guestCardSrc(g);
if ($("card-img").getAttribute("src") !== src) $("card-img").src = src;
$("download-btn").href = src;
$("download-btn").setAttribute("download", `zhiwu-guest-${g.code}.png`);
$("share-btn").hidden = true; // 伺服器沒有訪客紀錄,沒有可以分享的連結
$("done-login").hidden = false;
$("done-stats").textContent = guestStatsText(g);
updateInstallHint();
}
// 訪客的那一下:播影片、次數 +1(存在本機),播完而且小卡下載好才亮出小卡
async function zhiGuest(x, y) {
if (state.zhiBusy) return;
state.zhiBusy = true;
$("zhi-exit").disabled = true;
playVideo();
burst(x, y);
const ended = waitVideoEnd();
addGuestClick();
state.zhiLastAt = Date.now();
await Promise.all([ended, preloadImage(guestCardSrc(state.guest))]);
if (state.zhiMode !== "guest") return;
closeStage();
renderGuestCard(true);
}
// ---------- 手機:提示安裝到桌面 ----------
const INSTALL_KEY = "zhiwu_install_dismissed";
function canHintInstall() {
const mobile = window.matchMedia("(pointer: coarse)").matches && window.matchMedia("(max-width: 760px)").matches;
const installed = window.matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
let dismissed = false;
try { dismissed = localStorage.getItem(INSTALL_KEY) === "1"; } catch { /* 讀不到就當作沒關過 */ }
return mobile && !installed && !dismissed;
}
// 小卡下方的提示:Android Chrome 有安裝按鈕;iPhone 只能教他從分享選單加入主畫面
function updateInstallHint() {
const el = $("install-hint");
if (!canHintInstall()) { el.hidden = true; return; }
const ios = /iphone|ipad|ipod/i.test(navigator.userAgent);
$("install-text").textContent = t(ios ? "install.ios" : state.installPrompt ? "install.android" : "install.generic");
$("install-btn").hidden = !state.installPrompt;
el.hidden = false;
}
function bindInstall() {
window.addEventListener("beforeinstallprompt", (ev) => {
ev.preventDefault(); // 不要讓瀏覽器自己跳橫幅,改由提示上的按鈕觸發
state.installPrompt = ev;
if (!$("checkin-done").hidden) updateInstallHint();
});
window.addEventListener("appinstalled", () => { state.installPrompt = null; $("install-hint").hidden = true; });
$("install-btn").addEventListener("click", async () => {
const ev = state.installPrompt;
if (!ev) return;
state.installPrompt = null;
ev.prompt();
await ev.userChoice.catch(() => {});
$("install-hint").hidden = true;
});
$("install-close").addEventListener("click", () => {
try { localStorage.setItem(INSTALL_KEY, "1"); } catch { /* 存不了就只關這次 */ }
$("install-hint").hidden = true;
});
}
async function showCheckin() {
@@ -433,7 +564,8 @@ function waitVideoEnd() {
function showZhiCount(bump) {
const el = $("zhi-count");
el.textContent = t("zhi.count", { n: fmtNum(state.today?.clicks ?? 0) });
const n = state.guestOn ? state.guest.clicks : state.today?.clicks ?? 0;
el.textContent = t("zhi.count", { n: fmtNum(n) });
if (bump) { el.classList.remove("bump"); void el.offsetWidth; el.classList.add("bump"); }
}
@@ -499,10 +631,14 @@ function zhiMore(x, y) {
const play = ++state.zhiPlay;
playVideo();
burst(x, y, 12);
state.zhiPending++;
state.today.clicks++;
if (state.guestOn) {
addGuestClick(); // 訪客:只記在本機,不送伺服器
} else {
state.zhiPending++;
state.today.clicks++;
flushZhi();
}
showZhiCount(true);
flushZhi();
waitVideoEnd().then(() => {
if (state.zhiMode !== "more" || state.zhiPlay !== play) return; // 播到一半按了回到小卡(或離開後又進來)
resetVideo();
@@ -579,7 +715,12 @@ function flushZhiOnLeave() {
async function exitStage() {
const mode = state.zhiMode;
closeStage();
if (mode === "more") {
if (mode === "guest") {
state.guestOn = false; // 訪客按了等等再吱:回到首頁
showGuest();
} else if (mode === "more" && state.guestOn) {
renderGuestCard(false); // 小卡換成新的吱吱次數
} else if (mode === "more") {
$("done-stats").textContent = statsText(state.today); // 數字先更新,小卡等伺服器收到次數後再換
await flushZhi();
await refreshToday(); // 小卡換成新的吱吱次數
@@ -598,12 +739,14 @@ function bindCheckin() {
const x = ev.clientX || window.innerWidth / 2;
const y = ev.clientY || window.innerHeight / 2;
if (state.zhiMode === "checkin") zhiCheckin(x, y);
else if (state.zhiMode === "guest") zhiGuest(x, y);
else if (state.zhiMode === "more") zhiMore(x, y);
});
$("zhi-exit").addEventListener("click", exitStage);
$("zhi-auto").addEventListener("click", () => setZhiAuto(!state.zhiAuto));
$("zhi-open").addEventListener("click", () => { state.zhiSkipped = false; openStage("checkin"); });
$("zhi-more").addEventListener("click", () => openStage("more"));
$("guest-zhi").addEventListener("click", () => { ensureGuest(); state.guestOn = true; openStage("guest"); });
$("share-btn").addEventListener("click", shareCard);
window.addEventListener("pagehide", flushZhiOnLeave);
@@ -616,7 +759,7 @@ function bindCheckin() {
function showView(id) {
for (const v of ["view-checkin", "view-user", "view-upload", "view-review"]) $(v).hidden = v !== id;
if (id !== "view-checkin") { clearInterval(state.resetTimer); closeStage(); }
if (id !== "view-checkin") { clearInterval(state.resetTimer); closeStage(); state.guestOn = false; }
}
// ---------- 投稿迷因圖 ----------
@@ -900,6 +1043,7 @@ async function init() {
bindCheckin();
bindProfile();
bindTitle();
bindInstall();
bindUpload();
bindReview();
+12 -2
View File
@@ -24,7 +24,7 @@
"profile.save": "Save",
"profile.cancel": "Cancel",
"profile.saved": "Saved",
"checkin.login_first": "Log in to squeak in once a day and get a squeak card.",
"checkin.login_first": "Not a mouse. A flying squirrel. Squeak every day and get a card.",
"checkin.ready": "You haven't squeaked today",
"checkin.success": "Squeaked!",
"checkin.done_today": "You've already squeaked today",
@@ -95,5 +95,15 @@
"title.saved": "Title updated",
"err.title_too_long": "Titles can be up to 16 characters",
"err.invalid_color": "Invalid colour",
"err.user_not_found": "User not found"
"err.user_not_found": "User not found",
"guest.button": "Squeak as guest",
"guest.name": "Guest #{code}",
"guest.success": "Guest squeak done!",
"guest.card": "Guest card",
"about.yuzumi": "About Yuzumi",
"install.ios": "Add to your Home Screen for easier daily squeaks: tap Share, then Add to Home Screen",
"install.android": "Install the app for easier daily squeaks",
"install.generic": "Add to your home screen: browser menu, then Add to Home screen",
"install.button": "Install",
"install.close": "Close"
}
+12 -2
View File
@@ -24,7 +24,7 @@
"profile.save": "保存",
"profile.cancel": "キャンセル",
"profile.saved": "保存しました",
"checkin.login_first": "ログインすると毎日 1 回チューチューして、カードがもらえます。",
"checkin.login_first": "ネズミじゃなくて、モモンガです。毎日チューチューしてカードをもらおう。",
"checkin.ready": "今日はまだチューチューしていません",
"checkin.success": "チューチュー成功!",
"checkin.done_today": "今日はもうチューチュー済みです",
@@ -95,5 +95,15 @@
"title.saved": "称号を更新しました",
"err.title_too_long": "称号は 16 文字までです",
"err.invalid_color": "色の形式が正しくありません",
"err.user_not_found": "ユーザーが見つかりません"
"err.user_not_found": "ユーザーが見つかりません",
"guest.button": "ゲストでチューチュー",
"guest.name": "ゲスト #{code}",
"guest.success": "ゲストチューチュー成功!",
"guest.card": "ゲストのカード",
"about.yuzumi": "Yuzumi について",
"install.ios": "ホーム画面に追加すると毎日チューチューしやすくなります:「共有」→「ホーム画面に追加」",
"install.android": "インストールすると毎日チューチューしやすくなります",
"install.generic": "ホーム画面に追加すると便利です:ブラウザのメニュー →「ホーム画面に追加」",
"install.button": "インストール",
"install.close": "閉じる"
}
+12 -2
View File
@@ -24,7 +24,7 @@
"profile.save": "저장",
"profile.cancel": "취소",
"profile.saved": "저장했습니다",
"checkin.login_first": "로그인하면 하루에 한 번 찍찍 출석하고 카드를 받을 수 있습니다.",
"checkin.login_first": "쥐가 아니라 날다람쥐예요. 매일 찍찍하고 카드를 받으세요.",
"checkin.ready": "오늘은 아직 찍찍하지 않았어요",
"checkin.success": "찍찍 성공!",
"checkin.done_today": "오늘은 이미 찍찍했어요",
@@ -95,5 +95,15 @@
"title.saved": "칭호를 업데이트했습니다",
"err.title_too_long": "칭호는 최대 16자입니다",
"err.invalid_color": "색상 형식이 올바르지 않습니다",
"err.user_not_found": "사용자를 찾을 수 없습니다"
"err.user_not_found": "사용자를 찾을 수 없습니다",
"guest.button": "게스트 찍찍",
"guest.name": "게스트 #{code}",
"guest.success": "게스트 찍찍 성공!",
"guest.card": "게스트 카드",
"about.yuzumi": "Yuzumi 소개",
"install.ios": "홈 화면에 추가하면 매일 찍찍하기 편해요: 「공유」→「홈 화면에 추가」",
"install.android": "설치하면 매일 찍찍하기 편해요",
"install.generic": "홈 화면에 추가하면 편해요: 브라우저 메뉴 →「홈 화면에 추가」",
"install.button": "설치",
"install.close": "닫기"
}
+13 -3
View File
@@ -24,7 +24,7 @@
"profile.save": "保存",
"profile.cancel": "取消",
"profile.saved": "已保存",
"checkin.login_first": "不是松鼠,是鼯鼠。登录后每天吱吱签到一次,领一张吱吱小卡。",
"checkin.login_first": "不是老鼠,是鼯鼠。每天吱吱后领一张吱咪小卡。",
"checkin.ready": "今天还没吱吱",
"checkin.success": "吱吱成功!",
"checkin.done_today": "今天已经吱吱过了",
@@ -55,7 +55,7 @@
"nav.upload": "投稿图片",
"nav.review": "审核投稿({n})",
"upload.heading": "投稿图片",
"upload.hint": "上传你觉得适合放上小卡的图,审核通过后就会加入抽卡。每天最多 5 张(台湾时间 04:00 重置),上限 5MB。",
"upload.hint": "上传你觉得适合放上吱咪小卡的图,审核通过后就会加入抽卡。每天最多 5 张(台湾时间 04:00 重置),上限 5MB。",
"upload.choose": "选择图片",
"upload.remaining": "今天还能上传 {n} / {max} 张",
"upload.done": "已上传 {n} 张,等待审核",
@@ -95,5 +95,15 @@
"title.saved": "已更新称号",
"err.title_too_long": "称号最多 16 个字",
"err.invalid_color": "颜色格式不正确",
"err.user_not_found": "找不到这个用户"
"err.user_not_found": "找不到这个用户",
"guest.button": "访客吱吱",
"guest.name": "访客 #{code}",
"guest.success": "访客吱吱成功!",
"guest.card": "访客的吱咪小卡",
"about.yuzumi": "关于Yuzumi",
"install.ios": "添加到主屏幕,每天吱吱更方便:点「分享」→「添加到主屏幕」",
"install.android": "安装到桌面,每天吱吱更方便",
"install.generic": "添加到主屏幕,每天吱吱更方便:浏览器菜单 →「添加到主屏幕」",
"install.button": "安装",
"install.close": "关闭"
}
+13 -3
View File
@@ -24,7 +24,7 @@
"profile.save": "儲存",
"profile.cancel": "取消",
"profile.saved": "已儲存",
"checkin.login_first": "不是松鼠,是鼯鼠。登入後每天吱吱簽到一次,領一張吱吱小卡。",
"checkin.login_first": "不是老鼠,是鼯鼠。每天吱吱後領一張吱咪小卡。",
"checkin.ready": "今天還沒吱吱",
"checkin.success": "吱吱成功!",
"checkin.done_today": "今天已經吱吱過了",
@@ -55,7 +55,7 @@
"nav.upload": "投稿圖片",
"nav.review": "審核投稿({n})",
"upload.heading": "投稿圖片",
"upload.hint": "上傳你覺得適合放上吱吱小卡的圖,審核通過後就會加入抽卡。每天最多 5 張(台灣時間 04:00 重置),上限 5MB。",
"upload.hint": "上傳你覺得適合放上吱咪小卡的圖,審核通過後就會加入抽卡。每天最多 5 張(台灣時間 04:00 重置),上限 5MB。",
"upload.choose": "選擇圖片",
"upload.remaining": "今天還能上傳 {n} / {max} 張",
"upload.done": "已上傳 {n} 張,等待審核",
@@ -95,5 +95,15 @@
"title.saved": "已更新稱號",
"err.title_too_long": "稱號最多 16 個字",
"err.invalid_color": "顏色格式不正確",
"err.user_not_found": "找不到這個使用者"
"err.user_not_found": "找不到這個使用者",
"guest.button": "訪客吱吱",
"guest.name": "訪客 #{code}",
"guest.success": "訪客吱吱成功!",
"guest.card": "訪客的吱咪小卡",
"about.yuzumi": "關於Yuzumi",
"install.ios": "加到主畫面,每天吱吱更方便:點「分享」→「加入主畫面」",
"install.android": "安裝到桌面,每天吱吱更方便",
"install.generic": "加到主畫面,每天吱吱更方便:瀏覽器選單 →「加到主畫面」",
"install.button": "安裝",
"install.close": "關閉"
}
+17 -1
View File
@@ -79,7 +79,11 @@
<div class="big-mark">吱鼯計畫</div>
<p class="tagline" data-i18n="site.tagline"></p>
<p class="muted" data-i18n="checkin.login_first"></p>
<button id="guest-login" class="primary" type="button" data-i18n="auth.heading"></button>
<div class="row actions">
<button id="guest-login" class="primary" type="button" data-i18n="auth.heading"></button>
<button id="guest-zhi" type="button" data-i18n="guest.button"></button>
</div>
<p class="stats" id="guest-stats" hidden></p>
</div>
<!-- 今天還沒簽到、但先把全螢幕的吱吱畫面關掉(等等再吱)時顯示 -->
<div id="checkin-ready" class="center" hidden>
@@ -97,8 +101,15 @@
<button id="share-btn" class="primary" type="button" data-i18n="share.button"></button>
<a id="download-btn" class="button" download data-i18n="share.download"></a>
<button id="zhi-more" type="button" data-i18n="zhi.more"></button>
<button id="done-login" type="button" data-i18n="auth.heading" hidden></button>
</div>
<p class="stats" id="done-stats"></p>
<!-- 手機、還沒安裝到桌面時才顯示 -->
<div id="install-hint" class="install-hint" hidden>
<span id="install-text"></span>
<button id="install-btn" class="primary" type="button" data-i18n="install.button" hidden></button>
<button id="install-close" class="icon-btn" type="button" data-i18n-aria="install.close">×</button>
</div>
</div>
<p class="hint center-text" id="next-reset" hidden></p>
</section>
@@ -165,6 +176,11 @@
<p id="user-missing" class="center-text" hidden data-i18n="user.not_found"></p>
<p class="center-text"><a href="/" data-i18n="user.back"></a></p>
</section>
<footer class="site-footer">
<span data-i18n="about.yuzumi"></span><br>
<a href="https://official-website.meridianproject.tw/talents/yuzumi" target="_blank" rel="noopener noreferrer">official-website.meridianproject.tw/talents/yuzumi</a>
</footer>
</main>
</div>
+13 -2
View File
@@ -1,12 +1,23 @@
{
"id": "/",
"name": "吱鼯計畫",
"short_name": "吱鼯計畫",
"description": "你今天吱吱了嗎",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#1a0f06",
"theme_color": "#1a0f06",
"icons": [
{ "src": "/assets/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/assets/icon-512.png", "sizes": "512x512", "type": "image/png" }
{
"src": "/assets/icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/assets/icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
+35 -5
View File
@@ -96,17 +96,19 @@ button.link:disabled { color: var(--muted); }
.beta { font-size: 12px; font-weight: 600; color: var(--muted); }
/* UID 與稱號:管理員預設黃底(和 server/app/titles.py TIER_COLORS 一致);
/* UID 與稱號:每個 UID 都有底色。一般使用者淺咖啡、管理員黃(和 server/app/titles.py TIER_COLORS 一致);
管理員指定的顏色由 app.js 直接寫在 style 上 */
.uid-wrap { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.profile .uid-wrap { justify-content: center; }
.uid { color: var(--muted); font-variant-numeric: tabular-nums; }
.uid.badge, .title-badge {
.uid, .title-badge {
display: inline-block;
font-weight: 700;
font-variant-numeric: tabular-nums;
padding: 2px 10px;
border-radius: 8px;
margin-top: 2px;
background: #c9a27a;
color: #2a1400;
}
.uid.tier-admin, .title-badge.tier-admin { background: #ffd166; color: #2a1400; }
@@ -128,7 +130,35 @@ button.link:disabled { color: var(--muted); }
.lang { margin-top: auto; }
/* ---------- 主畫面 ---------- */
#main { flex: 1; padding: 40px 24px; display: flex; justify-content: center; }
#main { flex: 1; min-width: 0; padding: 40px 24px 24px; display: flex; flex-direction: column; align-items: center; }
/* 每一頁最底下:關於 Yuzumi */
.site-footer {
margin-top: auto;
padding-top: 48px;
text-align: center;
font-size: 13px;
line-height: 1.7;
color: var(--muted);
overflow-wrap: anywhere;
}
/* 手機:提示可以安裝到桌面 */
.install-hint {
width: 100%;
display: flex;
align-items: center;
gap: 10px;
text-align: left;
font-size: 14px;
padding: 10px 12px 10px 16px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: var(--radius);
}
.install-hint span { flex: 1; }
.install-hint .primary { padding: 6px 16px; white-space: nowrap; }
.install-hint .icon-btn { border: none; background: none; color: var(--muted); padding: 0 6px; }
#view-checkin, #view-user, #view-upload, #view-review { width: 100%; max-width: 560px; }
#view-upload h1, #view-review h1 { font-size: 24px; margin: 0 0 8px; }
#view-upload h2 { font-size: 18px; margin: 28px 0 12px; }
@@ -375,7 +405,7 @@ dialog h2 { margin: 0 0 4px; }
.only-mobile { display: inline-flex; }
#sidebar:not(.open) #sidebar-body { display: none; }
#sidebar-body { padding-bottom: 8px; }
#main { padding: 24px 16px; }
#main { padding: 24px 16px 20px; }
.big-logo { margin-top: 4vh; }
.big-mark { font-size: 48px; }
}