File size: 22,191 Bytes
7906d19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alarm Clock App</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom scrollbar */
.alarm-list::-webkit-scrollbar {
width: 6px;
}
.alarm-list::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px;
}
.alarm-list::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
.alarm-list::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Animation for active alarm */
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.active-alarm {
animation: pulse 1.5s infinite;
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}
/* Modal transition */
.modal {
transition: opacity 0.3s ease, transform 0.3s ease;
}
.modal-enter {
opacity: 0;
transform: scale(0.9);
}
.modal-enter-active {
opacity: 1;
transform: scale(1);
}
</style>
</head>
<body class="bg-gray-100 min-h-screen font-sans">
<div class="max-w-md mx-auto bg-white min-h-screen shadow-lg relative overflow-hidden">
<!-- Header -->
<header class="bg-blue-500 text-white p-6 shadow-md">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold">Alarm Clock</h1>
<div class="flex space-x-4">
<button id="settings-btn" class="text-white">
<i class="fas fa-cog"></i>
</button>
</div>
</div>
<div class="mt-6 text-center">
<div class="text-5xl font-light" id="current-time">00:00</div>
<div class="text-lg mt-2" id="current-date">Monday, January 1</div>
</div>
</header>
<!-- Alarm List -->
<div class="p-4">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-700">Your Alarms</h2>
<button id="add-alarm-btn" class="bg-blue-500 hover:bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center shadow-md">
<i class="fas fa-plus"></i>
</button>
</div>
<div id="alarm-list" class="alarm-list space-y-3 max-h-96 overflow-y-auto">
<!-- Alarms will be added here dynamically -->
<div class="text-center py-10 text-gray-500" id="no-alarms-message">
<i class="fas fa-bell-slash text-4xl mb-2"></i>
<p>No alarms set</p>
</div>
</div>
</div>
<!-- Add/Edit Alarm Modal -->
<div id="alarm-modal" class="modal fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden">
<div class="bg-white rounded-xl shadow-xl w-full max-w-sm p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-semibold" id="modal-title">Add New Alarm</h3>
<button id="close-modal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2">Time</label>
<div class="flex justify-center">
<input type="time" id="alarm-time" class="border-2 border-gray-200 rounded-lg p-3 text-xl w-full text-center" required>
</div>
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2">Label (optional)</label>
<input type="text" id="alarm-label" placeholder="Wake up, Medicine, etc." class="border-2 border-gray-200 rounded-lg p-3 w-full">
</div>
<div class="mb-6">
<label class="block text-gray-700 mb-2">Repeat</label>
<div class="grid grid-cols-7 gap-2">
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="0">S</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="1">M</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="2">T</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="3">W</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="4">T</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="5">F</button>
<button class="day-btn py-2 rounded-full border border-gray-200" data-day="6">S</button>
</div>
</div>
<div class="flex space-x-3">
<button id="delete-alarm" class="hidden bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded-lg flex-1">
Delete
</button>
<button id="save-alarm" class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded-lg flex-1">
Save
</button>
</div>
</div>
</div>
<!-- Alarm Ringing Modal -->
<div id="alarm-ringing-modal" class="modal fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden">
<div class="bg-white rounded-xl shadow-xl w-full max-w-sm p-6 text-center">
<div class="mb-6">
<i class="fas fa-bell text-5xl text-yellow-500 mb-4"></i>
<h3 class="text-2xl font-semibold" id="ringing-alarm-time">08:00</h3>
<p class="text-gray-600" id="ringing-alarm-label">Wake up</p>
</div>
<button id="dismiss-alarm" class="bg-blue-500 hover:bg-blue-600 text-white py-3 px-6 rounded-lg w-full">
Dismiss
</button>
</div>
</div>
</div>
<script>
// DOM Elements
const currentTimeEl = document.getElementById('current-time');
const currentDateEl = document.getElementById('current-date');
const alarmListEl = document.getElementById('alarm-list');
const noAlarmsMessage = document.getElementById('no-alarms-message');
const addAlarmBtn = document.getElementById('add-alarm-btn');
const alarmModal = document.getElementById('alarm-modal');
const closeModalBtn = document.getElementById('close-modal');
const alarmTimeInput = document.getElementById('alarm-time');
const alarmLabelInput = document.getElementById('alarm-label');
const saveAlarmBtn = document.getElementById('save-alarm');
const deleteAlarmBtn = document.getElementById('delete-alarm');
const dayButtons = document.querySelectorAll('.day-btn');
const alarmRingingModal = document.getElementById('alarm-ringing-modal');
const dismissAlarmBtn = document.getElementById('dismiss-alarm');
const ringingAlarmTime = document.getElementById('ringing-alarm-time');
const ringingAlarmLabel = document.getElementById('ringing-alarm-label');
const modalTitle = document.getElementById('modal-title');
// State
let alarms = JSON.parse(localStorage.getItem('alarms')) || [];
let editingAlarmId = null;
let selectedDays = [];
let audioContext;
let alarmSound;
let activeAlarmId = null;
// Initialize
function init() {
updateClock();
setInterval(updateClock, 1000);
renderAlarms();
checkAlarms();
setInterval(checkAlarms, 1000);
// Initialize Web Audio API
try {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
} catch (e) {
console.error('Web Audio API not supported');
}
}
// Update current time and date
function updateClock() {
const now = new Date();
const time = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
const date = now.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric' });
currentTimeEl.textContent = time;
currentDateEl.textContent = date;
}
// Render alarms list
function renderAlarms() {
if (alarms.length === 0) {
noAlarmsMessage.classList.remove('hidden');
alarmListEl.innerHTML = '';
alarmListEl.appendChild(noAlarmsMessage);
return;
}
noAlarmsMessage.classList.add('hidden');
alarmListEl.innerHTML = '';
// Sort alarms by time
alarms.sort((a, b) => {
const timeA = a.time.split(':').map(Number);
const timeB = b.time.split(':').map(Number);
return timeA[0] - timeB[0] || timeA[1] - timeB[1];
});
alarms.forEach(alarm => {
const alarmEl = document.createElement('div');
alarmEl.className = `bg-white p-4 rounded-xl shadow-sm border border-gray-100 flex items-center justify-between ${alarm.id === activeAlarmId ? 'active-alarm border-blue-300' : ''}`;
alarmEl.dataset.id = alarm.id;
const timeParts = alarm.time.split(':');
const hours = parseInt(timeParts[0]);
const minutes = timeParts[1];
const ampm = hours >= 12 ? 'PM' : 'AM';
const displayHours = hours % 12 || 12;
const displayTime = `${displayHours}:${minutes} ${ampm}`;
alarmEl.innerHTML = `
<div class="flex items-center">
<div class="mr-4">
<div class="text-2xl font-semibold">${displayTime}</div>
<div class="text-sm text-gray-500">${alarm.label || 'Alarm'}</div>
${alarm.days && alarm.days.length > 0 ?
`<div class="text-xs text-gray-400 mt-1">${getDaysText(alarm.days)}</div>` : ''}
</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" class="sr-only peer" ${alarm.active ? 'checked' : ''}>
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-500"></div>
</label>
`;
const toggle = alarmEl.querySelector('input[type="checkbox"]');
toggle.addEventListener('change', () => toggleAlarm(alarm.id));
alarmEl.addEventListener('click', (e) => {
if (!e.target.closest('label')) {
editAlarm(alarm.id);
}
});
alarmListEl.appendChild(alarmEl);
});
}
// Get days text for display
function getDaysText(days) {
if (days.length === 7) return 'Every day';
if (days.length === 5 && !days.includes(0) && !days.includes(6)) return 'Weekdays';
if (days.length === 2 && days.includes(0) && days.includes(6)) return 'Weekends';
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return days.map(day => dayNames[day]).join(', ');
}
// Toggle alarm active state
function toggleAlarm(id) {
alarms = alarms.map(alarm => {
if (alarm.id === id) {
return { ...alarm, active: !alarm.active };
}
return alarm;
});
saveAlarms();
renderAlarms();
}
// Open modal to add new alarm
addAlarmBtn.addEventListener('click', () => {
editingAlarmId = null;
modalTitle.textContent = 'Add New Alarm';
alarmTimeInput.value = '';
alarmLabelInput.value = '';
selectedDays = [];
resetDayButtons();
deleteAlarmBtn.classList.add('hidden');
alarmModal.classList.remove('hidden');
});
// Edit existing alarm
function editAlarm(id) {
const alarm = alarms.find(a => a.id === id);
if (!alarm) return;
editingAlarmId = id;
modalTitle.textContent = 'Edit Alarm';
alarmTimeInput.value = alarm.time;
alarmLabelInput.value = alarm.label || '';
selectedDays = alarm.days || [];
// Highlight selected days
resetDayButtons();
selectedDays.forEach(day => {
const btn = document.querySelector(`.day-btn[data-day="${day}"]`);
if (btn) {
btn.classList.add('bg-blue-500', 'text-white', 'border-blue-500');
}
});
deleteAlarmBtn.classList.remove('hidden');
alarmModal.classList.remove('hidden');
}
// Close modal
closeModalBtn.addEventListener('click', () => {
alarmModal.classList.add('hidden');
});
// Day selection
dayButtons.forEach(btn => {
btn.addEventListener('click', () => {
const day = parseInt(btn.dataset.day);
const index = selectedDays.indexOf(day);
if (index === -1) {
selectedDays.push(day);
btn.classList.add('bg-blue-500', 'text-white', 'border-blue-500');
} else {
selectedDays.splice(index, 1);
btn.classList.remove('bg-blue-500', 'text-white', 'border-blue-500');
}
// Sort days for consistency
selectedDays.sort((a, b) => a - b);
});
});
// Reset day buttons
function resetDayButtons() {
dayButtons.forEach(btn => {
btn.classList.remove('bg-blue-500', 'text-white', 'border-blue-500');
});
}
// Save alarm
saveAlarmBtn.addEventListener('click', () => {
const time = alarmTimeInput.value;
const label = alarmLabelInput.value.trim();
if (!time) {
alert('Please set a time for the alarm');
return;
}
if (editingAlarmId) {
// Update existing alarm
alarms = alarms.map(alarm => {
if (alarm.id === editingAlarmId) {
return {
...alarm,
time,
label: label || null,
days: selectedDays.length > 0 ? selectedDays : null
};
}
return alarm;
});
} else {
// Add new alarm
const newAlarm = {
id: Date.now().toString(),
time,
label: label || null,
days: selectedDays.length > 0 ? selectedDays : null,
active: true
};
alarms.push(newAlarm);
}
saveAlarms();
renderAlarms();
alarmModal.classList.add('hidden');
});
// Delete alarm
deleteAlarmBtn.addEventListener('click', () => {
if (editingAlarmId) {
alarms = alarms.filter(alarm => alarm.id !== editingAlarmId);
saveAlarms();
renderAlarms();
alarmModal.classList.add('hidden');
}
});
// Save alarms to localStorage
function saveAlarms() {
localStorage.setItem('alarms', JSON.stringify(alarms));
}
// Check if any alarms should trigger
function checkAlarms() {
const now = new Date();
const currentHours = now.getHours();
const currentMinutes = now.getMinutes();
const currentDay = now.getDay(); // 0 (Sun) to 6 (Sat)
alarms.forEach(alarm => {
if (!alarm.active) return;
const [alarmHours, alarmMinutes] = alarm.time.split(':').map(Number);
// Check if time matches
if (currentHours === alarmHours && currentMinutes === alarmMinutes) {
// Check if this is a repeating alarm and today is one of the selected days
if (alarm.days && alarm.days.length > 0) {
if (alarm.days.includes(currentDay)) {
triggerAlarm(alarm.id);
}
} else {
// One-time alarm - check if it hasn't been triggered today
const lastTriggered = alarm.lastTriggered ? new Date(alarm.lastTriggered) : null;
if (!lastTriggered || lastTriggered.getDate() !== now.getDate()) {
triggerAlarm(alarm.id);
// Update last triggered time
alarms = alarms.map(a => {
if (a.id === alarm.id) {
return { ...a, lastTriggered: now.toISOString() };
}
return a;
});
saveAlarms();
}
}
}
});
}
// Trigger alarm
function triggerAlarm(id) {
// Don't trigger if already ringing
if (activeAlarmId === id) return;
const alarm = alarms.find(a => a.id === id);
if (!alarm) return;
activeAlarmId = id;
ringingAlarmTime.textContent = alarm.time;
ringingAlarmLabel.textContent = alarm.label || 'Alarm';
alarmRingingModal.classList.remove('hidden');
// Play alarm sound
playAlarmSound();
// Update UI
renderAlarms();
}
// Play alarm sound
function playAlarmSound() {
if (!audioContext) return;
// Stop any existing sound
if (alarmSound) {
alarmSound.stop();
}
// Create oscillator
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.type = 'sine';
oscillator.frequency.value = 800;
gainNode.gain.value = 0.3;
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
// Create pulsing effect
let pulseCount = 0;
const pulseInterval = setInterval(() => {
pulseCount++;
if (pulseCount % 2 === 0) {
oscillator.frequency.value = 1000;
} else {
oscillator.frequency.value = 800;
}
}, 500);
oscillator.start();
alarmSound = {
oscillator,
gainNode,
stop: () => {
clearInterval(pulseInterval);
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.5);
setTimeout(() => {
oscillator.stop();
}, 500);
}
};
}
// Dismiss alarm
dismissAlarmBtn.addEventListener('click', () => {
if (alarmSound) {
alarmSound.stop();
alarmSound = null;
}
activeAlarmId = null;
alarmRingingModal.classList.add('hidden');
renderAlarms();
});
// Initialize the app
init();
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=miwf/e" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |