優化顯示與增強反作弊

This commit is contained in:
Sahik committed 2026-11-25 14:28:56 +08:00
1 parent d2be83ee77
commit 5bd77d2599
30 files changed
+764 -106

No files matched your search

+100 -9
View File
@@ -4,12 +4,13 @@ const HTML_LANG = { "zh-TW": "zh-Hant-TW", "zh-CN": "zh-Hans-CN", ja: "ja", ko:
const DEFAULT_AVATAR = "/assets/avatar.svg";
const $ = (id) => document.getElementById(id);
const HOME_TITLE = document.title; // 「吱鼯計畫 — 你今天吱吱了嗎」,伺服器會依 BETA 開關加上 (Beta)
const HOME_TITLE = document.title; // 「吱鼯計畫 — 你今天吱吱了嗎」
const SITE_TITLE = HOME_TITLE.split(" — ")[0]; // 其他頁面的標題只接站名
// 伺服器填入的檔案版本,語言檔網址也帶上,改版後不會拿到快取的舊檔
const ASSET_V = document.querySelector('meta[name="asset-version"]')?.content || "";
const VIDEO_MAX_MS = 4000; // 吱吱影片約 1.6 秒;ended 沒觸發(例如播放失敗)時的保險時間
const ZHI_GAP_MS = 1100; // 伺服器一個帳號一秒只收一下;補送沒送成功的次數時,每下隔這麼久
const ZHI_GAP_MS = 1550; // 伺服器一個帳號 1.5 秒只收一下;補送沒送成功的次數時,每下隔這麼久
const ZHI_COOL_MS = 10000; // 太頻繁被伺服器要求冷靜的時間
const SUBMIT_MAX_BYTES = 5 * 1024 * 1024;
const state = {
@@ -31,6 +32,8 @@ const state = {
zhiTimer: null,
zhiAuto: false, // 全自動吱吱開著:播完自動接下一次
zhiAutoTimer: null,
zhiCoolUntil: 0, // 冷靜到什麼時候
noticeCount: 0, // 通知匣已經載入幾則
zhiLastAt: 0, // 上一次繼續吱吱的時間
zhiPlay: 0, // 第幾次播放;離開再進來時,舊的那次播完不能動到新的
zhiFlush: null, // 正在送次數的 Promise(離開時等它送完)
@@ -157,7 +160,11 @@ function renderSidebar() {
showUid($("me-uid"), me);
$("me-link").href = `/u/${me.uid_str}`;
$("review-link").hidden = !me.is_admin;
if (me.is_admin) $("review-link").textContent = t("nav.review", { n: me.pending_reviews ?? 0 });
$("notices-link").hidden = !me.is_admin;
if (me.is_admin) {
$("review-link").textContent = t("nav.review", { n: me.pending_reviews ?? 0 });
$("notices-link").textContent = t("nav.notices", { n: me.unread_notices ?? 0 });
}
}
function showCodeStep(show) {
@@ -624,7 +631,8 @@ async function zhiCheckin(x, y) {
// 繼續吱吱:播放中再點沒有反應;播完回到第一幀才能點下一次
function zhiMore(x, y) {
if (state.zhiBusy) return;
// 一個帳號一秒只能吱一次(伺服器也會擋)。影片比 1 秒長,只有離開再馬上進來時會遇到
if (Date.now() < state.zhiCoolUntil) { toast(t("err.cooldown")); return; }
// 一個帳號 1.5 秒只能吱一次(伺服器也會擋)。影片比 1.5 秒長,只有離開再馬上進來時會遇到
if (Date.now() - state.zhiLastAt < ZHI_GAP_MS) return;
state.zhiLastAt = Date.now();
state.zhiBusy = true;
@@ -660,7 +668,7 @@ function setZhiAuto(on) {
if (on) zhiAutoTick();
}
// 可以吱就吱一下(從畫面中央);正在播就等它播完再被叫一次;離上一下不到 1 秒就等滿再吱
// 可以吱就吱一下(從畫面中央);正在播就等它播完再被叫一次;離上一下太近就等滿再吱
function zhiAutoTick() {
if (!state.zhiAuto || state.zhiMode !== "more" || state.zhiBusy) return;
const wait = ZHI_GAP_MS - (Date.now() - state.zhiLastAt);
@@ -674,7 +682,7 @@ function zhiAutoTick() {
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// 把還沒送的次數一下一下送給伺服器(伺服器一個帳號一秒只收一下)
// 把還沒送的次數一下一下送給伺服器(伺服器一個帳號 1.5 秒只收一下)
function flushZhi() {
clearTimeout(state.zhiTimer);
state.zhiTimer = null;
@@ -683,22 +691,36 @@ function flushZhi() {
}
async function sendZhi() {
let retried = false;
while (state.zhiPending > 0) {
const sentAt = Date.now();
try {
const r = await api("POST", "/api/zhi", { n: 1 });
state.zhiPending--;
// 網路抖動讓兩下太近、伺服器沒算到:重送一次。再失敗或已經積了幾下就放棄(例如兩台裝置同時在吱)
if (r.added || retried || state.zhiPending > 2) { state.zhiPending--; retried = false; } else retried = true;
// 以伺服器的數字為準,再加上還沒送出的
if (state.today) state.today.clicks = r.clicks + state.zhiPending;
} catch (e) {
if (e.status === 401 || e.status === 400) { state.zhiPending = 0; return; } // 登出了:這幾下就不算
if (e.code === "cooldown") return coolDown();
state.zhiTimer = setTimeout(flushZhi, ZHI_GAP_MS * 3); // 網路問題:留著等一下再送
return;
}
if (state.zhiPending > 0) await sleep(ZHI_GAP_MS);
if (state.zhiPending > 0) await sleep(Math.max(0, ZHI_GAP_MS - (Date.now() - sentAt)));
}
if (state.zhiMode === "more") showZhiCount(false);
}
// 太頻繁:伺服器要求冷靜 10 秒。沒送出的不算,畫面上的次數改回伺服器的數字
async function coolDown() {
state.zhiPending = 0;
state.zhiCoolUntil = Date.now() + ZHI_COOL_MS;
setZhiAuto(false);
toast(t("err.cooldown"));
try { state.today = await api("GET", "/api/checkin/today"); } catch { /* 下次重新整理會更新 */ }
if (state.zhiMode === "more") showZhiCount(false);
}
// 關掉分頁前把還沒送的那一下送出去(keepalive 讓請求在頁面關閉後繼續完成)
function flushZhiOnLeave() {
if (state.zhiPending <= 0 || state.zhiFlush) return; // 正在送的那個請求會自己完成
@@ -758,7 +780,7 @@ function bindCheckin() {
// ---------- 畫面切換 ----------
function showView(id) {
for (const v of ["view-checkin", "view-user", "view-upload", "view-review"]) $(v).hidden = v !== id;
for (const v of ["view-checkin", "view-user", "view-upload", "view-review", "view-notices"]) $(v).hidden = v !== id;
if (id !== "view-checkin") { clearInterval(state.resetTimer); closeStage(); state.guestOn = false; }
}
@@ -881,6 +903,71 @@ function bindReview() {
$("review-reject").addEventListener("click", () => decide("reject"));
}
// ---------- 管理員通知匣 ----------
function noticeItem(n) {
const li = document.createElement("li");
li.classList.toggle("unread", n.unread);
const title = document.createElement("b");
title.textContent = t(`notice.${n.kind}`);
li.append(title);
if (n.count > 1) li.append(` ×${fmtNum(n.count)}`);
if (n.uid_str) {
const a = document.createElement("a");
a.href = `/u/${n.uid_str}`;
a.textContent = `${n.display_name} (UID ${n.uid_str})`;
li.append(" ", a);
}
if (n.detail) {
const d = document.createElement("div");
d.textContent = n.detail;
li.append(d);
}
const time = document.createElement("div");
time.className = "hint";
time.textContent = new Date(n.updated_at).toLocaleString(HTML_LANG[state.lang]);
li.append(time);
return li;
}
async function loadNotices(reset) {
try {
if (reset) state.noticeCount = 0;
const r = await api("GET", `/api/admin/notices?offset=${state.noticeCount}`);
if (reset) $("notices-list").replaceChildren();
$("notices-list").append(...r.items.map(noticeItem));
state.noticeCount += r.items.length;
$("notices-empty").hidden = state.noticeCount > 0;
$("notices-more").hidden = !r.items.length || state.noticeCount >= r.total;
if (reset && r.items.length) { // 打開就算看過了
state.me.unread_notices = (await api("POST", "/api/admin/notices/read", { upto: r.upto })).unread;
renderSidebar();
}
} catch (e) {
if (e.status === 401 || e.status === 403) { location.replace("/"); return; }
toast(errText(e));
}
}
async function showNotices() {
showView("view-notices");
document.title = `${t("notices.heading")} · ${SITE_TITLE}`;
if (!state.me?.is_admin) { location.replace("/"); return; }
await loadNotices(true);
}
function bindNotices() {
$("notices-more").addEventListener("click", () => withBusy($("notices-more"), () => loadNotices(false)));
$("flag-clear").addEventListener("click", () => withBusy($("flag-clear"), async () => {
try {
const uid = $("flag-box").dataset.uid;
await api("DELETE", `/api/admin/users/${uid}/flag`);
toast(t("flag.cleared"));
await showUser(uid);
} catch (e) { toast(errText(e)); }
}));
}
// ---------- 個人頁 ----------
async function showUser(uid) {
@@ -895,6 +982,8 @@ async function showUser(uid) {
// 管理員:下面多一個設定這個 UID 顏色與稱號的表單
const form = $("title-form");
form.hidden = !state.me?.is_admin;
$("flag-box").hidden = !u.flagged;
$("flag-box").dataset.uid = u.uid;
form.dataset.uid = u.uid;
$("title-text").value = u.title || "";
$("title-color").value = u.title_color || "#ff8a1f";
@@ -1034,6 +1123,7 @@ async function route() {
if (m) return showUser(m[1]);
if (location.pathname === "/upload") return showUpload();
if (location.pathname === "/review") return showReview();
if (location.pathname === "/notices") return showNotices();
return showCheckin();
}
@@ -1046,6 +1136,7 @@ async function init() {
bindInstall();
bindUpload();
bindReview();
bindNotices();
$("menu-toggle").addEventListener("click", () => $("sidebar").classList.toggle("open"));
+14 -1
View File
@@ -105,5 +105,18 @@
"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"
"install.close": "Close",
"nav.notices": "Notifications ({n})",
"notices.heading": "Notifications",
"notices.empty": "No notifications",
"notices.more": "Load more",
"notice.flagged": "Account flagged: click count is above the theoretical limit",
"notice.cooldown": "Too frequent, cooling down",
"notice.error": "Server error",
"notice.mail_failed": "Failed to send verification email",
"notice.admin_locked": "Admin sign-in locked",
"flag.text": "This account is flagged: its click count is above the theoretical limit.",
"flag.clear": "Remove flag",
"flag.cleared": "Flag removed",
"err.cooldown": "Too fast. Take a 10 second break"
}
+14 -1
View File
@@ -105,5 +105,18 @@
"install.android": "インストールすると毎日チューチューしやすくなります",
"install.generic": "ホーム画面に追加すると便利です:ブラウザのメニュー →「ホーム画面に追加」",
"install.button": "インストール",
"install.close": "閉じる"
"install.close": "閉じる",
"nav.notices": "通知({n})",
"notices.heading": "通知",
"notices.empty": "通知はありません",
"notices.more": "もっと読み込む",
"notice.flagged": "アカウントをマーク:チューチューの回数が理論上の上限を超えています",
"notice.cooldown": "チューチューが頻繁すぎるためクールダウン中",
"notice.error": "サーバーエラー",
"notice.mail_failed": "確認メールの送信に失敗",
"notice.admin_locked": "管理者ログインがロックされました",
"flag.text": "このアカウントはマークされています:チューチューの回数が理論上の上限を超えています。",
"flag.clear": "マークを解除",
"flag.cleared": "マークを解除しました",
"err.cooldown": "速すぎます。10 秒待ってからどうぞ"
}
+14 -1
View File
@@ -105,5 +105,18 @@
"install.android": "설치하면 매일 찍찍하기 편해요",
"install.generic": "홈 화면에 추가하면 편해요: 브라우저 메뉴 →「홈 화면에 추가」",
"install.button": "설치",
"install.close": "닫기"
"install.close": "닫기",
"nav.notices": "알림함 ({n})",
"notices.heading": "알림함",
"notices.empty": "알림이 없어요",
"notices.more": "더 보기",
"notice.flagged": "계정 표시됨: 찍찍 횟수가 이론상 한도를 넘었어요",
"notice.cooldown": "찍찍가 너무 잦아 쿨다운",
"notice.error": "서버 오류",
"notice.mail_failed": "인증 메일 전송 실패",
"notice.admin_locked": "관리자 로그인 잠김",
"flag.text": "이 계정은 표시되었어요: 찍찍 횟수가 이론상 한도를 넘었어요.",
"flag.clear": "표시 해제",
"flag.cleared": "표시를 해제했어요",
"err.cooldown": "너무 빨라요. 10초 쉬었다 하세요"
}
+14 -1
View File
@@ -105,5 +105,18 @@
"install.android": "安装到桌面,每天吱吱更方便",
"install.generic": "添加到主屏幕,每天吱吱更方便:浏览器菜单 →「添加到主屏幕」",
"install.button": "安装",
"install.close": "关闭"
"install.close": "关闭",
"nav.notices": "通知箱({n})",
"notices.heading": "通知箱",
"notices.empty": "目前没有通知",
"notices.more": "加载更多",
"notice.flagged": "账号被标记:吱吱次数超过理论上限",
"notice.cooldown": "吱吱太频繁,进入冷静时间",
"notice.error": "服务器错误",
"notice.mail_failed": "验证邮件发送失败",
"notice.admin_locked": "管理员登录被锁定",
"flag.text": "这个账号被标记:吱吱次数超过理论上限。",
"flag.clear": "解除标记",
"flag.cleared": "已解除标记",
"err.cooldown": "吱太快了,冷静 10 秒再吱"
}
+14 -1
View File
@@ -105,5 +105,18 @@
"install.android": "安裝到桌面,每天吱吱更方便",
"install.generic": "加到主畫面,每天吱吱更方便:瀏覽器選單 →「加到主畫面」",
"install.button": "安裝",
"install.close": "關閉"
"install.close": "關閉",
"nav.notices": "通知匣({n})",
"notices.heading": "通知匣",
"notices.empty": "目前沒有通知",
"notices.more": "載入更多",
"notice.flagged": "帳號被標記:吱吱次數超過理論上限",
"notice.cooldown": "吱吱太頻繁,進入冷靜時間",
"notice.error": "伺服器錯誤",
"notice.mail_failed": "驗證信寄送失敗",
"notice.admin_locked": "管理員登入被鎖定",
"flag.text": "這個帳號被標記:吱吱次數超過理論上限。",
"flag.clear": "解除標記",
"flag.cleared": "已解除標記",
"err.cooldown": "吱太快了,冷靜 10 秒再吱"
}
+17 -3
View File
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>吱鼯計畫<!--BETA_TITLE--> — 你今天吱吱了嗎</title>
<title>吱鼯計畫 — 你今天吱吱了嗎</title>
<meta name="description" content="吱鼯計畫:你今天吱吱了嗎">
<meta name="theme-color" content="#1a0f06">
<link rel="icon" href="/favicon.ico" sizes="48x48">
@@ -19,7 +19,7 @@
<div class="layout">
<aside id="sidebar">
<div class="brand">
<a href="/"><img class="logo" src="/assets/logo.png" alt="" width="32" height="32"><span class="brand-text"><b>吱鼯計畫<!--BETA_BADGE--></b><small data-i18n="site.tagline"></small></span></a>
<a href="/"><img class="logo" src="/assets/logo.png" alt="" width="32" height="32"><span class="brand-text"><b>吱鼯計畫</b><small data-i18n="site.tagline"></small></span></a>
<button id="menu-toggle" class="icon-btn only-mobile" type="button" data-i18n-aria="menu">☰</button>
</div>
@@ -55,6 +55,7 @@
<a id="me-link" href="/" data-i18n="profile.view"></a>
<a id="upload-link" href="/upload" data-i18n="nav.upload"></a>
<a id="review-link" href="/review" hidden></a>
<a id="notices-link" href="/notices" hidden></a>
<button type="button" class="link" id="edit-profile" data-i18n="profile.edit"></button>
<button type="button" class="link" id="logout" data-i18n="auth.logout"></button>
</nav>
@@ -145,6 +146,13 @@
<p class="center-text muted" id="review-empty" data-i18n="review.empty" hidden></p>
</section>
<section id="view-notices" hidden>
<h1 data-i18n="notices.heading"></h1>
<p class="hint" id="notices-empty" data-i18n="notices.empty" hidden></p>
<ul class="notice-list" id="notices-list"></ul>
<button type="button" id="notices-more" data-i18n="notices.more" hidden></button>
</section>
<section id="view-user" hidden>
<div id="user-card" class="profile" hidden>
<img id="user-avatar" class="avatar large" alt="" width="160" height="160">
@@ -153,6 +161,11 @@
<p class="stats" id="user-stats"></p>
<div class="bio" id="user-bio"></div>
<p class="hint" id="user-joined"></p>
<!-- 管理員才看得到:這個帳號的吱吱次數超過理論上限 -->
<div id="flag-box" class="flag-box" hidden>
<p class="error" data-i18n="flag.text"></p>
<button type="button" id="flag-clear" data-i18n="flag.clear"></button>
</div>
<!-- 管理員才看得到:指定這個 UID 的顏色與稱號 -->
<form id="title-form" class="title-form" hidden novalidate>
<h2 data-i18n="title.heading"></h2>
@@ -179,7 +192,8 @@
<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>
<a href="https://official-website.meridianproject.tw/talents/yuzumi" target="_blank" rel="noopener noreferrer">official-website.meridianproject.tw/talents/yuzumi</a><br>
<span class="version">v<!--APP_VERSION--></span>
</footer>
</main>
</div>
+13 -4
View File
@@ -94,8 +94,6 @@ button.link:disabled { color: var(--muted); }
.avatar { border-radius: 50%; object-fit: cover; background: var(--panel-2); width: 96px; height: 96px; }
.avatar.large { width: 160px; height: 160px; }
.beta { font-size: 12px; font-weight: 600; color: var(--muted); }
/* UID 與稱號:每個 UID 都有底色。一般使用者淺咖啡、管理員黃(和 server/app/titles.py TIER_COLORS 一致);
管理員指定的顏色由 app.js 直接寫在 style 上 */
.uid-wrap { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
@@ -143,6 +141,14 @@ button.link:disabled { color: var(--muted); }
overflow-wrap: anywhere;
}
.site-footer .version { font-size: 12px; opacity: .7; }
/* 管理員:通知匣、被標記的帳號 */
.notice-list { list-style: none; margin: 16px 0; padding: 0; width: min(720px, 100%); display: flex; flex-direction: column; gap: 10px; }
.notice-list li { padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-wrap: anywhere; }
.notice-list li.unread { border-color: var(--accent); }
.flag-box { width: 100%; margin-top: 12px; padding: 12px 16px; border: 1px solid var(--error); border-radius: var(--radius); }
/* 手機:提示可以安裝到桌面 */
.install-hint {
width: 100%;
@@ -244,9 +250,11 @@ body.zhi-on { overflow: hidden; }
-webkit-text-stroke: 2px #2a1400;
paint-order: stroke fill;
text-shadow: 0 4px 0 #ff8a1f, 0 10px 32px #000a;
animation: zhi-breathe 1.4s ease-in-out infinite;
/* 晚 100ms 才出現:等門的圖先畫出來。每次重新顯示(display 變回來)動畫都會重跑 */
animation: zhi-show 1ms 100ms both, zhi-breathe 1.4s 100ms ease-in-out infinite;
}
.zhi-stage.playing .zhi-hint { display: none; }
@keyframes zhi-show { from { opacity: 0; } to { opacity: 1; } }
@keyframes zhi-breathe {
0%, 100% { transform: translate(-50%, -50%) scale(1); }
50% { transform: translate(-50%, -50%) scale(1.08); }
@@ -315,7 +323,8 @@ body.zhi-on { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) {
.particle { display: none; }
.zhi-hint, .zhi-count.bump { animation: none; }
.zhi-hint { animation: zhi-show 1ms 100ms both; }
.zhi-count.bump { animation: none; }
}
.checkin-msg { font-size: 22px; font-weight: 700; margin: 0; }