Compare commits
No commits in common. "76febca006ac250dcb553cba622c00d692650db2" and "0d16660d97cec5be1b2c84e0b647e3db3232f312" have entirely different histories.
76febca006
...
0d16660d97
@ -32,241 +32,74 @@ function bahnParseTrainName(dirty_train_name) {
|
|||||||
return dirty_train_name;
|
return dirty_train_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns HTML a as DOM object
|
|
||||||
*
|
|
||||||
* @param href URI as string
|
|
||||||
*/
|
|
||||||
function domCreateLink(href) {
|
function domCreateLink(href) {
|
||||||
var link = document.createElement("a");
|
var link = document.createElement("a");
|
||||||
link.setAttribute("href", href);
|
link.setAttribute("href", href);
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns HTML img as DOM object
|
|
||||||
*
|
|
||||||
* @param src Image URI as string
|
|
||||||
*/
|
|
||||||
function domCreateImage(src) {
|
function domCreateImage(src) {
|
||||||
var image = document.createElement("img");
|
var image = document.createElement("img");
|
||||||
image.setAttribute("src", src);
|
image.setAttribute("src", src);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns HTML br as DOM object
|
|
||||||
*/
|
|
||||||
function domCreateLinebreak() {
|
function domCreateLinebreak() {
|
||||||
var linebreak = document.createElement("br");
|
var linebreak = document.createElement("br");
|
||||||
return linebreak;
|
return linebreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns HTML span as DOM object
|
|
||||||
*/
|
|
||||||
function domCreateSpan() {
|
|
||||||
var span = document.createElement("span");
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an 'image button' like construct as DOM object
|
|
||||||
*
|
|
||||||
* @param href URI as string
|
|
||||||
* @param image_src Image URI as string
|
|
||||||
*/
|
|
||||||
function domCreateButton(href, image_src) {
|
function domCreateButton(href, image_src) {
|
||||||
var link = domCreateLink(href);
|
var link = domCreateLink(href);
|
||||||
link.setAttribute("target", "_blank");
|
link.setAttribute("target", "_blank");
|
||||||
var image = domCreateImage(image_src);
|
var image = domCreateImage(image_src);
|
||||||
image.setAttribute("style", "height: 16px; vertical-align:middle;");
|
image.setAttribute("style", "height: 2em; vertical-align:middle;")
|
||||||
link.append(image);
|
link.append(image);
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an 'image buttom' to specifically link to marudor.de
|
|
||||||
*
|
|
||||||
* @param path URL path part after https://marudor.de
|
|
||||||
*/
|
|
||||||
function domCreateButtonMarudor(path) {
|
function domCreateButtonMarudor(path) {
|
||||||
var button = domCreateButton("https://marudor.de" + path, getMediaURL("marudor.svg"));
|
var button = domCreateButton("https://marudor.de" + path, getMediaURL("marudor.svg"));
|
||||||
button.setAttribute("title", "marudor.de");
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an 'image buttom' to specifically link to dbf.finalrewind.org
|
|
||||||
*
|
|
||||||
* @param path URL path part after https://dbf.finalrewind.org
|
|
||||||
*/
|
|
||||||
function domCreateButtonDbf(path) {
|
|
||||||
var button = domCreateButton("https://dbf.finalrewind.org" + path, getMediaURL("dbf.png"));
|
|
||||||
button.setAttribute("title", "dbf.finalrewind.org");
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a 'bahn-insight' element as DOM object
|
|
||||||
*
|
|
||||||
* Used to determine if this is an object set by this extension itself
|
|
||||||
*/
|
|
||||||
function domCreateBahnInsightField() {
|
|
||||||
var span = domCreateSpan();
|
|
||||||
span.setAttribute("class", "bahn-insight");
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
var connection_result_observer = new MutationObserver((mutations) => {
|
var connection_result_observer = new MutationObserver((mutations) => {
|
||||||
log("change detected")
|
|
||||||
|
|
||||||
mutations.forEach((mutation) => {
|
mutations.forEach((mutation) => {
|
||||||
if (mutation.type === 'childList') {
|
if (mutation.type === 'childList') {
|
||||||
var target = mutation.target;
|
var target = mutation.target;
|
||||||
if (target.tagName === 'TD') {
|
if (target.tagName === 'TD') {
|
||||||
log("change is interesting");
|
|
||||||
|
|
||||||
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
||||||
|
|
||||||
/*
|
var trains = timetable.querySelectorAll("tr.first td.products");
|
||||||
* COLLECT DATA
|
trains.forEach((train) => {
|
||||||
*/
|
var train_names = train.querySelectorAll("span a");
|
||||||
var data = [];
|
train_names.forEach((train_name) => {
|
||||||
var relations = timetable.querySelectorAll("tr.first");
|
train_name_text = bahnParseTrainName(train_name.innerText);
|
||||||
relations.forEach((relation, i) => {
|
if(typeof train_name_text !== 'undefined') {
|
||||||
var relationend = relation.nextElementSibling;
|
var marudor_button = domCreateButtonMarudor("/details/" + train_name_text);
|
||||||
data[i] = {};
|
train_name.after(marudor_button);
|
||||||
data[i]["from"] = {}
|
|
||||||
data[i]["to"] = {}
|
|
||||||
|
|
||||||
// Depature station name
|
// Move linebreaks from link inner, after our button
|
||||||
var relation_from = relation.querySelector("td.station");
|
linebreaks = train_name.querySelectorAll("br");
|
||||||
data[i]["from"]["station"] = relation_from.innerText;
|
if(linebreaks.length != 0) {
|
||||||
|
linebreaks.forEach((linebreak) => {
|
||||||
|
train_name.removeChild(linebreak);
|
||||||
|
});
|
||||||
|
|
||||||
// Arrival station name
|
marudor_button.after(domCreateLinebreak());
|
||||||
var relation_to = relationend.querySelector("td.station");
|
}
|
||||||
data[i]["to"]["station"] = relation_to.innerText;
|
|
||||||
|
|
||||||
// Departure time & current estimation
|
|
||||||
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(relation_departure_current != null) {
|
|
||||||
data[i]["from"]["time_current"] = relation_departure_current.innerText.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arrival time & current estimation
|
|
||||||
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(relation_arrival_current != null) {
|
|
||||||
data[i]["to"]["time_current"] = relation_arrival_current.innerText.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Departure platform
|
|
||||||
var relation_platform = relation.querySelector("td.platform");
|
|
||||||
data[i]["from"]["platform"] = relation_platform.innerText;
|
|
||||||
|
|
||||||
// Arrival platform
|
|
||||||
var relation_to_platform = relationend.querySelector("td.platform");
|
|
||||||
data[i]["to"]["platform"] = relation_to_platform.innerText;
|
|
||||||
|
|
||||||
// Travel products
|
|
||||||
var relation_products = relation.querySelector("td.products");
|
|
||||||
data[i]["products"] = [];
|
|
||||||
|
|
||||||
// Fetch all products for this travel
|
|
||||||
var relation_trains = relation_products.querySelectorAll("span a");
|
|
||||||
relation_trains.forEach((train, j) => {
|
|
||||||
data[i]["products"][j] = {};
|
|
||||||
|
|
||||||
// Prodcut details
|
|
||||||
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(" ");
|
|
||||||
|
|
||||||
// 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) == ')') {
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
// Product name in format "ICE 234"
|
|
||||||
else {
|
|
||||||
data[i]["products"][j]["product"] = name_list[0];
|
|
||||||
data[i]["products"][j]["train_number"] = name_list[0] + " " + name_list[1];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Travel information
|
|
||||||
var relation_items = relation.querySelectorAll("td");
|
|
||||||
var relation_info = relation_items[relation_items.length-1];
|
|
||||||
data[i]["info"] = relation_info.innerText;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
log("data collected");
|
var stations = timetable.querySelectorAll("tr td.station");
|
||||||
|
stations.forEach((station) => {
|
||||||
console.log(data);
|
var station_name = station.innerText;
|
||||||
|
var marudor_button = domCreateButtonMarudor("/" + station_name);
|
||||||
/*
|
station.append(marudor_button);
|
||||||
* INJECT CUSTOM UI
|
|
||||||
*/
|
|
||||||
|
|
||||||
var relations = timetable.querySelectorAll("tr.first");
|
|
||||||
relations.forEach((relation, i) => {
|
|
||||||
var relationend = relation.nextElementSibling;
|
|
||||||
|
|
||||||
var products = relation.querySelectorAll("td.products span a");
|
|
||||||
products.forEach((product, j) => {
|
|
||||||
// Field for 'bahn-insight' stuff
|
|
||||||
var bahn_insight_field = domCreateBahnInsightField();
|
|
||||||
product.after(bahn_insight_field);
|
|
||||||
|
|
||||||
// Button linking to marudor.de
|
|
||||||
var marudor_button = domCreateButtonMarudor("/details/" + data[i]["products"][j]["train_number"]);
|
|
||||||
bahn_insight_field.appendChild(marudor_button);
|
|
||||||
|
|
||||||
// Move linebreaks from link inner, after our 'bahn-insight' field
|
|
||||||
var linebreaks = product.querySelectorAll("br");
|
|
||||||
if(linebreaks.length != 0) {
|
|
||||||
linebreaks.forEach((linebreak) => {
|
|
||||||
product.removeChild(linebreak);
|
|
||||||
});
|
|
||||||
bahn_insight_field.after(domCreateLinebreak());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var from = relation.querySelector("td.station");
|
|
||||||
var bahn_insight_field = domCreateBahnInsightField();
|
|
||||||
from.appendChild(bahn_insight_field);
|
|
||||||
|
|
||||||
var marudor_button = domCreateButtonMarudor("/" + data[i]["from"]["station"]);
|
|
||||||
bahn_insight_field.appendChild(marudor_button);
|
|
||||||
|
|
||||||
var dbf_button = domCreateButtonDbf("/" + data[i]["from"]["station"]);
|
|
||||||
bahn_insight_field.appendChild(dbf_button);
|
|
||||||
|
|
||||||
var to = relationend.querySelector("td.station");
|
|
||||||
var bahn_insight_field = domCreateBahnInsightField();
|
|
||||||
to.appendChild(bahn_insight_field);
|
|
||||||
|
|
||||||
var marudor_button = domCreateButtonMarudor("/" + data[i]["to"]["station"]);
|
|
||||||
bahn_insight_field.appendChild(marudor_button);
|
|
||||||
|
|
||||||
var dbf_button = domCreateButtonDbf("/" + data[i]["to"]["station"]);
|
|
||||||
bahn_insight_field.appendChild(dbf_button);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
log("ui injected");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -280,6 +113,4 @@ if(typeof target !== 'undefined') {
|
|||||||
subtree: true,
|
subtree: true,
|
||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
|
|
||||||
log("observation started")
|
|
||||||
}
|
}
|
||||||
|
BIN
media/dbf.png
BIN
media/dbf.png
Binary file not shown.
Before Width: | Height: | Size: 652 B |
Loading…
Reference in New Issue
Block a user