<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>网站导航</title>
<style>
* {
    box-sizing: border-box;
}
body {
    margin: 0;
    min-height: 100vh;
    padding: 30px 16px;
    background: #050b2e;
    color: #080f36;
    font-family: Arial, "Microsoft YaHei", sans-serif;
    text-align: center;
}
.title {
    display: inline-block;
    margin-bottom: 25px;
    padding: 6px 12px;
    background: white;
    border-radius: 6px;
    font-size: 28px;
    font-weight: bold;
}
.card {
    width: min(530px, 100%);
    margin: 0 auto 12px;
    padding: 28px 18px;
    background: white;
    border-radius: 6px;
}
.button {
    display: block;
    width: 75%;
    margin: 0 auto 25px;
    padding: 10px;
    border: 3px solid #080f36;
    color: #080f36;
    text-decoration: none;
    font-size: 20px;
    font-weight: bold;
}
.button:hover {
    color: white;
    background: #080f36;
}
.tip {
    line-height: 1.8;
}
.domain {
    margin-top: 8px;
    color: #687088;
}
.backup-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 18px;
}
.backup-links a {
    padding: 9px;
    border: 1px solid #080f36;
    border-radius: 4px;
    color: #687088;
    text-decoration: none;
}
@media (max-width: 480px) {
    .button {
        width: 100%;
    }
}
</style>
</head>
<body>

<div class="title">网站导航</div>

<div class="card">
    <a id="jumpButton" class="button" href="#">
        点击立即跳转
    </a>

    <div class="tip">
        <span id="countdown">3</span> 秒后自动跳转
    </div>

    <div id="domain" class="domain"></div>
</div>

<div class="card">
    <strong>永久地址</strong>
    <div class="domain">seyudao.com</div>
</div>

<div class="card">
    <strong>备用地址</strong>

    <div class="backup-links">
        <a href="https://ddhyjn.com">地址一</a>
    </div>
</div>

<script>
const targets = [
    "https://ddhyjn.com",
    "https://d3g6r93gts396gf9.yuman.xin"
];

const button = document.getElementById("jumpButton");
const countdown = document.getElementById("countdown");
const domain = document.getElementById("domain");

function shuffle(list) {
    return [...list].sort(() => Math.random() - 0.5);
}

async function checkTarget(url, timeout = 1500) {
    const controller = new AbortController();
    const timer = setTimeout(() => controller.abort(), timeout);

    try {
        await fetch(url, {
            method: "GET",
            mode: "no-cors",
            cache: "no-store",
            signal: controller.signal
        });

        return true;
    } catch (error) {
        return false;
    } finally {
        clearTimeout(timer);
    }
}

async function selectTarget() {
    domain.textContent = "正在检测可用地址……";
    button.textContent = "正在检测";
    button.removeAttribute("href");

    // 随机检测，避免总是优先使用同一个站点
    for (const target of shuffle(targets)) {
        domain.textContent =
            "正在检测：" + new URL(target).hostname;

        if (await checkTarget(target)) {
            return target;
        }
    }

    return null;
}

async function start() {
    const target = await selectTarget();

    if (!target) {
        countdown.textContent = "--";
        domain.textContent = "暂时没有检测到可用地址";
        button.textContent = "重新检测";
        button.href = "javascript:location.reload()";
        return;
    }

    button.href = target;
    button.textContent = "点击立即跳转";
    domain.textContent =
        "即将前往：" + new URL(target).hostname;

    let seconds = 3;
    countdown.textContent = seconds;

    const timer = setInterval(() => {
        seconds--;
        countdown.textContent = seconds;

        if (seconds <= 0) {
            clearInterval(timer);
            window.location.replace(target);
        }
    }, 1000);
}

start();
</script>

</body>
</html>