unify formatting
This commit is contained in:
parent
6419d5defd
commit
553f764e69
@ -74,7 +74,9 @@ function toWGS84(point) {
|
||||
*/
|
||||
function trackTitle(geoJson) {
|
||||
const route = geoJson.segments[0];
|
||||
const book = geoJson.book_route_number ? `${geoJson.book_route_number} - ` : "";
|
||||
const book = geoJson.book_route_number
|
||||
? `${geoJson.book_route_number} - `
|
||||
: "";
|
||||
|
||||
return `${book}${geoJson.title}`;
|
||||
}
|
||||
@ -86,16 +88,18 @@ function trackTitle(geoJson) {
|
||||
* @returns Simple gpx string.
|
||||
*/
|
||||
function toGpx(geoJson) {
|
||||
let trackSegments = geoJson.segments.map(segment => {
|
||||
let trackSegments = geoJson.segments.map((segment) => {
|
||||
return `<trkseg>
|
||||
${segment.geom.coordinates.map(toTrackPoint).join("")}
|
||||
</trkseg>`;
|
||||
}).join("");
|
||||
|
||||
let endPoint = geoJson.end_point ? toWayPoint(geoJson.end_point) : "";
|
||||
let waypoints = geoJson.waypoints ? geoJson.waypoints.map(wp => {
|
||||
let waypoints = geoJson.waypoints
|
||||
? geoJson.waypoints.map((wp) => {
|
||||
return toWayPoint(wp.reference_poi);
|
||||
}).join("") : "";
|
||||
}).join("")
|
||||
: "";
|
||||
|
||||
const routeTitle = trackTitle(geoJson);
|
||||
|
||||
@ -132,12 +136,12 @@ function listener(details) {
|
||||
let encoder = new TextEncoder();
|
||||
|
||||
let data = [];
|
||||
filter.ondata = event => {
|
||||
filter.ondata = (event) => {
|
||||
data.push(event.data);
|
||||
};
|
||||
|
||||
filter.onstop = async event => {
|
||||
let blob = new Blob(data, {type: 'text/html'});
|
||||
filter.onstop = async (event) => {
|
||||
let blob = new Blob(data, { type: "text/html" });
|
||||
let buffer = await blob.arrayBuffer();
|
||||
let str = decoder.decode(buffer);
|
||||
|
||||
@ -184,12 +188,13 @@ function handleClick(tab) {
|
||||
url: objectURL,
|
||||
filename: `${gpxTrack.title}.gpx`,
|
||||
saveAs: true,
|
||||
conflictAction : 'uniquify'
|
||||
conflictAction: "uniquify",
|
||||
});
|
||||
|
||||
downloading.then(
|
||||
(id) => console.log(`Started downloading: ${id}`),
|
||||
(error) => console.log(`Download failed: ${error}`));
|
||||
(error) => console.log(`Download failed: ${error}`),
|
||||
);
|
||||
gpxTrack = null;
|
||||
}
|
||||
|
||||
@ -203,7 +208,10 @@ function updateActiveTab(tabs) {
|
||||
}
|
||||
}
|
||||
|
||||
let gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
|
||||
let gettingActiveTab = browser.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true,
|
||||
});
|
||||
gettingActiveTab.then(updateTab);
|
||||
}
|
||||
|
||||
@ -214,23 +222,27 @@ function updateIcon(tab) {
|
||||
const hasTrack = checkTrack(tab);
|
||||
|
||||
browser.browserAction.setIcon({
|
||||
path: hasTrack ? {
|
||||
path: hasTrack
|
||||
? {
|
||||
48: "icons/map.png",
|
||||
} : {
|
||||
}
|
||||
: {
|
||||
48: "icons/map-disabled.png",
|
||||
},
|
||||
tabId: tab.id
|
||||
tabId: tab.id,
|
||||
});
|
||||
browser.browserAction.setTitle({
|
||||
title: hasTrack ? `Download track "${gpxTrack.title}"` : 'No track selected',
|
||||
tabId: tab.id
|
||||
title: hasTrack
|
||||
? `Download track "${gpxTrack.title}"`
|
||||
: "No track selected",
|
||||
tabId: tab.id,
|
||||
});
|
||||
}
|
||||
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
listener,
|
||||
{ urls: ["https://www.sac-cas.ch/*[routeId]*"] },
|
||||
["blocking"]
|
||||
["blocking"],
|
||||
);
|
||||
|
||||
browser.browserAction.onClicked.addListener(handleClick);
|
||||
|
Loading…
Reference in New Issue
Block a user