"use client"; import { useState, useEffect } from "react"; import { Monitor, Globe, Cpu, Info } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { toast } from "sonner"; export default function UAPage() { const [ua, setUa] = useState(""); const [info, setInfo] = useState(null); useEffect(() => { const currentUA = navigator.userAgent; setUa(currentUA); parseUA(currentUA); }, []); const parseUA = (userAgent: string) => { if (!userAgent) return; const browser = { name: "未知浏览器", version: "" }; const os = { name: "未知操作系统", version: "" }; // Simple Browser Detection if (userAgent.indexOf("Edg") > -1) { browser.name = "Edge"; } else if (userAgent.indexOf("Chrome") > -1) { browser.name = "Chrome"; } else if (userAgent.indexOf("Firefox") > -1) { browser.name = "Firefox"; } else if (userAgent.indexOf("Safari") > -1) { browser.name = "Safari"; } // Simple OS Detection if (userAgent.indexOf("Windows") > -1) { os.name = "Windows"; } else if (userAgent.indexOf("Mac OS") > -1) { os.name = "macOS"; } else if (userAgent.indexOf("Android") > -1) { os.name = "Android"; } else if (userAgent.indexOf("iPhone") > -1 || userAgent.indexOf("iPad") > -1) { os.name = "iOS"; } else if (userAgent.indexOf("Linux") > -1) { os.name = "Linux"; } setInfo({ browser, os }); }; const resetToMine = () => { const currentUA = navigator.userAgent; setUa(currentUA); parseUA(currentUA); toast.success("已重置为当前浏览器 UA"); }; return (

User-Agent 解析

解析浏览器 User-Agent 字符串详细信息

UA 字符串