From ed6a00dfdfe21c94026f76362383476b7cb086e5 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 12 Dec 2024 17:11:45 +0100 Subject: [PATCH] =?UTF-8?q?refactor(util):=20Verschieben=20von=20Methoden?= =?UTF-8?q?=20=C3=BCber=20Standort=20nach=20util.location.js.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EnvelopeGenerator.Web/wwwroot/js/util.js | 45 ------------------- .../wwwroot/js/util.location.js | 44 ++++++++++++++++++ EnvelopeGenerator.Web/wwwroot/js/util.min.js | 2 +- 3 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 EnvelopeGenerator.Web/wwwroot/js/util.location.js diff --git a/EnvelopeGenerator.Web/wwwroot/js/util.js b/EnvelopeGenerator.Web/wwwroot/js/util.js index 90d0f5be..5663930a 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/util.js +++ b/EnvelopeGenerator.Web/wwwroot/js/util.js @@ -1,50 +1,5 @@ const B64ToBuff = (base64String) => new Uint8Array(Array.from(atob(base64String), char => char.charCodeAt(0))).buffer; -function getCoordinates() { - return new Promise((resolve, reject) => { - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition( - position => resolve(position.coords), - error => reject(error) - ); - } else { - reject(new Error("Geolocation is not supported by this browser.")); - } - }); -} - -async function getCity() { - try { - const coords = await getCoordinates(); - const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`); - const data = await response.json(); - - if (data && data.address) { - const city = data.address.city || data.address.town || data.address.village || data.address.hamlet; - const postalCode = data.address.postcode; - return postalCode + ' ' + city || ''; - } - } catch { - return ''; - } -} - -async function getLocation() { - try { - const coords = await getCoordinates(); - const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`); - const data = await response.json(); - - if (data && data.address) { - const city = data.address.city || data.address.town || data.address.village || data.address.hamlet; - const postalCode = data.address.postcode; - return { postalCode: postalCode, city: city }; - } - } catch { - return { postalCode: '', city: '' }; - } -} - const getLocaleDateString = _ => new Date().toLocaleDateString('de-DE') function detailedCurrentDate() { diff --git a/EnvelopeGenerator.Web/wwwroot/js/util.location.js b/EnvelopeGenerator.Web/wwwroot/js/util.location.js new file mode 100644 index 00000000..c7fcda2f --- /dev/null +++ b/EnvelopeGenerator.Web/wwwroot/js/util.location.js @@ -0,0 +1,44 @@ +function getCoordinates() { + return new Promise((resolve, reject) => { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + position => resolve(position.coords), + error => reject(error) + ); + } else { + reject(new Error("Geolocation is not supported by this browser.")); + } + }); +} + +async function getCity() { + try { + const coords = await getCoordinates(); + const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`); + const data = await response.json(); + + if (data && data.address) { + const city = data.address.city || data.address.town || data.address.village || data.address.hamlet; + const postalCode = data.address.postcode; + return postalCode + ' ' + city || ''; + } + } catch { + return ''; + } +} + +async function getLocation() { + try { + const coords = await getCoordinates(); + const response = await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${coords.latitude}&lon=${coords.longitude}`); + const data = await response.json(); + + if (data && data.address) { + const city = data.address.city || data.address.town || data.address.village || data.address.hamlet; + const postalCode = data.address.postcode; + return { postalCode: postalCode, city: city }; + } + } catch { + return { postalCode: '', city: '' }; + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/util.min.js b/EnvelopeGenerator.Web/wwwroot/js/util.min.js index e70e8b90..bf9b7d7f 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/util.min.js +++ b/EnvelopeGenerator.Web/wwwroot/js/util.min.js @@ -1 +1 @@ -function getCoordinates(){return new Promise((n,t)=>{navigator.geolocation?navigator.geolocation.getCurrentPosition(t=>n(t.coords),n=>t(n)):t(new Error("Geolocation is not supported by this browser."))})}async function getCity(){try{const t=await getCoordinates(),i=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t.latitude}&lon=${t.longitude}`),n=await i.json();if(n&&n.address){const t=n.address.city||n.address.town||n.address.village||n.address.hamlet,i=n.address.postcode;return i+" "+t||""}}catch{return""}}async function getLocation(){try{const t=await getCoordinates(),i=await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${t.latitude}&lon=${t.longitude}`),n=await i.json();if(n&&n.address){const t=n.address.city||n.address.town||n.address.village||n.address.hamlet,i=n.address.postcode;return{postalCode:i,city:t}}}catch{return{postalCode:"",city:""}}}function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer;const getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE"); \ No newline at end of file +function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE"); \ No newline at end of file