From 73cc5ce38d42593011f5d0bf5ffb82827cc6adfe Mon Sep 17 00:00:00 2001 From: Hygna Date: Sat, 29 Oct 2022 12:46:53 +0100 Subject: [PATCH] Changes: Added note about Privacy Redirect Disabled maps redirects by default due to bugs Added timeout to osm web request Closes https://github.com/libredirect/libredirect/issues/485 --- src/assets/javascripts/services.js | 27 ++++++++++++++++++--------- src/config/config.json | 2 +- src/pages/options/widgets/about.ejs | 4 ++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 1e50b43d..432420fb 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -183,16 +183,25 @@ function redirect(url, type, initiator, forceRedirection) { function addressToLatLng(address) { const xmlhttp = new XMLHttpRequest() - xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false) - xmlhttp.send() - if (xmlhttp.status === 200) { - const json = JSON.parse(xmlhttp.responseText)[0] - if (json) { - console.log("json", json) - return [`${json.lat},${json.lon}`, `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`] - } + xmlhttp.timeout = 5000 + http.ontimeout = () => { + return } - console.info("Error: Status is " + xmlhttp.status) + http.onerror = () => { + return + } + xmlhttp.send() + http.onreadystatechange = () => { + if (xmlhttp.status === 200) { + const json = JSON.parse(xmlhttp.responseText)[0] + if (json) { + console.log("json", json) + return [`${json.lat},${json.lon}`, `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`] + } + } + console.info("Error: Status is " + xmlhttp.status) + } + xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false) } let mapCentre = "#" diff --git a/src/config/config.json b/src/config/config.json index 35ce8bf8..b1c4c8a4 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -579,7 +579,7 @@ "targets": ["^https?:\\/{2}maps\\.libredirect\\.invalid", "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], "name": "Maps", "options": { - "enabled": true, + "enabled": false, "frontend": "osm" }, "imageType": "svgMono", diff --git a/src/pages/options/widgets/about.ejs b/src/pages/options/widgets/about.ejs index 63c5b027..09cdab1d 100644 --- a/src/pages/options/widgets/about.ejs +++ b/src/pages/options/widgets/about.ejs @@ -20,5 +20,9 @@

Source Code:

https://libredirect.codeberg.page/source_code

+
+

Forked from:

+

Privacy Redirect

+