'use client'; import TopRightButtons from '@/components/TopRightButtons'; import { useEffect, useState } from 'react'; const H = { v4: 'https://tv.88531.cn', v6: 'https://tv6.88531.cn:4443', }; const URLS = [ 'https://tv6.88531.cn:4443/api/license-config?_=', 'https://tv6.88531.cn/api/license-config?_=', ]; type ProbeState = 'checking' | 'ok' | 'fail'; export default function IPv6Page() { const [state, setState] = useState('checking'); const [back, setBack] = useState('/'); useEffect(() => { const params = new URLSearchParams(window.location.search); setBack(params.get('back') || '/'); }, []); useEffect(() => { // If already on tv6 hostname, IPv6 is available if (window.location.hostname === 'tv6.88531.cn') { setState('ok'); return; } // Check cache (2 min) try { const cached = JSON.parse(localStorage.getItem('__v6probe') || 'null'); if (cached && Date.now() - cached.t < 120000) { setState(cached.ok ? 'ok' : 'fail'); return; } } catch (e) { // ignore // ignore parse errors } let cancelled = false; let i = 0; const probe = () => { if (i >= URLS.length) { if (!cancelled) { try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: false })); } catch (e) { // ignore // ignore } setState('fail'); } return; } const c = new AbortController(); const ti = setTimeout(() => c.abort(), 5000); fetch(URLS[i] + Date.now(), { mode: 'cors', signal: c.signal, cache: 'no-store', credentials: 'omit' }) .then((r) => r.json()) .then((j) => { clearTimeout(ti); if (cancelled) return; if (j && j.code === 200 && j.data) { try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: true })); } catch (e) { // ignore // ignore } setState('ok'); } else { i++; probe(); } }) .catch(() => { clearTimeout(ti); if (cancelled) return; i++; probe(); }); }; probe(); return () => { cancelled = true; }; }, []); const choose = (which: 'v4' | 'v6') => { const dest = which === 'v4' ? H.v4 : H.v6; let targetBack = back; try { const s = sessionStorage.getItem('__v6back'); if (s) { targetBack = s; sessionStorage.removeItem('__v6back'); } } catch (e) { /* ignore */ } try { localStorage.setItem('__v6dest', which); } catch (e) { // ignore // ignore } document.cookie = `__v6dest=${which}; path=/; max-age=31536000; samesite=lax`; // 去掉 search 里的 back 参数,避免透传到目标地址 const qs = new URLSearchParams(window.location.search); qs.delete('back'); const searchStr = qs.toString() ? '?' + qs.toString() : ''; const u = new URL(dest); const m = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(targetBack) || []; u.pathname = m[1] || '/'; if (m[2]) { const q2 = new URLSearchParams(m[2].slice(1)); q2.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); }); } if (searchStr) { const q3 = new URLSearchParams(searchStr.slice(1)); q3.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); }); } if (m[3]) u.hash = m[3]; window.location.href = u.toString(); }; const reprobe = () => { try { localStorage.removeItem('__v6probe'); } catch (e) { // ignore // ignore } setState('checking'); window.location.reload(); }; const forceV6 = () => { try { localStorage.setItem('__v6probe', JSON.stringify({ t: Date.now(), ok: true })); } catch (e) { // ignore // ignore } try { localStorage.setItem('__v6dest', 'v6'); } catch (e) { // ignore // ignore } document.cookie = '__v6dest=v6; path=/; max-age=31536000; samesite=lax'; let targetBack = back; try { const s = sessionStorage.getItem('__v6back'); if (s) { targetBack = s; sessionStorage.removeItem('__v6back'); } } catch (e) { /* ignore */ } const u = new URL(H.v6); const m = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(targetBack) || []; u.pathname = m[1] || '/'; if (m[2]) { const q2 = new URLSearchParams(m[2].slice(1)); q2.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); }); } const qs = new URLSearchParams(window.location.search); qs.delete('back'); qs.forEach((v, k) => { if (!u.searchParams.has(k)) u.searchParams.set(k, v); }); if (m[3]) u.hash = m[3]; window.location.href = u.toString(); }; return ( <>

KatelyaTV

选择访问线路

{state === 'checking' && (

正在检测 IPv6…

)} {state === 'ok' && (
)} {state === 'fail' && ( <>

⚠️ 检测到你的网络不支持 IPv6 访问

已隐藏 IPv6 线路。请使用 IPv4 线路访问。

)}
); } const btnStyle: React.CSSProperties = { padding: '12px 28px', borderRadius: 10, border: '1px solid rgba(255,255,255,.15)', background: 'rgba(255,255,255,.08)', color: '#fff', fontSize: 16, cursor: 'pointer', transition: 'background .2s', }; const btnStyleSecondary: React.CSSProperties = { ...btnStyle, background: 'rgba(255,255,255,.04)', fontSize: 14, };