zenpomodor-timer / index.html
FaxMe's picture
use the following code and edit the code to include ambient sounds and a beeping sound when timer goes to zero, also include an option to reset the timer and add any time that the user needs, <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pomodoro timer-ZenPomo - Focus Timer</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> @keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } } .pulse-animation { animation: pulse 2s infinite; } .progress-ring__circle { transition: stroke-dashoffset 0.35s; transform: rotate(-90deg); transform-origin: 50% 50%; } .tab-active { background-color: rgba(255, 255, 255, 0.2); } </style> </head> <body class="bg-gradient-to-br from-indigo-900 to-purple-800 min-h-screen text-white font-sans"> <div class="container mx-auto px-4 py-8 flex flex-col items-center"> <header class="mb-8 text-center"> <h1 class="text-4xl font-bold mb-2">ZenPomo</h1> <p class="text-indigo-200">Focus in intervals, achieve more</p> </header> <div class="bg-white/10 backdrop-blur-sm rounded-2xl p-6 w-full max-w-md shadow-xl"> <!-- Timer Modes --> <div class="flex justify-center mb-6 bg-indigo-800/30 rounded-full p-1"> <button id="pomodoro-btn" class="tab-active px-4 py-2 rounded-full font-medium transition-all">Pomodoro</button> <button id="short-break-btn" class="px-4 py-2 rounded-full font-medium transition-all">Short Break</button> <button id="long-break-btn" class="px-4 py-2 rounded-full font-medium transition-all">Long Break</button> </div> <!-- Timer Display --> <div class="relative flex justify-center mb-8"> <svg class="w-64 h-64"> <circle class="text-indigo-700/30" stroke-width="8" stroke="currentColor" fill="transparent" r="112" cx="128" cy="128" /> <circle id="progress-ring" class="progress-ring__circle text-indigo-400" stroke-width="8" stroke-linecap="round" stroke="currentColor" fill="transparent" r="112" cx="128" cy="128" stroke-dasharray="704" stroke-dashoffset="0" /> </svg> <div class="absolute inset-0 flex flex-col items-center justify-center"> <div id="time-display" class="text-6xl font-bold mb-2">25:00</div> <button id="start-btn" class="bg-white text-indigo-800 px-8 py-3 rounded-full font-bold hover:bg-indigo-100 transition-all"> START </button> </div> </div> <!-- Settings --> <div class="bg-indigo-800/20 rounded-xl p-4 mb-6"> <h3 class="font-medium mb-3 text-center">Timer Settings</h3> <div class="grid grid-cols-3 gap-4"> <div> <label class="block text-sm text-indigo-200 mb-1">Pomodoro</label> <input id="pomodoro-time" type="number" min="1" max="60" value="25" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center"> </div> <div> <label class="block text-sm text-indigo-200 mb-1">Short Break</label> <input id="short-break-time" type="number" min="1" max="30" value="5" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center"> </div> <div> <label class="block text-sm text-indigo-200 mb-1">Long Break</label> <input id="long-break-time" type="number" min="1" max="60" value="15" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center"> </div> </div> </div> <!-- Task List --> <div class="bg-indigo-800/20 rounded-xl p-4"> <h3 class="font-medium mb-3 text-center">Today's Tasks</h3> <div class="flex mb-3"> <input id="task-input" type="text" placeholder="Add a task..." class="flex-1 bg-indigo-800/30 rounded-l-md px-3 py-2 focus:outline-none"> <button id="add-task-btn" class="bg-indigo-600 px-4 rounded-r-md hover:bg-indigo-700 transition-all"> <i class="fas fa-plus"></i> </button> </div> <ul id="task-list" class="space-y-2 max-h-40 overflow-y-auto"> <!-- Tasks will be added here --> </ul> </div> </div> <!-- Stats --> <div class="mt-6 text-center text-indigo-200"> <p>Pomodoros completed today: <span id="pomo-count" class="font-bold">0</span></p> </div> </div> <!-- Notification Sound --> <audio id="alarm-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-alarm-digital-clock-beep-989.mp3" preload="auto"></audio> <script> // DOM Elements const timeDisplay = document.getElementById('time-display'); const startBtn = document.getElementById('start-btn'); const pomodoroBtn = document.getElementById('pomodoro-btn'); const shortBreakBtn = document.getElementById('short-break-btn'); const longBreakBtn = document.getElementById('long-break-btn'); const progressRing = document.getElementById('progress-ring'); const alarmSound = document.getElementById('alarm-sound'); const pomodoroTimeInput = document.getElementById('pomodoro-time'); const shortBreakTimeInput = document.getElementById('short-break-time'); const longBreakTimeInput = document.getElementById('long-break-time'); const taskInput = document.getElementById('task-input'); const addTaskBtn = document.getElementById('add-task-btn'); const taskList = document.getElementById('task-list'); const pomoCount = document.getElementById('pomo-count'); // Timer variables let timer; let timeLeft = 25 * 60; // 25 minutes in seconds let isRunning = false; let currentMode = 'pomodoro'; // 'pomodoro', 'shortBreak', 'longBreak' let pomodorosCompleted = 0; let pomodoroLength = 25; let shortBreakLength = 5; let longBreakLength = 15; const circumference = 2 * Math.PI * 112; // Initialize updateDisplay(); updateProgressRing(); // Event Listeners startBtn.addEventListener('click', toggleTimer); pomodoroBtn.addEventListener('click', () => switchMode('pomodoro')); shortBreakBtn.addEventListener('click', () => switchMode('shortBreak')); longBreakBtn.addEventListener('click', () => switchMode('longBreak')); pomodoroTimeInput.addEventListener('change', updateTimerSettings); shortBreakTimeInput.addEventListener('change', updateTimerSettings); longBreakTimeInput.addEventListener('change', updateTimerSettings); addTaskBtn.addEventListener('click', addTask); taskInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') addTask(); }); // Functions function toggleTimer() { if (isRunning) { pauseTimer(); } else { startTimer(); } } function startTimer() { isRunning = true; startBtn.textContent = 'PAUSE'; startBtn.classList.remove('bg-white', 'text-indigo-800'); startBtn.classList.add('bg-amber-400', 'text-amber-900'); timer = setInterval(() => { timeLeft--; updateDisplay(); updateProgressRing(); if (timeLeft <= 0) { clearInterval(timer); alarmSound.play(); isRunning = false; startBtn.textContent = 'START'; startBtn.classList.remove('bg-amber-400', 'text-amber-900'); startBtn.classList.add('bg-white', 'text-indigo-800'); if (currentMode === 'pomodoro') { pomodorosCompleted++; pomoCount.textContent = pomodorosCompleted; // Auto-switch to short break after 4 pomodoros if (pomodorosCompleted % 4 === 0) { setTimeout(() => switchMode('longBreak'), 1000); } else { setTimeout(() => switchMode('shortBreak'), 1000); } } else { setTimeout(() => switchMode('pomodoro'), 1000); } } }, 1000); } function pauseTimer() { clearInterval(timer); isRunning = false; startBtn.textContent = 'START'; startBtn.classList.remove('bg-amber-400', 'text-amber-900'); startBtn.classList.add('bg-white', 'text-indigo-800'); } function updateDisplay() { const minutes = Math.floor(timeLeft / 60); const seconds = timeLeft % 60; timeDisplay.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; // Add pulse animation when time is running low if (timeLeft <= 60 && isRunning) { timeDisplay.classList.add('pulse-animation', 'text-amber-400'); } else { timeDisplay.classList.remove('pulse-animation', 'text-amber-400'); } } function updateProgressRing() { let totalTime; if (currentMode === 'pomodoro') totalTime = pomodoroLength * 60; else if (currentMode === 'shortBreak') totalTime = shortBreakLength * 60; else totalTime = longBreakLength * 60; const offset = circumference - (timeLeft / totalTime) * circumference; progressRing.style.strokeDashoffset = offset; } function switchMode(mode) { currentMode = mode; // Update active tab pomodoroBtn.classList.remove('tab-active'); shortBreakBtn.classList.remove('tab-active'); longBreakBtn.classList.remove('tab-active'); if (mode === 'pomodoro') { pomodoroBtn.classList.add('tab-active'); timeLeft = pomodoroLength * 60; progressRing.classList.remove('text-emerald-400', 'text-amber-400'); progressRing.classList.add('text-indigo-400'); } else if (mode === 'shortBreak') { shortBreakBtn.classList.add('tab-active'); timeLeft = shortBreakLength * 60; progressRing.classList.remove('text-indigo-400', 'text-amber-400'); progressRing.classList.add('text-emerald-400'); } else { longBreakBtn.classList.add('tab-active'); timeLeft = longBreakLength * 60; progressRing.classList.remove('text-indigo-400', 'text-emerald-400'); progressRing.classList.add('text-amber-400'); } if (isRunning) { pauseTimer(); } updateDisplay(); updateProgressRing(); } function updateTimerSettings() { pomodoroLength = parseInt(pomodoroTimeInput.value) || 25; shortBreakLength = parseInt(shortBreakTimeInput.value) || 5; longBreakLength = parseInt(longBreakTimeInput.value) || 15; if (!isRunning) { if (currentMode === 'pomodoro') timeLeft = pomodoroLength * 60; else if (currentMode === 'shortBreak') timeLeft = shortBreakLength * 60; else timeLeft = longBreakLength * 60; updateDisplay(); updateProgressRing(); } } function addTask() { const taskText = taskInput.value.trim(); if (taskText) { const taskItem = document.createElement('li'); taskItem.className = 'flex items-center bg-indigo-800/30 rounded-md px-3 py-2'; const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.className = 'mr-2'; checkbox.addEventListener('change', function() { if (this.checked) { taskTextSpan.style.textDecoration = 'line-through'; taskTextSpan.style.opacity = '0.7'; } else { taskTextSpan.style.textDecoration = 'none'; taskTextSpan.style.opacity = '1'; } }); const taskTextSpan = document.createElement('span'); taskTextSpan.className = 'flex-1'; taskTextSpan.textContent = taskText; const deleteBtn = document.createElement('button'); deleteBtn.className = 'text-indigo-300 hover:text-white ml-2'; deleteBtn.innerHTML = '<i class="fas fa-trash-alt"></i>'; deleteBtn.addEventListener('click', function() { taskItem.remove(); }); taskItem.appendChild(checkbox); taskItem.appendChild(taskTextSpan); taskItem.appendChild(deleteBtn); taskList.appendChild(taskItem); taskInput.value = ''; } } </script> </body> </html> am - Initial Deployment
48266ea verified
Raw History Blame Contribute Delete
27.1 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ZenPomo Pro - Advanced Focus Timer</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>
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.pulse-animation {
animation: pulse 2s infinite;
}
.progress-ring__circle {
transition: stroke-dashoffset 0.35s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.tab-active {
background-color: rgba(255, 255, 255, 0.2);
}
.volume-slider {
-webkit-appearance: none;
width: 100%;
height: 6px;
border-radius: 3px;
background: rgba(255, 255, 255, 0.2);
outline: none;
}
.volume-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
cursor: pointer;
}
.volume-slider::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
cursor: pointer;
}
</style>
</head>
<body class="bg-gradient-to-br from-indigo-900 to-purple-800 min-h-screen text-white font-sans">
<div class="container mx-auto px-4 py-8 flex flex-col items-center">
<header class="mb-8 text-center">
<h1 class="text-4xl font-bold mb-2">ZenPomo Pro</h1>
<p class="text-indigo-200">Enhance your focus with ambient sounds</p>
</header>
<div class="bg-white/10 backdrop-blur-sm rounded-2xl p-6 w-full max-w-md shadow-xl">
<!-- Timer Modes -->
<div class="flex justify-center mb-6 bg-indigo-800/30 rounded-full p-1">
<button id="pomodoro-btn" class="tab-active px-4 py-2 rounded-full font-medium transition-all">Pomodoro</button>
<button id="short-break-btn" class="px-4 py-2 rounded-full font-medium transition-all">Short Break</button>
<button id="long-break-btn" class="px-4 py-2 rounded-full font-medium transition-all">Long Break</button>
<button id="custom-btn" class="px-4 py-2 rounded-full font-medium transition-all">Custom</button>
</div>
<!-- Timer Display -->
<div class="relative flex justify-center mb-8">
<svg class="w-64 h-64">
<circle
class="text-indigo-700/30"
stroke-width="8"
stroke="currentColor"
fill="transparent"
r="112"
cx="128"
cy="128"
/>
<circle
id="progress-ring"
class="progress-ring__circle text-indigo-400"
stroke-width="8"
stroke-linecap="round"
stroke="currentColor"
fill="transparent"
r="112"
cx="128"
cy="128"
stroke-dasharray="704"
stroke-dashoffset="0"
/>
</svg>
<div class="absolute inset-0 flex flex-col items-center justify-center">
<div id="time-display" class="text-6xl font-bold mb-2">25:00</div>
<div class="flex space-x-3">
<button id="start-btn" class="bg-white text-indigo-800 px-6 py-3 rounded-full font-bold hover:bg-indigo-100 transition-all">
START
</button>
<button id="reset-btn" class="bg-indigo-800/30 text-white px-4 py-3 rounded-full font-bold hover:bg-indigo-800/50 transition-all">
<i class="fas fa-redo"></i>
</button>
</div>
</div>
</div>
<!-- Custom Time Input (Hidden by default) -->
<div id="custom-time-container" class="hidden bg-indigo-800/20 rounded-xl p-4 mb-6">
<h3 class="font-medium mb-3 text-center">Set Custom Time</h3>
<div class="flex items-center justify-center space-x-4">
<div class="flex items-center">
<button id="custom-decrease" class="bg-indigo-800/30 rounded-l-md px-3 py-2 hover:bg-indigo-800/50">
<i class="fas fa-minus"></i>
</button>
<input id="custom-time" type="number" min="1" max="120" value="25"
class="w-16 bg-indigo-800/30 px-3 py-2 text-center border-l-0 border-r-0">
<button id="custom-increase" class="bg-indigo-800/30 rounded-r-md px-3 py-2 hover:bg-indigo-800/50">
<i class="fas fa-plus"></i>
</button>
</div>
<button id="apply-custom-time" class="bg-indigo-600 px-4 py-2 rounded-md hover:bg-indigo-700">
Apply
</button>
</div>
</div>
<!-- Ambient Sounds -->
<div class="bg-indigo-800/20 rounded-xl p-4 mb-6">
<h3 class="font-medium mb-3 text-center">Ambient Sounds</h3>
<div class="grid grid-cols-2 gap-3 mb-3">
<button id="rain-sound-btn" class="sound-btn bg-indigo-800/30 rounded-md px-3 py-2 hover:bg-indigo-800/50 transition-all flex items-center justify-center">
<i class="fas fa-cloud-rain mr-2"></i> Rain
</button>
<button id="forest-sound-btn" class="sound-btn bg-indigo-800/30 rounded-md px-3 py-2 hover:bg-indigo-800/50 transition-all flex items-center justify-center">
<i class="fas fa-tree mr-2"></i> Forest
</button>
<button id="coffee-sound-btn" class="sound-btn bg-indigo-800/30 rounded-md px-3 py-2 hover:bg-indigo-800/50 transition-all flex items-center justify-center">
<i class="fas fa-coffee mr-2"></i> Café
</button>
<button id="waves-sound-btn" class="sound-btn bg-indigo-800/30 rounded-md px-3 py-2 hover:bg-indigo-800/50 transition-all flex items-center justify-center">
<i class="fas fa-water mr-2"></i> Waves
</button>
</div>
<div class="flex items-center space-x-2">
<i class="fas fa-volume-down text-indigo-200"></i>
<input type="range" id="volume-slider" class="volume-slider" min="0" max="1" step="0.1" value="0.5">
<i class="fas fa-volume-up text-indigo-200"></i>
</div>
</div>
<!-- Timer Settings -->
<div class="bg-indigo-800/20 rounded-xl p-4 mb-6">
<h3 class="font-medium mb-3 text-center">Timer Settings</h3>
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-sm text-indigo-200 mb-1">Pomodoro</label>
<input id="pomodoro-time" type="number" min="1" max="60" value="25" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center">
</div>
<div>
<label class="block text-sm text-indigo-200 mb-1">Short Break</label>
<input id="short-break-time" type="number" min="1" max="30" value="5" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center">
</div>
<div>
<label class="block text-sm text-indigo-200 mb-1">Long Break</label>
<input id="long-break-time" type="number" min="1" max="60" value="15" class="w-full bg-indigo-800/30 rounded-md px-3 py-2 text-center">
</div>
</div>
</div>
<!-- Task List -->
<div class="bg-indigo-800/20 rounded-xl p-4">
<h3 class="font-medium mb-3 text-center">Today's Tasks</h3>
<div class="flex mb-3">
<input id="task-input" type="text" placeholder="Add a task..." class="flex-1 bg-indigo-800/30 rounded-l-md px-3 py-2 focus:outline-none">
<button id="add-task-btn" class="bg-indigo-600 px-4 rounded-r-md hover:bg-indigo-700 transition-all">
<i class="fas fa-plus"></i>
</button>
</div>
<ul id="task-list" class="space-y-2 max-h-40 overflow-y-auto">
<!-- Tasks will be added here -->
</ul>
</div>
</div>
<!-- Stats -->
<div class="mt-6 text-center text-indigo-200">
<p>Pomodoros completed today: <span id="pomo-count" class="font-bold">0</span></p>
</div>
</div>
<!-- Audio Elements -->
<audio id="alarm-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-alarm-digital-clock-beep-989.mp3" preload="auto"></audio>
<audio id="rain-sound" loop src="https://assets.mixkit.co/sfx/preview/mixkit-rain-loop-1243.mp3" preload="auto"></audio>
<audio id="forest-sound" loop src="https://assets.mixkit.co/sfx/preview/mixkit-forest-ambience-1681.mp3" preload="auto"></audio>
<audio id="coffee-sound" loop src="https://assets.mixkit.co/sfx/preview/mixkit-coffee-shop-ambience-170.mp3" preload="auto"></audio>
<audio id="waves-sound" loop src="https://assets.mixkit.co/sfx/preview/mixkit-waves-on-the-beach-1864.mp3" preload="auto"></audio>
<script>
// DOM Elements
const timeDisplay = document.getElementById('time-display');
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const pomodoroBtn = document.getElementById('pomodoro-btn');
const shortBreakBtn = document.getElementById('short-break-btn');
const longBreakBtn = document.getElementById('long-break-btn');
const customBtn = document.getElementById('custom-btn');
const progressRing = document.getElementById('progress-ring');
const alarmSound = document.getElementById('alarm-sound');
const pomodoroTimeInput = document.getElementById('pomodoro-time');
const shortBreakTimeInput = document.getElementById('short-break-time');
const longBreakTimeInput = document.getElementById('long-break-time');
const taskInput = document.getElementById('task-input');
const addTaskBtn = document.getElementById('add-task-btn');
const taskList = document.getElementById('task-list');
const pomoCount = document.getElementById('pomo-count');
const customTimeContainer = document.getElementById('custom-time-container');
const customTimeInput = document.getElementById('custom-time');
const customDecreaseBtn = document.getElementById('custom-decrease');
const customIncreaseBtn = document.getElementById('custom-increase');
const applyCustomTimeBtn = document.getElementById('apply-custom-time');
const volumeSlider = document.getElementById('volume-slider');
// Sound buttons
const rainSoundBtn = document.getElementById('rain-sound-btn');
const forestSoundBtn = document.getElementById('forest-sound-btn');
const coffeeSoundBtn = document.getElementById('coffee-sound-btn');
const wavesSoundBtn = document.getElementById('waves-sound-btn');
const rainSound = document.getElementById('rain-sound');
const forestSound = document.getElementById('forest-sound');
const coffeeSound = document.getElementById('coffee-sound');
const wavesSound = document.getElementById('waves-sound');
// Timer variables
let timer;
let timeLeft = 25 * 60; // 25 minutes in seconds
let isRunning = false;
let currentMode = 'pomodoro'; // 'pomodoro', 'shortBreak', 'longBreak', 'custom'
let pomodorosCompleted = 0;
let pomodoroLength = 25;
let shortBreakLength = 5;
let longBreakLength = 15;
let customLength = 25;
const circumference = 2 * Math.PI * 112;
// Sound variables
let activeSound = null;
let volume = 0.5;
// Initialize
updateDisplay();
updateProgressRing();
updateVolume();
// Event Listeners
startBtn.addEventListener('click', toggleTimer);
resetBtn.addEventListener('click', resetTimer);
pomodoroBtn.addEventListener('click', () => switchMode('pomodoro'));
shortBreakBtn.addEventListener('click', () => switchMode('shortBreak'));
longBreakBtn.addEventListener('click', () => switchMode('longBreak'));
customBtn.addEventListener('click', () => switchMode('custom'));
pomodoroTimeInput.addEventListener('change', updateTimerSettings);
shortBreakTimeInput.addEventListener('change', updateTimerSettings);
longBreakTimeInput.addEventListener('change', updateTimerSettings);
addTaskBtn.addEventListener('click', addTask);
taskInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') addTask();
});
// Custom time controls
customDecreaseBtn.addEventListener('click', () => {
customTimeInput.value = Math.max(1, parseInt(customTimeInput.value) - 1);
});
customIncreaseBtn.addEventListener('click', () => {
customTimeInput.value = Math.min(120, parseInt(customTimeInput.value) + 1);
});
applyCustomTimeBtn.addEventListener('click', () => {
customLength = parseInt(customTimeInput.value) || 25;
timeLeft = customLength * 60;
updateDisplay();
updateProgressRing();
});
// Sound controls
rainSoundBtn.addEventListener('click', () => toggleSound('rain'));
forestSoundBtn.addEventListener('click', () => toggleSound('forest'));
coffeeSoundBtn.addEventListener('click', () => toggleSound('coffee'));
wavesSoundBtn.addEventListener('click', () => toggleSound('waves'));
volumeSlider.addEventListener('input', updateVolume);
// Functions
function toggleTimer() {
if (isRunning) {
pauseTimer();
} else {
startTimer();
}
}
function resetTimer() {
pauseTimer();
if (currentMode === 'pomodoro') timeLeft = pomodoroLength * 60;
else if (currentMode === 'shortBreak') timeLeft = shortBreakLength * 60;
else if (currentMode === 'longBreak') timeLeft = longBreakLength * 60;
else timeLeft = customLength * 60;
updateDisplay();
updateProgressRing();
}
function startTimer() {
isRunning = true;
startBtn.textContent = 'PAUSE';
startBtn.classList.remove('bg-white', 'text-indigo-800');
startBtn.classList.add('bg-amber-400', 'text-amber-900');
timer = setInterval(() => {
timeLeft--;
updateDisplay();
updateProgressRing();
if (timeLeft <= 0) {
clearInterval(timer);
playAlarm();
isRunning = false;
startBtn.textContent = 'START';
startBtn.classList.remove('bg-amber-400', 'text-amber-900');
startBtn.classList.add('bg-white', 'text-indigo-800');
if (currentMode === 'pomodoro') {
pomodorosCompleted++;
pomoCount.textContent = pomodorosCompleted;
// Auto-switch to short break after 4 pomodoros
if (pomodorosCompleted % 4 === 0) {
setTimeout(() => switchMode('longBreak'), 1000);
} else {
setTimeout(() => switchMode('shortBreak'), 1000);
}
} else {
setTimeout(() => switchMode('pomodoro'), 1000);
}
}
}, 1000);
}
function playAlarm() {
// Stop any ambient sound when alarm plays
stopAllSounds();
// Play alarm sound at full volume
alarmSound.volume = 1;
alarmSound.play();
// Flash the screen
document.body.classList.add('bg-amber-500');
setTimeout(() => {
document.body.classList.remove('bg-amber-500');
}, 300);
setTimeout(() => {
document.body.classList.add('bg-amber-500');
}, 600);
setTimeout(() => {
document.body.classList.remove('bg-amber-500');
}, 900);
// Resume ambient sound after alarm
setTimeout(() => {
if (activeSound) {
activeSound.play();
}
}, 3000);
}
function pauseTimer() {
clearInterval(timer);
isRunning = false;
startBtn.textContent = 'START';
startBtn.classList.remove('bg-amber-400', 'text-amber-900');
startBtn.classList.add('bg-white', 'text-indigo-800');
}
function updateDisplay() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timeDisplay.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Add pulse animation when time is running low
if (timeLeft <= 60 && isRunning) {
timeDisplay.classList.add('pulse-animation', 'text-amber-400');
} else {
timeDisplay.classList.remove('pulse-animation', 'text-amber-400');
}
}
function updateProgressRing() {
let totalTime;
if (currentMode === 'pomodoro') totalTime = pomodoroLength * 60;
else if (currentMode === 'shortBreak') totalTime = shortBreakLength * 60;
else if (currentMode === 'longBreak') totalTime = longBreakLength * 60;
else totalTime = customLength * 60;
const offset = circumference - (timeLeft / totalTime) * circumference;
progressRing.style.strokeDashoffset = offset;
}
function switchMode(mode) {
currentMode = mode;
// Update active tab
pomodoroBtn.classList.remove('tab-active');
shortBreakBtn.classList.remove('tab-active');
longBreakBtn.classList.remove('tab-active');
customBtn.classList.remove('tab-active');
if (mode === 'pomodoro') {
pomodoroBtn.classList.add('tab-active');
timeLeft = pomodoroLength * 60;
progressRing.classList.remove('text-emerald-400', 'text-amber-400');
progressRing.classList.add('text-indigo-400');
customTimeContainer.classList.add('hidden');
} else if (mode === 'shortBreak') {
shortBreakBtn.classList.add('tab-active');
timeLeft = shortBreakLength * 60;
progressRing.classList.remove('text-indigo-400', 'text-amber-400');
progressRing.classList.add('text-emerald-400');
customTimeContainer.classList.add('hidden');
} else if (mode === 'longBreak') {
longBreakBtn.classList.add('tab-active');
timeLeft = longBreakLength * 60;
progressRing.classList.remove('text-indigo-400', 'text-emerald-400');
progressRing.classList.add('text-amber-400');
customTimeContainer.classList.add('hidden');
} else {
customBtn.classList.add('tab-active');
timeLeft = customLength * 60;
progressRing.classList.remove('text-indigo-400', 'text-emerald-400', 'text-amber-400');
progressRing.classList.add('text-purple-400');
customTimeContainer.classList.remove('hidden');
}
if (isRunning) {
pauseTimer();
}
updateDisplay();
updateProgressRing();
}
function updateTimerSettings() {
pomodoroLength = parseInt(pomodoroTimeInput.value) || 25;
shortBreakLength = parseInt(shortBreakTimeInput.value) || 5;
longBreakLength = parseInt(longBreakTimeInput.value) || 15;
if (!isRunning) {
if (currentMode === 'pomodoro') timeLeft = pomodoroLength * 60;
else if (currentMode === 'shortBreak') timeLeft = shortBreakLength * 60;
else if (currentMode === 'longBreak') timeLeft = longBreakLength * 60;
else timeLeft = customLength * 60;
updateDisplay();
updateProgressRing();
}
}
function addTask() {
const taskText = taskInput.value.trim();
if (taskText) {
const taskItem = document.createElement('li');
taskItem.className = 'flex items-center bg-indigo-800/30 rounded-md px-3 py-2';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'mr-2';
checkbox.addEventListener('change', function() {
if (this.checked) {
taskTextSpan.style.textDecoration = 'line-through';
taskTextSpan.style.opacity = '0.7';
} else {
taskTextSpan.style.textDecoration = 'none';
taskTextSpan.style.opacity = '1';
}
});
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'flex-1';
taskTextSpan.textContent = taskText;
const deleteBtn = document.createElement('button');
deleteBtn.className = 'text-indigo-300 hover:text-white ml-2';
deleteBtn.innerHTML = '<i class="fas fa-trash-alt"></i>';
deleteBtn.addEventListener('click', function() {
taskItem.remove();
});
taskItem.appendChild(checkbox);
taskItem.appendChild(taskTextSpan);
taskItem.appendChild(deleteBtn);
taskList.appendChild(taskItem);
taskInput.value = '';
}
}
// Sound functions
function toggleSound(soundType) {
const soundBtns = document.querySelectorAll('.sound-btn');
soundBtns.forEach(btn => {
btn.classList.remove('bg-indigo-600');
btn.classList.add('bg-indigo-800/30');
});
// Stop any currently playing sound
stopAllSounds();
// If clicking the same sound button, just stop it
if (activeSound === soundType) {
activeSound = null;
return;
}
// Start the selected sound
activeSound = soundType;
let soundElement;
switch(soundType) {
case 'rain':
soundElement = rainSound;
rainSoundBtn.classList.add('bg-indigo-600');
rainSoundBtn.classList.remove('bg-indigo-800/30');
break;
case 'forest':
soundElement = forestSound;
forestSoundBtn.classList.add('bg-indigo-600');
forestSoundBtn.classList.remove('bg-indigo-800/30');
break;
case 'coffee':
soundElement = coffeeSound;
coffeeSoundBtn.classList.add('bg-indigo-600');
coffeeSoundBtn.classList.remove('bg-indigo-800/30');
break;
case 'waves':
soundElement = wavesSound;
wavesSoundBtn.classList.add('bg-indigo-600');
wavesSoundBtn.classList.remove('bg-indigo-800/30');
break;
}
soundElement.volume = volume;
soundElement.play();
}
function stopAllSounds() {
rainSound.pause();
forestSound.pause();
coffeeSound.pause();
wavesSound.pause();
}
function updateVolume() {
volume = parseFloat(volumeSlider.value);
// Update all sounds with new volume
if (activeSound) {
switch(activeSound) {
case 'rain':
rainSound.volume = volume;
break;
case 'forest':
forestSound.volume = volume;
break;
case 'coffee':
coffeeSound.volume = volume;
break;
case 'waves':
wavesSound.volume = volume;
break;
}
}
}
</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=FaxMe/zenpomodor-timer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>