1
0

Compare commits

..

4 Commits

Author SHA1 Message Date
0ec0d9164e Version 0.7 2020-09-21 16:22:40 +02:00
678d00a57b Ignore rows not containing any collectable data 2020-09-20 19:55:03 +02:00
7b3e750513 Change product naming scheme to match marudor 2020-09-20 15:51:31 +02:00
a216984bb4 Comment station links 2020-09-20 13:07:49 +02:00
2 changed files with 19 additions and 10 deletions

View File

@ -151,6 +151,10 @@ var connection_result_observer = new MutationObserver((mutations) => {
var relations = timetable.querySelectorAll("tr.first"); var relations = timetable.querySelectorAll("tr.first");
relations.forEach((relation, i) => { relations.forEach((relation, i) => {
var relationend = relation.nextElementSibling; var relationend = relation.nextElementSibling;
while(relationend.querySelector("td.station") == null) {
relationend = relationend.nextElementSibling;
}
data[i] = {}; data[i] = {};
data[i]["from"] = {} data[i]["from"] = {}
data[i]["to"] = {} data[i]["to"] = {}
@ -201,25 +205,25 @@ var connection_result_observer = new MutationObserver((mutations) => {
data[i]["products"][j] = {}; data[i]["products"][j] = {};
// Prodcut details // Prodcut details
data[i]["products"][j]["product"] = null; data[i]["products"][j]["type"] = null;
data[i]["products"][j]["train_id"] = null;
data[i]["products"][j]["train_number"] = null; data[i]["products"][j]["train_number"] = null;
data[i]["products"][j]["train_name"] = null;
data[i]["products"][j]["line_name"] = null; data[i]["products"][j]["line_name"] = null;
var name_list = train.innerText.trim().replace(/ +/g, ' ').split(" "); var name_list = train.innerText.trim().replace(/ +/g, ' ').split(" ");
// Product name in format "STB 12 (23561)" // Product 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) == ')') { 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]["type"] = name_list[0];
data[i]["products"][j]["train_id"] = name_list[2].substring(1, name_list[2].length-1) data[i]["products"][j]["train_number"] = name_list[2].substring(1, name_list[2].length-1)
data[i]["products"][j]["line_name"] = name_list[0] + " " + name_list[1]; data[i]["products"][j]["line_name"] = name_list[0] + " " + name_list[1];
} }
// Product name in format "ICE 234" // Product name in format "ICE 234"
else { else {
data[i]["products"][j]["product"] = name_list[0]; data[i]["products"][j]["type"] = name_list[0];
data[i]["products"][j]["train_id"] = name_list[1]; data[i]["products"][j]["train_number"] = name_list[1];
} }
data[i]["products"][j]["train_number"] = data[i]["products"][j]["product"] + " " + data[i]["products"][j]["train_id"]; data[i]["products"][j]["train_name"] = data[i]["products"][j]["type"] + " " + data[i]["products"][j]["train_number"];
}); });
// Travel information // Travel information
@ -240,6 +244,9 @@ var connection_result_observer = new MutationObserver((mutations) => {
var relations = timetable.querySelectorAll("tr.first"); var relations = timetable.querySelectorAll("tr.first");
relations.forEach((relation, i) => { relations.forEach((relation, i) => {
var relationend = relation.nextElementSibling; var relationend = relation.nextElementSibling;
while(relationend.querySelector("td.station") == null) {
relationend = relationend.nextElementSibling;
}
var products = relation.querySelectorAll("td.products span a"); var products = relation.querySelectorAll("td.products span a");
products.forEach((product, j) => { products.forEach((product, j) => {
@ -250,10 +257,10 @@ var connection_result_observer = new MutationObserver((mutations) => {
var departure_time = new Date(Date.parse(connection_result_date + " " + data[i]["from"]["time"])); var departure_time = new Date(Date.parse(connection_result_date + " " + data[i]["from"]["time"]));
// Button linking to marudor.de // Button linking to marudor.de
var marudor_button = domCreateButtonMarudor("/details/" + data[i]["products"][j]["train_number"] + "/" + departure_time.getTime()); var marudor_button = domCreateButtonMarudor("/details/" + data[i]["products"][j]["train_name"] + "/" + departure_time.getTime());
bahn_insight_field.appendChild(marudor_button); bahn_insight_field.appendChild(marudor_button);
var dbf_button = domCreateButtonDbf("/_wr/" + data[i]["products"][j]["train_id"] + "/" + datetimeToYYYYMMDDHHMM(departure_time)); var dbf_button = domCreateButtonDbf("/_wr/" + data[i]["products"][j]["train_number"] + "/" + datetimeToYYYYMMDDHHMM(departure_time));
bahn_insight_field.appendChild(dbf_button); bahn_insight_field.appendChild(dbf_button);
// Move linebreaks from link inner, after our 'bahn-insight' field // Move linebreaks from link inner, after our 'bahn-insight' field
@ -266,6 +273,7 @@ var connection_result_observer = new MutationObserver((mutations) => {
} }
}); });
// Linking to station
var from = relation.querySelector("td.station"); var from = relation.querySelector("td.station");
var bahn_insight_field = domCreateBahnInsightField(); var bahn_insight_field = domCreateBahnInsightField();
from.appendChild(bahn_insight_field); from.appendChild(bahn_insight_field);
@ -276,6 +284,7 @@ var connection_result_observer = new MutationObserver((mutations) => {
var dbf_button = domCreateButtonDbf("/" + data[i]["from"]["station"]); var dbf_button = domCreateButtonDbf("/" + data[i]["from"]["station"]);
bahn_insight_field.appendChild(dbf_button); bahn_insight_field.appendChild(dbf_button);
// Linking to station
var to = relationend.querySelector("td.station"); var to = relationend.querySelector("td.station");
var bahn_insight_field = domCreateBahnInsightField(); var bahn_insight_field = domCreateBahnInsightField();
to.appendChild(bahn_insight_field); to.appendChild(bahn_insight_field);

View File

@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Bahn Insight", "name": "Bahn Insight",
"version": "0.6", "version": "0.7",
"description": "Extends the booking portal of bahn.de with linking to useful information.", "description": "Extends the booking portal of bahn.de with linking to useful information.",
"homepage_url": "https://git.clerie.de/clerie/bahn-insight/", "homepage_url": "https://git.clerie.de/clerie/bahn-insight/",