//Clickbot to download all delivery reports from DispatchTrack
<html>
    <head>

    </head>
    <body>
        <div id="links">
        <?php
        //http://10.1.1.41/DT_Fetch/getDTReports.php
        $prefix = "https://fam.dispatchtrack.com/download_delivery_report/";
        //load filenames into array, filter out anything starting with a dot
        $fileArr = preg_grep('/^([^.])/',scandir('DTHistoryNew'));
        //step through array to create links
        foreach ($fileArr as $file) {
            $dt = substr($file,0,10); // output like 2020-01-03
            $x = date('m-d-Y', strtotime($dt)); //rearrange the date format
            echo "<a href='".$prefix.$x."/".$x."/0/0/0/deliver-report.pdf' target='_blank'>$dt</a><br>";
        }
        ?>  
        </div>
    </body>
    <script>
        //javascript doesn't have a sleep function, so define one using Promise and setTimout
        function sleep(ms){
            return new Promise(resolve => setTimeout(resolve, ms));
        }
        async function doClick(){
            //var div = document.getElementById("links");
            var links = document.getElementsByTagName("a");
            if (links.length > 0){
                //alert(links.length);  //returns 3401
                for (var i = 0; i < links.length; i++){
                    //alert(links[i]); //test to see what is returned
                    links[i].click();
                    await sleep(60000);
                }
            }
        }
        window.onload = function(){
            doClick();
        };
    </script>
</html>
