web/marathon-serpentine-2018/reloader.php
author ymh <ymh.work@gmail.com>
Fri, 21 Sep 2018 13:58:48 +0200
changeset 1449 f337cfef91da
parent 1441 a0968287653f
child 1450 8066d700510c
permissions -rw-r--r--
Update php libraries

<?php
include_once('./config.php');
header("Content-type: application/x-javascript");
?>
var startYoutubeCode = "<?php echo($youtube_code ? $youtube_code : '') ?>";

function getCurrentYoutubeCode() {
    var resCode = null;
    var youtubeCodeList = [
    <?php foreach ($youtube_code_list as $time_entry): ?>
        [<?php echo($time_entry[0]->getTimestamp() * 1000); ?>, <?php echo($time_entry[1]->getTimestamp() * 1000); ?>, "<?php echo($time_entry[2]);?>"],
    <?php endforeach; ?>
    ];
    var currentTime = Date.now();
    youtubeCodeList.some(function(timeEntry) {
        if(currentTime >= timeEntry[0] && currentTime <= timeEntry[1]) {
            resCode = timeEntry[2];
            return true;
        }
    });
    return resCode ? resCode : '';
}

setInterval(function() {
    if(getCurrentYoutubeCode() !== startYoutubeCode) {
        window.location.reload(true);
    }
}, 5000);