{% extends 'template.html' %}

{% set styles=['sidebar'] %}



{% block content %}

{% include 'sidebar.html' %}

<div id='update' class='column-left'>
    <h2>Update</h2>
    
    
    <p id='pub-date'>Accessing GitHub's API...</p>
    
    <p>To do: add an Update button!</p>
    <div style='text-align:center'>
        <img src={{url_for('static',filename='img/github.png')}}>
    </div>


</div>
{% endblock %}



{% block scripts %}
<script src='{{ url_for("static", filename="js/jquery.min.js") }}'></script>
<script type='text/javascript'>
// Grab the publishing date of the latest release from GitHub's API and log it to the console:

String.prototype.format = function() {
    var s = this,
        i = arguments.length;
    while (i--) {s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);}
    return s;
};

$.getJSON('https://api.github.com/repos/bas-stringer/scry/releases/latest', function(data) {
    var pub = data['published_at'].split('T');
    $('#pub-date')[0].innerText = "SCRY's latest release ({0}) was published on GitHub {1} at {2}.".format(data['tag_name'], pub[0], pub[1].slice(0,-1));
})
</script>
{% endblock %}