v1.0.0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
clipboard = (text) => {
|
||||
navigator.clipboard.writeText(text)
|
||||
.then(() => console.log("Текст скопійовано!"))
|
||||
.then(() => alert("Посилання скопійовано!"))
|
||||
.catch(err => console.error(err))
|
||||
}
|
||||
@@ -1,9 +1,34 @@
|
||||
let formattedDate = (unix_timestamp) => {
|
||||
if(!unix_timestamp) return
|
||||
|
||||
if (!unix_timestamp) return
|
||||
|
||||
let date = new Date(unix_timestamp);
|
||||
let year = date.getFullYear() >= 10 ? date.getFullYear() : "0" + date.getFullYear();
|
||||
let month = (date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1);
|
||||
let weekday = date.getDate() >= 10 ? date.getDate() : "0" + date.getDate();
|
||||
return weekday + '.' + month + '.' + year;
|
||||
}
|
||||
|
||||
let formattedDateTime = (unix_timestamp) => {
|
||||
let a
|
||||
if (unix_timestamp > 1000000000000) a = new Date(unix_timestamp);
|
||||
else a = new Date(unix_timestamp * 1000);
|
||||
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
let year = a.getFullYear();
|
||||
let month = (a.getMonth() + 1) < 10 ? `0${(a.getMonth() + 1)}` : (a.getMonth() + 1);
|
||||
let date = a.getDate() < 10 ? `0${a.getDate()}` : a.getDate();
|
||||
let hour = a.getHours() < 10 ? `0${a.getHours()}` : a.getHours();
|
||||
let min = a.getMinutes() < 10 ? `0${a.getMinutes()}` : a.getMinutes();
|
||||
let sec = a.getSeconds() < 10 ? `0${a.getSeconds()}` : a.getSeconds();
|
||||
let time = date + '.' + month + '.' + year + ' ' + hour + ':' + min;
|
||||
return time;
|
||||
}
|
||||
|
||||
function getTimeInSeconds(time = Date.now()) {
|
||||
// Если время больше 10 знаков (это значит, что время в миллисекундах)
|
||||
if (time.toString().length < 10) {
|
||||
// Округляем до секунд, убирая последние 3 цифры (миллисекунды)
|
||||
time = Math.floor(time * 1000);
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
9
web/lib/components/setLeafletCursor.js
Normal file
9
web/lib/components/setLeafletCursor.js
Normal file
@@ -0,0 +1,9 @@
|
||||
function setLeafletCursor(cursor) {
|
||||
let styleTag = document.getElementById('leaflet-cursor-style');
|
||||
if (!styleTag) {
|
||||
styleTag = document.createElement('style');
|
||||
styleTag.id = 'leaflet-cursor-style';
|
||||
document.head.appendChild(styleTag);
|
||||
}
|
||||
styleTag.innerHTML = `.leaflet-interactive { cursor: ${cursor} !important; }`;
|
||||
}
|
||||
104
web/lib/components/webPush.js
Normal file
104
web/lib/components/webPush.js
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
const webPush = {
|
||||
async init() {
|
||||
if (!('serviceWorker' in navigator) || !('PushManager' in window)) {
|
||||
console.error('Push уведомления не поддерживаются');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Получаем публичный ключ VAPID с сервера
|
||||
const uuid = localStorage.getItem('uuid');
|
||||
const res = await fetch(`${CONFIG.api}push/key`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
}
|
||||
});
|
||||
const { publicKey } = await res.json();
|
||||
|
||||
// Преобразуем ключ
|
||||
function urlBase64ToUint8Array(base64String) {
|
||||
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
|
||||
const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
|
||||
const raw = atob(base64);
|
||||
return Uint8Array.from([...raw].map(ch => ch.charCodeAt(0)));
|
||||
}
|
||||
|
||||
// Берем уже зарегистрированный Service Worker
|
||||
const registration = await navigator.serviceWorker.ready;
|
||||
|
||||
// Проверяем, есть ли уже подписка
|
||||
let subscription = await registration.pushManager.getSubscription();
|
||||
|
||||
if (!subscription) {
|
||||
|
||||
// Запрашиваем разрешение
|
||||
const permission = await Notification.requestPermission();
|
||||
if (permission !== 'granted') {
|
||||
console.warn('Пуш уведомления запрещены пользователем');
|
||||
return;
|
||||
}
|
||||
|
||||
// Подписка на push
|
||||
subscription = await registration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: urlBase64ToUint8Array(publicKey)
|
||||
});
|
||||
|
||||
// данные устройства
|
||||
const deviceInfo = {
|
||||
name: navigator.userAgent,
|
||||
model: navigator.platform || "unknown"
|
||||
};
|
||||
|
||||
// Отправка на сервер
|
||||
await fetch(`${CONFIG.api}push/subscribe`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
},
|
||||
body: JSON.stringify({ subscription, device: deviceInfo })
|
||||
});
|
||||
|
||||
console.log('Push подписка готова:', subscription);
|
||||
|
||||
console.log('Создана новая подписка');
|
||||
} else {
|
||||
console.log('Подписка уже существует');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Ошибка инициализации push:', err);
|
||||
}
|
||||
},
|
||||
|
||||
async unsubscribe() {
|
||||
const uuid = localStorage.getItem('uuid');
|
||||
const registration = await navigator.serviceWorker.ready;
|
||||
const subscription = await registration.pushManager.getSubscription();
|
||||
|
||||
if (subscription) {
|
||||
// удаляем подписку в браузере
|
||||
const success = await subscription.unsubscribe();
|
||||
|
||||
if (success) {
|
||||
console.log("Локальная подписка отменена");
|
||||
|
||||
// уведомляем сервер
|
||||
await fetch(`${CONFIG.api}push//unsubscribe`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": uuid
|
||||
},
|
||||
body: JSON.stringify({ endpoint: subscription.endpoint })
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("Подписки нет");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user