From 5723906af96c9dcd7bdbf4fc2d0c19b63800d2e1 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Sat, 15 Apr 2017 14:19:48 +0000 Subject: [PATCH] Reload page on script changes --- index.js | 4 +++- common.js | 27 +++++++++++++++++++++++++++ version.php | 2 ++ lang_en.js | 1 + lang_pl.js | 1 + 5 files changed, 34 insertions(+), 1 deletions(-) diff --git a/common.js b/common.js index bd564a6..1f236aa 100644 --- a/common.js +++ b/common.js @@ -4,6 +4,33 @@ 'Zajezdnia Podgórze' : 'P', }; +var script_version; +var script_version_xhr; + +// Check for website updates +function checkVersion() { + if(script_version_xhr) script_version_xhr.abort(); + + script_version_xhr = $.get( + 'version.php' + ).done(function(data) { + if(!script_version) { + script_version = data; + return; + } + + if(script_version != data) { + fail(lang.error_new_version); + location.reload(true); + } + }); +} + +function checkVersionInit() { + checkVersion(); + setInterval(checkVersion, 3600000); +} + // Webservice-related functions function parseVehicle(vehicleId) { if(!vehicleId) return; diff --git a/index.js b/index.js index 8a13dcc..30ff195 100644 --- a/index.js +++ b/index.js @@ -115,7 +115,7 @@ setText(alert_text, message); alert.style.display = 'block'; - console.log(message + ' More details follow.'); + console.log(message + (more ? ' More details follow.' : '')); if(more) console.log(more); } @@ -437,6 +437,8 @@ hash(); window.addEventListener('hashchange', hash); + + checkVersionInit(); } init(); diff --git a/lang_en.js b/lang_en.js index 3508f47..5f10c13 100644 --- a/lang_en.js +++ b/lang_en.js @@ -63,4 +63,5 @@ error_request_failed: 'Internet request failed.', error_request_failed_status: 'Internet request failed with error: $status.', error_request_failed_connectivity: 'Request failed - please check your network connectivity.', + error_new_version: 'Website has been updated, reloading...', }; diff --git a/lang_pl.js b/lang_pl.js index c918c5c..92a95ac 100644 --- a/lang_pl.js +++ b/lang_pl.js @@ -63,4 +63,5 @@ error_request_failed: 'Wykonanie żądania internetowego nie udało się.', error_request_failed_status: 'Wykonanie żądania internetowego nie udało się. Błąd: $status.', error_request_failed_connectivity: 'Wykonanie żądania internetowego nie udało się - sprawdź połączenie z siecią.', + error_new_version: 'Strona została zaktualizowana, przeładowuję...', }; diff --git a/version.php b/version.php new file mode 100644 index 0000000..569683e --- /dev/null +++ b/version.php @@ -0,0 +1,2 @@ +<?php +echo max(array_map('filemtime', glob('*.{html,js,css}', GLOB_NOSORT|GLOB_BRACE))); -- Gitblit v1.9.1