|
|
|
@ -114,14 +114,25 @@ function refresh() {
|
|
|
|
|
reschedule(10000) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
return response.json() |
|
|
|
|
var cacheDate = response.headers.get('SW-Cached-At') |
|
|
|
|
return response.json().then(function (data) { |
|
|
|
|
data['$cacheDate'] = cacheDate |
|
|
|
|
return data |
|
|
|
|
}) |
|
|
|
|
}).then(function (response) { |
|
|
|
|
if (!response) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
var cacheDate = response['$cacheDate'] |
|
|
|
|
if (cacheDate) { |
|
|
|
|
cacheDate = new Date(cacheDate) |
|
|
|
|
} |
|
|
|
|
var success = !cacheDate |
|
|
|
|
stationData = response |
|
|
|
|
onStationData(response) |
|
|
|
|
reschedule() |
|
|
|
|
// Check in 1 seconds if network error
|
|
|
|
|
reschedule(success ? undefined : 1000) |
|
|
|
|
return success |
|
|
|
|
}).catch(function (e) { |
|
|
|
|
// Check in 1 second if network error
|
|
|
|
|
reschedule(1000) |
|
|
|
@ -136,7 +147,24 @@ window.addEventListener('unload', function (e) {
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function rsk() { |
|
|
|
|
refresh() |
|
|
|
|
function changeRskText(newText) { |
|
|
|
|
document.querySelectorAll('.rsk').forEach(function (elem) { |
|
|
|
|
elem.textContent = newText |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
changeRskText('Refreshing...') |
|
|
|
|
refresh().catch(function () { return false}).then(function (success) { |
|
|
|
|
if (!success) { |
|
|
|
|
changeRskText('Refreshing failed') |
|
|
|
|
setTimeout(function (_) { |
|
|
|
|
changeRskText('Refresh') |
|
|
|
|
}, 3000) |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
changeRskText('Refresh') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.addEventListener('load', function (e) { |
|
|
|
|