<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>解析失败</title>
    <style>
        /* 1. 页面整体清新暗黑风 */
        body {
            background-color: #0f172a;
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            color: #f8fafc;
        }

        #player-shade {
            width: 100%;
            height: 100vh;
            position: fixed;
            opacity: 0;
            z-index: 10000;
            display: none;
        }

        #box {
            display: flex;
            width: 100%;
            height: 100vh;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            padding: 20px;
            box-sizing: border-box;
            text-align: center;
        }

        /* 2. 主提示文字美化 */
        #text {
            font-size: 1.25rem;
            font-weight: 600;
            color: #f1f5f9;
            margin-bottom: 25px;
            line-height: 1.6;
        }

        .sub-text {
            display: block;
            font-size: 0.95rem;
            color: #94a3b8;
            margin-top: 12px;
            font-weight: normal;
            line-height: 1.8;
        }

        /* 3. 清新现代风按钮 */
        #route-text {
            display: none;
            cursor: pointer;
            font-weight: 500;
            color: #ffffff;
            font-size: 16px;
            background: linear-gradient(135deg, #38bdf8, #0ea5e9);
            padding: 12px 36px;
            border-radius: 50px;
            box-shadow: 0 4px 15px rgba(14, 165, 233, 0.25);
            transition: all 0.2s ease;
            user-select: none;
            letter-spacing: 1px;
        }

        #route-text:hover {
            box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
            transform: translateY(-1px);
        }

        #route-text:active {
            transform: scale(0.96);
            box-shadow: 0 2px 8px rgba(14, 165, 233, 0.2);
        }

        /* 4. 按钮下方：当前线路提示框 */
        #route-name {
            display: none;
            margin-top: 16px;
            font-size: 13px;
            color: #cbd5e1;
            background-color: rgba(255, 255, 255, 0.05);
            padding: 6px 16px;
            border-radius: 20px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            letter-spacing: 0.5px;
        }

        /* 5. 侧边栏：毛玻璃质感 */
        #route-menu {
            position: fixed;
            z-index: 11000;
            right: 0;
            top: 0;
            width: 200px;
            height: 100vh;
            background-color: rgba(15, 23, 42, 0.85);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border-left: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: -5px 0 25px rgba(0,0,0,0.4);
            transform: translateX(100%);
            transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1);
            overflow-y: auto;
            display: none;
            padding: 20px 15px;
            box-sizing: border-box;
        }

        #route-menu::-webkit-scrollbar { width: 4px; }
        #route-menu::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

        /* 隐藏原有的那个不明显的提示文本 */
        .route-menu-title {
            display: none !important;
        }

        /* 6. 侧边栏按钮列表 */
        .route-menu-item {
            width: 100%;
            height: 44px;
            line-height: 44px;
            text-align: center;
            color: #e2e8f0;
            background-color: #1e293b;
            border-radius: 8px;
            margin-bottom: 12px;
            cursor: pointer;
            font-size: 14px;
            border: 1px solid rgba(255, 255, 255, 0.05);
            transition: all 0.2s ease;
            user-select: none;
        }

        /* 🌟 选中状态：浅蓝高亮显示 */
        .route-menu-item.active {
            background-color: rgba(14, 165, 233, 0.15) !important;
            color: #38bdf8 !important;
            border: 1px solid rgba(56, 189, 248, 0.4) !important;
            font-weight: 600;
        }

        .route-menu-item:hover:not(.active) {
            background-color: #334155;
            color: #38bdf8;
        }
    </style>
</head>
<body>
<div id="player-shade"></div>
<div id="box">
    <div id="text">No static resource sitemap.xml.</div>
    <div id="route-text">点此切换线路</div>
    <div id="route-name"></div>
    <div id="route-menu"></div>
</div>

<script id="TempScript">
    let RouteUrls = "";
</script>
<script src="/extend/layui/layui.js"></script>
<script src="/public/js/fail.js"></script>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        // 【逻辑1】拦截报错文字
        let textBox = document.getElementById('text');
        if (textBox && textBox.innerHTML.includes('没有匹配到解析接口')) {
            textBox.innerHTML = '没有匹配到解析接口！<br><span class="sub-text">如果你是网站管理员请检查接口配置<br>如果你是用户/使用者请检查输入链接是否正确</span>';
        }

        let routeMenu = document.getElementById('route-menu');
        
        // 【核心逻辑】更新侧边栏按钮状态
        function refreshRouteItems() {
            // 获取当前URL中的route参数
            const urlParams = new URLSearchParams(window.location.search);
            const currentRouteParam = urlParams.get('route'); // 比如 "1080P1"
            
            // 获取 fail.js 注入的文字内容来判定是否为“自动”
            let currentNameFromText = "";
            Array.from(routeMenu.childNodes).forEach(node => {
                let txt = node.textContent || node.innerText;
                if (txt && txt.includes('当前线路-')) {
                    currentNameFromText = txt.split('-')[1].trim();
                }
            });

            // 判断当前是否处于“自动”模式
            const isAuto = currentNameFromText === "自动" || !currentRouteParam;

            // 1. 处理“自动”按钮置顶
            let autoBtn = document.getElementById('auto-route-btn');
            if (!autoBtn) {
                autoBtn = document.createElement('div');
                autoBtn.id = 'auto-route-btn';
                autoBtn.className = 'route-menu-item';
                autoBtn.innerText = '自动';
                // 点击自动通常是不带参数刷新页面或由 fail.js 处理
                autoBtn.onclick = function() { 
                    const url = new URL(window.location.href);
                    url.searchParams.delete('route');
                    window.location.href = url.toString();
                };
                routeMenu.prepend(autoBtn);
            }

            // 2. 遍历所有按钮，更新文字和高亮样式
            let items = routeMenu.querySelectorAll('.route-menu-item');
            items.forEach(item => {
                // 排除自动按钮的特殊处理逻辑
                if (item.id === 'auto-route-btn') {
                    if (isAuto) {
                        item.innerText = "当前：自动";
                        item.classList.add('active');
                    } else {
                        item.innerText = "自动";
                        item.classList.remove('active');
                    }
                    return;
                }

                // 获取线路名（去掉可能已经存在的“当前：”前缀）
                let rawName = item.innerText.replace('当前：', '').trim();
                
                // 判定是否选中：通过文字匹配或者URL参数匹配
                // 这里的判断逻辑是：如果URL里的参数包含在按钮名里，或者按钮名等于当前线路文本
                if ((currentRouteParam && rawName.includes(currentRouteParam)) || rawName === currentNameFromText) {
                    item.innerText = "当前：" + rawName;
                    item.classList.add('active');
                } else {
                    item.innerText = rawName;
                    item.classList.remove('active');
                }
            });

            // 3. 同步主页面下方的提示框
            let routeNameDisplay = document.getElementById('route-name');
            if (routeNameDisplay && currentNameFromText) {
                routeNameDisplay.innerText = "当前使用线路：" + currentNameFromText;
                routeNameDisplay.style.display = "inline-block";
            }
        }

        if (routeMenu) {
            // 监听侧边栏内容的注入
            let observer = new MutationObserver(function() {
                // 每次 fail.js 改变内容时，我们执行一次重新格式化
                // 停止监听一瞬防止死循环，改完后再开启
                observer.disconnect();
                
                // 把原有的提示文字节点隐藏或包装
                Array.from(routeMenu.childNodes).forEach(node => {
                    if (node.nodeType === Node.TEXT_NODE && node.textContent.includes('当前线路')) {
                        let span = document.createElement('span');
                        span.className = 'route-menu-title'; // 样式里设置了 display: none
                        span.innerText = node.textContent;
                        node.parentNode.replaceChild(span, node);
                    } else if (node.nodeType === Node.ELEMENT_NODE && node.innerText.includes('当前线路')) {
                        node.classList.add('route-menu-title');
                    }
                });

                refreshRouteItems();
                
                observer.observe(routeMenu, { childList: true, subtree: true });
            });
            
            observer.observe(routeMenu, { childList: true, subtree: true });
            
            // 初次加载也执行一次
            setTimeout(refreshRouteItems, 100);
        }
    });
</script>
</body>
</html>
