42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
function log(msg) {
|
|
console.log("[Bahn Insight] " + msg);
|
|
}
|
|
|
|
function getMediaURL(path) {
|
|
path = "media/" + path;
|
|
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
|
|
}
|
|
|
|
|
|
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) => {
|
|
var train_name = product.querySelector("span a").innerText;
|
|
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>';
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
var target = document.getElementById('resultsOverview');
|
|
|
|
if(typeof target !== 'undefined') {
|
|
observer.observe(target, {
|
|
subtree: true,
|
|
childList: true
|
|
});
|
|
}
|