// source --> https://beritakotamakassar.com/wp-content/themes/generatepress/yt/syt.js 
    $(document).ready(function() {
            const channelId = 'UCAV2pns1cUCl5b0Itv5WoTw';  // YouTube Channel ID
            const videoCount = 6;  // Number of videos to display
            const videoList = $('#ytWrap');
            const feedUrl = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`;

            // CORS Proxy to bypass CORS issues
            const proxyUrl = 'https://api.allorigins.win/get?url=' + encodeURIComponent(feedUrl);

            // Step 1: Fetch the RSS feed (XML) from the channel using CORS proxy
            $.ajax({
                type: 'GET',
                url: proxyUrl,
                dataType: 'json',  // We expect the response to be a JSON object (from the proxy)
                success: function(response) {
                    // Check if we have valid data
                    const data = $(response.contents);  // Get the actual XML content from the proxy response
                    const entries = data.find('entry');
                    if (entries.length) {
                        // Loop through the entries and append video thumbnails and titles
                        entries.each(function(i, entry) {
                            const title = $(entry).find('title').text();
                            const link = $(entry).find('link').attr('href');
                            const thumbnailUrl = $(entry).find('media\\:thumbnail').attr('url') || $(entry).find('thumbnail').attr('url');
                            
                            // Append video item to the list
                            videoList.append(`
                                <div class="yt-grid-item">
                                    <div class="yt-thumb">
                                        <a href="${link}" target="_blank" class="item-link">
                                            <img src="${thumbnailUrl}" alt="${title}">
                                        </a>
                                    </div>
                                    <h5>${title}</h5>
                                </div>
                            `);
                            
                            // Limit the number of videos to display
                            if (i + 1 >= videoCount) return false;  // Stop after the specified count
                        });
                    } else {
                        // Handle the case where there are no videos
                        videoList.append('<p>No videos found on this channel.</p>');
                    }
                },
                error: function() {
                    videoList.append('<p class="error-message">Error loading videos. Please try again later.</p>');
                }
            });

            // Open modal on thumbnail click
            $(document).on('click', '.item-link', function(event) {
                event.preventDefault();
                const videoUrl = $(this).attr('href'); // Get the video link
                const videoId = new URL(videoUrl).searchParams.get('v');  // Extract the video ID from the URL

                if (videoId) {
                    $('#ytFrame').attr('src', `https://www.youtube.com/embed/${videoId}?autoplay=1`);  // Set the embed URL with autoplay
                    $('#ytTitle').text($(this).siblings('h5').text());  // Set the title of the video
                    $('#ytModal').addClass('show');  // Show the modal
                } else {
                    alert("Video ID not found.");
                }
            });

            // Close modal when clicking outside of it
            $(window).on('click', function(event) {
                if ($(event.target).is('#ytModal')) {
                    closeModal();
                }
            });

            // Close modal
            $('#closeModal').on('click', function() {
                closeModal();
            });

            // Function to close the modal
            function closeModal() {
                $('#ytModal').removeClass('show');  // Hide the modal
                $('#ytFrame').attr('src', '');  // Stop the video
                $('#ytTitle').text('');  // Clear the title
            }
        });