<!DOCTYPE html>
<html lang="tr">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.2/plyr.css" />
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;800&amp;amp;display=swap" rel="stylesheet" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta name="robots" content="noindex" />
    <meta name="IzlenenSiteName" content="testt" />
    <meta name="matchhlsurl"
        content="https://cdn.quertinoxer.xyz/v/<%=id%>/index.css?token=848388441032e198f40e1e237ff14d6240ec09e1-f511cbab0f8193776f5881edb85b3df1-1732665236-1732654436" />
    <meta name="adsUrl" content="http://localhost:3001/ForBiggerEscapes.mp4" />
    <meta name="devicetype" content="desktop" />
    <meta name="matchid" content="<%=id%>" />
    <style>
        * {
            box-sizing: border-box
        }

        body {
            padding: 0;
            margin: 0;
            height: 100vh;
            width: 100%;
            font-family: "Inter", Arial, sans-serif
        }

        video {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
        }

        [data-plyr="play"]:not(.plyr__controls__item) {
            background: #22c55e !important
        }



        [data-plyr="volume"] {
            color: #22c55e !important
        }

        .fa-primary {
            opacity: .6
        }

        .fa-seconday {
            opacity: .3
        }

        .feedback-form {
            display: none
        }


        .ads {
            position: fixed;
            bottom: 3em;
            right: 0;
            z-index: 9999;
            border: 1px solid rgba(255, 255, 255, 0.5);
            border-right: 0;
            -moz-box-sizing: content-box;
            box-sizing: content-box;
            color: #fff;
            direction: ltr;
            font-size: 18px;
            line-height: normal;
            min-width: 0;
            padding: 10px 6px 8px 10px;
            width: auto;
            text-align: center;
            cursor: pointer;
            opacity: .5
        }

        .ads.active {
            opacity: 1
        }

        .plyr__progress {
            display: none;
        }
        .plyr__progress__container {
            display: none;
        }

        .logo-container {
            position: absolute;
            top: 20px;
            right: 10px;
            z-index: 10;
            user-select: none;
        }

        .logo {
            width: 150px;
            height: auto;
            user-select: none;
        }

    </style>
    <title>255987404066119680</title>
</head>

<body>
    <video id="player" playsinline="playsinline" preload="none" controls="controls"
        crossorigin="crossorigin"></video>

    <div class="logo-container">
        <img src="https://media.discordapp.net/attachments/1154524915706363945/1320104513721335880/9ec1772e-1e05-4b02-acca-f6d9c6ae7ad1.png?ex=676862a2&is=67671122&hm=ef6ae3d7a178d3aade11816c3ba5f10153ccbae027cd46a9b11f990bc6c398a0&=&format=webp&quality=lossless"
            alt="Logo" class="logo">
    </div>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.2/plyr.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.14.13/hls.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
    <script>
        let matchID = document.querySelector("meta[name='matchid']").content + document.querySelector("meta[name='IzlenenSiteName']").content
        if (!window.localStorage.getItem(matchID)) {
            window.localStorage.setItem(matchID, "true");
        }
        if (window.localStorage.getItem("plyr")) {
            window.localStorage.setItem("plyr", JSON.stringify({
                volume: "10",
            }));
        }
        let posterURL = "https://cdn.discordapp.com/attachments/1159519498764812390/1311382547443486731/image.png?ex=6748a7ab&is=6747562b&hm=43cf32400a380390a4214bb32320f901e7ca7934a400a99cc830583bae66015d&";

        let ads_isActive = document.querySelector("meta[name='IzlenenSiteName']").content == 'Aronshire';
        let adsObject = {
            autoplay: true,
            mute: true
        };
        if (ads_isActive) {
            adsObject = {}
        }
        const plyr = new Plyr('#player', {
            ...adsObject,
            //autoplay: true,
            controls: ['play-large',
                // 'restart',
                // 'rewind',
                'play',
                // 'fast-forward',
                'progress',
                'mute',
                'volume',
                'captions',
                'settings',
                'pip',
                'airplay',
                'fullscreen',],
            i18n: {
                play: 'Oynat',
                pause: 'Durdur',
                mute: 'Sesi Aç',
                unmute: 'Sesi Kapat'
            }
        });


        plyr.pip = true;

        plyr.on('canplay', () => {
            if (document.querySelector('.paused-screen')) {
                document.querySelectorAll('.paused-screen').forEach(item => item.remove())
            }
        })
        let video = document.querySelector('#player');
        let devicetype = document.querySelector("meta[name='devicetype']").content;
        let adsUrl = document.querySelector("meta[name='adsUrl']").content;
        let hlsSource = document.querySelector("meta[name='matchhlsurl']").content;
        video.addEventListener('ended', function () {
            if (document.querySelector('.ads')) document.querySelector('.ads').remove();
            video.poster = posterURL;

            playMatchHLS(hlsSource, true);
        });
        let playMatchHLS = function (HLS_URL, autoplay) {
            console.log(HLS_URL)
            if (Hls.isSupported()) {
                var hls = new Hls();
                hls.loadSource(HLS_URL);
                hls.attachMedia(video);
                hls.on(Hls.Events.MANIFEST_PARSED, function () {
                    if (autoplay == true) {
                        video.play();
                    }
                });
                hls.on(Hls.Events.ERROR, function (event, data) {
                    console.log(event, data)
                });
            } else {
                video.src = HLS_URL;
                video.load();
                video.addEventListener('canplay', function () {
                    if (autoplay == true) {
                        video.play();
                    }
                });
            }
        }
        if (document.querySelector("meta[name='IzlenenSiteName']").content == 'test') {

                     playMatchHLS(hlsSource, true);
        video.play();
            if (true) {
                //playMatchHLS(adsUrl, true);
                let adsCounter = 10;
                let adsInterval;
                // Reklam Geç Butonunu Oluştur
                const skipButton = $('<div>')
                    .addClass('ads') // Sağ altta görünecek
                    .text(`${adsCounter}sn / Reklamı Geç ->`) // Başlangıç metni
                    .appendTo('body'); // Sayfaya ekle

                function checkStoped() {

                }
                // Zamanlayıcı Başlat
                function startCountdown() {
                    adsInterval = setInterval(() => {
                        adsCounter--; // Geri sayımı azalt
                        skipButton.text(`${adsCounter}sn / Reklamı Geç ->`);

                        if (adsCounter <= 0) {
                            clearInterval(adsInterval); // Zamanlayıcıyı durdur
                            skipButton.text(`Reklamı Geç ->`).addClass('active'); // Butonu aktif yap
                        }
                    }, 1000);
                }

                // Geri Sayımı Durduran Fonksiyon
                function stopCountdown() {
                    clearInterval(adsInterval);
                }

                // Geç Butonuna Tıklama
                skipButton.on('click', function () {
                    if (adsCounter <= 0) {
                        clearInterval(adsInterval); // Zamanlayıcıyı durdur
                        $('#player').prop('muted', false); // Videonun sesini aç
                        $(this).remove(); // Butonu kaldır

                        video.poster = posterURL;

                        playMatchHLS(hlsSource, true);
                    }
                });

                $('#player').on('play', function () {
                    startCountdown();
                });

                // Video Duraklatıldığında Geri Sayımı Durdur
                $('#player').on('pause', function () {
                    stopCountdown();
                });

                video.src = adsUrl
                video.volume = 10;
            }
        } else {
            playMatchHLS(hlsSource, true);
            video.play();
        }
        window.addEventListener('pointerup', function (e) {
            if (e.target.closest('.ads.active')) {
                if (document.querySelector('.ads')) document.querySelector('.ads').remove();
                video.poster = posterURL;
                window.localStorage.setItem(matchID, "false");
                return playMatchHLS(hlsSource, true);
            }
            if (e.target.closest('.plyr__video-wrapper') && devicetype == 'mobile' && document.querySelector('.ads')) {
                if (video.paused == true) {
                    video.play();
                } else {
                    video.pause()
                }
            }
        })

        window.onload = () => {
            //playMatchHLS("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4", true)
        }
    </script>

</body>

</html>