summaryrefslogtreecommitdiff
path: root/static/js/reload.js
blob: 2a3fbf37384ebbfdc90cc32cab7acceb89010ea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
document.addEventListener("DOMContentLoaded", function() {
	const departureList = document.getElementById('departurelist');
	const syncFailedMarker = document.getElementById('syncfailedmarker');

	const showDepartures = (departureText) => {
		departureList.innerHTML = departureText;
	};

	const fetchDepartures = () => {
		var fetchUrl = window.location.href;
		if (fetchUrl.includes("?")) {
			fetchUrl += "&ajax=1";
		} else {
			fetchUrl += "?ajax=1";
		}
		fetch(fetchUrl)
			.then(response => {
				if (!response.ok) {
					throw Error(response.statusText);
				}
				return response.text()
			})
			.then(departureText => {
				syncFailedMarker.style.display = "none";
				showDepartures(departureText);
			})
			.catch(err => {
				syncFailedMarker.style.display = "inline-block";
			});
	};

	setInterval(fetchDepartures, 60000);
});