<!DOCTYPE html>
<html lang="el">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Αποτροπή Ποντικιών με Υπερηχητικό Ήχο</title>
    <style>
        #youtubePlayer {
            width: 0;
            height: 0;
            visibility: hidden;
        }
        .button-container {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        button {
            margin: 0 10px;
            padding: 10px 20px;
        }
        #pauseButton {
            display: none;
        }
    </style>
</head>
<body>

    <iframe id="youtubePlayer" src="https://www.youtube.com/embed/NCpL8xpzafE?enablejsapi=1" frameborder="0" allow="autoplay; encrypted-media"></iframe>

    <script>
        var player;
        var audioCtx;
        var oscillator;
        var frequencyInterval;
        const appStartTime = localStorage.getItem('appStartTime');
        const currentTime = Date.now();

        // Ελέγχει αν έχει περάσει το όριο των 48 ωρών
        if (appStartTime) {
            const elapsedTime = currentTime - parseInt(appStartTime);
            if (elapsedTime > 48 * 60 * 60 * 1000) {
                document.body.innerHTML = "<h1>Η εφαρμογή έληξε</h1>";
            }
        } else {
            localStorage.setItem('appStartTime', currentTime);
        }

        // Ανίχνευση αν η συσκευή είναι desktop
        const isDesktop = /Win|Mac|Linux/.test(navigator.platform);
        if (isDesktop) {
            document.body.innerHTML = "<h1>When downloaded on a desktop computer, this program self-destructs completely.</h1>";
        }

        function onYouTubeIframeAPIReady() {
            player = new YT.Player('youtubePlayer', {
                events: {
                    'onReady': onPlayerReady
                }
            });
        }

        function onPlayerReady(event) {
        }

        function startOscillator() {
            audioCtx = new (window.AudioContext || window.webkitAudioContext)();
            oscillator = audioCtx.createOscillator();
            oscillator.type = 'sine';
            oscillator.connect(audioCtx.destination);
            oscillator.start();

            frequencyInterval = setInterval(() => {
                let randomFrequency = 5000 + Math.random() * 3000;
                oscillator.frequency.setValueAtTime(randomFrequency, audioCtx.currentTime);
            }, 1000);
        }

        function stopOscillator() {
            clearInterval(frequencyInterval);
            if (oscillator) {
                oscillator.stop();
                oscillator.disconnect();
            }
            if (audioCtx) {
                audioCtx.close();
            }
        }

        function playSound() {
            document.getElementById('playButton').style.display = 'none';
            document.getElementById('pauseButton').style.display = 'inline';

            player.playVideo();
            startOscillator();
        }

        function pauseSound() {
            document.getElementById('pauseButton').style.display = 'none';
            document.getElementById('playButton').style.display = 'inline';

            player.pauseVideo();
            stopOscillator();
        }
    </script>

    <div class="button-container">
        <button id="playButton" onclick="playSound()">Play Sound</button>
        <button id="pauseButton" onclick="pauseSound()">Pause Sound</button>
    </div>

    <script src="https://www.youtube.com/iframe_api"></script>

</body>
</html>
