Compare commits
6 Commits
a4c68ec801
...
6c9bd60235
Author | SHA1 | Date | |
---|---|---|---|
6c9bd60235 | |||
bf884ac39c | |||
d3d1aeecd8 | |||
83feb9af10 | |||
d4d97d899d | |||
0c17dfc94f |
@ -17,7 +17,7 @@ function getMediaURL(path) {
|
|||||||
* they will also be cleaned up and returned as undefined, because we can't link to them correctly
|
* they will also be cleaned up and returned as undefined, because we can't link to them correctly
|
||||||
*/
|
*/
|
||||||
function bahnParseTrainName(dirty_train_name) {
|
function bahnParseTrainName(dirty_train_name) {
|
||||||
var name_list = dirty_train_name.split(" ");
|
var name_list = dirty_train_name.trim().replace(/ +/g, ' ').split(" ");
|
||||||
|
|
||||||
// Train name in format "STB 12 (23561)"
|
// 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) == ')') {
|
if(name_list.length == 3 && name_list[2].charAt(0) == '(' && name_list[2].charAt(name_list[2].length-1) == ')') {
|
||||||
@ -32,35 +32,67 @@ function bahnParseTrainName(dirty_train_name) {
|
|||||||
return dirty_train_name;
|
return dirty_train_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var observer = new MutationObserver((mutations, observer) => {
|
function domCreateLink(href) {
|
||||||
mutations.forEach((mutation) => {
|
var link = document.createElement("a");
|
||||||
if (mutation.type === 'childList') {
|
link.setAttribute("href", href);
|
||||||
var target = mutation.target;
|
return link;
|
||||||
if (target.tagName === 'TD') {
|
}
|
||||||
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
|
||||||
var products = timetable.querySelectorAll("tr.first td.products");
|
function domCreateImage(src) {
|
||||||
products.forEach((product) => {
|
var image = document.createElement("img");
|
||||||
var train_name = bahnParseTrainName(product.querySelector("span a").innerText);
|
image.setAttribute("src", src);
|
||||||
if(typeof train_name !== 'undefined') {
|
return image;
|
||||||
product.innerHTML = product.innerHTML + ' <a href="https://marudor.de/details/' + train_name + '" target="_blank"><img src="' + getMediaURL("marudor.svg") + '" style="height: 2em; vertical-align:middle;"></a>';
|
}
|
||||||
|
|
||||||
|
function domCreateButton(href, image_src) {
|
||||||
|
var link = domCreateLink(href);
|
||||||
|
var image = domCreateImage(image_src);
|
||||||
|
image.setAttribute("style", "height: 2em; vertical-align:middle;")
|
||||||
|
link.append(image);
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function domCreateButtonMarudor(path) {
|
||||||
|
var button = domCreateButton("https://marudor.de" + path, getMediaURL("marudor.svg"));
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
var connection_result_observer = new MutationObserver((mutations) => {
|
||||||
|
mutations.forEach((mutation) => {
|
||||||
|
if (mutation.type === 'childList') {
|
||||||
|
var target = mutation.target;
|
||||||
|
if (target.tagName === 'TD') {
|
||||||
|
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
||||||
|
|
||||||
|
var trains = timetable.querySelectorAll("tr.first td.products");
|
||||||
|
trains.forEach((train) => {
|
||||||
|
var train_names = train.querySelectorAll("span a");
|
||||||
|
train_names.forEach((train_name) => {
|
||||||
|
train_name_text = bahnParseTrainName(train_name.innerText);
|
||||||
|
if(typeof train_name_text !== 'undefined') {
|
||||||
|
var marudor_button = domCreateButtonMarudor("/details/" + train_name_text);
|
||||||
|
train_name.after(marudor_button);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var stations = timetable.querySelectorAll("tr td.station");
|
});
|
||||||
stations.forEach((station) => {
|
|
||||||
var station_name = station.innerText;
|
var stations = timetable.querySelectorAll("tr td.station");
|
||||||
station.innerHTML = station.innerHTML + ' <a href="https://marudor.de/' + station_name + '" target="_blank"><img src="' + getMediaURL("marudor.svg") + '" style="height: 2em; vertical-align:middle;"></a>';
|
stations.forEach((station) => {
|
||||||
});
|
var station_name = station.innerText;
|
||||||
|
var marudor_button = domCreateButtonMarudor("/" + station_name);
|
||||||
|
station.append(marudor_button);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var target = document.getElementById('resultsOverview');
|
var target = document.getElementById('resultsOverview');
|
||||||
|
|
||||||
if(typeof target !== 'undefined') {
|
if(typeof target !== 'undefined') {
|
||||||
observer.observe(target, {
|
connection_result_observer.observe(target, {
|
||||||
subtree: true,
|
subtree: true,
|
||||||
childList: true
|
childList: true
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Bahn Insight",
|
"name": "Bahn Insight",
|
||||||
"version": "0.3",
|
"version": "0.4",
|
||||||
|
|
||||||
"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/",
|
||||||
|
Loading…
Reference in New Issue
Block a user