unction shuffleArray

unction shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } } // Function to refresh the page every 250 seconds function refreshPage() { var refreshInterval = 250000; // Refresh every 250 seconds setInterval(function () { location.reload(); }, refreshInterval); } // Function to open the modal, show the iframe with the link, and switch after 20 seconds function executeLoop(modalId, iframeId, links) { shuffleArray(links); // Shuffle the links randomly let currentIndex = 0; // Keep track of the current index in the links array function openLink() { var link = links[currentIndex]; openModal(modalId); // Open the modal validateLink(link, function (isValid) { if (isValid) { document.getElementById(iframeId).src = link; // Set the iframe's src to the link } else { console.error("Invalid link:", link); // Log if the link is invalid nextLink(); } }); setTimeout(function () { closeModal(modalId, iframeId); // Close the modal after 20 seconds currentIndex = (currentIndex + 1) % links.length; // Update the current index for the next link openLink(); // Open the next link }, 20000); // 20 seconds } openLink(); // Start opening the links } // Function to validate if a link is valid (i.e., does it exist?) function validateLink(link, callback) { var xhr = new XMLHttpRequest(); xhr.open('HEAD', link, true); xhr.onreadystatechange = function () { Modal and Iframe Example

Comments