Create object containing all data for connection
This commit is contained in:
parent
0d16660d97
commit
357fff97f2
@ -70,6 +70,77 @@ var connection_result_observer = new MutationObserver((mutations) => {
|
||||
if (target.tagName === 'TD') {
|
||||
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
||||
|
||||
var data = [];
|
||||
|
||||
var relations = timetable.querySelectorAll("tr.first");
|
||||
relations.forEach((relation, i) => {
|
||||
var relationend = relation.nextElementSibling;
|
||||
data[i] = {};
|
||||
data[i]["from"] = {}
|
||||
data[i]["to"] = {}
|
||||
|
||||
var relation_from = relation.querySelector("td.station");
|
||||
data[i]["from"]["station"] = relation_from.innerText;
|
||||
|
||||
var relation_to = relationend.querySelector("td.station");
|
||||
data[i]["to"]["station"] = relation_to.innerText;
|
||||
|
||||
var relation_departure = relation.querySelector("td.time");
|
||||
var relation_departure_list = relation_departure.firstChild.textContent.trim().split(" ");
|
||||
data[i]["from"]["time"] = relation_departure_list[1];
|
||||
data[i]["from"]["time_current"] = null;
|
||||
var relation_departure_current = relation_departure.querySelector("span.delay, span.delayOnTime");
|
||||
if(typeof relation_departure_list !== 'undfined') {
|
||||
data[i]["from"]["time_current"] = relation_departure_current.innerText.trim();
|
||||
}
|
||||
|
||||
var relation_arrival = relationend.querySelector("td.time");
|
||||
var relation_arrival_list = relation_arrival.firstChild.textContent.trim().split(" ");
|
||||
data[i]["to"]["time"] = relation_arrival_list[1];
|
||||
data[i]["to"]["time_current"] = null;
|
||||
var relation_arrival_current = relation_arrival.querySelector("span.delay, span.delayOnTime");
|
||||
if(typeof relation_arrival_list !== 'undfined') {
|
||||
data[i]["to"]["time_current"] = relation_arrival_current.innerText.trim();
|
||||
}
|
||||
|
||||
var relation_platform = relation.querySelector("td.platform");
|
||||
data[i]["from"]["platform"] = relation_platform.innerText;
|
||||
|
||||
var relation_to_platform = relationend.querySelector("td.platform");
|
||||
data[i]["to"]["platform"] = relation_to_platform.innerText;
|
||||
|
||||
var relation_products = relation.querySelector("td.products");
|
||||
data[i]["products"] = [];
|
||||
|
||||
var relation_trains = relation_products.querySelectorAll("span a");
|
||||
relation_trains.forEach((train, j) => {
|
||||
data[i]["products"][j] = {};
|
||||
data[i]["products"][j]["product"] = null;
|
||||
data[i]["products"][j]["train_number"] = null;
|
||||
data[i]["products"][j]["line_name"] = null;
|
||||
|
||||
var name_list = train.innerText.trim().replace(/ +/g, ' ').split(" ");
|
||||
|
||||
// Train name in format "STB 12 (23561)"
|
||||
if(name_list.length == 3 && name_list[2].charAt(0) == '(' && name_list[2].charAt(name_list[2].length-1) == ')') {
|
||||
data[i]["products"][j]["product"] = name_list[0];
|
||||
data[i]["products"][j]["train_number"] = name_list[0] + " " + name_list[2].substring(1, name_list[2].length-1);
|
||||
data[i]["products"][j]["line_name"] = name_list[0] + " " + name_list[1];
|
||||
}
|
||||
else {
|
||||
data[i]["products"][j]["product"] = name_list[0];
|
||||
data[i]["products"][j]["train_number"] = name_list[0] + " " + name_list[1];
|
||||
}
|
||||
});
|
||||
|
||||
var relation_items = relation.querySelectorAll("td");
|
||||
var relation_info = relation_items[relation_items.length-1];
|
||||
data[i]["info"] = relation_info.innerText;
|
||||
|
||||
});
|
||||
|
||||
console.log(data);
|
||||
|
||||
var trains = timetable.querySelectorAll("tr.first td.products");
|
||||
trains.forEach((train) => {
|
||||
var train_names = train.querySelectorAll("span a");
|
||||
|
Loading…
Reference in New Issue
Block a user