<!DOCTYPE html>

<html>

<head>

    <title>Slideshow Instantâneo</title>

    <style>

        body {

            margin: 0;

            padding: 0;

        }

        img {

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            object-fit: cover;

            display: none;

        }

    </style>

</head>

<body>



<div id="slideshow"></div>



<script>

    const slideshow = document.getElementById("slideshow");



   fetch('ads4.php?rnd=' + Math.random(), { cache: 'no-store' })



        .then(r => r.json())

        .then(data => {

            const urls = data.map(o => o.AdUrl);

            shuffle(urls);

            loadSlides(urls);

        });



    // embaralhamento real

    function shuffle(arr) {

        for (let i = arr.length - 1; i > 0; i--) {

            const j = Math.floor(Math.random() * (i + 1));

            [arr[i], arr[j]] = [arr[j], arr[i]];

        }

    }



    function loadSlides(urls) {

        urls.forEach(url => {

            const img = document.createElement("img");

            img.src = url;

            slideshow.appendChild(img);

        });

        startSlides();

    }



    let index = 0;



    function startSlides() {

        const slides = slideshow.querySelectorAll("img");



        slides.forEach(s => s.style.display = "none");



        slides[index].style.display = "block";



        index++;

        if (index >= slides.length) index = 0;



        setTimeout(startSlides, 5000);

    }

</script>



</body>

</html>