mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-05-05 05:30:44 +08:00
12 lines
488 B
TypeScript
12 lines
488 B
TypeScript
|
|
/**
|
||
|
|
* Detect whether the current device is mobile.
|
||
|
|
* Uses navigator.userAgentData (modern API) with UA regex fallback.
|
||
|
|
*/
|
||
|
|
export function isMobileDevice(): boolean {
|
||
|
|
const nav = navigator as unknown as Record<string, unknown>
|
||
|
|
if (nav.userAgentData && typeof (nav.userAgentData as Record<string, unknown>).mobile === 'boolean') {
|
||
|
|
return (nav.userAgentData as Record<string, unknown>).mobile as boolean
|
||
|
|
}
|
||
|
|
return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent)
|
||
|
|
}
|