versionDisplay() let data // Maybe this is a bad idea? init() async function init() { const headcode = await getQuery('headcode') if (headcode == 'false') { parse([]) // Pass an empty array to parse() } const res = await get(headcode) parse(res) } async function get(headcode) { const apiPath = `train/headcode/today/${headcode}` data = await getApi(apiPath, auth = true) if (typeof data == 'number' || !data) { log('train-detail.get: Status: ' + data, 'ERR') return [] } log(data, 'DBUG') return data } async function parse(data) { if (data.length >= 1) { document.getElementById('train_options').style = 'display:none;' displayOne(data[0]) } displayOptions(data) document.getElementById('train_data').style = 'display:block;' } async function displayOptions(data) { for (service in data) { if (data[service]) { const serviceData = data[service] const lastStop = serviceData?.stops[(serviceData['stops'].length - 1)] log(`displayOptions: data[${service}] = ${serviceData}`, 'dbug') let button = ` ` document.getElementById('train_options').insertAdjacentHTML('beforeend', button) } document.getElementById('train_options').style = 'display:block;' return data } } async function displayOne(object) { // Display a single service const dataTableHead = `
${object['headcode']}
PIS Code: ${object['pis']}
Location | Arr. | Dep. |
---|