- IS_MOBILE_DEVICE als globalen konstanten Wert hinzugefügt - DEVICE_TYPE geändert in DEVICE_SCREEN_TYPE - IS_DESKTOP zu IS_DESKTOP_SIZE geändert
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
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() {
|
|
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();
|
|
} |