From d462400ff40b77d446ed024238d800317e99108a Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 16 Sep 2020 12:39:29 +0200 Subject: [PATCH] Version 0.1 --- js/reiseauskunft.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 24 +++++++++++++++++++++++ media/marudor.svg | 10 ++++++++++ 3 files changed, 80 insertions(+) create mode 100644 js/reiseauskunft.js create mode 100644 manifest.json create mode 100644 media/marudor.svg diff --git a/js/reiseauskunft.js b/js/reiseauskunft.js new file mode 100644 index 0000000..12e2dd1 --- /dev/null +++ b/js/reiseauskunft.js @@ -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 + ' '; + 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 + ' '; + }); + + } + } + }); +}); + +observer.observe(target, { + subtree: true, + childList: true +}); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..9dfca24 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + + "manifest_version": 2, + "name": "Bahn Insight", + "version": "0.1", + + "description": "Extends the booking portal of bahn.de with linking to useful information.", + "homepage_url": "https://git.clerie.de/clerie/bahn-insight/", + + "content_scripts": [ + { + "matches": [ + "*://reiseauskunft.bahn.de/*" + ], + "js": [ + "js/reiseauskunft.js" + ] + } + ], + + "web_accessible_resources": [ + "media/*" + ] +} diff --git a/media/marudor.svg b/media/marudor.svg new file mode 100644 index 0000000..50425fd --- /dev/null +++ b/media/marudor.svg @@ -0,0 +1,10 @@ + + + + \ No newline at end of file