-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (67 loc) · 2.07 KB
/
Copy pathscript.js
File metadata and controls
78 lines (67 loc) · 2.07 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const app = {};
let trainsEastbound;
let eastboundTimes;
let trainsWestbound;
let westboundTimes;
app.displayTrainTimes = function() {
$('.eastboundTimes').append(`
<li>${eastboundTimes[0]}</li>
<li>${eastboundTimes[1]}</li>
<li>${eastboundTimes[2]}</li>
`);
$('.westboundTimes').append(`
<li>${westboundTimes[0]}</li>
<li>${westboundTimes[1]}</li>
<li>${westboundTimes[2]}</li>
`);
};
app.getTrainTimes = function(query) {
$.ajax({
url: 'http://proxy.hackeryou.com',
method: "GET",
dataType: "json",
data: {
reqUrl: `https://myttc.ca/${query}_station.json`,
params: {
method: 'GET',
dataType: 'json'
}
}
}).then(function (res) {
if (query === 'ossington') {
trainsEastbound = res.stops[4].routes[0].stop_times;
trainsWestbound = res.stops[6].routes[0].stop_times;
} else {
// (query === 'christie')
trainsEastbound = res.stops[2].routes[0].stop_times;
trainsWestbound = res.stops[5].routes[0].stop_times;
};
eastboundTimes = [
trainsEastbound[0].departure_time,
trainsEastbound[1].departure_time,
trainsEastbound[2].departure_time
];
westboundTimes = [
trainsWestbound[0].departure_time,
trainsWestbound[1].departure_time,
trainsWestbound[2].departure_time
];
console.log(`eastbound times: ${eastboundTimes.join(', ')}`);
console.log(`westbound times: ${westboundTimes.join(', ')}`);
app.displayTrainTimes();
});
};
app.getStationSelection = function() {
$('.stationSelect').on('change', function() {
const selection = $('option:selected').val();
$('.eastboundTimes').empty();
$('.westboundTimes').empty();
app.getTrainTimes(selection);
});
};
app.init = function(){
app.getStationSelection();
};
$(document).ready(function() {
app.init();
});