<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>TG @CRICSPORTCENTRAL</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      font-family: Arial, sans-serif;
      background-color: #000;
      color: #fff;
    }
    #player {
      position: absolute;
      width: 100% !important;
      height: 100% !important;
    }
    .watermark {
      position: absolute;
      top: 7px;
      left: 10px;
      z-index: 10;
    }
    .watermark img {
      width: 100px;
      opacity: 0.8;
    }
  </style>
  <script src="https://content.jwplatform.com/libraries/KB5zFt7A.js"></script>
</head>
<body>
  <div id="player"></div>
  <div class="watermark">
    <img src="https://i.postimg.cc/VsT7gT3R/Picsart-24-12-25-12-00-51-804.png" alt="Watermark">
  </div>
  <script>
          // Display Telegram pop-up on page load
    window.onload = function () {
      if (confirm("Join Our Telegram Channel @CRICSPORTCENTRAL")) {
        window.location.href = "https://t.me/CRICSPORTCENTRAL";
      }
    };
      
    // Extract match ID from the URL
    const urlParams = new URLSearchParams(window.location.search);
    const matchId = urlParams.get('id');

    // Fetch match data and initialize the player with the ad-free stream
    async function fetchVideoUrl() {
      try {
        const response = await fetch("https://raw.githubusercontent.com/drmlive/fancode-live-events/main/fancode.json");
        const data = await response.json();
        const match = data.matches.find(m => m.match_id === parseInt(matchId, 10));

        if (match) {
          return match.adfree_url; // Return the ad-free stream URL
        } else {
          console.error("Match not found for id:", matchId);
          return null;
        }
      } catch (error) {
        console.error("Error fetching match data:", error);
        return null;
      }
    }

    // Initialize the JWPlayer
    async function initializePlayer() {
      const videoUrl = await fetchVideoUrl();
      if (videoUrl) {
        jwplayer("player").setup({
          file: videoUrl,
          preload: "metadata",
          width: "100%",
          height: "100%",
        });
      } else {
        alert("Error: Unable to load the match stream.");
      }
    }

    initializePlayer();
  </script>
</body>
</html>