2020-09-16 12:39:29 +02:00
|
|
|
function log(msg) {
|
|
|
|
console.log("[Bahn Insight] " + msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMediaURL(path) {
|
|
|
|
path = "media/" + path;
|
|
|
|
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
|
|
|
|
}
|
2020-09-16 13:17:49 +02:00
|
|
|
/**
|
|
|
|
* Return train name in format "PRODUCT TRAIN_NUMER"
|
|
|
|
* i.e. "ICE 112", "RE 12734"
|
|
|
|
* Sometimes train name is in format "PRODUCT LINE_NUMER (TRAIN_NUMER)"
|
|
|
|
* i.e. "STB 12 (62371)"
|
|
|
|
* this will be cleaned up
|
|
|
|
*/
|
|
|
|
function bahnParseTrainName(dirty_train_name) {
|
|
|
|
var name_list = dirty_train_name.split(" ");
|
2020-09-16 12:39:29 +02:00
|
|
|
|
2020-09-16 13:17:49 +02:00
|
|
|
// 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) == ')') {
|
|
|
|
return name_list[0] + " " + name_list[2].substring(1, name_list[2].length-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dirty_train_name;
|
|
|
|
}
|
2020-09-16 12:39:29 +02:00
|
|
|
|
|
|
|
var observer = new MutationObserver((mutations, observer) => {
|
|
|
|
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 products = timetable.querySelectorAll("tr.first td.products");
|
|
|
|
products.forEach((product) => {
|
2020-09-16 13:17:49 +02:00
|
|
|
var train_name = bahnParseTrainName(product.querySelector("span a").innerText);
|
2020-09-16 12:39:29 +02:00
|
|
|
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>';
|
|
|
|
});
|
|
|
|
var stations = timetable.querySelectorAll("tr td.station");
|
|
|
|
stations.forEach((station) => {
|
|
|
|
var station_name = station.innerText;
|
|
|
|
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>';
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-16 13:03:05 +02:00
|
|
|
|
|
|
|
var target = document.getElementById('resultsOverview');
|
|
|
|
|
|
|
|
if(typeof target !== 'undefined') {
|
|
|
|
observer.observe(target, {
|
|
|
|
subtree: true,
|
|
|
|
childList: true
|
|
|
|
});
|
|
|
|
}
|