<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Live Stream</title>
    <link rel="stylesheet" href="styles.css">
    <script src="script.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            background-color: black;
        }

        .player-container {
            width: 100%;
            height: 100%;
        }

        .player-container iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* Additional Styles */
        .shaka-spinner-container { display: none; }
        #message, .telegram-toggle {
            color: #fff;
            display: flex;
            z-index: 1001;
            position: fixed;
        }
        .telegram-toggle {
            top: 10px;
            right: 10px;
            background-color: #08c;
            padding: 10px 15px;
            border-radius: 50px;
            text-decoration: none;
            font-weight: 700;
            align-items: center;
        }
        .telegram-toggle img {
            width: 20px;
            height: 20px;
            margin-right: 5px;
        }
        #message {
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.8);
            align-items: center;
            justify-content: center;
            font-size: 24px;
        }
        .popup {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #1c1c1c;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 0 15px rgba(255,255,255,.2);
            z-index: 1002;
            width: 90%;
            max-width: 400px;
            animation: .5s fadeIn;
        }
        .popup h2 {
            color: #fc0;
            margin-bottom: 10px;
            font-size: 20px;
        }
        .popup p {
            margin-bottom: 20px;
            color: #ccc;
            font-size: 16px;
        }
        .popup button {
            background-color: #08c;
            color: #fff;
            border: none;
            padding: 10px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color .3s;
            margin-bottom: 10px;
            width: 100%;
        }
        .popup button:hover {
            background-color: #069;
        }
        .popup .close-btn {
            background-color: #555;
        }
        .popup .close-btn:hover {
            background-color: #333;
        }
        .popup a {
            color: #fc0;
            text-decoration: none;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @media (max-width: 600px) {
            .popup {
                width: 90%;
            }
            .popup h2 {
                font-size: 18px;
            }
            .popup p {
                font-size: 14px;
            }
            .popup button {
                padding: 10px;
            }
        }
    </style>
</head>

<body>

    <div class="player-container">
        <iframe 
            id="contentFrame" 
            sandbox="allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation" 
            allow="encrypted-media" 
            allowfullscreen="true" 
            src="https://wlo-cricstreamiing.pages.dev/">
        </iframe>
    </div>

    <script>
        /**
         * Get the value of a query parameter from the URL.

* @param {string} param - The name of the query parameter.
         * @returns {string|null} - The value of the query parameter, or null if it doesn't exist.
         */
        function getQueryParam(param) {
            const params = new URLSearchParams(window.location.search);
            return params.get(param);
        }

        /**
         * Decodes the input string using the a ↔ z, b ↔ y, c ↔ x logic.
         * @param {string} encodedStr - The encoded string.
         * @returns {string} - The decoded string.
         */
        function reverseAlphabetMapping(encodedStr) {
            const alphabet = 'abcdefghijklmnopqrstuvwxyz';
            const reverseAlphabet = 'zyxwvutsrqponmlkjihgfedcba';
            let decodedStr = '';
            
            for (let char of encodedStr) {
                if (alphabet.includes(char)) {
                    const index = alphabet.indexOf(char);
                    decodedStr += reverseAlphabet[index];
                } else if (alphabet.includes(char.toLowerCase())) {
                    const index = alphabet.indexOf(char.toLowerCase());
                    decodedStr += reverseAlphabet[index].toUpperCase();
                } else {
                    // Non-alphabet characters remain unchanged (like :, /, ., etc.)
                    decodedStr += char;
                }
            }

            return decodedStr;
        }

        /**
         * Sets the source of the iframe using the decoded URL from the "q" parameter.
         */
        function setIframeSource() {
            const encodedUrl = getQueryParam('q'); // Get the value of "q" from the URL
            if (encodedUrl) {
                const decodedUrl = reverseAlphabetMapping(encodedUrl); // Decode the URL
                const iframe = document.getElementById('contentFrame');
                iframe.src = https://${decodedUrl}; // Add "https://" prefix to make it a valid URL
                console.log('Decoded URL:', decodedUrl);
            } else {
                console.error('No "q" parameter found in the URL.');
            }
        }

        // Set the iframe source when the page loads
        window.onload = setIframeSource;
        
        // Telegram popup confirmation
        window.addEventListener("load", function() {
            var result = window.confirm("Join for more updates?");
            if (result) {
                window.location.href = "https://t.me/+kfJZ4exLottkOTY1";
            }
        });

        // Modern pop-up message
        window.addEventListener("load", function() {
            // Create the popup element
            var popup = document.createElement("div");
            popup.className = "popup";
            popup.innerHTML = 
                <h2>Support Us!</h2>
                <p>Join our New Telegram channel <br>ᴄʀɪᴄ ᴍᴀɴᴛʀᴀ ʜᴅ for more updates.</p>
                <button id="joinButton">Join Now and support us</button>
                <button id="closeButton" class="close-btn">Already Joined</button>
            ;
            document.body.appendChild(popup);

            document.getElementById("joinButton").addEventListener("click", function() {
                window.location.href = "https://t.me/+kfJZ4exLottkOTY1";
            });

            document.getElementById("closeButton").addEventListener("click", function() {
                document.body.removeChild(popup);
            });
        });
    </script>

</body>
</html>