<!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: #ffffff;
    border-radius: 6px;
    font-size: 28px;
    font-weight: bold;
}
.card {
    width: min(530px, 100%);
    margin: 0 auto 12px;
    padding: 28px 18px;
    background: #ffffff;
    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: #ffffff;
    background: #080f36;
}
.tip {
    line-height: 1.8;
}
.domain {
    margin-top: 8px;
    color: #687088;
    word-break: break-all;
}
.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;
}
.backup-links a:hover {
    color: #ffffff;
    background: #080f36;
}
@media (max-width: 480px) {
    .button {
        width: 100%;
    }
    .backup-links {
        grid-template-columns: 1fr;
    }
}
</style>
</head>
<body>

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

<div class="card">
    <a id="jumpButton" class="button" href="#">
        正在检测
    </a>

    <div class="tip">
        <span id="countdown">--</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>
        <a href="https://d3g6r93gts396gf9.yuman.xin">地址二</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) {
    const result = [...list];

    for (let i = result.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        const temporary = result[i];

        result[i] = result[j];
        result[j] = temporary;
    }

    return result;
}

async function checkTarget(url, timeout = 4000) {
    const controller = new AbortController();

    const timer = setTimeout(function () {
        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() {
    const shuffledTargets = shuffle(targets);

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

    for (const target of shuffledTargets) {
        const hostname = new URL(target).hostname;

        domain.textContent = "正在检测：" + hostname;

        if (await checkTarget(target)) {
            return {
                target: target,
                detected: true
            };
        }
    }

    const randomIndex = Math.floor(
        Math.random() * shuffledTargets.length
    );

    return {
        target: shuffledTargets[randomIndex],
        detected: false
    };
}

async function start() {
    if (targets.length === 0) {
        button.textContent = "暂无跳转地址";
        button.removeAttribute("href");
        countdown.textContent = "--";
        domain.textContent = "没有配置跳转地址";
        return;
    }

    const result = await selectTarget();
    const target = result.target;
    const hostname = new URL(target).hostname;

    button.href = target;
    button.textContent = "点击立即跳转";

    if (result.detected) {
        domain.textContent = "即将前往：" + hostname;
    } else {
        domain.textContent = "检测未成功，随机前往：" + hostname;
    }

    countdown.textContent = "1 秒后自动跳转";

    setTimeout(function () {
        window.location.replace(target);
    }, 1000);
}

start();
</script>

</body>
</html>