From 093556b600340a6a25249372818b861e5596d2ca Mon Sep 17 00:00:00 2001 From: Madina Date: Mon, 10 Aug 2026 09:32:24 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B1=D1=83=D0=B4=D0=B8=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=82=D1=80=D0=B5=D0=BD=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D1=83=20=D1=81=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 4b7a530..71040a0 100644 --- a/index.html +++ b/index.html @@ -414,6 +414,18 @@

🔥 Тренировка на сегодня

+ +
+

🔔 Будильник на тренировку

+
+ + + + +
+

💡 Браузер покажет уведомление в заданное время (разреши уведомления при первом запуске)

+
+

🎵 Мотивационная музыка

@@ -589,7 +601,8 @@ { type: "Отдых", exercises: [] } ]; - let progressData = JSON.parse(localStorage.getItem('fitproProgress') || '{"entries":[],"completedDays":[],"water":[],"waterToday":0,"habits":{}}'); + let progressData = JSON.parse(localStorage.getItem('fitproProgress') || '{"entries":[],"completedDays":[],"water":[],"waterToday":0,"habits":{},"alarm":null}'); + let alarmTimeout = null; // === ИНИЦИАЛИЗАЦИЯ === function init() { @@ -779,6 +792,89 @@ } init(); + + // === БУДИЛЬНИК === + function setAlarm() { + const time = document.getElementById('alarm-time').value; + if (!time) return alert('Выбери время!'); + + progressData.alarm = time; + localStorage.setItem('fitproProgress', JSON.stringify(progressData)); + + // Запрос разрешений на уведомления + if ('Notification' in window && Notification.permission === 'default') { + Notification.requestPermission(); + } + + checkAlarm(); + alert('⏰ Будильник установлен на ' + time + '!'); + } + + function cancelAlarm() { + progressData.alarm = null; + localStorage.setItem('fitproProgress', JSON.stringify(progressData)); + if (alarmTimeout) clearTimeout(alarmTimeout); + document.getElementById('alarm-status').textContent = ''; + alert('Будильник отменён'); + } + + function checkAlarm() { + if (!progressData.alarm) return; + + const now = new Date(); + const alarmTime = progressData.alarm; + const [hours, minutes] = alarmTime.split(':').map(Number); + + const alarmDate = new Date(); + alarmDate.setHours(hours, minutes, 0, 0); + + // Если время уже прошло сегодня, ставим на завтра + if (alarmDate <= now) { + alarmDate.setDate(alarmDate.getDate() + 1); + } + + const msUntilAlarm = alarmDate - now; + + document.getElementById('alarm-status').textContent = '⏰ Будильник на ' + alarmTime + ' (через ' + Math.round(msUntilAlarm / 60000) + ' мин)'; + + if (alarmTimeout) clearTimeout(alarmTimeout); + + alarmTimeout = setTimeout(() => { + triggerAlarm(); + // Переставить на завтра + setTimeout(checkAlarm, 1000); + }, msUntilAlarm); + } + + function triggerAlarm() { + // Звук + const audio = new Audio('https://actions.google.com/sounds/v1/alarms/beep_short.ogg'); + audio.play(); + + // Уведомление + if ('Notification' in window && Notification.permission === 'granted') { + new Notification('💪 Пора на тренировку!', { + body: 'Твоя тренировка началась! Вперёд к цели! 🔥', + icon: 'https://cdn-icons-png.flaticon.com/512/2964/2964536.png' + }); + } else { + alert('💪 ПОРА НА ТРЕНИРОВКУ! 🔥'); + } + + // Воспроизвести звук ещё раз через 5 минут + setTimeout(() => { + audio.play(); + }, 300000); + } + + // Проверка будильника при загрузке + if (progressData.alarm) { + document.getElementById('alarm-time').value = progressData.alarm; + checkAlarm(); + } + + // Проверка каждую минуту + setInterval(checkAlarm, 60000);