fix: 吃瓜改网页式浏览 + 音量轨道对齐 + 桌面闲置隐藏 UI
- 分类/吃瓜列表点击直接进图文详情页(不再走播放器) - 图文正文按净化后的 HTML 渲染;图片地址补全绝对路径、优先取 data-src,修复图片加载不出 - 桌面播放器闲置 2.8s 淡出控制条/右侧操作栏/信息区,鼠标移动恢复 - 音量:轨道与滑块单独绘制并对齐;换源后重新套用音量/倍速,切集不再丢音量 - 移动端:栈页隐藏底栏(评论抽屉输入框不再被遮挡);横屏视频在首页保持黑边,沉浸模式才旋转横屏
This commit is contained in:
+5
-2
@@ -103,6 +103,9 @@ function AppBody() {
|
||||
const vis = (k: Tab) => (tab === k ? "absolute inset-0" : "absolute inset-0 invisible pointer-events-none");
|
||||
const pageActive = stack.length === 0 && !loginOpen;
|
||||
const bottomInset = platform === "android" ? (fs ? 0 : 48) : 14;
|
||||
/* 栈页(从搜索/分类/我的进入的播放页、图文页)不显示底栏:
|
||||
底栏会盖住评论抽屉的输入框,且这些页面本身是沉浸的 */
|
||||
const stackInset = platform === "android" ? (fs ? 0 : 20) : 14;
|
||||
|
||||
return (
|
||||
<div className={`absolute inset-0 flex bg-canvas plat-${platform}`}>
|
||||
@@ -115,11 +118,11 @@ function AppBody() {
|
||||
|
||||
{stack.map((p, i) => (
|
||||
<div key={p.key} className="absolute inset-0 z-30 bg-bg a-page-in" style={{ boxShadow: "-18px 0 40px rgba(0,0,0,.5)" }}>
|
||||
<StackPage page={p} onBack={pop} wide={wide} top={i === stack.length - 1} bottomInset={bottomInset} />
|
||||
<StackPage page={p} onBack={pop} wide={wide} top={i === stack.length - 1} bottomInset={stackInset} />
|
||||
</div>
|
||||
))}
|
||||
|
||||
{platform === "android" && !fs && <TabBar />}
|
||||
{platform === "android" && !fs && stack.length === 0 && <TabBar />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
+23
-3
@@ -57,6 +57,23 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
const setTheater = store.setTheater;
|
||||
const fs = store.fs;
|
||||
const setFs = store.setFs;
|
||||
|
||||
/* 桌面:鼠标闲置 2.8s 自动隐藏播放器 UI(沉浸) */
|
||||
const [idle, setIdle] = useState(false);
|
||||
const idleTimer = useRef<number | undefined>(undefined);
|
||||
const wake = useCallback(() => {
|
||||
setIdle(false);
|
||||
window.clearTimeout(idleTimer.current);
|
||||
idleTimer.current = window.setTimeout(() => setIdle(true), 2800);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (!isDesktop) return undefined;
|
||||
wake();
|
||||
return () => window.clearTimeout(idleTimer.current);
|
||||
}, [isDesktop, wake]);
|
||||
useEffect(() => {
|
||||
if (paused) { setIdle(false); window.clearTimeout(idleTimer.current); }
|
||||
}, [paused]);
|
||||
const [fullscreen, setFullscreen] = useState(false);
|
||||
const [heartBurst, setHeartBurst] = useState(0);
|
||||
/* —— 移动端手势 —— */
|
||||
@@ -442,7 +459,9 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`absolute inset-0 overflow-hidden bg-black player-root ${isDesktop ? "player-surface" : ""} ${theater ? "is-theater" : ""} ${rotated ? "fs-landscape" : ""}`}>
|
||||
<div
|
||||
className={`absolute inset-0 overflow-hidden bg-black player-root ${isDesktop ? "player-surface" : ""} ${theater ? "is-theater" : ""} ${rotated ? "fs-landscape" : ""} ${isDesktop && idle ? "is-idle" : ""}`}
|
||||
onPointerMove={() => { if (isDesktop) wake(); }}>
|
||||
{/* 氛围背景 */}
|
||||
<div className="absolute inset-0 scale-110 blur-3xl opacity-25 pointer-events-none">
|
||||
{posterUrl && <img src={posterUrl} alt="" className="w-full h-full object-cover" />}
|
||||
@@ -459,7 +478,8 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
<div className="absolute inset-0" style={{ touchAction: "pan-y" }}
|
||||
onPointerDown={onDown} onPointerMove={onMove} onPointerUp={onUp} onPointerCancel={onUp}>
|
||||
<VideoSurface ref={videoRef} src={playUrl} poster={posterUrl} autoPlay muted={muted}
|
||||
fit={isDesktop ? "contain" : "cover"}
|
||||
volume={volume} rate={effRate}
|
||||
fit={isDesktop || (vsize.w > 0 && vsize.w > vsize.h) ? "contain" : "cover"}
|
||||
onClick={() => { if (isDesktop) videoRef.current?.toggle(); }}
|
||||
onTime={setTime}
|
||||
onDuration={setDuration}
|
||||
@@ -644,7 +664,7 @@ export default function Feed({ videoIds, startIndex = 0, title = "", mode, kind
|
||||
<PlayerControls
|
||||
paused={paused} time={time} duration={duration} buffered={buffered} rate={rate}
|
||||
muted={muted} volume={volume} theater={theater} fullscreen={fullscreen}
|
||||
visible={active}
|
||||
visible={active && !idle}
|
||||
nextDisabled={!episodes.some((e) => e.ep_num === curEp + 1) && index >= videoIds.length - 1}
|
||||
nextTitle={episodes.some((e) => e.ep_num === curEp + 1) ? "下一集 E" : "下一部 ↓"}
|
||||
onToggle={() => videoRef.current?.toggle()}
|
||||
|
||||
@@ -20,6 +20,9 @@ type Props = {
|
||||
muted?: boolean;
|
||||
loop?: boolean;
|
||||
fit?: "contain" | "cover";
|
||||
/** 换源后重新套用,避免切集时音量/倍速被浏览器重置 */
|
||||
volume?: number;
|
||||
rate?: number;
|
||||
onTime?: (t: number) => void;
|
||||
onDuration?: (d: number) => void;
|
||||
onSize?: (w: number, h: number) => void;
|
||||
@@ -34,7 +37,7 @@ type Props = {
|
||||
|
||||
/** 只负责「播」:hls.js + video 元素,控制条由外层渲染。 */
|
||||
const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
{ src, poster, autoPlay = true, muted = false, loop = false, fit = "contain",
|
||||
{ src, poster, autoPlay = true, muted = false, loop = false, fit = "contain", volume = 1, rate = 1,
|
||||
onTime, onDuration, onSize, onPlaying, onPause, onWaiting, onEnded, onError, onClick, className = "" },
|
||||
ref,
|
||||
) {
|
||||
@@ -67,6 +70,16 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
const url = proxied ? src : playlist(src);
|
||||
const useHls = !url.includes("/seg?u=");
|
||||
|
||||
/* 换源时先把音量/倍速套回去:hls 重新 attach 后浏览器会把它们重置成默认值 */
|
||||
const applySettings = () => {
|
||||
const v = videoRef.current;
|
||||
if (!v) return;
|
||||
v.volume = volume;
|
||||
v.muted = muted;
|
||||
v.playbackRate = rate;
|
||||
};
|
||||
applySettings();
|
||||
|
||||
if (useHls && Hls.isSupported()) {
|
||||
const hls = new Hls({
|
||||
enableWorker: true,
|
||||
@@ -101,6 +114,14 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
}, [src]);
|
||||
|
||||
useEffect(() => { if (videoRef.current) videoRef.current.muted = muted; }, [muted]);
|
||||
useEffect(() => { if (videoRef.current) videoRef.current.volume = volume; }, [volume]);
|
||||
useEffect(() => { if (videoRef.current) videoRef.current.playbackRate = rate; }, [rate]);
|
||||
|
||||
const reapply = (v: HTMLVideoElement) => {
|
||||
v.volume = volume;
|
||||
v.muted = muted;
|
||||
v.playbackRate = rate;
|
||||
};
|
||||
|
||||
return (
|
||||
<video
|
||||
@@ -111,10 +132,11 @@ const VideoSurface = forwardRef<VideoHandle, Props>(function VideoSurface(
|
||||
onClick={onClick}
|
||||
className={`w-full h-full bg-black ${fit === "cover" ? "object-cover" : "object-contain"} ${className}`}
|
||||
style={{ opacity: ready ? 1 : 0, transition: "opacity .35s" }}
|
||||
onLoadedData={() => setReady(true)}
|
||||
onLoadedData={(e) => { setReady(true); reapply(e.target as HTMLVideoElement); }}
|
||||
onTimeUpdate={(e) => onTime?.((e.target as HTMLVideoElement).currentTime)}
|
||||
onLoadedMetadata={(e) => {
|
||||
const v = e.target as HTMLVideoElement;
|
||||
reapply(v);
|
||||
onDuration?.(v.duration || 0);
|
||||
onSize?.(v.videoWidth || 0, v.videoHeight || 0);
|
||||
}}
|
||||
|
||||
+37
-3
@@ -1,16 +1,50 @@
|
||||
import { LOCAL } from "./api";
|
||||
|
||||
/** 站点根地址:正文里的相对路径要补全 */
|
||||
const SITE = "https://huangguoai.com";
|
||||
|
||||
/** 把各种写法的图片地址补成绝对地址;占位符(data:)返回空串 */
|
||||
function abs(raw: string): string {
|
||||
const s = (raw || "").trim();
|
||||
if (!s) return "";
|
||||
if (/^data:/i.test(s)) return "";
|
||||
if (s.startsWith("//")) return `https:${s}`;
|
||||
if (/^https?:\/\//i.test(s)) return s;
|
||||
if (s.startsWith("/")) return `${SITE}${s}`;
|
||||
return `${SITE}/${s.replace(/^\.\//, "")}`;
|
||||
}
|
||||
|
||||
/** 把正文里的图片换成走本地协议(带 Referer / 解密能力) */
|
||||
export function proxyImages(html: string): string {
|
||||
if (!html) return "";
|
||||
const doc = new DOMParser().parseFromString(html, "text/html");
|
||||
doc.querySelectorAll("img").forEach((img) => {
|
||||
const src = img.getAttribute("src") || img.getAttribute("data-src") || "";
|
||||
if (!src) return;
|
||||
// 懒加载图:真实地址常在 data-* 上,src 只是占位
|
||||
const raw =
|
||||
img.getAttribute("data-src") ||
|
||||
img.getAttribute("data-original") ||
|
||||
img.getAttribute("data-lazy-src") ||
|
||||
img.getAttribute("src") ||
|
||||
"";
|
||||
const src = abs(raw);
|
||||
if (!src) {
|
||||
img.remove();
|
||||
return;
|
||||
}
|
||||
img.setAttribute("src", `${LOCAL}/img?u=${encodeURIComponent(src)}`);
|
||||
img.removeAttribute("srcset");
|
||||
img.removeAttribute("data-src");
|
||||
img.removeAttribute("data-original");
|
||||
img.removeAttribute("loading");
|
||||
img.setAttribute("loading", "lazy");
|
||||
});
|
||||
// 正文链接补全,避免点开指向本地
|
||||
doc.querySelectorAll("a[href]").forEach((a) => {
|
||||
const href = (a.getAttribute("href") || "").trim();
|
||||
if (!href || href.startsWith("#") || /^(mailto|tel|javascript):/i.test(href)) return;
|
||||
const full = abs(href);
|
||||
if (full) a.setAttribute("href", full);
|
||||
});
|
||||
return doc.body.innerHTML;
|
||||
}
|
||||
|
||||
@@ -27,4 +61,4 @@ export function sanitizeHtml(html: string): string {
|
||||
}
|
||||
});
|
||||
return proxyImages(doc.body.innerHTML);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-3
@@ -381,17 +381,41 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w
|
||||
.player-speed-menu button:hover { background: rgba(255,255,255,.07); color: #fff; }
|
||||
.player-speed-menu button[aria-checked="true"] { color: var(--p-primary); }
|
||||
.player-volume { display: flex; align-items: center; }
|
||||
.player-volume-slider { width: 0; overflow: hidden; transition: width .2s ease; }
|
||||
.player-volume-slider { width: 0; overflow: hidden; transition: width .2s ease; display: flex; align-items: center; }
|
||||
.player-volume:hover .player-volume-slider,
|
||||
.player-volume:focus-within .player-volume-slider { width: 74px; }
|
||||
.player-volume-slider input {
|
||||
-webkit-appearance: none; appearance: none; width: 68px; height: 4px; border-radius: 99px;
|
||||
-webkit-appearance: none; appearance: none; display: block; width: 68px; height: 20px;
|
||||
background: transparent; margin: 0 3px; cursor: pointer;
|
||||
}
|
||||
/* 轨道单独画:滑块才和轨道同轴,不会上下错位 */
|
||||
.player-volume-slider input::-webkit-slider-runnable-track {
|
||||
height: 3px; border-radius: 99px;
|
||||
background: linear-gradient(to right, var(--p-primary) var(--fill,70%), rgba(255,255,255,.2) var(--fill,70%));
|
||||
margin: 0 3px; cursor: pointer;
|
||||
}
|
||||
.player-volume-slider input::-webkit-slider-thumb {
|
||||
-webkit-appearance: none; width: 10px; height: 10px; border-radius: 50%; background: #fff;
|
||||
margin-top: -3.5px; box-shadow: 0 1px 3px rgba(0,0,0,.45);
|
||||
}
|
||||
.player-volume-slider input::-moz-range-track {
|
||||
height: 3px; border-radius: 99px; background: rgba(255,255,255,.2);
|
||||
}
|
||||
.player-volume-slider input::-moz-range-progress {
|
||||
height: 3px; border-radius: 99px; background: var(--p-primary);
|
||||
}
|
||||
.player-volume-slider input::-moz-range-thumb {
|
||||
width: 10px; height: 10px; border: 0; border-radius: 50%; background: #fff;
|
||||
}
|
||||
|
||||
/* —— 桌面沉浸:鼠标闲置时淡出播放器 UI(鼠标一动就回来) —— */
|
||||
.player-root .desktop-controls,
|
||||
.player-root .desktop-social,
|
||||
.player-root .desktop-video-meta,
|
||||
.player-root .desktop-browse-inline { transition: opacity .28s ease; }
|
||||
.player-root.is-idle .desktop-controls,
|
||||
.player-root.is-idle .desktop-social,
|
||||
.player-root.is-idle .desktop-video-meta,
|
||||
.player-root.is-idle .desktop-browse-inline { opacity: 0; pointer-events: none; }
|
||||
|
||||
/* —— 进度条 —— */
|
||||
.desktop-seek { position: relative; height: 19px; display: flex; align-items: center; cursor: pointer; }
|
||||
|
||||
@@ -108,7 +108,7 @@ export default function Category({ wide }: { wide: boolean }) {
|
||||
</button>
|
||||
<div className="scroll-x flex gap-2.5 px-4 snap-x">
|
||||
{posts.map((post) => (
|
||||
<button key={post.id} onClick={() => push({ kind: "feed", videoIds: posts.map((x) => x.id), index: posts.findIndex((x) => x.id === post.id), title: "黄果吃瓜", feedKind: "post" })}
|
||||
<button key={post.id} onClick={() => push({ kind: "post", id: post.id })}
|
||||
className="w-[104px] shrink-0 text-left snap-start pressable">
|
||||
<div className="relative w-full rounded-(--r-sm) overflow-hidden bg-s1 elev-1" style={{ paddingTop: "133%" }}>
|
||||
<Img src={post.cover} />
|
||||
|
||||
+8
-3
@@ -5,6 +5,7 @@ import { useStore } from "../store";
|
||||
import { Empty, Img } from "../components/ui";
|
||||
import Player from "../components/Player";
|
||||
import { IBack, IFireF, IPlayF } from "../icons";
|
||||
import { sanitizeHtml } from "../html";
|
||||
|
||||
/* ================= 吃瓜列表 ================= */
|
||||
export function PostsPage({ onBack, wide }: { onBack: () => void; wide: boolean }) {
|
||||
@@ -56,7 +57,7 @@ export function PostsPage({ onBack, wide }: { onBack: () => void; wide: boolean
|
||||
{items.length ? (
|
||||
<div className={`${wide ? "columns-3 xl:columns-4" : "columns-2"} gap-2`}>
|
||||
{items.map((p) => (
|
||||
<button key={p.id} onClick={() => push({ kind: "feed", videoIds: items.map((x) => x.id), index: items.findIndex((x) => x.id === p.id), title: "黄果吃瓜", feedKind: "post" })}
|
||||
<button key={p.id} onClick={() => push({ kind: "post", id: p.id })}
|
||||
className="w-full break-inside-avoid mb-2 relative rounded-(--r-sm) overflow-hidden bg-s1 elev-1 pressable block"
|
||||
style={{ paddingTop: "128%" }}>
|
||||
<Img src={p.cover} />
|
||||
@@ -82,7 +83,9 @@ export function PostsPage({ onBack, wide }: { onBack: () => void; wide: boolean
|
||||
);
|
||||
}
|
||||
|
||||
/* ================= 吃瓜详情 ================= */
|
||||
const isHtml = (s: string) => /<(p|div|br|img|h[1-6]|ul|ol|li|blockquote|span|strong|em)\b/i.test(s);
|
||||
|
||||
/* ================= 吃瓜详情(网页式浏览) ================= */
|
||||
export function PostDetail({ id, onBack }: { id: number; onBack: () => void }) {
|
||||
const { toast } = useStore();
|
||||
const [post, setPost] = useState<(Post & { content?: string; video_url?: string }) | null>(null);
|
||||
@@ -137,7 +140,9 @@ export function PostDetail({ id, onBack }: { id: number; onBack: () => void }) {
|
||||
))}
|
||||
</div>
|
||||
{post.content && (
|
||||
<div className="mt-3.5 rounded-(--r-md) bg-s2 p-3.5 text-[12.5px] leading-relaxed text-on/80 whitespace-pre-wrap">{post.content}</div>
|
||||
isHtml(post.content)
|
||||
? <div className="article-body mt-3.5" dangerouslySetInnerHTML={{ __html: sanitizeHtml(post.content) }} />
|
||||
: <div className="mt-3.5 rounded-(--r-md) bg-s2 p-3.5 text-[12.5px] leading-relaxed text-on/80 whitespace-pre-wrap">{post.content}</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user