Files
Lark-Snooper/snooper_web.html

412 lines
20 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>会话过滤 · Lark Snooper</title>
<style>
:root {
color-scheme: light;
--canvas: #f4f5f1;
--surface: #ffffff;
--ink: #202a27;
--muted: #6c7772;
--line: #e1e5df;
--green: #176b52;
--green-dark: #10533f;
--green-soft: #e6f2ec;
--red: #a3483f;
--red-soft: #faece8;
--amber: #8a5b17;
--amber-soft: #fff5dc;
--shadow: 0 1px 2px rgb(24 44 35 / 4%), 0 10px 32px rgb(24 44 35 / 5%);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-width: 320px;
background: var(--canvas);
color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
font-size: 14px;
line-height: 1.5;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible, input:focus-visible, summary:focus-visible {
outline: 3px solid rgb(23 107 82 / 20%);
outline-offset: 2px;
}
.shell { width: min(1060px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 46px; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 13px; font-weight: 650; letter-spacing: .02em; }
.brand-mark {
display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
background: var(--ink); color: #fff; font-size: 12px; font-weight: 800;
}
.local-badge { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.local-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 9px; color: var(--green); font-size: 11px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(29px, 4vw, 40px); line-height: 1.18; letter-spacing: -.035em; font-weight: 720; }
.intro { margin: 13px 0 0; max-width: 580px; color: var(--muted); font-size: 14px; }
.refresh {
flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 11px;
background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(24 44 35 / 3%);
}
.refresh:hover { border-color: #bdc9c1; background: #fafbf9; }
.refresh-icon { font-size: 18px; line-height: 1; }
.refresh.loading .refresh-icon { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: rgb(255 255 255 / 58%); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin-top: 3px; font-size: 25px; line-height: 1.25; font-weight: 700; letter-spacing: -.025em; }
.stat-value.ignored { color: var(--red); }
.notice {
display: none; margin: 0 0 16px; padding: 12px 15px; border: 1px solid #ead8ad;
border-radius: 11px; background: var(--amber-soft); color: var(--amber); font-size: 13px;
}
.notice.visible { display: block; }
.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow); }
.toolbar { display: flex; align-items: center; gap: 18px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.search-wrap { position: relative; flex: 1; min-width: 160px; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: #829089; pointer-events: none; }
.search {
width: 100%; height: 42px; padding: 0 42px 0 39px; border: 1px solid var(--line);
border-radius: 10px; background: #f8f9f7; color: var(--ink); outline: none;
}
.search::placeholder { color: #929b96; }
.search:focus { border-color: var(--green); background: #fff; box-shadow: 0 0 0 3px rgb(23 107 82 / 9%); }
.key-hint {
position: absolute; right: 12px; top: 50%; transform: translateY(-50%); padding: 0 6px;
border: 1px solid #dce1dc; border-radius: 5px; color: #8a938e; font-size: 11px; line-height: 20px;
}
.filters { display: flex; flex: none; gap: 3px; padding: 3px; border-radius: 10px; background: #f0f2ee; }
.filter {
min-height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent;
color: var(--muted); font-size: 12px; font-weight: 600;
}
.filter.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgb(24 44 35 / 10%); }
.list-head { display: flex; justify-content: space-between; padding: 13px 20px 9px; color: var(--muted); font-size: 11px; }
.chat-list { min-height: 220px; }
.chat-row {
display: flex; align-items: center; gap: 14px; min-height: 78px; padding: 14px 18px;
border-top: 1px solid #edf0ec; transition: background .15s ease;
}
.chat-row:hover { background: #fbfcfa; }
.chat-row.is-ignored { background: #fdfaf9; }
.avatar {
display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 12px;
background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 750;
}
.is-ignored .avatar { background: var(--red-soft); color: var(--red); }
.chat-main { min-width: 0; flex: 1; }
.name-line { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.chat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 650; }
.tag { flex: none; padding: 1px 7px; border-radius: 5px; background: #f0f2ee; color: var(--muted); font-size: 10px; }
.tag.stale { background: var(--amber-soft); color: var(--amber); }
.chat-id { display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; color: #7d8782; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
.row-action {
flex: none; min-width: 74px; height: 34px; padding: 0 12px; border: 1px solid #d8ded8;
border-radius: 9px; background: #fff; color: var(--muted); font-size: 12px; font-weight: 650;
}
.row-action:hover { border-color: var(--red); color: var(--red); background: #fffafa; }
.is-ignored .row-action { border-color: #e6c8c2; background: var(--red-soft); color: var(--red); }
.is-ignored .row-action:hover { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.empty { display: grid; place-items: center; min-height: 240px; padding: 36px; text-align: center; color: var(--muted); }
.empty-symbol { margin-bottom: 10px; color: #a3ada7; font-size: 27px; }
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 14px; }
.manual { border-top: 1px solid var(--line); background: #fafbf9; }
.manual summary { padding: 14px 20px; color: var(--muted); cursor: pointer; font-size: 12px; user-select: none; }
.manual-form { display: flex; gap: 9px; padding: 0 20px 18px; }
.manual-input {
flex: 1; min-width: 0; height: 38px; padding: 0 11px; border: 1px solid var(--line);
border-radius: 9px; background: #fff; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}
.manual-submit { padding: 0 14px; border: 0; border-radius: 9px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 600; }
.footer { display: flex; justify-content: space-between; gap: 16px; margin-top: 16px; color: #7c8680; font-size: 11px; }
.toast {
position: fixed; left: 50%; bottom: 28px; z-index: 10; max-width: calc(100% - 32px);
padding: 11px 17px; border-radius: 10px; background: var(--ink); color: #fff;
box-shadow: 0 8px 28px rgb(20 35 29 / 22%); font-size: 13px;
opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .18s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #833d36; }
@media (max-width: 700px) {
.shell { width: min(100% - 24px, 1060px); padding-top: 24px; }
.topbar { margin-bottom: 32px; }
.hero { align-items: flex-start; margin-bottom: 24px; }
.intro { font-size: 13px; }
.refresh { min-width: 42px; padding: 0 12px; }
.refresh-label { display: none; }
.toolbar { align-items: stretch; flex-direction: column; gap: 11px; }
.filters { align-self: flex-start; }
.stats { gap: 8px; }
.stat { padding: 14px; }
.stat-value { font-size: 22px; }
.footer { flex-direction: column; gap: 4px; }
}
@media (max-width: 430px) {
.local-badge { display: none; }
.chat-row { gap: 10px; padding: 13px; }
.avatar { width: 35px; height: 35px; border-radius: 10px; }
.row-action { min-width: 62px; padding: 0 9px; }
.tag { display: none; }
.filter { padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
</style>
</head>
<body>
<main class="shell">
<header class="topbar">
<div class="brand"><span class="brand-mark">LS</span> LARK SNOOPER</div>
<span class="local-badge">仅本机访问</span>
</header>
<section class="hero">
<div>
<p class="eyebrow">Chat filters</p>
<h1>会话过滤</h1>
<p class="intro">选择不参与历史同步和每日总结的会话。更改会立即写入配置,下一次运行时生效。</p>
</div>
<button class="refresh" id="refresh" type="button" title="重新获取飞书会话">
<span class="refresh-icon" aria-hidden="true">↻</span><span class="refresh-label">刷新列表</span>
</button>
</section>
<section class="stats" aria-label="会话统计">
<div class="stat"><span class="stat-label">全部会话</span><strong class="stat-value" id="total-count">—</strong></div>
<div class="stat"><span class="stat-label">参与总结</span><strong class="stat-value" id="active-count">—</strong></div>
<div class="stat"><span class="stat-label">已忽略</span><strong class="stat-value ignored" id="ignored-count">—</strong></div>
</section>
<div class="notice" id="notice" role="alert"></div>
<section class="panel" aria-label="会话配置">
<div class="toolbar">
<div class="search-wrap">
<span class="search-icon" aria-hidden="true">⌕</span>
<input class="search" id="search" type="search" placeholder="搜索会话名称或 chat_id" autocomplete="off" spellcheck="false">
<span class="key-hint" aria-hidden="true">/</span>
</div>
<div class="filters" role="group" aria-label="筛选会话">
<button class="filter active" type="button" data-filter="all">全部</button>
<button class="filter" type="button" data-filter="group">群聊</button>
<button class="filter" type="button" data-filter="ignored">已忽略</button>
</div>
</div>
<div class="list-head"><span>会话</span><span id="result-count">正在加载…</span></div>
<div class="chat-list" id="chat-list" aria-live="polite">
<div class="empty"><div><div class="empty-symbol">↻</div><strong>正在获取会话</strong>首次加载可能需要几秒钟</div></div>
</div>
<details class="manual">
<summary>列表里找不到?按 chat_id 添加忽略</summary>
<form class="manual-form" id="manual-form">
<input class="manual-input" id="manual-id" required placeholder="输入完整 chat_id" aria-label="要忽略的 chat_id">
<button class="manual-submit" type="submit">添加忽略</button>
</form>
</details>
</section>
<footer class="footer">
<span>配置源:config.yaml · chats.exclude</span>
<span>不读取或展示消息正文</span>
</footer>
</main>
<div class="toast" id="toast" role="status"></div>
<script>
const CSRF_TOKEN = "__CSRF_TOKEN__";
const state = { chats: [], query: "", filter: "all", pending: new Set() };
const $ = (selector) => document.querySelector(selector);
const list = $("#chat-list");
let toastTimer;
function element(tag, className, text) {
const node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined) node.textContent = text;
return node;
}
function toast(message, error = false) {
const node = $("#toast");
clearTimeout(toastTimer);
node.textContent = message;
node.className = `toast visible${error ? " error" : ""}`;
toastTimer = setTimeout(() => { node.className = "toast"; }, 2800);
}
function kind(chat) {
return { 1: "私聊", 2: "群聊", 3: "话题群" }[chat.chat_type] || "会话";
}
function displayName(chat) {
return chat.name || "未命名会话";
}
function visibleChats() {
const query = state.query.trim().toLocaleLowerCase();
return state.chats.filter((chat) => {
if (state.filter === "group" && ![2, 3].includes(chat.chat_type)) return false;
if (state.filter === "ignored" && !chat.ignored) return false;
return !query || `${chat.name} ${chat.chat_id}`.toLocaleLowerCase().includes(query);
});
}
function render() {
const ignored = state.chats.filter((chat) => chat.ignored).length;
$("#total-count").textContent = state.chats.length;
$("#active-count").textContent = state.chats.length - ignored;
$("#ignored-count").textContent = ignored;
const chats = visibleChats();
$("#result-count").textContent = `${chats.length} 个结果`;
list.replaceChildren();
if (!chats.length) {
const empty = element("div", "empty");
const content = element("div");
content.append(
element("div", "empty-symbol", "⌕"),
element("strong", "", state.query ? "没有匹配的会话" : "这里还没有会话"),
element("span", "", state.query ? "试试其他名称或 chat_id" : "刷新飞书列表,或按 chat_id 手动添加")
);
empty.append(content);
list.append(empty);
return;
}
const fragment = document.createDocumentFragment();
for (const chat of chats) {
const row = element("article", `chat-row${chat.ignored ? " is-ignored" : ""}`);
row.dataset.chatId = chat.chat_id;
const avatar = element("div", "avatar", chat.chat_type === 1 ? "私" : chat.chat_type === 2 ? "群" : chat.chat_type === 3 ? "话" : "会");
const main = element("div", "chat-main");
const nameLine = element("div", "name-line");
nameLine.append(element("span", "chat-name", displayName(chat)), element("span", "tag", kind(chat)));
if (chat.ignored && !chat.sources.includes("feishu")) {
nameLine.append(element("span", "tag stale", "不在当前飞书列表"));
}
const id = element("code", "chat-id", chat.chat_id);
id.title = chat.chat_id;
main.append(nameLine, id);
const action = element("button", "row-action", chat.ignored ? "恢复" : "忽略");
action.type = "button";
action.dataset.action = "toggle";
action.disabled = state.pending.has(chat.chat_id);
action.setAttribute("aria-label", `${chat.ignored ? "恢复" : "忽略"} ${displayName(chat)}`);
row.append(avatar, main, action);
fragment.append(row);
}
list.append(fragment);
}
async function request(url, options = {}) {
const response = await fetch(url, { cache: "no-store", ...options });
let data;
try { data = await response.json(); } catch { data = {}; }
if (!response.ok) throw new Error(data.error || `请求失败(${response.status})`);
return data;
}
async function loadChats() {
const button = $("#refresh");
button.disabled = true;
button.classList.add("loading");
$("#notice").className = "notice";
try {
const data = await request("/api/chats?refresh=1");
state.chats = data.chats;
render();
if (data.warnings.length) {
$("#notice").textContent = data.warnings.join(" ");
$("#notice").className = "notice visible";
}
} catch (error) {
$("#notice").textContent = error.message;
$("#notice").className = "notice visible";
render();
} finally {
button.disabled = false;
button.classList.remove("loading");
}
}
async function setIgnored(chat, ignored) {
state.pending.add(chat.chat_id);
render();
try {
await request("/api/ignore", {
method: "POST",
headers: { "Content-Type": "application/json", "X-CSRF-Token": CSRF_TOKEN },
body: JSON.stringify({ chat_id: chat.chat_id, ignored })
});
const current = state.chats.find((item) => item.chat_id === chat.chat_id) || chat;
current.ignored = ignored;
if (ignored && !current.sources.includes("config")) current.sources.push("config");
toast(ignored ? `已忽略「${displayName(current)}」` : `已恢复「${displayName(current)}」`);
} catch (error) {
toast(error.message, true);
} finally {
state.pending.delete(chat.chat_id);
render();
}
}
list.addEventListener("click", (event) => {
const button = event.target.closest("button[data-action='toggle']");
if (!button) return;
const chatId = button.closest(".chat-row").dataset.chatId;
const chat = state.chats.find((item) => item.chat_id === chatId);
if (chat) setIgnored(chat, !chat.ignored);
});
$("#search").addEventListener("input", (event) => {
state.query = event.target.value;
render();
});
document.querySelectorAll("[data-filter]").forEach((button) => {
button.addEventListener("click", () => {
state.filter = button.dataset.filter;
document.querySelectorAll("[data-filter]").forEach((item) => item.classList.toggle("active", item === button));
render();
});
});
document.addEventListener("keydown", (event) => {
if (event.key === "/" && !["INPUT", "TEXTAREA"].includes(document.activeElement.tagName)) {
event.preventDefault();
$("#search").focus();
}
});
$("#refresh").addEventListener("click", loadChats);
$("#manual-form").addEventListener("submit", async (event) => {
event.preventDefault();
const input = $("#manual-id");
const chatId = input.value.trim();
if (!chatId || state.pending.has(chatId)) return;
const existing = state.chats.find((chat) => chat.chat_id === chatId);
const chat = existing || { chat_id: chatId, name: "", chat_type: 0, ignored: false, sources: ["config"] };
if (!existing) state.chats.push(chat);
input.value = "";
state.filter = "ignored";
state.query = "";
$("#search").value = "";
document.querySelectorAll("[data-filter]").forEach((item) => item.classList.toggle("active", item.dataset.filter === "ignored"));
await setIgnored(chat, true);
});
loadChats();
</script>
</body>
</html>