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,67 +32,35 @@ 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"); mutations.forEach((mutation) => {
link.setAttribute("href", href); if (mutation.type === 'childList') {
return link; var target = mutation.target;
} if (target.tagName === 'TD') {
var timetable = target.querySelector("td div.detailContainer table.result tbody");
function domCreateImage(src) { var products = timetable.querySelectorAll("tr.first td.products");
var image = document.createElement("img"); products.forEach((product) => {
image.setAttribute("src", src); var train_name = bahnParseTrainName(product.querySelector("span a").innerText);
return image; if(typeof train_name !== 'undefined') {
} 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 stations = timetable.querySelectorAll("tr td.station"); var station_name = station.innerText;
stations.forEach((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>';
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') {
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/",