v-fixed43: IPv6检测改严格模式(cors+校验JSON),缓存10分钟→2分钟,新增重新检测按钮
This commit is contained in:
1 parent
a47487293f
commit
4f71088fe0
1 file changed
+21
-9
+21
-9
@@ -38,11 +38,14 @@ background:color-mix(in srgb,var(--c) 22%,transparent);color:var(--c);border:1px
|
||||
.go{margin-top:20px;padding:10px 24px;border:none;border-radius:10px;font-size:14px;font-weight:600;
|
||||
background:linear-gradient(90deg,#a855f7,#3b82f6);color:#fff;cursor:pointer}
|
||||
.go:hover{opacity:.9}
|
||||
.rebtn{margin-top:10px;padding:7px 18px;border:1px solid rgba(239,68,68,.5);border-radius:8px;
|
||||
background:rgba(239,68,68,.15);color:#fca5a5;font-size:13px;cursor:pointer;transition:all .2s}
|
||||
.rebtn:hover{background:rgba(239,68,68,.3);color:#fff}
|
||||
</style></head><body>
|
||||
<div class="logo">米视TV</div>
|
||||
<div class="sub">选择你当前网络可用的访问线路</div>
|
||||
<div class="status" id="st">正在检测 IPv6 可用性…</div>
|
||||
<div class="notice" id="nt">⚠️ 检测到你的网络<b>不支持 IPv6 访问</b>,已隐藏 IPv6 线路。<br>请使用 IPv4 线路访问。</div>
|
||||
<div class="notice" id="nt">⚠️ 检测到你的网络<b>不支持 IPv6 访问</b>,已隐藏 IPv6 线路。<br>请使用 IPv4 线路访问。<br><button class="rebtn" onclick="__reprobe()">重新检测</button></div>
|
||||
<div class="cards">
|
||||
<div class="card v4" onclick="__go('v4')">
|
||||
<div class="icon">🌐</div>
|
||||
@@ -80,20 +83,29 @@ var s=document.getElementById('st');if(s){s.textContent='✓ 已检测到你的
|
||||
function __probe(){
|
||||
// 当前就在 IPv6 域名上,必然可用
|
||||
if(location.hostname==='tv6.88531.cn'){__showV6();return}
|
||||
// 结果缓存 10 分钟,避免每次刷新都等检测
|
||||
// 结果缓存 2 分钟,避免每次刷新都等检测(但不失效太快)
|
||||
try{var j=JSON.parse(localStorage.getItem("__v6probe")||"null");
|
||||
if(j&&(Date.now()-j.t)<600000){j.ok?__showV6():__hideV6();return}}catch(e){}
|
||||
// tv6.88531.cn 只有 AAAA 记录,连不上即说明无 IPv6
|
||||
if(j&&(Date.now()-j.t)<120000){j.ok?__showV6():__hideV6();return}}catch(e){}
|
||||
// tv6.88531.cn 只有 AAAA 记录:用 cors 模式拿真实状态并校验响应体,
|
||||
// 只有真正连通并返回合法 JSON 才算支持 IPv6
|
||||
var c=new AbortController();
|
||||
var ti=setTimeout(function(){c.abort()},4000);
|
||||
var ti=setTimeout(function(){c.abort()},5000);
|
||||
fetch("https://tv6.88531.cn/api/license-config?_="+Date.now(),
|
||||
{mode:"no-cors",signal:c.signal,cache:"no-store"})
|
||||
.then(function(){clearTimeout(ti);
|
||||
try{localStorage.setItem("__v6probe",JSON.stringify({t:Date.now(),ok:true}))}catch(e){}
|
||||
__showV6()})
|
||||
{mode:"cors",signal:c.signal,cache:"no-store",credentials:"omit"})
|
||||
.then(function(r){return r.json()})
|
||||
.then(function(j){
|
||||
clearTimeout(ti);
|
||||
var ok=!!(j&&j.code===200&&j.data);
|
||||
try{localStorage.setItem("__v6probe",JSON.stringify({t:Date.now(),ok:ok}))}catch(e){}
|
||||
ok?__showV6():__hideV6()})
|
||||
.catch(function(){clearTimeout(ti);
|
||||
try{localStorage.setItem("__v6probe",JSON.stringify({t:Date.now(),ok:false}))}catch(e){}
|
||||
__hideV6()})}
|
||||
function __reprobe(){try{localStorage.removeItem("__v6probe")}catch(e){}
|
||||
var s=document.getElementById('st');if(s){s.textContent='正在重新检测 IPv6…';s.style.color='rgba(255,255,255,.45)';s.style.display='block'}
|
||||
var n=document.getElementById('nt');if(n)n.style.display='none';
|
||||
var c=document.getElementById('c6');if(c)c.style.display='';
|
||||
__probe()}
|
||||
try{var __c=localStorage.getItem("__v6dest");
|
||||
if(__c){document.querySelectorAll(".card").forEach(function(c){if((__c==='v6'&&c.classList.contains("v6"))||(__c==='v4'&&c.classList.contains("v4"))){
|
||||
c.style.borderColor=getComputedStyle(c).getPropertyValue("--c");
|
||||
|
||||
Reference in new issue
Block a user