<?php
// Define available routes and corresponding script URLs
$routes = [
    "bahamut" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/bahamuts.js",
    "steam" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/steam.js",
    "bilibili" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/bilibili.js",
    "spotify" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/spotify.js",
    "scamalytics" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/scamalytics.js",
    "disney" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/disney.js",
    "netflix" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/netflix.js",
    "chatgpt" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/chatgpt.js",
    "tiktok" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/tiktok.js",
    "youtube" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/youtube.js",
    "max" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/max.js",
    "primevideo" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/primevideo.js",
    "bing" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/bing.js",
    "nicovideo" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/niconico.js",
    "googleplay" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/googleplay.js",
    "wikipedia" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/wikipedia.js",
    "starz" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/starz.js",
    "iqiyi" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/iqiyi.js",
    "dazn" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/dazn.js",
    "paramountplus" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/paramountplus.js",
    "viutv" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/viutv.js",
    "nowe" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/nowe.js",
    "kktv" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/kktv.js",
    "linetv" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/linetv.js",
    "ip" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/ip.js",
    "dns" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/surfsharkdns.js",
    "front-end" => "https://raw.githubusercontent.com/huskydsb/Shadowrocket/main/Streaming/js/front-end.js"
];

// Get the requested route from URL
$route = $_GET['route'] ?? '';

// If the route exists, fetch the script and return it
if (isset($routes[$route])) {
    header("Content-Type: application/javascript");

    // Fetch the script content
    $scriptContent = file_get_contents($routes[$route]);

    // Check if the script was successfully fetched
    if ($scriptContent !== false) {
        echo $scriptContent;
    } else {
        http_response_code(500);
        echo "Error: Failed to load script.";
    }
    exit;
}

// Display a simple HTML page for the homepage
if ($route === '') {
    ?>
    <!DOCTYPE html>
    <html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>流媒体解锁测试</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                text-align: center;
                padding: 20px;
            }
            h1 {
                color: #333;
            }
            ul {
                list-style-type: none;
                padding: 0;
            }
            li {
                margin: 10px 0;
            }
            a {
                text-decoration: none;
                color: #007bff;
                font-size: 18px;
            }
            a:hover {
                text-decoration: underline;
            }
        </style>
    </head>
    <body>
        <h1>流媒体解锁测试</h1>
        <p>点击以下链接测试各个流媒体平台的解锁情况：</p>
        <ul>
            <?php
            foreach ($routes as $name => $url) {
                echo "<li><a href='/$name/' target='_blank'>" . ucfirst($name) . "</a></li>";
            }
            ?>
        </ul>
    </body>
    </html>
    <?php
    exit;
}

// If route is invalid, return 404
http_response_code(404);
echo "404 Not Found";
?>
