Compare commits
No commits in common. "b426fb304e51848ea44d37d0907889ac44ccaa3c" and "d462400ff40b77d446ed024238d800317e99108a" have entirely different histories.
b426fb304e
...
d462400ff4
@ -6,34 +6,28 @@ function getMediaURL(path) {
|
|||||||
path = "media/" + path;
|
path = "media/" + path;
|
||||||
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
|
return chrome.runtime.getURL(path) || browser.runtime.getURL(path);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 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(" ");
|
|
||||||
|
|
||||||
// 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;
|
log("Bahn Insight loaded");
|
||||||
}
|
|
||||||
|
var target = document.getElementById('resultsOverview');
|
||||||
|
|
||||||
|
log("target");
|
||||||
|
console.log(target);
|
||||||
|
|
||||||
var observer = new MutationObserver((mutations, observer) => {
|
var observer = new MutationObserver((mutations, observer) => {
|
||||||
mutations.forEach((mutation) => {
|
mutations.forEach((mutation) => {
|
||||||
if (mutation.type === 'childList') {
|
if (mutation.type === 'childList') {
|
||||||
|
// Changed object
|
||||||
var target = mutation.target;
|
var target = mutation.target;
|
||||||
if (target.tagName === 'TD') {
|
if (target.tagName === 'TD') {
|
||||||
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
var timetable = target.querySelector("td div.detailContainer table.result tbody");
|
||||||
var products = timetable.querySelectorAll("tr.first td.products");
|
var products = timetable.querySelectorAll("tr.first td.products");
|
||||||
products.forEach((product) => {
|
products.forEach((product) => {
|
||||||
var train_name = bahnParseTrainName(product.querySelector("span a").innerText);
|
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>';
|
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");
|
var stations = timetable.querySelectorAll("tr td.station");
|
||||||
stations.forEach((station) => {
|
stations.forEach((station) => {
|
||||||
@ -46,12 +40,7 @@ var observer = new MutationObserver((mutations, observer) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
observer.observe(target, {
|
||||||
var target = document.getElementById('resultsOverview');
|
subtree: true,
|
||||||
|
childList: true
|
||||||
if(typeof target !== 'undefined') {
|
});
|
||||||
observer.observe(target, {
|
|
||||||
subtree: true,
|
|
||||||
childList: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Bahn Insight",
|
"name": "Bahn Insight",
|
||||||
"version": "0.2",
|
"version": "0.1",
|
||||||
|
|
||||||
"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/",
|
||||||
|
Loading…
Reference in New Issue
Block a user