devshort

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/devshort.git
Log | Files | Refs | README | LICENSE

commit 3d4edb3a5bb02e12e504188f30d9911a9fd5d22a
parent a0b65e8d50a38c27636eece762a0e445a4f7657f
Author: Florian <flokX@users.noreply.github.com>
Date:   Sun, 29 Dec 2019 11:30:48 +0100

Add update checker

Call API and retrieve latest version

Diffstat:
Madmin.php | 8++++----
Massets/main.js | 13+++++++++++++
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/admin.php b/admin.php @@ -117,9 +117,9 @@ if ($config_content["settings"]["custom_links"]) { </form> </div> </div> - <div class="card d-none d-md-block"> + <div class="card d-none d-md-block mb-3"> <div class="card-body"> - <p class="mb-0">powered by <a href="https://github.com/flokX/devShort">devShort</a> v3.0.0</p> + <p class="mb-0" id="version-1">powered by <a href="https://github.com/flokX/devShort">devShort</a></p> </div> </div> <div class="card d-md-none mb-3"> @@ -131,14 +131,14 @@ if ($config_content["settings"]["custom_links"]) { </div> <div class="col-md-8 col-lg-9"> <div class="d-flex justify-content-center"> - <div class="spinner-border text-primary mt-4" id="spinner" role="status"> + <div class="spinner-border text-primary my-4" id="spinner" role="status"> <span class="sr-only">Loading...</span> </div> </div> <div id="charts"></div> </div> </div> - <p class="text-center d-md-none mt-1 mb-5">powered by <a href="https://github.com/flokX/devShort">devShort</a> v3.0.0</p> + <p class="text-center d-md-none mt-1 mb-5" id="version-2">powered by <a href="https://github.com/flokX/devShort">devShort</a></p> </div> </main> diff --git a/assets/main.js b/assets/main.js @@ -4,6 +4,7 @@ const startDate = new Date(new Date().setFullYear(currentDate.getFullYear() - 1) const spinner = document.getElementById('spinner'); const chartsDiv = document.getElementById('charts'); const statusDiv = document.getElementById('status'); +const version = "v3.0.0"; /* Helper function to post to page api */ function post(url, data) { @@ -68,6 +69,18 @@ function refreshCharts(event) { document.getElementById('refresh-1').addEventListener('click', refreshCharts); document.getElementById('refresh-2').addEventListener('click', refreshCharts); +/* Check for updates */ +fetch('https://devshort.flokX.dev/api.php?mode=version&current=' + version).then(function (response) { + return response.json(); +}).then(function (json) { + let inner = ' ' + version; + if (json['latest'] !== version) { + inner += ' <span class="text-warning">(<a class="text-warning" href="https://github.com/flokX/devShort/releases/latest">update available</a>!)</span>'; + } + document.getElementById('version-1').insertAdjacentHTML('beforeend', inner); + document.getElementById('version-2').insertAdjacentHTML('beforeend', inner); +}); + /* Get charts and date (remove old when necessary) */ function getCharts() { 'use strict';