web/marathon-serpentine-2018/reloader.php
author ymh <ymh.work@gmail.com>
Sun, 23 Sep 2018 17:14:07 +0200
changeset 1479 2b510a3a0f7d
parent 1474 53f0f4ed20c8
permissions -rw-r--r--
Added tag V06.008 for changeset adb28b75f2c7
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
?>
1474
53f0f4ed20c8 Add support for extended tweets
ymh <ymh.work@gmail.com>
parents: 1450
diff changeset
     5
var startEmbedCode = '<?php echo(addslashes($islive_embed ? $islive_embed : '')) ?>';
1439
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
1450
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
     7
function getCurrentEmbedCode() {
1439
df4c992749ea Add dynamic code for youtube code and a automatic reloader
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    var resCode = null;
1450
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
     9
    var embedCodeList = [
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
    10
    <?php foreach ($embed_code_list as $time_entry): ?>
1474
53f0f4ed20c8 Add support for extended tweets
ymh <ymh.work@gmail.com>
parents: 1450
diff changeset
    11
        [<?php echo($time_entry[0]->getTimestamp() * 1000); ?>, <?php echo($time_entry[1]->getTimestamp() * 1000); ?>, '<?php echo(addslashes($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();
1450
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
    15
    embedCodeList.some(function(timeEntry) {
1439
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() {
1450
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
    25
    if(getCurrentEmbedCode() !== startEmbedCode) {
1439
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
    }
1450
8066d700510c Update serpentine's embed code
ymh <ymh.work@gmail.com>
parents: 1441
diff changeset
    28
}, 60000);