Fix OSM embed bbox & add default zoom (17)
This commit is contained in:
parent
cfd51cb1ad
commit
c0eff66775
|
@ -87,7 +87,10 @@ function addressToLatLon(address, callback) {
|
||||||
if (xmlhttp.status === 200) {
|
if (xmlhttp.status === 200) {
|
||||||
const json = JSON.parse(xmlhttp.responseText)[0];
|
const json = JSON.parse(xmlhttp.responseText)[0];
|
||||||
if (json) {
|
if (json) {
|
||||||
callback(`${json.lat}%2C${json.lon}`, json.boundingbox.join('%2C'));
|
callback(
|
||||||
|
`${json.lat}%2C${json.lon}`,
|
||||||
|
`${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -139,6 +142,7 @@ function redirectInstagram(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectGoogleMaps(url) {
|
function redirectGoogleMaps(url) {
|
||||||
|
let redirect;
|
||||||
let mapCentre = '';
|
let mapCentre = '';
|
||||||
if (url.pathname.match(latLngZoomRegex)) {
|
if (url.pathname.match(latLngZoomRegex)) {
|
||||||
const [, lat, lon, zoom] = url.pathname.match(latLngZoomRegex);
|
const [, lat, lon, zoom] = url.pathname.match(latLngZoomRegex);
|
||||||
|
@ -154,7 +158,7 @@ function redirectGoogleMaps(url) {
|
||||||
marker = coords;
|
marker = coords;
|
||||||
bbox = boundingbox;
|
bbox = boundingbox;
|
||||||
});
|
});
|
||||||
return `${osmInstance}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`;
|
redirect = `${osmInstance}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`;
|
||||||
} else if (url.pathname.includes('/dir')) {
|
} else if (url.pathname.includes('/dir')) {
|
||||||
const travelMode = travelModes[url.searchParams.get('travelmode')] || travelModes['driving'];
|
const travelMode = travelModes[url.searchParams.get('travelmode')] || travelModes['driving'];
|
||||||
let origin;
|
let origin;
|
||||||
|
@ -165,17 +169,24 @@ function redirectGoogleMaps(url) {
|
||||||
addressToLatLon(url.searchParams.get('destination'), coords => {
|
addressToLatLon(url.searchParams.get('destination'), coords => {
|
||||||
destination = coords;
|
destination = coords;
|
||||||
});
|
});
|
||||||
return `${osmInstance}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}`;
|
redirect = `${osmInstance}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}`;
|
||||||
} else if (url.pathname.includes('data=')) {
|
} else if (url.pathname.includes('data=')) {
|
||||||
const [mlat, mlon] = url.pathname.match(dataLatLngRegex);
|
const [mlat, mlon] = url.pathname.match(dataLatLngRegex);
|
||||||
return `${osmInstance}/?mlat=${mlat.replace('!3d', '')}&mlon=${mlon.replace('!4d', '')}${mapCentre}`;
|
redirect = `${osmInstance}/?mlat=${mlat.replace('!3d', '')}&mlon=${mlon.replace('!4d', '')}${mapCentre}`;
|
||||||
} else if (url.search.includes('ll=')) {
|
} else if (url.search.includes('ll=')) {
|
||||||
const [mlat, mlon] = url.searchParams.get('ll').split(',');
|
const [mlat, mlon] = url.searchParams.get('ll').split(',');
|
||||||
return `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}`;
|
redirect = `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}`;
|
||||||
} else {
|
} else {
|
||||||
const query = url.searchParams.get('q') || url.searchParams.get('query') || url.pathname.split('/')[3];
|
const query = url.searchParams.get('q') || url.searchParams.get('query') || url.pathname.split('/')[3];
|
||||||
return `${osmInstance}/${query ? 'search?query=' + query : ''}${mapCentre || '#'}`;
|
redirect = `${osmInstance}/${query ? 'search?query=' + query : ''}${mapCentre || '#'}`;
|
||||||
}
|
}
|
||||||
|
// Set default zoom if mapCentre not present
|
||||||
|
if (!mapCentre) {
|
||||||
|
const redirectUrl = new URL(redirect);
|
||||||
|
redirectUrl.searchParams.set('zoom', '17');
|
||||||
|
redirect = redirectUrl.href;
|
||||||
|
}
|
||||||
|
return redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Privacy Redirect",
|
"name": "Privacy Redirect",
|
||||||
"description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.",
|
"description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.",
|
||||||
"version": "1.1.12",
|
"version": "1.1.13",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
|
|
Loading…
Reference in New Issue