64 lines
2.2 KiB
JavaScript
64 lines
2.2 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 locale_date_dd_mm_yyyy() {
|
|
const today = new Date();
|
|
const day = String(today.getDate()).padStart(2, '0');
|
|
const month = String(today.getMonth() + 1).padStart(2, '0');
|
|
const year = String(today.getFullYear()).slice(-4);
|
|
return `${day}/${month}/${year}`;
|
|
}
|
|
|
|
let __is_mobile = null;
|
|
function isMobile() {
|
|
if (__is_mobile === null) {
|
|
__is_mobile = /Mobi|Android/i.test(window.navigator.userAgent);
|
|
}
|
|
return __is_mobile;
|
|
} |