document.addEventListener("DOMContentLoaded", async function () {
try {
// 尝试请求 secret.key 以验证关键安全文件是否存在
let response = await fetch('secret.key', {
method: 'HEAD',
headers: {
'Cache-Control': 'no-store, no-cache, must-revalidate, proxy-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
}
});
if (!response.ok) {
throw new Error("secret.key 不存在或无法访问");
}
} catch (error) {
// 处理错误,显示安全警告
console.error("安全检查失败:", error);
document.body.innerHTML = `
`;
return;
}
const progressBar = document.querySelector(".progress");
let progress = 0;
let fastestUrl = "";
let timeout;
// 如果主线路全部检测失败(超时),才会随机打开备用线路。
const fallbackUrls = [
atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzcxLw=="),
atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzcyLw=="),
atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzczLw=="),
atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3Nzc0Lw==")
];
// 首先检测主线路(进行测速)自动打开最快线路。
const routes = [
{ url: atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzcxLw=="), text: "①线路" },
{ url: atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzcyLw=="), text: "②线路" },
{ url: atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3NzczLw=="), text: "③线路" },
{ url: atob("aHR0cHM6Ly8xMDMuODIuMjE1LjEyNDo3Nzc0Lw=="), text: "④线路" }
];
// 开始倒计时,5 秒后跳转到最快的线路
function startTimeout() {
timeout = setTimeout(function () {
window.location.href = fastestUrl;
}, 5000);
}
// 进度条模拟加载进度
function updateProgress() {
if (progress < 100) {
progress += Math.random() * 20; // 随机增加进度
if (progress > 100) progress = 100;
progressBar.style.width = progress + "%";
setTimeout(updateProgress, 500);
}
}
updateProgress();
const routeButtons = document.getElementById("route-buttons");
// 创建线路按钮
routes.forEach(route => {
let a = document.createElement("a");
a.href = route.url;
a.className = "route-btn";
a.innerText = `${route.text} → 检测中...`;
routeButtons.appendChild(a);
route.element = a;
});
// 测试线路速度
async function measureSpeed(url, retries = 2) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const start = performance.now();
let success = false;
try {
await fetch(`${url}/favicon.ico`, { method: 'HEAD', mode: 'no-cors', signal: controller.signal });
success = true;
} catch (e) {
if (retries > 1) {
return measureSpeed(url, retries - 1);
}
}
clearTimeout(timeoutId);
const elapsed = (performance.now() - start) / 1000;
return success ? parseFloat(elapsed.toFixed(2)) : Infinity;
}
// 更新线路状态并选择最快线路
async function updateRoutes() {
let mainSpeeds = await Promise.all(routes.map(route => measureSpeed(route.url)));
let allMainFailed = mainSpeeds.every(speed => speed === Infinity);
let bestIndexes = [];
if (allMainFailed) {
// 如果所有主线路失败,则测试备用线路
let fallbackSpeeds = await Promise.all(fallbackUrls.map(url => measureSpeed(url)));
let minFallbackSpeed = Math.min(...fallbackSpeeds);
bestIndexes = fallbackSpeeds
.map((speed, index) => (speed === minFallbackSpeed ? index : -1))
.filter(index => index !== -1);
fastestUrl = fallbackUrls[bestIndexes[Math.floor(Math.random() * bestIndexes.length)]];
} else {
let minMainSpeed = Math.min(...mainSpeeds);
bestIndexes = mainSpeeds
.map((speed, index) => (speed === minMainSpeed ? index : -1))
.filter(index => index !== -1);
fastestUrl = routes[bestIndexes[Math.floor(Math.random() * bestIndexes.length)]].url;
}
// 更新按钮显示速度信息
routes.forEach((route, index) => {
let speed = mainSpeeds[index];
let speedText = speed === Infinity ? '超时' : `${speed}秒`;
let category = speed === Infinity ? '超时' : speed === Math.min(...mainSpeeds) ? '最快' : speed <= Math.min(...mainSpeeds) + 0.5 ? '较快' : '一般';
let color = category === '最快' ? '#008000' : category === '较快' ? '#4A7AC9' : category === '一般' ? '#808080' : '#FF0000';
route.element.style.backgroundColor = color;
route.element.style.color = "white";
route.element.innerText = `${route.text} → 点击前往 ${speedText} (${category})`;
});
clearTimeout(timeout);
startTimeout();
}
updateRoutes();
});