Version 0.1
This commit is contained in:
46
js/reiseauskunft.js
Normal file
46
js/reiseauskunft.js
Normal file
@@ -0,0 +1,46 @@
|
||||
function log(msg) {
|
||||
console.log("[Bahn Insight] " + msg);
|
||||
}
|
||||
|
||||
function getMediaURL(path) {
|
||||
path = "media/" + path;
|
||||
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
|
||||
}
|
||||
|
||||
|
||||
log("Bahn Insight loaded");
|
||||
|
||||
var target = document.getElementById('resultsOverview');
|
||||
|
||||
log("target");
|
||||
console.log(target);
|
||||
|
||||
var observer = new MutationObserver((mutations, observer) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'childList') {
|
||||
// Changed object
|
||||
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>';
|
||||
log("added to");
|
||||
console.log(product);
|
||||
});
|
||||
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>';
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(target, {
|
||||
subtree: true,
|
||||
childList: true
|
||||
});
|
Reference in New Issue
Block a user