mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-30 16:26:36 +08:00
32 lines
867 B
TypeScript
32 lines
867 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
import { DEFAULT_MOBILE_BREAKPOINT } from "@/hooks/useMobileBreakpoint";
|
|
|
|
const detectH5Mode = (): boolean => {
|
|
const isMobile = window.innerWidth <= DEFAULT_MOBILE_BREAKPOINT;
|
|
const isMobileBrowser =
|
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
navigator.userAgent,
|
|
);
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const isH5Param = urlParams.get("h5") === "true";
|
|
|
|
return isMobile || isMobileBrowser || isH5Param;
|
|
};
|
|
|
|
export const useH5Mode = (): boolean => {
|
|
const [isH5, setIsH5] = useState(detectH5Mode);
|
|
|
|
useEffect(() => {
|
|
const checkH5Mode = () => {
|
|
setIsH5(detectH5Mode());
|
|
};
|
|
|
|
window.addEventListener("resize", checkH5Mode);
|
|
|
|
return () => window.removeEventListener("resize", checkH5Mode);
|
|
}, []);
|
|
|
|
return isH5;
|
|
};
|