Files
deerflow-code/offline-backend-20260512/backend/skills/public/facebook-page-generator/assets/facebook-template.html
T

1583 lines
113 KiB
HTML

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#4f5ee8" />
<meta name="description" content="Facebook 风格的现代社交信息流网页。" />
<title>Facebook · 社交动态</title>
<style>
:root {
color-scheme: light;
--primary: #4f5ee8;
--primary-strong: #3d49c8;
--primary-soft: #eef0ff;
--accent: #16a36a;
--danger: #e64d61;
--bg: #f3f5fa;
--surface: #ffffff;
--surface-2: #f7f8fc;
--text: #161923;
--muted: #677087;
--line: #e5e8f0;
--shadow: 0 10px 32px rgba(25, 32, 64, .07);
--shadow-sm: 0 3px 14px rgba(25, 32, 64, .06);
--radius: 18px;
--header-h: 68px;
--focus: 0 0 0 3px rgba(79, 94, 232, .25);
}
[data-theme="dark"] {
color-scheme: dark;
--primary: #8f9aff;
--primary-strong: #b4bbff;
--primary-soft: #272d53;
--accent: #49d59a;
--danger: #ff7f90;
--bg: #11131a;
--surface: #1b1e28;
--surface-2: #222632;
--text: #f5f6fa;
--muted: #a7aec1;
--line: #303544;
--shadow: 0 14px 34px rgba(0, 0, 0, .24);
--shadow-sm: 0 4px 16px rgba(0, 0, 0, .18);
--focus: 0 0 0 3px rgba(143, 154, 255, .3);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
margin: 0;
min-width: 320px;
background: var(--bg);
color: var(--text);
font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
font-size: 16px;
line-height: 1.5;
transition: background-color .2s ease, color .2s ease;
}
body.modal-open { overflow: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
outline: none;
box-shadow: var(--focus);
}
button, [role="button"] { cursor: pointer; }
svg { display: block; }
.sr-only {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
position: fixed; z-index: 200; left: 12px; top: calc(var(--df-generated-header-height, 0px) + 10px); padding: 10px 14px; border-radius: 10px;
color: #fff; background: var(--primary); text-decoration: none; transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }
.app-header {
position: fixed; inset: var(--df-generated-header-height, 0px) 0 auto; z-index: 50; height: var(--header-h);
display: grid; grid-template-columns: minmax(280px, 1fr) minmax(420px, 620px) minmax(280px, 1fr);
align-items: center; gap: 24px; padding: 0 24px;
background: color-mix(in srgb, var(--surface) 92%, transparent);
border-bottom: 1px solid var(--line); backdrop-filter: blur(18px);
}
.brand-zone, .header-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
width: 42px; height: 42px; flex: 0 0 auto; border-radius: 14px;
display: grid; place-items: center; color: #fff;
background: linear-gradient(145deg, #5368ff, #7d4ee8);
box-shadow: 0 8px 20px rgba(79, 94, 232, .28);
}
.logo svg { width: 26px; height: 26px; }
.brand-word { font-weight: 800; font-size: 22px; letter-spacing: -.6px; }
.search-wrap { position: relative; width: min(290px, 100%); }
.search-wrap svg { position: absolute; left: 14px; top: 50%; width: 19px; height: 19px; color: var(--muted); transform: translateY(-50%); }
.search-input {
width: 100%; height: 44px; border: 1px solid transparent; border-radius: 14px;
padding: 0 14px 0 43px; color: var(--text); background: var(--surface-2); outline: none;
transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--primary); background: var(--surface); }
.main-nav { height: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.top-nav-button {
position: relative; min-width: 70px; border: 0; background: transparent; color: var(--muted);
display: grid; place-items: center; border-radius: 14px; transition: color .18s, background .18s;
}
.top-nav-button:hover { color: var(--primary); background: var(--primary-soft); }
.top-nav-button.active { color: var(--primary); }
.top-nav-button.active::after {
content: ""; position: absolute; inset: auto 10px -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary);
}
.top-nav-button svg { width: 24px; height: 24px; }
.header-actions { justify-content: flex-end; }
.icon-button {
position: relative; width: 44px; height: 44px; border: 0; border-radius: 50%;
display: grid; place-items: center; color: var(--text); background: var(--surface-2);
transition: transform .18s ease, background .18s ease, color .18s ease;
}
.icon-button:hover { color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }
.icon-button svg { width: 20px; height: 20px; }
.badge {
position: absolute; right: -2px; top: -3px; min-width: 18px; height: 18px; padding: 0 4px;
display: grid; place-items: center; border-radius: 9px; color: #fff; background: var(--danger);
border: 2px solid var(--surface); font-size: 10px; font-weight: 800;
}
.avatar {
--avatar-a: #6776ff; --avatar-b: #b15bea;
width: 42px; height: 42px; flex: 0 0 auto; border-radius: 50%;
display: grid; place-items: center; color: #fff; font-weight: 800; letter-spacing: .2px;
background: linear-gradient(145deg, var(--avatar-a), var(--avatar-b));
box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}
.avatar-sm { width: 34px; height: 34px; font-size: 12px; }
.avatar-lg { width: 52px; height: 52px; }
.profile-button { border: 0; padding: 0; background: none; border-radius: 50%; }
.app-shell {
width: min(1440px, 100%); margin: 0 auto; padding: calc(var(--header-h) + 24px) 24px 40px;
display: grid; grid-template-columns: minmax(220px, 270px) minmax(480px, 660px) minmax(250px, 320px);
justify-content: space-between; gap: 34px;
}
.sidebar { position: sticky; top: calc(var(--df-generated-header-height, 0px) + var(--header-h) + 20px); height: calc(100dvh - var(--df-generated-header-height, 0px) - var(--header-h) - 36px); overflow: auto; scrollbar-width: none; }
.sidebar::-webkit-scrollbar { display: none; }
.menu-list { display: grid; gap: 5px; }
.menu-item {
min-height: 48px; display: flex; align-items: center; gap: 13px; padding: 8px 12px;
color: var(--text); text-decoration: none; border-radius: 14px; font-weight: 650;
transition: background .18s, color .18s, transform .18s;
}
.menu-item:hover { background: var(--surface); color: var(--primary); transform: translateX(2px); }
.menu-item.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.menu-icon {
width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center;
color: var(--primary); border-radius: 11px; background: var(--primary-soft);
}
.menu-icon svg { width: 19px; height: 19px; }
.divider { height: 1px; margin: 16px 8px; background: var(--line); }
.section-title {
display: flex; justify-content: space-between; align-items: center; margin: 0 8px 10px;
color: var(--muted); font-size: 14px; font-weight: 750;
}
.text-button { min-height: 44px; border: 0; padding: 6px 8px; color: var(--primary); background: none; border-radius: 8px; font-weight: 650; }
.text-button:hover { background: var(--primary-soft); }
.shortcut-cover {
width: 34px; height: 34px; flex: 0 0 auto; border-radius: 10px; display: grid; place-items: center;
color: #fff; background: linear-gradient(140deg, #ff9e64, #ed5374); font-weight: 800;
}
.sidebar-footer { padding: 20px 10px 12px; color: var(--muted); font-size: 12px; }
.feed { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stories-card { padding: 16px; overflow: hidden; }
.stories-row { display: grid; grid-template-columns: repeat(5, minmax(92px, 1fr)); gap: 10px; overflow-x: auto; scrollbar-width: none; }
.stories-row::-webkit-scrollbar { display: none; }
.story {
position: relative; isolation: isolate; height: 172px; min-width: 92px; overflow: hidden;
border: 0; border-radius: 16px; background: #dfe3f2; text-align: left;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); transition: transform .2s ease;
}
.story:hover { transform: translateY(-3px); }
.story::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, transparent 38%, rgba(11,13,24,.78)); }
.story-bg { position: absolute; inset: 0; z-index: -2; transition: transform .3s ease; }
.story:hover .story-bg { transform: scale(1.04); }
.story-1 { background: radial-gradient(circle at 22% 23%, #fff6cc 0 10%, transparent 11%), linear-gradient(145deg, #83c8ff, #7580df 50%, #352e75); }
.story-2 { background: radial-gradient(circle at 72% 25%, #ffd6df 0 10%, transparent 11%), linear-gradient(160deg, #ffcb9a, #ef6e83 52%, #813b72); }
.story-3 { background: radial-gradient(ellipse at 60% 82%, #173a43 0 27%, transparent 28%), linear-gradient(155deg, #bbf2da, #6ec6aa 50%, #26717d); }
.story-4 { background: linear-gradient(135deg, #edd5ff 0 35%, #a57bea 36% 66%, #5b43a8 67%); }
.story-5 { background: radial-gradient(circle at 45% 45%, #fff0a4 0 16%, transparent 17%), linear-gradient(150deg, #ffb76b, #eb5c76 58%, #5e2c72); }
.story-avatar { position: absolute; top: 10px; left: 10px; border: 3px solid #fff; }
.story-name { position: absolute; inset: auto 10px 10px; color: #fff; font-size: 13px; font-weight: 750; line-height: 1.25; }
.create-story { background: var(--surface-2); }
.create-story::after { background: linear-gradient(180deg, transparent 46%, var(--surface) 47%); }
.create-story .story-bg { height: 72%; background: linear-gradient(140deg, #7888ff, #9458df); }
.story-add {
position: absolute; z-index: 2; left: 50%; bottom: 32px; width: 38px; height: 38px; transform: translateX(-50%);
display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--primary); border: 4px solid var(--surface);
}
.story-add svg { width: 18px; height: 18px; }
.create-story .story-name { color: var(--text); text-align: center; inset: auto 8px 9px; }
.composer { margin-top: 16px; padding: 16px; }
.composer-top { display: flex; align-items: center; gap: 11px; }
.composer-prompt {
flex: 1; height: 44px; padding: 0 17px; border: 0; border-radius: 22px; color: var(--muted);
background: var(--surface-2); text-align: left; transition: background .18s, color .18s;
}
.composer-prompt:hover { background: var(--primary-soft); color: var(--primary); }
.composer-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding-top: 11px; margin-top: 12px; border-top: 1px solid var(--line); }
.composer-action {
min-height: 42px; border: 0; border-radius: 11px; display: flex; align-items: center; justify-content: center; gap: 8px;
color: var(--muted); background: transparent; font-weight: 650; transition: background .18s, color .18s;
}
.composer-action:hover { background: var(--surface-2); color: var(--text); }
.composer-action svg { width: 20px; height: 20px; }
.composer-action:nth-child(1) svg { color: var(--danger); }
.composer-action:nth-child(2) svg { color: var(--accent); }
.composer-action:nth-child(3) svg { color: #e49a22; }
.feed-filter { margin: 18px 3px 11px; display: flex; justify-content: space-between; align-items: center; }
.feed-filter h2 { margin: 0; font-size: 17px; letter-spacing: -.2px; }
.filter-pill {
min-height: 44px; display: flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid var(--line);
border-radius: 10px; color: var(--muted); background: var(--surface); font-size: 13px;
}
.filter-pill svg { width: 15px; height: 15px; }
.post { margin-bottom: 16px; overflow: hidden; }
.post-header { display: flex; align-items: flex-start; gap: 11px; padding: 16px 16px 0; }
.post-author { flex: 1; min-width: 0; }
.post-author strong { display: inline-flex; align-items: center; gap: 5px; font-size: 15px; }
.verified { width: 16px; height: 16px; color: var(--primary); }
.post-meta { display: flex; align-items: center; gap: 5px; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.post-meta svg { width: 13px; height: 13px; }
.more-button { width: 38px; height: 38px; }
.post-copy { margin: 13px 16px 15px; white-space: pre-wrap; }
.post-copy a { color: var(--primary); text-decoration: none; font-weight: 650; }
.post-copy a:hover { text-decoration: underline; }
.post-source { margin: 0 16px 8px; font-size: 12px; line-height: 1.45; }
.post-source a { color: var(--primary); font-weight: 700; text-decoration: none; }
.post-media { position: relative; width: 100%; aspect-ratio: 16 / 10; overflow: hidden; background: var(--surface-2); }
.post-media svg { width: 100%; height: 100%; }
.post-media > img, .post-media > video, .post-media > iframe { width: 100%; height: 100%; display: block; border: 0; object-fit: cover; background: #080b12; }
.post-media > iframe { object-fit: initial; }
.post-media-link { position: absolute; inset: auto 12px 12px auto; z-index: 2; min-height: 36px; padding: 0 13px; display: inline-flex; align-items: center; border-radius: 999px; color: #fff; background: rgba(12,17,37,.78); text-decoration: none; font-size: 12px; font-weight: 750; backdrop-filter: blur(8px); }
.webpage-card { margin: 4px 16px 16px; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-2); }
.webpage-card .post-media { aspect-ratio: 16 / 8; }
.webpage-copy { display: block; padding: 14px 16px; color: var(--text); text-decoration: none; }
.webpage-copy strong, .webpage-copy span { display: block; }
.webpage-copy span { margin-top: 5px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.media-label {
position: absolute; left: 18px; bottom: 18px; padding: 8px 11px; border-radius: 10px;
color: #fff; background: rgba(12, 17, 37, .55); backdrop-filter: blur(8px); font-weight: 650; font-size: 13px;
}
.quote-card {
margin: 4px 16px 16px; padding: 20px; border-radius: 15px; color: #fff;
background: linear-gradient(145deg, #4f5ee8, #824fc6); position: relative; overflow: hidden;
}
.quote-card::after { content: ""; position: absolute; width: 120px; height: 120px; right: -26px; top: -44px; border: 24px solid rgba(255,255,255,.1); border-radius: 50%; }
.quote-card p { position: relative; z-index: 1; margin: 0; max-width: 88%; font-size: 20px; line-height: 1.45; font-weight: 720; letter-spacing: -.3px; }
.quote-card small { display: block; margin-top: 13px; opacity: .76; }
.engagement { display: flex; justify-content: space-between; align-items: center; min-height: 42px; margin: 0 16px; color: var(--muted); font-size: 13px; }
.reaction-summary { display: flex; align-items: center; gap: 7px; }
.reaction-bubbles { display: flex; }
.reaction-dot { width: 21px; height: 21px; display: grid; place-items: center; border: 2px solid var(--surface); border-radius: 50%; color: #fff; }
.reaction-dot + .reaction-dot { margin-left: -5px; }
.reaction-dot svg { width: 11px; height: 11px; fill: currentColor; }
.reaction-like { background: var(--primary); }
.reaction-heart { background: var(--danger); }
.engagement-details { display: flex; gap: 12px; }
.post-actions { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 16px; border-top: 1px solid var(--line); }
.post-action {
min-height: 46px; border: 0; background: none; display: flex; align-items: center; justify-content: center; gap: 7px;
color: var(--muted); font-weight: 650; border-radius: 10px; transition: background .18s, color .18s;
}
.post-action:hover { background: var(--surface-2); color: var(--text); }
.post-action svg { width: 19px; height: 19px; }
.post-action.liked { color: var(--primary); }
.post-action.liked svg { fill: currentColor; }
.comments { display: none; padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.comments.open { display: block; }
.comment-tools { min-height: 38px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.comment-tools[hidden] { display: none; }
.comment-summary { font-size: 13px; }
.comment-tools > div { display: flex; gap: 4px; }
.comment-sort { padding: 6px 10px; border: 0; border-radius: 999px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.comment-sort:hover, .comment-sort.active { color: var(--primary); background: var(--primary-soft); }
.comment-list { display: grid; gap: 0; }
.comment { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 11px; }
.comment-body { min-width: 0; flex: 1; }
.comment-bubble { padding: 9px 12px; border-radius: 6px 15px 15px 15px; background: var(--surface-2); }
.comment-bubble strong { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.comment-bubble strong svg { width: 14px; height: 14px; flex: 0 0 auto; }
.comment-bubble strong small { color: var(--muted); font-size: 11px; font-weight: 500; }
.comment-bubble > span { display: block; margin-top: 2px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.comment-meta { min-height: 22px; padding: 2px 8px 0; display: flex; align-items: center; flex-wrap: wrap; gap: 9px; color: var(--muted); font-size: 11px; }
.comment-meta button { padding: 0; border: 0; color: inherit; background: transparent; font-weight: 700; }
.comment-meta button:hover { color: var(--primary); }
.comment-pagination { margin: 0 0 10px 46px; display: flex; flex-wrap: wrap; gap: 8px; }
.comment-pagination button { min-height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--primary); background: var(--surface); font-size: 12px; font-weight: 700; }
.comment-pagination button:hover { background: var(--primary-soft); }
.comment-pagination button[hidden] { display: none; }
.comment-form { display: flex; gap: 8px; }
.comment-form input { flex: 1; height: 38px; min-width: 0; border: 1px solid var(--line); border-radius: 19px; padding: 0 14px; color: var(--text); background: var(--surface-2); }
.comment-send { width: 38px; height: 38px; color: #fff; background: var(--primary); }
.empty-search { display: none; padding: 32px 20px; text-align: center; }
.empty-search svg { width: 38px; height: 38px; margin: 0 auto 10px; color: var(--muted); }
.empty-search h3 { margin: 0 0 4px; }
.empty-search p { margin: 0; color: var(--muted); }
.right-sidebar .card { margin-bottom: 14px; }
.side-card { padding: 16px; }
.profile-summary { display: flex; align-items: center; gap: 11px; }
.profile-summary strong { display: block; }
.profile-summary span { color: var(--muted); font-size: 12px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line); text-align: center; }
.profile-stats strong { display: block; font-size: 15px; }
.profile-stats span { color: var(--muted); font-size: 11px; }
.birthday { display: flex; gap: 11px; align-items: center; }
.birthday-icon {
width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
color: #fff; background: linear-gradient(145deg, #ff6d90, #ff9b61);
}
.birthday-icon svg { width: 20px; height: 20px; }
.birthday p { margin: 0; font-size: 13px; }
.contact-row { position: relative; display: flex; align-items: center; gap: 10px; min-height: 47px; padding: 5px; border-radius: 12px; }
.contact-row:hover { background: var(--surface-2); }
.contact-row strong { font-size: 13px; }
.online-dot { position: absolute; left: 31px; bottom: 6px; width: 10px; height: 10px; border: 2px solid var(--surface); border-radius: 50%; background: #27bd73; }
.sponsor {
display: grid; grid-template-columns: 74px 1fr; gap: 11px; align-items: center; padding: 7px; border-radius: 12px; text-decoration: none; color: inherit;
}
.sponsor:hover { background: var(--surface-2); }
.sponsor-art { height: 64px; border-radius: 11px; background: linear-gradient(145deg, #b8e6ff, #5d8bea 50%, #6744b2); position: relative; overflow: hidden; }
.sponsor-art::after { content: ""; position: absolute; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.35); top: -14px; right: -10px; }
.sponsor small { color: var(--muted); }
.right-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.right-head h3 { margin: 0; font-size: 14px; color: var(--muted); }
.tiny-actions { display: flex; gap: 4px; }
.tiny-actions .icon-button { width: 44px; height: 44px; background: transparent; }
.drawer {
position: fixed; z-index: 70; right: 18px; top: calc(var(--df-generated-header-height, 0px) + var(--header-h) + 10px); width: min(380px, calc(100vw - 36px));
max-height: calc(100dvh - var(--df-generated-header-height, 0px) - var(--header-h) - 24px); overflow: auto; padding: 16px;
border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow);
opacity: 0; visibility: hidden; transform: translateY(-8px) scale(.98); transform-origin: top right;
transition: opacity .18s ease, visibility .18s ease, transform .18s ease;
}
.drawer.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.drawer-head h2 { margin: 0; font-size: 21px; }
.notification { display: flex; gap: 10px; padding: 11px 7px; border-radius: 13px; }
.notification:hover { background: var(--surface-2); }
.notification p { margin: 0; font-size: 13px; }
.notification time { display: block; margin-top: 3px; color: var(--primary); font-size: 11px; font-weight: 650; }
.unread-mark { width: 8px; height: 8px; margin: 17px 0 0 auto; flex: 0 0 auto; border-radius: 50%; background: var(--primary); }
.modal-backdrop {
position: fixed; z-index: 100; inset: 0; padding: 20px; display: grid; place-items: center;
background: rgba(12, 16, 31, .52); backdrop-filter: blur(5px);
opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}
.modal-backdrop.open { opacity: 1; visibility: visible; }
.modal {
width: min(530px, 100%); max-height: calc(100dvh - 40px); overflow: auto;
border-radius: 20px; background: var(--surface); box-shadow: 0 28px 80px rgba(0,0,0,.3);
transform: translateY(12px) scale(.98); transition: transform .2s ease;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-header { position: relative; padding: 16px 62px; border-bottom: 1px solid var(--line); text-align: center; }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-close { position: absolute; right: 14px; top: 10px; }
.modal-body { padding: 16px; }
.visibility-select { display: inline-flex; align-items: center; gap: 5px; margin-top: 2px; padding: 3px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 650; }
.visibility-select svg { width: 12px; height: 12px; }
.post-textarea {
width: 100%; min-height: 150px; margin: 14px 0 10px; padding: 0; resize: vertical;
border: 0; outline: none; color: var(--text); background: transparent; font-size: 20px; line-height: 1.5;
}
.post-textarea::placeholder { color: var(--muted); }
.add-to-post { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; }
.add-to-post strong { font-size: 13px; }
.add-buttons { display: flex; gap: 3px; }
.add-buttons .icon-button { width: 36px; height: 36px; background: transparent; }
.publish-button {
width: 100%; height: 44px; margin-top: 13px; border: 0; border-radius: 11px; color: #fff;
background: var(--primary); font-weight: 750; transition: background .18s, transform .18s, opacity .18s;
}
.publish-button:hover:not(:disabled) { background: var(--primary-strong); transform: translateY(-1px); }
.publish-button:disabled { cursor: not-allowed; opacity: .45; }
.settings-backdrop {
position: fixed; z-index: 110; inset: 0; padding: 24px; display: grid; place-items: center;
background: rgba(10, 14, 28, .7); backdrop-filter: blur(8px);
opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}
.settings-backdrop.open { opacity: 1; visibility: visible; }
.settings-panel {
width: min(1180px, 100%); max-height: calc(100dvh - 48px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
overflow: hidden; border: 1px solid color-mix(in srgb, var(--primary) 52%, var(--line)); border-radius: 20px;
background: var(--surface); box-shadow: 0 32px 90px rgba(0, 0, 0, .42);
transform: translateY(14px) scale(.985); transition: transform .2s ease;
}
.settings-backdrop.open .settings-panel { transform: none; }
.settings-header {
min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 20px;
padding: 18px 22px; border-bottom: 1px solid var(--line);
background: linear-gradient(135deg, color-mix(in srgb, var(--primary-soft) 72%, var(--surface)), var(--surface));
}
.settings-kicker { display: block; margin-bottom: 2px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.settings-header h2 { margin: 0; font-size: 24px; letter-spacing: -.3px; }
.settings-body { min-height: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.settings-modules { min-height: 0; overflow: auto; padding: 18px; border-right: 1px solid var(--line); background: var(--surface-2); }
.settings-modules h3 { margin: 0 0 12px; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.module-tabs { display: grid; gap: 7px; }
.module-tab {
min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
padding: 10px 12px; border: 1px solid transparent; border-radius: 12px; color: var(--text); background: transparent;
text-align: left; font-weight: 700; transition: background .18s ease, border-color .18s ease, color .18s ease;
}
.module-tab:hover { color: var(--primary); background: var(--surface); }
.module-tab[aria-selected="true"] { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 42%, var(--line)); background: var(--surface); box-shadow: var(--shadow-sm); }
.module-tab span:last-child { color: var(--muted); font-size: 11px; font-weight: 650; }
.settings-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.summary-tile { padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.summary-tile strong { display: block; color: var(--primary); font-size: 18px; }
.summary-tile span { color: var(--muted); font-size: 11px; }
.settings-editor { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: 18px; }
.editor-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.editor-head label { font-weight: 800; }
.editor-help { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 500; }
.json-status { display: inline-flex; align-items: center; gap: 7px; color: var(--accent); font-size: 12px; font-weight: 750; white-space: nowrap; }
.json-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.json-status.invalid { color: var(--danger); }
.json-editor {
width: 100%; min-height: 360px; resize: none; padding: 18px; border: 1px solid #263149; border-radius: 14px;
outline: none; color: #dbe8ff; background: #0b1220; caret-color: #8f9aff;
font: 14px/1.65 "Cascadia Code", "SFMono-Regular", Consolas, monospace; tab-size: 2;
box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
.json-editor:focus { border-color: #7f8cff; box-shadow: 0 0 0 3px rgba(127,140,255,.22); }
.editor-error { min-height: 20px; margin-top: 8px; color: var(--danger); font-size: 12px; }
.settings-footer {
min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface);
}
.settings-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.settings-button {
min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 11px;
color: var(--text); background: var(--surface); font-weight: 750; transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}
.settings-button:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.settings-button.primary { min-width: 142px; color: #fff; border-color: var(--primary); background: var(--primary); }
.settings-button.primary:hover { color: #fff; background: var(--primary-strong); transform: translateY(-1px); }
.settings-button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.settings-note { color: var(--muted); font-size: 12px; }
.toast {
position: fixed; z-index: 120; left: 50%; bottom: 26px; padding: 11px 15px;
border-radius: 11px; color: #fff; background: #202534; box-shadow: 0 12px 30px rgba(0,0,0,.25);
opacity: 0; visibility: hidden; transform: translate(-50%, 12px); transition: opacity .2s, visibility .2s, transform .2s;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.mobile-nav { display: none; }
@media (max-width: 1180px) {
.app-header { grid-template-columns: minmax(230px, 1fr) minmax(360px, 560px) minmax(210px, 1fr); }
.brand-word { display: none; }
.app-shell { grid-template-columns: 210px minmax(480px, 650px) 270px; gap: 22px; }
}
@media (max-width: 980px) {
.app-header { grid-template-columns: 240px 1fr 200px; }
.main-nav { justify-self: stretch; }
.app-shell { grid-template-columns: 205px minmax(460px, 650px); justify-content: center; }
.right-sidebar { display: none; }
}
@media (max-width: 760px) {
:root { --header-h: 60px; }
body { padding-bottom: 65px; }
.app-header { grid-template-columns: 1fr auto; padding: 0 14px; gap: 10px; }
.brand-zone { min-width: 0; }
.logo { width: 38px; height: 38px; border-radius: 12px; }
.search-wrap { width: min(260px, calc(100vw - 246px)); }
.search-input { height: 40px; }
.main-nav, .header-actions .desktop-only, .left-sidebar { display: none; }
.header-actions .profile-button { display: none; }
.app-shell { display: block; padding: calc(var(--header-h) + 12px) 10px 22px; }
.feed { width: min(640px, 100%); margin: 0 auto; }
.stories-card { padding: 11px; }
.stories-row { grid-template-columns: repeat(5, 92px); }
.story { height: 155px; }
.card { border-radius: 15px; }
.mobile-nav {
position: fixed; z-index: 60; inset: auto 0 0; height: 62px; display: grid; grid-template-columns: repeat(5, 1fr);
padding: 4px 8px max(4px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent);
border-top: 1px solid var(--line); backdrop-filter: blur(16px);
}
.mobile-nav button { min-height: 50px; border: 0; border-radius: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); background: transparent; font-size: 10px; }
.mobile-nav button.active { color: var(--primary); background: var(--primary-soft); }
.mobile-nav svg { width: 22px; height: 22px; }
.drawer { right: 10px; top: calc(var(--df-generated-header-height, 0px) + var(--header-h) + 7px); }
.settings-backdrop { padding: 0; }
.settings-panel { width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; }
.settings-header { min-height: 76px; padding: 14px 16px; }
.settings-header h2 { font-size: 21px; }
.settings-body { display: block; overflow: auto; }
.settings-modules { position: sticky; top: 0; z-index: 2; overflow: hidden; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
.settings-modules h3, .settings-summary { display: none; }
.module-tabs { display: flex; overflow-x: auto; gap: 7px; scrollbar-width: none; }
.module-tabs::-webkit-scrollbar { display: none; }
.module-tab { min-width: max-content; min-height: 44px; }
.module-tab span:last-child { display: none; }
.settings-editor { min-height: 58dvh; padding: 14px 12px; }
.json-editor { min-height: 46dvh; }
.settings-footer { align-items: flex-start; padding: 12px; }
.settings-note { display: none; }
}
@media (max-width: 460px) {
.header-actions .theme-toggle { display: none; }
.search-wrap { width: calc(100vw - 204px); }
.stories-row { grid-template-columns: repeat(5, 84px); }
.story { min-width: 84px; height: 146px; }
.composer-action span { display: none; }
.post-copy { font-size: 16px; }
.quote-card p { font-size: 18px; }
.post-action span { font-size: 13px; }
.engagement { align-items: flex-start; gap: 8px; }
.engagement-details { gap: 7px; text-align: right; }
.settings-footer { display: block; }
.settings-actions { display: grid; grid-template-columns: 1fr 1fr; }
.settings-button { padding: 0 10px; }
.settings-button.primary { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
.skip-link { transform: translateY(calc(-100% - var(--df-generated-header-height, 0px) - 24px)); }
.skip-link:focus { transform: translateY(0); }
.modal-backdrop { z-index: 1200; }
.settings-backdrop { z-index: 1300; }
</style>
</head>
<body>
<a class="skip-link" href="#feed">跳到动态内容</a>
<svg aria-hidden="true" width="0" height="0" style="position:absolute">
<symbol id="i-circle" viewBox="0 0 24 24"><path d="M7.5 5.7A8 8 0 1 1 5.7 8" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/><path d="M7.3 3.7v4.6H2.7" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/><circle cx="12" cy="12" r="2.7" fill="currentColor"/></symbol>
<symbol id="i-search" viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" fill="none" stroke="currentColor" stroke-width="2"/><path d="m16.2 16.2 4.1 4.1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-home" viewBox="0 0 24 24"><path d="m3 10 9-7 9 7v10a1 1 0 0 1-1 1h-5v-7H9v7H4a1 1 0 0 1-1-1Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-users" viewBox="0 0 24 24"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm13 10v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-video" viewBox="0 0 24 24"><rect x="3" y="5" width="15" height="14" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="m18 10 4-2v8l-4-2ZM10 9l4 3-4 3Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-grid" viewBox="0 0 24 24"><rect x="3" y="3" width="7" height="7" rx="1" fill="none" stroke="currentColor" stroke-width="2"/><rect x="14" y="3" width="7" height="7" rx="1" fill="none" stroke="currentColor" stroke-width="2"/><rect x="3" y="14" width="7" height="7" rx="1" fill="none" stroke="currentColor" stroke-width="2"/><rect x="14" y="14" width="7" height="7" rx="1" fill="none" stroke="currentColor" stroke-width="2"/></symbol>
<symbol id="i-message" viewBox="0 0 24 24"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 9.7 9.7 0 0 1-4.1-.9L3 21l1.5-4.4A8.4 8.4 0 1 1 21 11.5Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-bell" viewBox="0 0 24 24"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9ZM10 21h4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-moon" viewBox="0 0 24 24"><path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 2v2m0 16v2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M2 12h2m16 0h2M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-chevron" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-bookmark" viewBox="0 0 24 24"><path d="M6 3h12a1 1 0 0 1 1 1v17l-7-4-7 4V4a1 1 0 0 1 1-1Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-calendar" viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M16 3v4M8 3v4M3 11h18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-store" viewBox="0 0 24 24"><path d="m3 9 2-6h14l2 6a4 4 0 0 1-5 3.9A4 4 0 0 1 12 15a4 4 0 0 1-4-2.1A4 4 0 0 1 3 9Zm2 5v7h14v-7" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-clock" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 7v5l3 2" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-more" viewBox="0 0 24 24"><circle cx="5" cy="12" r="1.7" fill="currentColor"/><circle cx="12" cy="12" r="1.7" fill="currentColor"/><circle cx="19" cy="12" r="1.7" fill="currentColor"/></symbol>
<symbol id="i-plus" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round"/></symbol>
<symbol id="i-image" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="8.5" cy="9" r="1.5" fill="currentColor"/><path d="m4 17 5-5 4 4 2-2 5 4" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-smile" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/><path d="M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-globe" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-width="2"/><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" fill="none" stroke="currentColor" stroke-width="1.6"/></symbol>
<symbol id="i-verified" viewBox="0 0 24 24"><path d="m12 2 2.2 2.1 3-.4.9 2.9 2.7 1.4-1.3 2.8 1.3 2.8-2.7 1.4-.9 2.9-3-.4L12 22l-2.2-2.1-3 .4-.9-2.9L3.2 16l1.3-2.8-1.3-2.8L5.9 9l.9-2.9 3 .4Z" fill="currentColor"/><path d="m8.5 12 2.2 2.2 4.8-5" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-thumb" viewBox="0 0 24 24"><path d="M7 10v11H3V10h4Zm0 10h10.4a2 2 0 0 0 2-1.6l1.5-7A2 2 0 0 0 19 9h-4l.7-3.2A2.3 2.3 0 0 0 13.5 3L9 10H7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
<symbol id="i-heart" viewBox="0 0 24 24"><path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1.1-1.1a5.5 5.5 0 0 0-7.8 7.8l1.1 1.1L12 21l7.8-7.5 1.1-1.1a5.5 5.5 0 0 0-.1-7.8Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-comment" viewBox="0 0 24 24"><path d="M21 15a4 4 0 0 1-4 4H8l-5 3V7a4 4 0 0 1 4-4h10a4 4 0 0 1 4 4Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-share" viewBox="0 0 24 24"><circle cx="18" cy="5" r="3" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="6" cy="12" r="3" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="18" cy="19" r="3" fill="none" stroke="currentColor" stroke-width="2"/><path d="m8.7 10.7 6.6-4.2m-6.6 6.8 6.6 4.2" fill="none" stroke="currentColor" stroke-width="2"/></symbol>
<symbol id="i-filter" viewBox="0 0 24 24"><path d="M4 6h16M7 12h10m-7 6h4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-cake" viewBox="0 0 24 24"><path d="M4 13h16v8H4Zm2-4h12v4H6Zm6-6c2 2 1 4 0 4s-2-2 0-4Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></symbol>
<symbol id="i-send" viewBox="0 0 24 24"><path d="m22 2-7 20-4-9-9-4Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M22 2 11 13" fill="none" stroke="currentColor" stroke-width="2"/></symbol>
<symbol id="i-close" viewBox="0 0 24 24"><path d="m6 6 12 12M18 6 6 18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
<symbol id="i-settings" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3" fill="none" stroke="currentColor" stroke-width="2"/><path d="M19.4 15a1.7 1.7 0 0 0 .34 1.88l.06.06-2.83 2.83-.06-.06a1.7 1.7 0 0 0-1.88-.34 1.7 1.7 0 0 0-1.03 1.56V21h-4v-.08A1.7 1.7 0 0 0 8.96 19.4a1.7 1.7 0 0 0-1.88.34l-.06.06-2.83-2.83.06-.06A1.7 1.7 0 0 0 4.6 15a1.7 1.7 0 0 0-1.56-1.03H3v-4h.08A1.7 1.7 0 0 0 4.6 8.96a1.7 1.7 0 0 0-.34-1.88l-.06-.06L7.03 4.2l.06.06a1.7 1.7 0 0 0 1.88.34A1.7 1.7 0 0 0 10 3.04V3h4v.08a1.7 1.7 0 0 0 1.03 1.56 1.7 1.7 0 0 0 1.88-.34l.06-.06 2.83 2.83-.06.06a1.7 1.7 0 0 0-.34 1.88 1.7 1.7 0 0 0 1.56 1.03H21v4h-.08A1.7 1.7 0 0 0 19.4 15Z" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></symbol>
</svg>
<header class="app-header">
<div class="brand-zone">
<div class="logo" aria-hidden="true"><svg><use href="#i-circle"/></svg></div>
<span class="brand-word" id="brandWord">Circle</span>
<label class="search-wrap">
<span class="sr-only">搜索动态和联系人</span>
<svg aria-hidden="true"><use href="#i-search"/></svg>
<input id="globalSearch" class="search-input" type="search" placeholder="搜索 Circle" autocomplete="off" />
</label>
</div>
<nav class="main-nav" id="mainNav" aria-label="主导航"></nav>
<div class="header-actions">
<button class="icon-button theme-toggle" id="themeToggle" aria-label="切换深色模式" title="切换主题"><svg><use href="#i-moon"/></svg></button>
<button class="icon-button" id="openSettings" aria-label="打开 JSON 设置" title="编辑页面 JSON"><svg><use href="#i-settings"/></svg></button>
<button class="icon-button desktop-only" data-drawer="messagesDrawer" aria-label="打开消息" title="消息"><svg><use href="#i-message"/></svg><span class="badge">3</span></button>
<button class="icon-button" data-drawer="notificationDrawer" aria-label="打开通知" title="通知"><svg><use href="#i-bell"/></svg><span class="badge">5</span></button>
<button class="profile-button" id="headerProfile" aria-label="打开个人资料"></button>
</div>
</header>
<main class="app-shell">
<aside class="sidebar left-sidebar" aria-label="快捷导航">
<nav class="menu-list" id="primaryMenu"></nav>
<div class="divider"></div>
<div class="section-title"><span id="shortcutsTitle">你的快捷方式</span><button class="text-button">编辑</button></div>
<nav class="menu-list" id="shortcutsMenu"></nav>
<div class="sidebar-footer" id="sidebarFooter"></div>
</aside>
<section class="feed" id="feed" aria-label="动态信息流">
<h1 class="sr-only">Circle 社交动态首页</h1>
<div class="card stories-card">
<div class="stories-row" id="storiesRow" aria-label="限时动态"></div>
</div>
<div class="card composer">
<div class="composer-top"><span id="composerAvatar"></span><button class="composer-prompt" id="composerPrompt" data-open-composer></button></div>
<div class="composer-actions">
<button class="composer-action" data-open-composer><svg><use href="#i-video"/></svg><span>直播</span></button>
<button class="composer-action" data-open-composer><svg><use href="#i-image"/></svg><span>照片 / 视频</span></button>
<button class="composer-action" data-open-composer><svg><use href="#i-smile"/></svg><span>心情 / 活动</span></button>
</div>
</div>
<div class="feed-filter"><h2 id="feedTitle"></h2><button class="filter-pill"><svg><use href="#i-filter"/></svg><span id="feedSort"></span></button></div>
<div id="postsContainer">
<article class="card post" data-search="许知夏 城市 早晨 跑步 河岸 秋天">
<header class="post-header">
<span class="avatar" style="--avatar-a:#15a5a5;--avatar-b:#57c873">许</span>
<div class="post-author"><strong>许知夏 <svg class="verified"><use href="#i-verified"/></svg></strong><div class="post-meta"><span>38 分钟前</span><span>·</span><svg><use href="#i-globe"/></svg></div></div>
<button class="icon-button more-button" aria-label="更多操作"><svg><use href="#i-more"/></svg></button>
</header>
<p class="post-copy">把清晨六点的风装进口袋。沿河跑完五公里,整座城市才刚刚醒来。<a href="#morning">#城市晨跑</a> <a href="#autumn">#秋日计划</a></p>
<div class="post-media" role="img" aria-label="河岸清晨的抽象风景插画">
<svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice">
<defs><linearGradient id="sky" x1="0" y1="0" x2="0" y2="1"><stop stop-color="#abcdf6"/><stop offset=".55" stop-color="#f4cfbc"/><stop offset="1" stop-color="#eaa37e"/></linearGradient><linearGradient id="river" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#7198c1"/><stop offset="1" stop-color="#314b73"/></linearGradient></defs>
<rect width="800" height="500" fill="url(#sky)"/><circle cx="610" cy="120" r="55" fill="#fff2c9" opacity=".9"/><path d="M0 270 160 210l90 45 120-85 150 105 110-70 170 100v195H0Z" fill="#5d7390"/><path d="M0 315c170-60 300-10 420-25 155-20 250-5 380 46v164H0Z" fill="url(#river)"/><path d="M0 310c180-22 314 14 460-2 110-12 230-6 340 36" fill="none" stroke="#f7e7d4" stroke-width="8" opacity=".46"/><path d="M0 382c155-42 250-23 370-38 150-18 250 0 430 68" fill="none" stroke="#fff" stroke-width="5" opacity=".2"/><path d="M110 260v115m0-101-42-46m42 42 48-57" stroke="#314a50" stroke-width="12" stroke-linecap="round"/><circle cx="68" cy="220" r="44" fill="#486d63"/><circle cx="148" cy="207" r="58" fill="#567e6d"/></svg>
<span class="media-label">滨江绿道 · 06:18</span>
</div>
<div class="engagement"><div class="reaction-summary"><span class="reaction-bubbles"><span class="reaction-dot reaction-like"><svg><use href="#i-thumb"/></svg></span><span class="reaction-dot reaction-heart"><svg><use href="#i-heart"/></svg></span></span><span class="like-count">128</span></div><div class="engagement-details"><span><span class="comment-count">18</span> 条评论</span><span>6 次分享</span></div></div>
<div class="post-actions"><button class="post-action like-button"><svg><use href="#i-thumb"/></svg><span>赞</span></button><button class="post-action comment-button"><svg><use href="#i-comment"/></svg><span>评论</span></button><button class="post-action share-button"><svg><use href="#i-share"/></svg><span>分享</span></button></div>
<div class="comments">
<div class="comment"><span class="avatar avatar-sm" style="--avatar-a:#ff7657;--avatar-b:#d54d9d">周</span><div class="comment-bubble"><strong>周野</strong><span>照片里的光也太温柔了,下次一起!</span></div></div>
<form class="comment-form"><label class="sr-only">添加评论</label><input maxlength="120" placeholder="写评论…" /><button class="icon-button comment-send" aria-label="发送评论"><svg><use href="#i-send"/></svg></button></form>
</div>
</article>
<article class="card post" data-search="陈默 设计 产品 灵感 习惯 创造力">
<header class="post-header">
<span class="avatar" style="--avatar-a:#2d8d78;--avatar-b:#57c995">陈</span>
<div class="post-author"><strong>陈默</strong><div class="post-meta"><span>2 小时前</span><span>·</span><svg><use href="#i-users"/></svg></div></div>
<button class="icon-button more-button" aria-label="更多操作"><svg><use href="#i-more"/></svg></button>
</header>
<p class="post-copy">今天的设计札记:真正好用的产品,往往不是替你完成所有事情,而是在你需要的时候,恰好递来一个合适的支点。</p>
<div class="quote-card"><p>“减少一次犹豫,比增加一个功能更有价值。”</p><small>陈默 · 产品设计札记 024</small></div>
<div class="engagement"><div class="reaction-summary"><span class="reaction-bubbles"><span class="reaction-dot reaction-like"><svg><use href="#i-thumb"/></svg></span><span class="reaction-dot reaction-heart"><svg><use href="#i-heart"/></svg></span></span><span class="like-count">86</span></div><div class="engagement-details"><span><span class="comment-count">9</span> 条评论</span><span>12 次分享</span></div></div>
<div class="post-actions"><button class="post-action like-button"><svg><use href="#i-thumb"/></svg><span>赞</span></button><button class="post-action comment-button"><svg><use href="#i-comment"/></svg><span>评论</span></button><button class="post-action share-button"><svg><use href="#i-share"/></svg><span>分享</span></button></div>
<div class="comments"><form class="comment-form"><label class="sr-only">添加评论</label><input maxlength="120" placeholder="写评论…" /><button class="icon-button comment-send" aria-label="发送评论"><svg><use href="#i-send"/></svg></button></form></div>
</article>
<article class="card post" data-search="宋可心 周末 市集 咖啡 手作 朋友">
<header class="post-header">
<span class="avatar" style="--avatar-a:#a95cd8;--avatar-b:#5365da">宋</span>
<div class="post-author"><strong>宋可心 <svg class="verified"><use href="#i-verified"/></svg></strong><div class="post-meta"><span>昨天 20:46</span><span>·</span><svg><use href="#i-globe"/></svg></div></div>
<button class="icon-button more-button" aria-label="更多操作"><svg><use href="#i-more"/></svg></button>
</header>
<p class="post-copy">周末的手作市集圆满收摊。谢谢每一个停下来聊天、喝咖啡、带走小物件的朋友。下个月再见! <a href="#market">#城市小店</a></p>
<div class="post-media" role="img" aria-label="温暖的周末市集抽象插画">
<svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice">
<defs><linearGradient id="marketSky" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#f7d1a7"/><stop offset="1" stop-color="#c67286"/></linearGradient></defs>
<rect width="800" height="500" fill="url(#marketSky)"/><circle cx="120" cy="92" r="50" fill="#fff1bf" opacity=".86"/><path d="M0 325 95 260l105 55 92-80 112 92 116-107 130 98 150-70v252H0Z" fill="#765378" opacity=".72"/><rect x="70" y="258" width="270" height="160" rx="8" fill="#fff0d8"/><path d="M50 258h310l-38-78H88Z" fill="#e85f66"/><path d="M88 180h58l-18 78H50Zm116 0h58l20 78h-96Z" fill="#fff3d7"/><rect x="115" y="307" width="70" height="111" rx="4" fill="#714d5d"/><rect x="225" y="300" width="72" height="60" rx="6" fill="#9ccbc1"/><rect x="462" y="310" width="220" height="108" rx="8" fill="#f6e0be"/><path d="M440 310h264l-34-72H475Z" fill="#5e82a8"/><circle cx="542" cy="337" r="20" fill="#df8667"/><circle cx="615" cy="340" r="21" fill="#6f9d82"/></svg>
<span class="media-label">南山创意公园 · 周末市集</span>
</div>
<div class="engagement"><div class="reaction-summary"><span class="reaction-bubbles"><span class="reaction-dot reaction-heart"><svg><use href="#i-heart"/></svg></span><span class="reaction-dot reaction-like"><svg><use href="#i-thumb"/></svg></span></span><span class="like-count">243</span></div><div class="engagement-details"><span><span class="comment-count">32</span> 条评论</span><span>21 次分享</span></div></div>
<div class="post-actions"><button class="post-action like-button"><svg><use href="#i-thumb"/></svg><span>赞</span></button><button class="post-action comment-button"><svg><use href="#i-comment"/></svg><span>评论</span></button><button class="post-action share-button"><svg><use href="#i-share"/></svg><span>分享</span></button></div>
<div class="comments"><form class="comment-form"><label class="sr-only">添加评论</label><input maxlength="120" placeholder="写评论…" /><button class="icon-button comment-send" aria-label="发送评论"><svg><use href="#i-send"/></svg></button></form></div>
</article>
</div>
<div id="emptySearch" class="card empty-search"><svg><use href="#i-search"/></svg><h3>没有找到相关动态</h3><p>换一个关键词试试看吧。</p></div>
</section>
<aside class="sidebar right-sidebar" aria-label="联系人与推荐">
<div class="card side-card" id="profileCard"></div>
<div class="card side-card birthday" id="birthdayCard"></div>
<div class="side-card" id="sponsorBlock"></div>
<div class="divider"></div>
<div id="contactsBlock"></div>
</aside>
</main>
<nav class="mobile-nav" id="mobileNav" aria-label="移动端导航"></nav>
<section class="drawer" id="notificationDrawer" aria-label="通知" aria-hidden="true">
<div class="drawer-head"><h2>通知</h2><button class="icon-button" data-close-drawer aria-label="关闭通知"><svg><use href="#i-close"/></svg></button></div>
<div id="notificationsList"></div>
</section>
<section class="drawer" id="messagesDrawer" aria-label="消息" aria-hidden="true">
<div class="drawer-head"><h2>消息</h2><button class="icon-button" data-close-drawer aria-label="关闭消息"><svg><use href="#i-close"/></svg></button></div>
<div id="messagesList"></div>
</section>
<div class="modal-backdrop" id="composerModal" aria-hidden="true">
<section class="modal" role="dialog" aria-modal="true" aria-labelledby="composerTitle">
<header class="modal-header"><h2 id="composerTitle">创建动态</h2><button class="icon-button modal-close" id="closeComposer" aria-label="关闭发帖窗口"><svg><use href="#i-close"/></svg></button></header>
<div class="modal-body">
<div class="profile-summary" id="composerProfile"></div>
<textarea class="post-textarea" id="postTextarea" maxlength="500"></textarea>
<div class="add-to-post"><strong>添加到动态</strong><div class="add-buttons"><button class="icon-button" aria-label="添加照片"><svg style="color:var(--accent)"><use href="#i-image"/></svg></button><button class="icon-button" aria-label="添加心情"><svg style="color:#e49a22"><use href="#i-smile"/></svg></button></div></div>
<button class="publish-button" id="publishPost" disabled>发布</button>
</div>
</section>
</div>
<div class="settings-backdrop" id="settingsModal" aria-hidden="true">
<section class="settings-panel" role="dialog" aria-modal="true" aria-labelledby="settingsTitle">
<header class="settings-header">
<div><span class="settings-kicker">页面数据控制台</span><h2 id="settingsTitle">JSON 内容编辑器</h2></div>
<button class="icon-button" id="closeSettings" aria-label="关闭 JSON 编辑器"><svg><use href="#i-close"/></svg></button>
</header>
<div class="settings-body">
<aside class="settings-modules" aria-label="JSON 模块">
<h3>选择编辑模块</h3>
<div class="module-tabs" id="moduleTabs" role="tablist" aria-label="页面数据模块"></div>
<div class="settings-summary">
<div class="summary-tile"><strong id="moduleCount">7</strong><span>数据模块</span></div>
<div class="summary-tile"><strong id="postCount">0</strong><span>动态内容</span></div>
</div>
</aside>
<div class="settings-editor">
<div class="editor-head"><label for="jsonEditor"><span id="editorModuleTitle">站点信息</span><span class="editor-help" id="editorModuleHelp">品牌、当前用户和信息流标题</span></label><span class="json-status" id="jsonStatus" aria-live="polite">JSON 有效</span></div>
<textarea class="json-editor" id="jsonEditor" spellcheck="false" aria-describedby="jsonError"></textarea>
<div class="editor-error" id="jsonError" aria-live="polite"></div>
</div>
</div>
<footer class="settings-footer">
<span class="settings-note">修改当前模块后应用,页面会立即使用新的 JSON 重新渲染。</span>
<div class="settings-actions">
<button class="settings-button" id="resetModule">恢复默认</button>
<button class="settings-button" id="copyJson">复制 JSON</button>
<button class="settings-button" id="downloadJson">下载 JSON</button>
<button class="settings-button primary" id="applyJson">应用并渲染</button>
</div>
</footer>
</section>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="application/json" id="circleData">
__FACEBOOK_PAGE_DATA__
</script>
<script>
(() => {
'use strict';
const qs = (selector, root = document) => root.querySelector(selector);
const qsa = (selector, root = document) => [...root.querySelectorAll(selector)];
const clone = (value) => JSON.parse(JSON.stringify(value));
const defaultData = JSON.parse(qs('#circleData').textContent);
const dataFingerprint = (() => {
const input = JSON.stringify(defaultData);
let hash = 2166136261;
for (let index = 0; index < input.length; index += 1) {
hash ^= input.charCodeAt(index);
hash = Math.imul(hash, 16777619);
}
return (hash >>> 0).toString(36);
})();
const storageKey = `facebook-page-data-v2:${dataFingerprint}`;
const readStorage = (key) => {
try { return window.localStorage.getItem(key); }
catch { return null; }
};
const writeStorage = (key, value) => {
try { window.localStorage.setItem(key, value); }
catch { /* Sandboxed previews may disallow persistent storage. */ }
};
const toast = qs('#toast');
let toastTimer;
const moduleMeta = {
site: { label: '站点信息', help: '品牌、当前用户和信息流标题' },
navigation: { label: '导航菜单', help: '顶部导航、侧栏、快捷方式和移动导航' },
stories: { label: '限时动态', help: '创建入口和故事卡片数据' },
posts: { label: '动态内容', help: '作者、正文、图片/视频/网页、互动数和评论' },
sidebar: { label: '推荐卡片', help: '生日提醒和赞助内容' },
contacts: { label: '联系人', help: '联系人名称、头像配色和在线状态' },
inbox: { label: '消息通知', help: '通知抽屉和私信抽屉内容' }
};
const allowedIcons = new Set(['i-circle','i-search','i-home','i-users','i-video','i-grid','i-message','i-bell','i-moon','i-sun','i-chevron','i-bookmark','i-calendar','i-store','i-clock','i-more','i-plus','i-image','i-smile','i-globe','i-verified','i-thumb','i-heart','i-comment','i-share','i-filter','i-cake','i-send','i-close','i-settings']);
const allowedStoryBackgrounds = new Set(['story-1','story-2','story-3','story-4','story-5']);
const escapeHTML = (value) => String(value ?? '').replace(/[&<>'"]/g, (char) => ({'&':'&amp;','<':'&lt;','>':'&gt;',"'":'&#39;','"':'&quot;'}[char]));
const safeColor = (value, fallback) => /^#[0-9a-f]{6}$/i.test(String(value || '')) ? value : fallback;
const safeHref = (value) => /^#[a-z][\w-]*$/i.test(String(value || '')) ? value : '#feed';
const safeRemoteUrl = (value, kind = 'link') => {
const source = String(value || '').trim();
if (!source) return '';
const lowered = source.toLowerCase();
if (kind === 'image' && lowered.startsWith('data:image/')) return source;
if (kind === 'video' && lowered.startsWith('data:video/')) return source;
try {
const url = new URL(source);
return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : '';
} catch { return ''; }
};
const safeId = (value) => String(value || 'item').replace(/[^a-z0-9_-]/gi, '-').slice(0, 48);
const safeIcon = (value, fallback = 'i-circle') => allowedIcons.has(value) ? value : fallback;
const icon = (id, className = '') => `<svg class="${escapeHTML(className)}" aria-hidden="true"><use href="#${safeIcon(id)}"/></svg>`;
const avatar = (person, className = '') => {
const colors = Array.isArray(person?.colors) ? person.colors : [];
const a = safeColor(colors[0], '#6776ff');
const b = safeColor(colors[1], '#b15bea');
return `<span class="avatar ${escapeHTML(className)}" style="--avatar-a:${a};--avatar-b:${b}">${escapeHTML(person?.initial || String(person?.name || '?').slice(0, 1))}</span>`;
};
const showToast = (message) => {
toast.textContent = message;
toast.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove('show'), 2600);
};
const loadData = () => {
try {
const saved = JSON.parse(readStorage(storageKey) || 'null');
if (!saved || typeof saved !== 'object' || Array.isArray(saved)) return clone(defaultData);
return Object.fromEntries(Object.keys(defaultData).map((key) => [key, saved[key] && typeof saved[key] === 'object' ? saved[key] : clone(defaultData[key])]));
} catch { return clone(defaultData); }
};
let pageData = loadData();
const saveData = () => writeStorage(storageKey, JSON.stringify(pageData));
const renderSite = () => {
const data = pageData.site || {};
const user = data.currentUser || {};
qs('#brandWord').textContent = data.brand || 'Circle';
document.title = data.pageTitle || data.brand || 'Circle';
const description = qs('meta[name="description"]');
if (description) description.content = data.description || '';
qs('#globalSearch').placeholder = data.searchPlaceholder || '搜索';
qs('#headerProfile').innerHTML = avatar(user);
qs('#composerAvatar').innerHTML = avatar(user);
qs('#composerPrompt').textContent = data.currentUser?.composerPrompt || '分享一下你的新鲜事吧';
qs('#feedTitle').textContent = data.feedTitle || '为你推荐';
qs('#feedSort').textContent = data.feedSort || '最新动态';
qs('#postTextarea').placeholder = user.composerPlaceholder || '你在想什么?';
qs('#composerProfile').innerHTML = `${avatar(user)}<div><strong>${escapeHTML(user.name || '当前用户')}</strong><span class="visibility-select">${icon('i-globe')}公开</span></div>`;
const stats = Array.isArray(user.stats) ? user.stats : [];
qs('#profileCard').innerHTML = `<div class="profile-summary">${avatar(user, 'avatar-lg')}<div><strong>${escapeHTML(user.name || '')}</strong><span>${escapeHTML(user.handle || '')}</span></div></div><div class="profile-stats">${stats.map((item) => `<div><strong>${escapeHTML(item.value)}</strong><span>${escapeHTML(item.label)}</span></div>`).join('')}</div>`;
};
const renderNavigation = () => {
const data = pageData.navigation || {};
const user = pageData.site?.currentUser || {};
const top = Array.isArray(data.top) ? data.top : [];
const mainNav = qs('#mainNav');
mainNav.style.gridTemplateColumns = `repeat(${Math.max(1, top.length)}, 1fr)`;
mainNav.innerHTML = top.map((item, index) => `<button class="top-nav-button${index === 0 ? ' active' : ''}" aria-label="${escapeHTML(item.label)}" title="${escapeHTML(item.label)}">${icon(item.icon, '')}</button>`).join('');
const primary = Array.isArray(data.primary) ? data.primary : [];
qs('#primaryMenu').innerHTML = primary.map((item, index) => `<a class="menu-item${index === 0 ? ' active' : ''}" href="${safeHref(item.href)}">${item.profile ? avatar(user, 'avatar-sm') : `<span class="menu-icon">${icon(item.icon)}</span>`}<span>${escapeHTML(item.label)}</span></a>`).join('');
qs('#shortcutsTitle').textContent = data.shortcutsTitle || '你的快捷方式';
const shortcuts = Array.isArray(data.shortcuts) ? data.shortcuts : [];
qs('#shortcutsMenu').innerHTML = shortcuts.map((item) => {
const colors = Array.isArray(item.colors) ? item.colors : [];
const style = `background:linear-gradient(140deg,${safeColor(colors[0], '#ff9e64')},${safeColor(colors[1], '#ed5374')})`;
return `<a class="menu-item" href="${safeHref(item.href)}"><span class="shortcut-cover" style="${style}">${escapeHTML(item.badge)}</span><span>${escapeHTML(item.label)}</span></a>`;
}).join('');
qs('#sidebarFooter').textContent = data.footer || '';
const mobile = Array.isArray(data.mobile) ? data.mobile : [];
const mobileNav = qs('#mobileNav');
mobileNav.style.gridTemplateColumns = `repeat(${Math.max(1, mobile.length)}, 1fr)`;
mobileNav.innerHTML = mobile.map((item, index) => `<button class="${index === 0 ? 'active' : ''}" ${item.action === 'composer' ? 'data-open-composer' : ''} ${item.drawer ? `data-drawer="${escapeHTML(item.drawer)}"` : ''} aria-label="${escapeHTML(item.label)}">${icon(item.icon)}<span>${escapeHTML(item.label)}</span></button>`).join('');
};
const renderStories = () => {
const data = pageData.stories || {};
const items = Array.isArray(data.items) ? data.items : [];
qs('#storiesRow').innerHTML = `<button class="story create-story" data-open-composer aria-label="${escapeHTML(data.createLabel || '创建动态')}"><span class="story-bg"></span><span class="story-add">${icon('i-plus')}</span><span class="story-name">${escapeHTML(data.createLabel || '创建动态')}</span></button>${items.map((item) => `<button class="story"><span class="story-bg ${allowedStoryBackgrounds.has(item.background) ? item.background : 'story-1'}"></span>${avatar(item, 'avatar-sm story-avatar')}<span class="story-name">${escapeHTML(item.name)}</span></button>`).join('')}`;
};
const mediaMarkup = (media, postId) => {
if (!media || typeof media !== 'object') return '';
if (media.type === 'quote') return `<div class="quote-card"><p>“${escapeHTML(media.quote)}”</p><small>${escapeHTML(media.attribution)}</small></div>`;
if (media.type === 'image') {
const source = safeRemoteUrl(media.mediaUrl, 'image');
if (!source) return '';
const pageUrl = safeRemoteUrl(media.pageUrl);
return `<div class="post-media"><img src="${escapeHTML(source)}" alt="${escapeHTML(media.alt || media.label || '动态图片')}" loading="lazy" referrerpolicy="no-referrer"/>${pageUrl ? `<a class="post-media-link" href="${escapeHTML(pageUrl)}" target="_blank" rel="noopener noreferrer">打开来源</a>` : ''}</div>`;
}
if (media.type === 'video') {
const source = safeRemoteUrl(media.mediaUrl, 'video');
if (!source) return '';
const poster = safeRemoteUrl(media.posterUrl, 'image');
const pageUrl = safeRemoteUrl(media.pageUrl);
return `<div class="post-media"><video src="${escapeHTML(source)}"${poster ? ` poster="${escapeHTML(poster)}"` : ''} controls playsinline preload="metadata" aria-label="${escapeHTML(media.alt || media.label || '动态视频')}"></video>${pageUrl ? `<a class="post-media-link" href="${escapeHTML(pageUrl)}" target="_blank" rel="noopener noreferrer">打开来源</a>` : ''}</div>`;
}
if (media.type === 'webpage') {
const pageUrl = safeRemoteUrl(media.pageUrl);
if (!pageUrl) return '';
const preview = safeRemoteUrl(media.mediaUrl, 'image');
const frame = media.embed === true ? `<div class="post-media"><iframe src="${escapeHTML(pageUrl)}" title="${escapeHTML(media.title || '网页预览')}" loading="lazy" referrerpolicy="no-referrer" sandbox="allow-forms allow-popups allow-scripts"></iframe><a class="post-media-link" href="${escapeHTML(pageUrl)}" target="_blank" rel="noopener noreferrer">新窗口打开</a></div>` : (preview ? `<div class="post-media"><img src="${escapeHTML(preview)}" alt="${escapeHTML(media.alt || media.title || '网页预览图')}" loading="lazy" referrerpolicy="no-referrer"/></div>` : '');
return `<div class="webpage-card">${frame}<a class="webpage-copy" href="${escapeHTML(pageUrl)}" target="_blank" rel="noopener noreferrer"><strong>${escapeHTML(media.title || pageUrl)}</strong>${media.description ? `<span>${escapeHTML(media.description)}</span>` : ''}</a></div>`;
}
const id = safeId(postId);
if (media.type === 'river') return `<div class="post-media" role="img" aria-label="${escapeHTML(media.alt)}"><svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice"><defs><linearGradient id="sky-${id}" x2="0" y2="1"><stop stop-color="#abcdf6"/><stop offset=".55" stop-color="#f4cfbc"/><stop offset="1" stop-color="#eaa37e"/></linearGradient><linearGradient id="river-${id}" x2="1" y2="1"><stop stop-color="#7198c1"/><stop offset="1" stop-color="#314b73"/></linearGradient></defs><rect width="800" height="500" fill="url(#sky-${id})"/><circle cx="610" cy="120" r="55" fill="#fff2c9" opacity=".9"/><path d="M0 270 160 210l90 45 120-85 150 105 110-70 170 100v195H0Z" fill="#5d7390"/><path d="M0 315c170-60 300-10 420-25 155-20 250-5 380 46v164H0Z" fill="url(#river-${id})"/><path d="M0 310c180-22 314 14 460-2 110-12 230-6 340 36" fill="none" stroke="#f7e7d4" stroke-width="8" opacity=".46"/><path d="M110 260v115m0-101-42-46m42 42 48-57" stroke="#314a50" stroke-width="12" stroke-linecap="round"/><circle cx="68" cy="220" r="44" fill="#486d63"/><circle cx="148" cy="207" r="58" fill="#567e6d"/></svg><span class="media-label">${escapeHTML(media.label)}</span></div>`;
if (media.type === 'market') return `<div class="post-media" role="img" aria-label="${escapeHTML(media.alt)}"><svg viewBox="0 0 800 500" preserveAspectRatio="xMidYMid slice"><defs><linearGradient id="market-${id}" x2="1" y2="1"><stop stop-color="#f7d1a7"/><stop offset="1" stop-color="#c67286"/></linearGradient></defs><rect width="800" height="500" fill="url(#market-${id})"/><circle cx="120" cy="92" r="50" fill="#fff1bf" opacity=".86"/><path d="M0 325 95 260l105 55 92-80 112 92 116-107 130 98 150-70v252H0Z" fill="#765378" opacity=".72"/><rect x="70" y="258" width="270" height="160" rx="8" fill="#fff0d8"/><path d="M50 258h310l-38-78H88Z" fill="#e85f66"/><path d="M88 180h58l-18 78H50Zm116 0h58l20 78h-96Z" fill="#fff3d7"/><rect x="115" y="307" width="70" height="111" rx="4" fill="#714d5d"/><rect x="462" y="310" width="220" height="108" rx="8" fill="#f6e0be"/><path d="M440 310h264l-34-72H475Z" fill="#5e82a8"/></svg><span class="media-label">${escapeHTML(media.label)}</span></div>`;
return '';
};
const commentUI = () => ({
defaultSort: 'hot',
initialVisible: 10,
pageSize: 10,
hotLabel: '热门',
latestLabel: '最新',
showMoreLabel: '查看更多',
showAllLabel: '查看全部',
...(pageData.posts?.commentUI || {})
});
const renderComment = (comment) => {
const likes = Math.max(0, Number(comment.likes) || 0);
const replies = Math.max(0, Number(comment.replyCount) || 0);
return `<div class="comment">${avatar(comment, 'avatar-sm')}<div class="comment-body"><div class="comment-bubble"><strong>${escapeHTML(comment.author)}${comment.verified ? ` ${icon('i-verified', 'verified')}` : ''}${comment.handle ? ` <small>${escapeHTML(comment.handle)}</small>` : ''}</strong><span>${escapeHTML(comment.text)}</span></div><div class="comment-meta">${comment.time ? `<span>${escapeHTML(comment.time)}</span>` : ''}<button type="button">赞</button><button type="button">回复</button><span>${likes} 个赞</span>${replies ? `<span>${replies} 条回复</span>` : ''}</div></div></div>`;
};
const postSource = (post) => {
const sourceUrl = safeRemoteUrl(post.sourceUrl);
if (!sourceUrl) return '';
return `<div class="post-source"><a href="${escapeHTML(sourceUrl)}" target="_blank" rel="noopener noreferrer">查看原帖</a></div>`;
};
const renderCommentList = (postElement, postData, state) => {
const comments = Array.isArray(postData.comments) ? postData.comments : [];
const ui = commentUI();
const sorted = comments.map((comment, index) => ({ comment, index }));
if (state.sort === 'hot') {
sorted.sort((left, right) => (Number(right.comment.likes) || 0) - (Number(left.comment.likes) || 0) || (Number(right.comment.replyCount) || 0) - (Number(left.comment.replyCount) || 0) || left.index - right.index);
}
state.visible = Math.min(Math.max(1, state.visible), Math.max(1, comments.length));
qs('.comment-list', postElement).innerHTML = sorted.slice(0, state.visible).map(({ comment }) => renderComment(comment)).join('');
const tools = qs('.comment-tools', postElement);
tools.hidden = comments.length === 0;
qs('.comment-summary', postElement).textContent = `${comments.length} 条评论`;
qsa('.comment-sort', postElement).forEach((button) => {
button.textContent = button.dataset.sort === 'latest' ? ui.latestLabel : ui.hotLabel;
const active = button.dataset.sort === state.sort;
button.classList.toggle('active', active);
button.setAttribute('aria-pressed', String(active));
});
const remaining = Math.max(0, comments.length - state.visible);
const moreButton = qs('.comment-more', postElement);
const allButton = qs('.comment-all', postElement);
moreButton.hidden = remaining === 0;
allButton.hidden = remaining === 0 || remaining <= Math.max(1, Number(ui.pageSize) || 10);
moreButton.textContent = `${ui.showMoreLabel} ${Math.min(remaining, Math.max(1, Number(ui.pageSize) || 10))} 条`;
allButton.textContent = `${ui.showAllLabel} ${comments.length} 条`;
};
const renderPost = (post) => {
const tags = Array.isArray(post.tags) ? post.tags : [];
const metrics = post.metrics || {};
const searchText = [post.author, post.text, ...tags].join(' ');
return `<article class="card post" data-post-id="${escapeHTML(post.id)}" data-search="${escapeHTML(searchText)}"><header class="post-header">${avatar(post)}<div class="post-author"><strong>${escapeHTML(post.author)}${post.verified ? ` ${icon('i-verified', 'verified')}` : ''}</strong><div class="post-meta"><span>${escapeHTML(post.time)}</span><span>·</span>${icon(post.privacyIcon, '')}</div></div><button class="icon-button more-button" aria-label="更多操作">${icon('i-more')}</button></header>${postSource(post)}<p class="post-copy">${escapeHTML(post.text)}${tags.map((tag) => ` <a href="#${safeId(tag)}">#${escapeHTML(tag)}</a>`).join('')}</p>${mediaMarkup(post.media, post.id)}<div class="engagement"><div class="reaction-summary"><span class="reaction-bubbles"><span class="reaction-dot reaction-like">${icon('i-thumb')}</span><span class="reaction-dot reaction-heart">${icon('i-heart')}</span></span><span class="like-count">${Number(metrics.likes) || 0}</span></div><div class="engagement-details"><span><span class="comment-count">${Number(metrics.comments) || 0}</span> 条评论</span><span>${Number(metrics.shares) || 0} 次分享</span></div></div><div class="post-actions"><button class="post-action like-button" aria-pressed="false">${icon('i-thumb')}<span>赞</span></button><button class="post-action comment-button">${icon('i-comment')}<span>评论</span></button><button class="post-action share-button">${icon('i-share')}<span>分享</span></button></div><div class="comments${post.commentsExpanded === true ? ' open' : ''}"><div class="comment-tools" hidden><strong class="comment-summary"></strong><div><button type="button" class="comment-sort" data-sort="hot">热门</button><button type="button" class="comment-sort" data-sort="latest">最新</button></div></div><div class="comment-list"></div><div class="comment-pagination"><button type="button" class="comment-more"></button><button type="button" class="comment-all"></button></div><form class="comment-form"><label class="sr-only">添加评论</label><input maxlength="120" placeholder="写评论…"/><button class="icon-button comment-send" aria-label="发送评论">${icon('i-send')}</button></form></div></article>`;
};
const renderPosts = () => {
const posts = Array.isArray(pageData.posts?.items) ? pageData.posts.items : [];
qs('#postsContainer').innerHTML = posts.map(renderPost).join('');
qsa('.post').forEach((post, index) => bindPost(post, posts[index]));
filterPosts();
};
const renderSidebar = () => {
renderSite();
const data = pageData.sidebar || {};
const birthday = data.birthday || {};
const sponsor = data.sponsor || {};
qs('#birthdayCard').innerHTML = `<div class="birthday-icon">${icon('i-cake')}</div><p><strong>${escapeHTML(birthday.title)}</strong><br/>${escapeHTML(birthday.text)}</p>`;
qs('#sponsorBlock').innerHTML = `<div class="right-head"><h3>${escapeHTML(sponsor.heading)}</h3><button class="icon-button" aria-label="赞助内容选项">${icon('i-more')}</button></div><a class="sponsor" href="${safeHref(sponsor.href)}"><span class="sponsor-art"></span><span><strong>${escapeHTML(sponsor.title)}</strong><br/><small>${escapeHTML(sponsor.domain)}</small></span></a>`;
};
const renderContacts = () => {
const data = pageData.contacts || {};
const items = Array.isArray(data.items) ? data.items : [];
qs('#contactsBlock').innerHTML = `<div class="right-head"><h3>${escapeHTML(data.title || '联系人')}</h3><div class="tiny-actions"><button class="icon-button" aria-label="搜索联系人">${icon('i-search')}</button><button class="icon-button" aria-label="联系人选项">${icon('i-more')}</button></div></div>${items.map((item) => `<div class="contact-row">${avatar(item, 'avatar-sm')}${item.online ? '<span class="online-dot"></span>' : ''}<strong>${escapeHTML(item.name)}</strong></div>`).join('')}`;
};
const inboxItem = (item, message = false) => `<div class="notification">${avatar(item, 'avatar-sm')}<div><p><strong>${escapeHTML(item.name)}</strong>${message ? '<br/>' : ' '}${escapeHTML(item.text)}</p><time>${escapeHTML(item.time)}</time></div>${item.unread ? '<span class="unread-mark"></span>' : ''}</div>`;
const renderInbox = () => {
const data = pageData.inbox || {};
qs('#notificationsList').innerHTML = (Array.isArray(data.notifications) ? data.notifications : []).map((item) => inboxItem(item)).join('');
qs('#messagesList').innerHTML = (Array.isArray(data.messages) ? data.messages : []).map((item) => inboxItem(item, true)).join('');
};
const renderAll = () => { renderSite(); renderNavigation(); renderStories(); renderPosts(); renderSidebar(); renderContacts(); renderInbox(); updateSummary(); };
const renderModule = (name) => {
({ site: renderSidebar, navigation: renderNavigation, stories: renderStories, posts: renderPosts, sidebar: renderSidebar, contacts: renderContacts, inbox: renderInbox }[name] || renderAll)();
updateSummary();
};
const closeDrawers = () => qsa('.drawer.open').forEach((drawer) => { drawer.classList.remove('open'); drawer.setAttribute('aria-hidden', 'true'); });
const composerModal = qs('#composerModal');
const postTextarea = qs('#postTextarea');
const publishButton = qs('#publishPost');
let composerOpener = null;
const openComposer = (trigger) => {
composerOpener = trigger || document.activeElement;
closeDrawers();
composerModal.classList.add('open');
composerModal.setAttribute('aria-hidden', 'false');
document.body.classList.add('modal-open');
setTimeout(() => postTextarea.focus(), 60);
};
const closeComposer = () => {
composerModal.classList.remove('open');
composerModal.setAttribute('aria-hidden', 'true');
if (!qs('#settingsModal').classList.contains('open')) document.body.classList.remove('modal-open');
composerOpener?.focus();
};
function bindPost(post, postData) {
const ui = commentUI();
const state = {
sort: ui.defaultSort === 'latest' ? 'latest' : 'hot',
visible: Math.max(1, Number(ui.initialVisible) || 10)
};
const paintComments = () => renderCommentList(post, postData, state);
const likeButton = qs('.like-button', post);
const commentButton = qs('.comment-button', post);
const shareButton = qs('.share-button', post);
const form = qs('.comment-form', post);
likeButton?.addEventListener('click', () => {
const count = qs('.like-count', post);
const liked = likeButton.classList.toggle('liked');
count.textContent = Math.max(0, Number(count.textContent) + (liked ? 1 : -1));
qs('span', likeButton).textContent = liked ? '已赞' : '赞';
likeButton.setAttribute('aria-pressed', String(liked));
});
commentButton?.addEventListener('click', () => {
const comments = qs('.comments', post);
comments.classList.toggle('open');
if (comments.classList.contains('open')) qs('input', comments)?.focus();
});
qsa('.comment-sort', post).forEach((button) => button.addEventListener('click', () => {
state.sort = button.dataset.sort === 'latest' ? 'latest' : 'hot';
state.visible = Math.max(1, Number(commentUI().initialVisible) || 10);
paintComments();
}));
qs('.comment-more', post)?.addEventListener('click', () => {
state.visible += Math.max(1, Number(commentUI().pageSize) || 10);
paintComments();
});
qs('.comment-all', post)?.addEventListener('click', () => {
state.visible = Array.isArray(postData.comments) ? postData.comments.length : 0;
paintComments();
});
shareButton?.addEventListener('click', async () => {
try {
if (navigator.share) await navigator.share({ title: `${pageData.site?.brand || 'Circle'} 动态`, text: qs('.post-copy', post)?.textContent || '' });
else { await navigator.clipboard?.writeText(location.href); showToast('动态链接已复制'); }
} catch (error) { if (error.name !== 'AbortError') showToast('已打开分享选项'); }
});
form?.addEventListener('submit', (event) => {
event.preventDefault();
const input = qs('input', form);
const value = input.value.trim();
if (!value) return;
const user = pageData.site?.currentUser || {};
if (!Array.isArray(postData.comments)) postData.comments = [];
postData.comments.unshift({
id: `local-${Date.now()}`,
author: user.name || '我',
handle: user.handle || '',
initial: user.initial || '我',
colors: user.colors || ['#4d6aff', '#8f4bd2'],
time: '刚刚',
text: value,
likes: 0,
replyCount: 0
});
input.value = '';
postData.metrics = postData.metrics || {};
postData.metrics.comments = Math.max(Number(postData.metrics.comments) || 0, postData.comments.length - 1) + 1;
const count = qs('.comment-count', post);
count.textContent = postData.metrics.comments;
state.visible += 1;
paintComments();
showToast('评论已发布');
});
paintComments();
}
function filterPosts() {
const query = qs('#globalSearch').value.trim().toLocaleLowerCase();
let matches = 0;
qsa('.post').forEach((post) => {
const visible = !query || post.dataset.search.toLocaleLowerCase().includes(query) || post.textContent.toLocaleLowerCase().includes(query);
post.hidden = !visible;
if (visible) matches++;
});
qs('#emptySearch').style.display = matches ? 'none' : 'block';
}
const settingsModal = qs('#settingsModal');
const jsonEditor = qs('#jsonEditor');
const jsonStatus = qs('#jsonStatus');
const jsonError = qs('#jsonError');
const applyButton = qs('#applyJson');
const drafts = {};
let activeModule = 'site';
let settingsOpener = null;
const moduleCount = (name) => {
const data = pageData[name] || {};
if (name === 'navigation') return ['top','primary','shortcuts','mobile'].reduce((sum, key) => sum + (Array.isArray(data[key]) ? data[key].length : 0), 0);
if (name === 'stories' || name === 'posts' || name === 'contacts') return Array.isArray(data.items) ? data.items.length : 0;
if (name === 'inbox') return (data.notifications?.length || 0) + (data.messages?.length || 0);
return Object.keys(data).length;
};
function updateSummary() {
qs('#moduleCount').textContent = Object.keys(moduleMeta).length;
qs('#postCount').textContent = pageData.posts?.items?.length || 0;
qsa('.module-tab').forEach((tab) => { const count = qs('span:last-child', tab); if (count) count.textContent = moduleCount(tab.dataset.module); });
}
const renderModuleTabs = () => {
qs('#moduleTabs').innerHTML = Object.entries(moduleMeta).map(([key, meta]) => `<button class="module-tab" role="tab" data-module="${key}" aria-selected="${key === activeModule}"><span>${escapeHTML(meta.label)}</span><span>${moduleCount(key)}</span></button>`).join('');
};
const validateModule = (name, value) => {
if (!value || typeof value !== 'object' || Array.isArray(value)) return '模块根节点必须是 JSON 对象。';
if (name === 'site' && (!value.brand || !value.currentUser || typeof value.currentUser !== 'object')) return '站点信息需要 brand 和 currentUser。';
if (name === 'navigation' && ['top','primary','shortcuts','mobile'].some((key) => !Array.isArray(value[key]))) return '导航菜单需要 top、primary、shortcuts、mobile 四个数组。';
if (['stories','posts','contacts'].includes(name) && !Array.isArray(value.items)) return `${moduleMeta[name].label}需要 items 数组。`;
if (name === 'posts') {
for (const [index, post] of value.items.entries()) {
const media = post?.media;
if (!media || !['image','video','webpage'].includes(media.type)) continue;
const mediaUrl = safeRemoteUrl(media.mediaUrl, media.type === 'video' ? 'video' : 'image');
if ((media.type === 'image' || media.type === 'video') && !mediaUrl) return `第 ${index + 1} 条动态的 mediaUrl 无效。`;
if (media.type === 'webpage' && !safeRemoteUrl(media.pageUrl)) return `第 ${index + 1} 条动态的 pageUrl 无效。`;
if (media.posterUrl && !safeRemoteUrl(media.posterUrl, 'image')) return `第 ${index + 1} 条动态的 posterUrl 无效。`;
}
}
if (name === 'sidebar' && (!value.birthday || !value.sponsor)) return '推荐卡片需要 birthday 和 sponsor。';
if (name === 'inbox' && (!Array.isArray(value.notifications) || !Array.isArray(value.messages))) return '消息通知需要 notifications 和 messages 数组。';
return '';
};
const parseEditor = () => {
try {
const value = JSON.parse(jsonEditor.value);
const error = validateModule(activeModule, value);
if (error) throw new Error(error);
jsonStatus.textContent = 'JSON 有效';
jsonStatus.classList.remove('invalid');
jsonError.textContent = '';
applyButton.disabled = false;
return value;
} catch (error) {
jsonStatus.textContent = 'JSON 无效';
jsonStatus.classList.add('invalid');
jsonError.textContent = error.message;
applyButton.disabled = true;
return null;
}
};
const selectModule = (name, preserveDraft = true) => {
if (!moduleMeta[name]) return;
if (preserveDraft && activeModule) drafts[activeModule] = jsonEditor.value;
activeModule = name;
const meta = moduleMeta[name];
qs('#editorModuleTitle').textContent = meta.label;
qs('#editorModuleHelp').textContent = meta.help;
jsonEditor.value = drafts[name] ?? JSON.stringify(pageData[name], null, 2);
jsonEditor.setSelectionRange(0, 0);
jsonEditor.scrollTop = 0;
jsonEditor.scrollLeft = 0;
renderModuleTabs();
parseEditor();
};
const openSettings = () => {
settingsOpener = qs('#openSettings');
closeDrawers();
if (composerModal.classList.contains('open')) closeComposer();
renderModuleTabs();
selectModule(activeModule, false);
settingsModal.classList.add('open');
settingsModal.setAttribute('aria-hidden', 'false');
document.body.classList.add('modal-open');
setTimeout(() => jsonEditor.focus(), 60);
};
const closeSettings = () => {
drafts[activeModule] = jsonEditor.value;
settingsModal.classList.remove('open');
settingsModal.setAttribute('aria-hidden', 'true');
document.body.classList.remove('modal-open');
settingsOpener?.focus();
};
const themeToggle = qs('#themeToggle');
const savedTheme = readStorage('circle-theme');
if (savedTheme === 'dark' || (!savedTheme && matchMedia('(prefers-color-scheme: dark)').matches)) document.documentElement.dataset.theme = 'dark';
const syncThemeIcon = () => {
const dark = document.documentElement.dataset.theme === 'dark';
themeToggle.innerHTML = icon(dark ? 'i-sun' : 'i-moon');
themeToggle.setAttribute('aria-label', dark ? '切换浅色模式' : '切换深色模式');
};
themeToggle.addEventListener('click', () => {
const next = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
document.documentElement.dataset.theme = next;
writeStorage('circle-theme', next);
syncThemeIcon();
});
syncThemeIcon();
renderAll();
qs('#globalSearch').addEventListener('input', filterPosts);
postTextarea.addEventListener('input', () => publishButton.disabled = !postTextarea.value.trim());
publishButton.addEventListener('click', () => {
const text = postTextarea.value.trim();
if (!text) return;
const user = pageData.site?.currentUser || {};
pageData.posts.items.unshift({ id: `user-${Date.now()}`, author: user.name || '当前用户', initial: user.initial || '我', colors: user.colors, verified: false, time: '刚刚', privacyIcon: 'i-globe', text, tags: [], metrics: { likes: 0, comments: 0, shares: 0 }, comments: [] });
saveData();
drafts.posts = JSON.stringify(pageData.posts, null, 2);
renderPosts();
postTextarea.value = '';
publishButton.disabled = true;
closeComposer();
qs('.post')?.scrollIntoView({ behavior: matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth', block: 'center' });
showToast('动态已发布并写入 JSON');
});
qs('#openSettings').addEventListener('click', openSettings);
qs('#closeSettings').addEventListener('click', closeSettings);
settingsModal.addEventListener('click', (event) => { if (event.target === settingsModal) closeSettings(); });
qs('#moduleTabs').addEventListener('click', (event) => { const tab = event.target.closest('[data-module]'); if (tab) selectModule(tab.dataset.module); });
jsonEditor.addEventListener('input', () => { drafts[activeModule] = jsonEditor.value; parseEditor(); });
qs('#applyJson').addEventListener('click', () => {
const value = parseEditor();
if (!value) return;
pageData[activeModule] = value;
drafts[activeModule] = JSON.stringify(value, null, 2);
saveData();
renderModule(activeModule);
renderModuleTabs();
showToast(`${moduleMeta[activeModule].label}已应用并渲染`);
});
qs('#resetModule').addEventListener('click', () => {
jsonEditor.value = JSON.stringify(defaultData[activeModule], null, 2);
drafts[activeModule] = jsonEditor.value;
parseEditor();
showToast('已恢复默认草稿,点击应用后生效');
});
qs('#copyJson').addEventListener('click', async () => {
try { await navigator.clipboard.writeText(jsonEditor.value); }
catch { jsonEditor.select(); document.execCommand('copy'); }
showToast('当前模块 JSON 已复制');
});
qs('#downloadJson').addEventListener('click', () => {
const blob = new Blob([jsonEditor.value], { type: 'application/json;charset=utf-8' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `circle-${activeModule}.json`;
link.click();
setTimeout(() => URL.revokeObjectURL(url), 0);
showToast('当前模块 JSON 已下载');
});
qs('#closeComposer').addEventListener('click', closeComposer);
composerModal.addEventListener('click', (event) => { if (event.target === composerModal) closeComposer(); });
document.addEventListener('click', (event) => {
const composerTrigger = event.target.closest('[data-open-composer]');
if (composerTrigger) { openComposer(composerTrigger); return; }
const closeDrawer = event.target.closest('[data-close-drawer]');
if (closeDrawer) { closeDrawers(); return; }
const drawerTrigger = event.target.closest('[data-drawer]');
if (drawerTrigger) {
event.stopPropagation();
const drawer = qs(`#${drawerTrigger.dataset.drawer}`);
const open = drawer && !drawer.classList.contains('open');
closeDrawers();
if (open) { drawer.classList.add('open'); drawer.setAttribute('aria-hidden', 'false'); }
return;
}
const navButton = event.target.closest('.top-nav-button, .mobile-nav > button:not([data-open-composer])');
if (navButton) {
const group = navButton.closest('.main-nav, .mobile-nav');
qsa('button', group).forEach((item) => item.classList.remove('active'));
navButton.classList.add('active');
}
const link = event.target.closest('a[href^="#"]');
if (link) {
const href = link.getAttribute('href');
if (!href || href === '#' || !qs(href)) { event.preventDefault(); showToast('这个功能正在准备中'); }
}
if (!event.target.closest('.drawer')) closeDrawers();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
if (settingsModal.classList.contains('open')) closeSettings();
else if (composerModal.classList.contains('open')) closeComposer();
else closeDrawers();
}
if (event.key === 'Tab' && settingsModal.classList.contains('open')) {
const focusable = qsa('button:not(:disabled), textarea', settingsModal).filter((node) => node.offsetParent !== null);
if (!focusable.length) return;
const first = focusable[0], last = focusable[focusable.length - 1];
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
}
});
function installJsonMediaUpload() {
const editor = document.getElementById('jsonEditor');
const applyButton = document.getElementById('applyJson');
if (!editor || !applyButton || document.getElementById('uploadJsonMedia')) return;
const actions = applyButton.parentElement;
const button = document.createElement('button');
const input = document.createElement('input');
const reference = actions.querySelector('#downloadJson, #copyJson, #validateJson, #resetJson');
button.type = 'button';
button.id = 'uploadJsonMedia';
button.className = reference ? reference.className : applyButton.className;
button.textContent = '上传图片/视频';
button.title = '先把光标放进要替换的内容对象,再选择图片或视频';
input.type = 'file';
input.accept = 'image/*,video/*';
input.hidden = true;
actions.insertBefore(button, applyButton);
actions.appendChild(input);
const report = (message) => {
const status = document.getElementById('settingsStatus') || document.getElementById('jsonError') || document.getElementById('jsonStatus');
if (status) status.textContent = message;
};
const findTarget = (text, cursor) => {
const stack = [], matches = [];
let quoted = false, escaped = false;
for (let index = 0; index < text.length; index += 1) {
const char = text[index];
if (quoted) {
if (escaped) escaped = false;
else if (char === '\\') escaped = true;
else if (char === '"') quoted = false;
continue;
}
if (char === '"') { quoted = true; continue; }
if (char === '{') stack.push(index);
else if (char === '}') {
const start = stack.pop();
if (start === undefined || cursor < start || cursor > index + 1) continue;
try {
const value = JSON.parse(text.slice(start, index + 1));
const own = (key) => Object.prototype.hasOwnProperty.call(value, key);
const suitable = value && !Array.isArray(value) && (own('media') || own('visual') || (own('id') && (own('text') || own('title')) && (own('author') || own('channel') || own('user'))));
if (suitable) matches.push({ start, end: index + 1, value });
} catch (_error) { /* the complete module validator reports malformed JSON */ }
}
}
return matches.sort((left, right) => (left.end - left.start) - (right.end - right.start))[0] || null;
};
button.addEventListener('click', () => {
input.value = '';
report('请选择图片或视频;文件会写入光标所在内容对象的 media 字段。');
input.click();
});
input.addEventListener('change', () => {
const file = input.files && input.files[0];
if (!file) return;
const mediaType = file.type.startsWith('image/') ? 'image' : file.type.startsWith('video/') ? 'video' : '';
if (!mediaType) { report('仅支持图片或视频文件。'); return; }
const target = findTarget(editor.value, editor.selectionStart);
if (!target) { report('请先把光标放进带 visual/media 的内容对象,或带 id 的帖子/视频对象内。'); return; }
const reader = new FileReader();
reader.onerror = () => report('文件读取失败,请重新选择。');
reader.onload = () => {
const previous = target.value.media && typeof target.value.media === 'object' ? target.value.media : {};
const media = { type: mediaType, mediaUrl: String(reader.result) };
for (const key of ['alt', 'label', 'caption', 'pageUrl']) if (typeof previous[key] === 'string') media[key] = previous[key];
if (!media.alt) media.alt = mediaType === 'image' ? '用户上传的图片' : '用户上传的视频';
target.value.media = media;
const lineStart = editor.value.lastIndexOf('\n', target.start - 1) + 1;
const indent = (editor.value.slice(lineStart, target.start).match(/^\s*/) || [''])[0];
const replacement = JSON.stringify(target.value, null, 2).split('\n').map((line, index) => index ? indent + line : line).join('\n');
editor.value = editor.value.slice(0, target.start) + replacement + editor.value.slice(target.end);
editor.dispatchEvent(new Event('input', { bubbles: true }));
const mediaIndex = replacement.indexOf('"media"');
editor.focus();
editor.setSelectionRange(target.start + Math.max(mediaIndex, 0), target.start + Math.max(mediaIndex, 0));
report(`已把 ${file.name} 写入 JSON,请点击“应用并渲染”。${file.size > 2 * 1024 * 1024 ? ' 文件较大,建议同时下载 JSON 保存。' : ''}`);
};
reader.readAsDataURL(file);
});
}
installJsonMediaUpload();
function installInlineMediaReplace() {
if (document.getElementById("dfInlineMediaInput")) return;
const visualHostSelector = ".post-media,.video-visual,.thumbnail-visual,.short-thumb,.watch-visual,.thread-media,.visual,.lead-visual,.mini-visual,.compact-media,.card-art,.story-visual,.art,.video-art,.media-art,.player-stage,.thumbnail,.thumb,.list-thumb,.focus-thumb,.involve-bg,.hero-art,#heroArt,#adminArt";
const getRootData = () => {
if (typeof pageData !== "undefined") return pageData;
if (typeof data !== "undefined") return data;
return null;
};
const input = document.createElement("input");
input.id = "dfInlineMediaInput";
input.type = "file";
input.hidden = true;
document.body.appendChild(input);
const style = document.createElement("style");
style.dataset.dfInlineMediaReplace = "true";
style.textContent = ".df-inline-media-host{position:relative!important}.df-inline-media-button{position:absolute;z-index:40;top:10px;right:10px;width:40px;height:40px;padding:0;border:1px solid rgba(255,255,255,.55);border-radius:50%;display:grid;place-items:center;color:#fff;background:rgba(8,15,28,.78);box-shadow:0 8px 24px rgba(0,0,0,.28);backdrop-filter:blur(8px);cursor:pointer;opacity:0;transform:translateY(-4px);transition:opacity .16s,transform .16s,background .16s}.df-inline-media-button:hover{background:rgba(20,110,240,.92)}.df-inline-media-button svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.df-inline-media-host:hover>.df-inline-media-button,.df-inline-media-host:focus-within>.df-inline-media-button,.df-inline-media-button:focus-visible{opacity:1;transform:none}@media(hover:none){.df-inline-media-button{opacity:1;transform:none}}.df-inline-media-toast{position:fixed;z-index:2147483647;left:50%;bottom:28px;max-width:min(88vw,520px);padding:10px 14px;border-radius:10px;color:#fff;background:rgba(15,23,42,.94);box-shadow:0 12px 32px rgba(0,0,0,.28);font:600 13px/1.45 system-ui,sans-serif;transform:translateX(-50%)}";
document.head.appendChild(style);
const notify = (message) => {
if (typeof showToast === "function") { showToast(message); return; }
if (typeof toast === "function") { toast(message); return; }
let notice = document.getElementById("dfInlineMediaToast");
if (!notice) {
notice = document.createElement("div");
notice.id = "dfInlineMediaToast";
notice.className = "df-inline-media-toast";
document.body.appendChild(notice);
}
notice.textContent = message;
window.clearTimeout(notice._timer);
notice._timer = window.setTimeout(() => notice.remove(), 2600);
};
const sameSource = (value, source, absolute) => {
if (typeof value !== "string") return false;
if (value === source || value === absolute) return true;
try { return new URL(value, location.href).href === absolute; } catch (_error) { return false; }
};
const findMatches = (source, absolute) => {
const matches = [];
const stack = [];
const visit = (value) => {
if (Array.isArray(value)) { value.forEach(visit); return; }
if (!value || typeof value !== "object") return;
stack.push(value);
Object.entries(value).forEach(([key, item]) => {
if ((key === "mediaUrl" || key === "posterUrl") && sameSource(item, source, absolute)) {
const ancestors = stack.slice(0, -1).reverse();
const owner = ancestors.find((candidate) => candidate && typeof candidate === "object" && !Array.isArray(candidate) && ("id" in candidate || "title" in candidate || "text" in candidate || "name" in candidate || "author" in candidate)) || ancestors[0] || value;
matches.push({ owner, previous: value, key });
}
if (item && typeof item === "object") visit(item);
});
stack.pop();
};
visit(getRootData());
return matches;
};
const visualOwners = () => {
const owners = [];
const seen = new Set();
const visit = (value) => {
if (Array.isArray(value)) { value.forEach(visit); return; }
if (!value || typeof value !== "object") return;
const hasVisual = Object.prototype.hasOwnProperty.call(value, "visual") || (value.media && typeof value.media === "object");
const hasIdentity = ["id", "title", "text", "leadTitle", "feature", "name", "author"].some((key) => typeof value[key] === "string" && value[key].trim());
if (hasVisual && hasIdentity && !seen.has(value)) { seen.add(value); owners.push(value); }
Object.values(value).forEach((item) => { if (item && typeof item === "object") visit(item); });
};
visit(getRootData());
return owners;
};
const domIdentifiers = (element) => {
const values = new Set();
let cursor = element;
for (let depth = 0; cursor && cursor !== document.body && depth < 8; depth += 1, cursor = cursor.parentElement) {
Object.values(cursor.dataset || {}).forEach((value) => { if (value) values.add(String(value)); });
}
return values;
};
const chooseVisualTarget = (element) => {
const identifiers = domIdentifiers(element);
const context = element.closest("article,button,[data-post-id],[data-video-id],[data-short-id],.post,.video-card,.news-card,.story-card,.lead-story,.hero") || element.parentElement || element;
const contextText = String(context.textContent || "").replace(/\s+/g, " ").trim();
const visualNode = element.closest("[data-visual]") || element.querySelector && element.querySelector("[data-visual]");
const visualValue = visualNode && visualNode.dataset ? visualNode.dataset.visual : "";
let best = null;
let bestScore = 0;
visualOwners().forEach((owner) => {
let score = 0;
Object.entries(owner).forEach(([key, value]) => {
if (/id$/i.test(key) && identifiers.has(String(value))) score += 100;
});
["title", "text", "leadTitle", "feature", "visualLabel", "label", "author", "name", "summary"].forEach((key) => {
const value = typeof owner[key] === "string" ? owner[key].trim() : "";
if (value.length >= 2 && contextText.includes(value)) score += Math.min(40, value.length);
});
if (visualValue && owner.visual === visualValue) score += 20;
if (score > bestScore) { best = owner; bestScore = score; }
});
if (!best || bestScore <= 0) return null;
return { owner: best, previous: best.media && typeof best.media === "object" ? best.media : { type: "image" }, key: "mediaUrl" };
};
const chooseTarget = (element) => {
const source = element.getAttribute("src") || "";
const absolute = element.currentSrc || element.src || source;
const matches = findMatches(source, absolute);
if (!matches.length) return null;
const identifiers = domIdentifiers(element);
return matches.find(({ owner }) => Object.entries(owner).some(([key, value]) => /id$/i.test(key) && identifiers.has(String(value)))) || matches[0];
};
const persist = () => {
const root = getRootData();
if (typeof saveData === "function") return saveData();
if (typeof writeStorage === "function" && typeof storageKey !== "undefined") return writeStorage(storageKey, JSON.stringify(root));
if (typeof writeStorage === "function" && typeof dataKey !== "undefined") return writeStorage(dataKey, JSON.stringify(root));
return false;
};
let active = null;
const attachButton = (host, target) => {
if (!host || !target || host.querySelector(":scope > .df-inline-media-button")) return;
host.classList.add("df-inline-media-host");
const button = document.createElement("button");
button.type = "button";
button.className = "df-inline-media-button";
button.setAttribute("aria-label", "替换图片或视频");
button.title = "上传图片或视频并替换";
button.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5"/><path d="M5 14v4a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-4"/></svg>';
button.addEventListener("click", (event) => {
event.preventDefault();
event.stopPropagation();
active = { ...target };
input.accept = "image/*,video/*";
input.value = "";
input.click();
});
host.appendChild(button);
};
const decorateBuiltInVisuals = () => {
document.querySelectorAll(visualHostSelector).forEach((host) => {
if (host.querySelector("img[src],video[src],iframe[src],:scope > .df-inline-media-button")) return;
if (!host.querySelector("svg") && !host.dataset.visual) return;
const target = chooseVisualTarget(host);
if (!target) return;
attachButton(host, target);
});
};
const decorate = () => {
decorateBuiltInVisuals();
document.querySelectorAll("img[src],video[src]").forEach((media) => {
if (media.dataset.dfInlineMediaReady === "true") return;
const target = chooseTarget(media);
if (!target) return;
const host = media.closest(visualHostSelector) || media.parentElement;
if (!host) return;
media.dataset.dfInlineMediaReady = "true";
attachButton(host, target);
});
};
input.addEventListener("change", () => {
const file = input.files && input.files[0];
if (!file || !active) return;
const uploadedType = file.type.startsWith("image/") ? "image" : file.type.startsWith("video/") ? "video" : "";
if (!uploadedType) {
notify("请选择图片或视频文件。");
return;
}
const reader = new FileReader();
reader.onerror = () => notify("文件读取失败,请重新选择。");
reader.onload = () => {
const next = { ...(active.previous || {}) };
const result = String(reader.result);
next.type = uploadedType;
next.mediaUrl = result;
delete next.posterUrl;
if (!next.alt) next.alt = uploadedType === "video" ? "用户上传的视频" : "用户上传的图片";
active.owner.media = next;
const stored = persist();
renderAll();
notify(stored === false ? "媒体已替换;浏览器未能缓存,请下载 JSON 留存。" : "媒体已替换并写入页面 JSON。");
active = null;
};
reader.readAsDataURL(file);
});
let queued = false;
const queueDecorate = () => {
if (queued) return;
queued = true;
requestAnimationFrame(() => { queued = false; decorate(); });
};
new MutationObserver(queueDecorate).observe(document.body, { childList: true, subtree: true });
decorate();
}
installInlineMediaReplace();
})();
</script>
</body>
</html>