<!-- Auto-modified logic added -->
<!DOCTYPE html>
<html lang="el">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Αποτροπή Ποντικιών με Υπερηχητικό Ήχο</title>
    <style>
        /* Κρύβουμε το iframe */
        #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; /* Κρύβουμε το Pause αρχικά */
        }
    </style>
</head>
<body>

    <!-- YouTube iframe embed -->
    <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 gainNode;
        var frequencyInterval;

        // Ρύθμιση του YouTube Player API
        function onYouTubeIframeAPIReady() {
            player = new YT.Player('youtubePlayer', {
                events: {
                    'onReady': onPlayerReady
                }
            });
        }

        function onPlayerReady(event) {
            // Εδώ μπορούμε να ξεκινήσουμε την αναπαραγωγή αν χρειαστεί
        }

        function startOscillator() {
            audioCtx = new (window.AudioContext || window.webkitAudioContext)();
            oscillator = audioCtx.createOscillator();
            gainNode = audioCtx.createGain();

            oscillator.type = 'sine';
            oscillator.connect(gainNode);
            gainNode.connect(audioCtx.destination);

            // Ρυθμίζουμε την ένταση στο μέγιστο επίπεδο dB που υποστηρίζεται
            gainNode.gain.setValueAtTime(1.0, audioCtx.currentTime);

            oscillator.start();

            // Ρυθμίζουμε την συχνότητα να αλλάζει μεταξύ 5kHz και 8kHz κάθε δευτερόλεπτο
            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 (gainNode) {
                gainNode.disconnect();
            }
            if (audioCtx) {
                audioCtx.close();
            }
        }

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

            player.playVideo(); // Ξεκινάμε το YouTube βίντεο
            startOscillator();  // Ξεκινάμε τον ηχητικό τόνο
        }

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

            player.pauseVideo(); // Παύση του YouTube βίντεο
            stopOscillator(); // Σταματάμε τον ηχητικό τόνο
        }
    </script>

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

    <!-- YouTube IFrame API -->
    <script src="https://www.youtube.com/iframe_api"></script>

</body>
</html>

<!-- End of auto-modifications -->