import { useEffect, useState } from 'react' import { useAtom } from 'jotai' import { Switch } from '@headlessui/react' import { toast } from 'react-hot-toast' import { hashAtom, voiceAtom } from '@/state' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Button } from './ui/button' import { Input } from './ui/input' import { ChunkKeys, parseCookies, extraCurlFromCookie, randomIP, encodeHeadersToCookie } from '@/lib/utils' import { ExternalLink } from './external-link' import { useCopyToClipboard } from '@/lib/hooks/use-copy-to-clipboard' export function Settings() { const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2000 }) const [loc, setLoc] = useAtom(hashAtom) const [curlValue, setCurlValue] = useState(extraCurlFromCookie(parseCookies(document.cookie, ChunkKeys))) const [enableTTS, setEnableTTS] = useAtom(voiceAtom) useEffect(() => { if (isCopied) { toast.success('复制成功') } }, [isCopied]) if (loc === 'settings') { return ( setLoc('')} modal> 设置你的用户信息 请使用 Edge 浏览器 打开并登录 Bing ,然后再打开 Challenge 接口 右键 》检查。打开开发者工具,在网络里面找到 Create 接口 》右键复制》复制为 cURL(bash),粘贴到此处,然后保存。 图文示例: 如何获取 BING_HEADER setCurlValue(e.target.value)} /> copyToClipboard(btoa(curlValue))}> 转成 BING_HEADER 并复制 { let headerValue = curlValue if (headerValue) { try { headerValue = atob(headerValue) } catch (e) {} if (!/^\s*curl ['"]https:\/\/www\.bing\.com\/turing\/captcha\/challenge['"]/.test(headerValue)) { toast.error('格式不正确') return } const maxAge = 86400 * 30 encodeHeadersToCookie(headerValue).forEach(cookie => document.cookie = `${cookie}; Max-Age=${maxAge}; Path=/; SameSite=None; Secure`) } else { [...ChunkKeys, 'BING_COOKIE', 'BING_UA', 'BING_IP'].forEach(key => document.cookie = `${key}=; Path=/; SameSite=None; Secure`) } toast.success('保存成功') setLoc('') setTimeout(() => { location.href = './' }, 2000) }} > 保存 ) } else if (loc === 'voice') { return ( setLoc('')} modal> 语音设置 目前仅支持 PC 端 Edge 及 Chrome 浏览器 启用语音回答 setEnableTTS(checked)} > { toast.success('保存成功') setLoc('') setTimeout(() => { location.href = './' }, 2000) }} > 保存 ) } return null }