Skip to content

Instantly share code, notes, and snippets.

@CunningDJ
Created March 27, 2019 00:11
Show Gist options
  • Save CunningDJ/a485204b601c9b493a18016dea8b3f1a to your computer and use it in GitHub Desktop.
Save CunningDJ/a485204b601c9b493a18016dea8b3f1a to your computer and use it in GitHub Desktop.
United Flight Stats - use on United Inflight Website
/**
*
* % United Flight Stats %
* Paste into your browser after loading the inflight website (https://unitedwifi.com)
*
*/
// flight data API - used in the demo video
(function() {
const flightdataUrl = "https://services.inflightpanasonic.aero/inflight/services/flightdata/v1/flightdata";
let $indexHeader = $('#indexHeader');
function generateFlightDataMessage(flightdata) {
return "Alt: " + String(Number.parseInt(flightdata.td_id_fltdata_altitude))
+ " \n Speed: " + String(Number.parseInt(flightdata.td_id_fltdata_ground_speed))
+ " \n Distance: " + String(Number.parseFloat(flightdata.td_id_fltdata_distance_from_origin));
//+ " \n Distance: " + String(Number.parseInt(flightdata.td_id_fltdata_distance_to_destination));
}
function updateHeaderWithFlightData() {
$.get(flightdataUrl)
.then((data) => {
$indexHeader.html(generateFlightDataMessage(data))
})
}
setInterval(updateHeaderWithFlightData, 500);
})()
// Session data API - wouldn't work because of CORS objections (for the same domain)
// Function call not added to this, just keeping it here as demo code.
(function(){
const sessiondataUrl = "https://www.unitedwifi.com/portal/r/getAllSessionData";
const MILLISECONDS_PER_MINUTE = 60*1000;
function logMinutesRemaining(sessiondata) {
let currentDate = new Date();
let arrivalDate = new Date(sessiondata.flifo.estimatedArrivalTimeLocal);
console.log('Minutes Remaining:', Math.floor((arrivalDate-currentDate)/MILLISECONDS_PER_MINUTE));
}
function pingAndLogMinutesRemaining() {
$.get(sessiondataUrl).then(logMinutesRemaining);
}
setInterval(pingAndLogMinutesRemaining, 1000);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment