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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1439
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
include_once('./config.php');
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
header("Content-type: application/x-javascript");
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
?>
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
var startYoutubeCode = "<?php echo($youtube_code ? $youtube_code : '') ?>";
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
function getCurrentYoutubeCode() {
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    var resCode = null;
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    var youtubeCodeList = [
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    <?php foreach ($youtube_code_list as $time_entry): ?>
1441
a0968287653f Correct syntax error on javascript declaration
ymh <ymh.work@gmail.com>
parents: 1439
diff changeset
    11
        [<?php echo($time_entry[0]->getTimestamp() * 1000); ?>, <?php echo($time_entry[1]->getTimestamp() * 1000); ?>, "<?php echo($time_entry[2]);?>"],
1439
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    <?php endforeach; ?>
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    ];
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    var currentTime = Date.now();
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    youtubeCodeList.some(function(timeEntry) {
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        if(currentTime >= timeEntry[0] && currentTime <= timeEntry[1]) {
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
            resCode = timeEntry[2];
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
            return true;
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        }
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    });
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    return resCode ? resCode : '';
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
}
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
setInterval(function() {
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    if(getCurrentYoutubeCode() !== startYoutubeCode) {
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        window.location.reload(true);
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    }
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
}, 5000);