1
0

Compare commits

..

No commits in common. "6c9bd60235e9d131be1a7e03b0bfccf738898982" and "a4c68ec8014654927edcbd22ff4c8b6b9c675a01" have entirely different histories.

2 changed files with 21 additions and 53 deletions

View File

@ -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.trim().replace(/ +/g, ' ').split(" "); var name_list = dirty_train_name.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,55 +32,23 @@ function bahnParseTrainName(dirty_train_name) {
return dirty_train_name; return dirty_train_name;
} }
function domCreateLink(href) { var observer = new MutationObserver((mutations, observer) => {
var link = document.createElement("a");
link.setAttribute("href", href);
return link;
}
function domCreateImage(src) {
var image = document.createElement("img");
image.setAttribute("src", src);
return image;
}
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) => { 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') {
var timetable = target.querySelector("td div.detailContainer table.result tbody"); var timetable = target.querySelector("td div.detailContainer table.result tbody");
var products = timetable.querySelectorAll("tr.first td.products");
var trains = timetable.querySelectorAll("tr.first td.products"); products.forEach((product) => {
trains.forEach((train) => { var train_name = bahnParseTrainName(product.querySelector("span a").innerText);
var train_names = train.querySelectorAll("span a"); if(typeof train_name !== 'undefined') {
train_names.forEach((train_name) => { 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>';
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"); var stations = timetable.querySelectorAll("tr td.station");
stations.forEach((station) => { stations.forEach((station) => {
var station_name = station.innerText; var station_name = station.innerText;
var marudor_button = domCreateButtonMarudor("/" + station_name); 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>';
station.append(marudor_button);
}); });
} }
@ -92,7 +60,7 @@ var connection_result_observer = new MutationObserver((mutations) => {
var target = document.getElementById('resultsOverview'); var target = document.getElementById('resultsOverview');
if(typeof target !== 'undefined') { if(typeof target !== 'undefined') {
connection_result_observer.observe(target, { observer.observe(target, {
subtree: true, subtree: true,
childList: true childList: true
}); });

View File

@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Bahn Insight", "name": "Bahn Insight",
"version": "0.4", "version": "0.3",
"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/",