-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.js
28 lines (24 loc) · 1010 Bytes
/
info.js
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
let infoDiv = document.getElementById("infoDiv");
let planeToText = (plane) => {
const flight = plane.flight.trim();
let flightLink = `<a href='https://uk.flightaware.com/live/flight/${flight}' target="_blank">${flight}</a>`;
if(flight === "") flightLink = "No name";
const validString = plane.validposition ? "valid" : "invalid";
const positionString = plane.validposition ? `(${plane.lat},${plane.lon}@${plane.altitude})` : `(?,?@${plane.altitude})`;
const timeString = `Seen ${plane.seen}s ago`
return `${flightLink},(${plane.hex}): ${validString} - ${positionString}. ${timeString}`
};
let planesToText = (planes) => {
const values = Object.values(planes);
if(values.length == 0) return "None tracked";
let text = "";
values.forEach(plane => {
text += planeToText(plane);
text += "<br>\n";
});
return text;
}
let planeUpdate = (planes) => {
infoDiv.innerHTML = planesToText(planes);
};
window.planeAnnouncements.push(planeUpdate);