Absolutely! Let's enhance the desk clock web application with a more modern design, adding some visual appeal and further features while preserving your initial requirements.
Here’s the revised HTML code:
Enhanced HTML Code for Smart Desk Clock
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smart Desk Clock</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
transition: background-color 0.3s;
}
#container {
text-align: center;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
padding: 20px;
width: 300px;
transition: all 0.3s;
}
#clock {
font-size: 4em;
margin: 10px 0;
color: #333;
}
#date {
font-size: 1.5em;
color: #888;
}
#alarm-container {
margin: 20px 0;
}
#alarm-input {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
width: 100%;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
width: 100%;
margin: 5px 0;
}
button:hover {
background-color: #45a049;
}
#theme-toggle {
background-color: #333;
}
#theme-toggle:hover {
background-color: #555;
}
</style>
</head>
<body>
<div id="container">
<div id="clock">00:00:00</div>
<div id="date">Monday, January 1</div>
<div id="alarm-container">
<input type="time" id="alarm-input" placeholder="Set Alarm">
<button id="set-alarm">Set Alarm</button>
<button id="snooze">Snooze</button>
</div>
<button id="theme-toggle">Toggle Light/Dark Mode</button>
</div>
<script>
let alarmTime = null;
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const date = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}`;
document.getElementById('date').textContent = date;
if (alarmTime && now.getHours() == alarmTime.hours && now.getMinutes() == alarmTime.minutes && now.getSeconds() == 0) {
alert("Alarm ringing!");
resetAlarm();
}
}
function resetAlarm() {
alarmTime = null;
document.getElementById('alarm-input').value = '';
}
document.getElementById('set-alarm').onclick = function() {
const alarmInput = document.getElementById('alarm-input').value;
if (alarmInput) {
const [hours, minutes] = alarmInput.split(':');
alarmTime = { hours: parseInt(hours), minutes: parseInt(minutes) };
alert(`Alarm set for ${hours}:${minutes}`);
}
};
document.getElementById('snooze').onclick = function() {
if (alarmTime) {
let currentMinutes = new Date().getMinutes();
alarmTime.minutes = (currentMinutes + 10) % 60; // Snooze for 10 minutes
alert(`Snoozed for 10 minutes`);
}
};
document.getElementById('theme-toggle').onclick = function() {
const isDark = document.body.style.backgroundColor === 'black';
document.body.style.backgroundColor = isDark ? '#f0f0f0' : 'black';
document.body.style.color = isDark ? 'black' : 'white';
// Make the container match background
const container = document.getElementById('container');
container.style.backgroundColor = isDark ? '#fff' : '#444';
container.style.color = isDark ? '#333' : '#fff';
};
setInterval(updateClock, 1000);
</script>
</body>
</html>
Enhancements Made
-
Visual Aesthetics:
- Container Design: Added a container with rounded borders and a subtle shadow to elevate the clock's appearance.
- Font and Color: Used Google Fonts for a modern look and improved color contrast for readability.
-
Responsive Design:
- The container has defined width and adjusts automatically for mobile devices. Flexbox centering gives a balanced look.
-
Improved Button Interaction:
- Buttons are uniformly styled with hover effects to improve user experience.
-
Light/Dark Mode:
- The toggle changes the background and text colors dynamically, including the container style for seamless transition.
-
Snooze Functionality:
- Improved usability by informing users when they set or snooze alarms.
Considerations
- The alarm can still only produce a simple alert. For a better user experience, consider adding sound notifications or visual alerts.
- Additional features such as persistent alarm storage, more theme options, or even animations can be added as the application evolves.
Feel free to adapt the code further based on your requirements. Let me know if you have any questions or additional features in mind!