Fix OSM redirects

This commit is contained in:
SimonBrazell 2020-02-24 19:22:10 +11:00
parent fb0dad56ba
commit dcef0c8076
2 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,7 @@ const bibliogramDefault = 'https://bibliogram.art';
const instagramRegex = /((www|about|help)\.)?instagram\.com/; const instagramRegex = /((www|about|help)\.)?instagram\.com/;
const instagramPathsRegex = /(\/a|\/admin|\/api|\/favicon.ico|\/static|\/imageproxy|\/p|\/u|\/developer|\/about|\/legal|\/explore|\/director)/; const instagramPathsRegex = /(\/a|\/admin|\/api|\/favicon.ico|\/static|\/imageproxy|\/p|\/u|\/developer|\/about|\/legal|\/explore|\/director)/;
const osmDefault = 'https://openstreetmap.org'; const osmDefault = 'https://openstreetmap.org';
const googleMapsRegex = /https?:\/\/((www|maps)\.)?(google).*(\/maps)/; const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google).*(\/maps)|maps\.(google).*)/;
const latLngZoomRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; const latLngZoomRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g; const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g;
@ -113,18 +113,20 @@ function redirectGoogleMaps(url) {
if (url.pathname.includes('/embed')) { if (url.pathname.includes('/embed')) {
return; return;
} }
let lat = ''; let mapCentre = '';
let lon = '';
let zoom = '';
if (url.pathname.match(latLngZoomRegex)) { if (url.pathname.match(latLngZoomRegex)) {
[, lat, lon, zoom] = url.pathname.match(latLngZoomRegex); [, lat, lon, zoom] = url.pathname.match(latLngZoomRegex);
mapCentre = `#map=${zoom}/${lat}/${lon}`;
} }
if (url.pathname.includes('data=')) { 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', '')}#map=${zoom}/${lat}/${lon}`; return `${osmInstance}/?mlat=${mlat.replace('!3d', '')}&mlon=${mlon.replace('!4d', '')}${mapCentre}`;
} else if (url.search.includes('ll=')) {
const [mlat, mlon] = url.searchParams.get('ll').split(',');
return `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}`;
} else { } else {
const query = encodeURI(url.searchParams.get('q')) || url.pathname.split('/')[3]; const query = url.searchParams.get('q') || url.searchParams.get('query') || url.pathname.split('/')[3];
return `${osmInstance}/search?query=${query}#map=${zoom}/${lat}/${lon}`; return `${osmInstance}/search?query=${encodeURI(query)}${mapCentre}`;
} }
} }

View File

@ -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.10", "version": "1.1.11",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": [ "scripts": [