Spaces:
Running
Running
i am not able to now pause it please fix this issues and also whenever i leave the whole timer block it need to show only time or if i start timer then only timer
Browse files- index.html +58 -19
index.html
CHANGED
|
@@ -99,6 +99,7 @@
|
|
| 99 |
startTime = Date.now() - elapsedTime;
|
| 100 |
timerInterval = setInterval(updateTimer, 10); // More frequent updates for smoother animation
|
| 101 |
isRunning = true;
|
|
|
|
| 102 |
}
|
| 103 |
}
|
| 104 |
|
|
@@ -106,6 +107,7 @@
|
|
| 106 |
if (isRunning) {
|
| 107 |
clearInterval(timerInterval);
|
| 108 |
isRunning = false;
|
|
|
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
|
@@ -116,26 +118,15 @@
|
|
| 116 |
// Save reset state
|
| 117 |
localStorage.setItem('timerElapsed', 0);
|
| 118 |
localStorage.setItem('timerRunning', false);
|
|
|
|
| 119 |
}
|
| 120 |
-
|
| 121 |
-
function updateTimer() {
|
| 122 |
elapsedTime = Date.now() - startTime;
|
| 123 |
updateDisplay(elapsedTime);
|
| 124 |
}
|
| 125 |
-
|
| 126 |
function updateDisplay(time) {
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
const minutes = Math.floor((totalSeconds / 60) % 60);
|
| 130 |
-
const hours = Math.floor(totalSeconds / 3600);
|
| 131 |
-
|
| 132 |
-
const formattedTime = [
|
| 133 |
-
hours.toString().padStart(2, '0'),
|
| 134 |
-
minutes.toString().padStart(2, '0'),
|
| 135 |
-
seconds.toString().padStart(2, '0')
|
| 136 |
-
].join(':');
|
| 137 |
-
|
| 138 |
-
document.getElementById('live-clock').textContent = formattedTime;
|
| 139 |
}
|
| 140 |
// Drag functionality
|
| 141 |
let isDragging = false;
|
|
@@ -217,11 +208,57 @@
|
|
| 217 |
document.getElementById('live-clock').textContent = timeStr;
|
| 218 |
document.getElementById('live-date').textContent = dateStr;
|
| 219 |
}
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
// Update live clock immediately and every second
|
| 222 |
updateLiveClock();
|
| 223 |
setInterval(updateLiveClock, 1000);
|
| 224 |
-
|
| 225 |
const noteInput = document.getElementById('time-note');
|
| 226 |
noteInput.addEventListener('input', (e) => {
|
| 227 |
e.stopPropagation(); // Prevent triggering drag
|
|
@@ -251,7 +288,7 @@
|
|
| 251 |
document.getElementById('note-text').textContent = savedNote;
|
| 252 |
widget.classList.add('has-note');
|
| 253 |
}
|
| 254 |
-
// Load timer state from localStorage
|
| 255 |
const savedElapsed = localStorage.getItem('timerElapsed');
|
| 256 |
const savedRunning = localStorage.getItem('timerRunning') === 'true';
|
| 257 |
|
|
@@ -261,12 +298,14 @@
|
|
| 261 |
|
| 262 |
if (savedRunning) {
|
| 263 |
startTimer();
|
|
|
|
|
|
|
| 264 |
}
|
| 265 |
} else {
|
| 266 |
// Initialize with stopped state
|
| 267 |
resetTimer();
|
| 268 |
}
|
| 269 |
-
|
| 270 |
function saveTimerState() {
|
| 271 |
localStorage.setItem('timerElapsed', elapsedTime);
|
| 272 |
localStorage.setItem('timerRunning', isRunning);
|
|
|
|
| 99 |
startTime = Date.now() - elapsedTime;
|
| 100 |
timerInterval = setInterval(updateTimer, 10); // More frequent updates for smoother animation
|
| 101 |
isRunning = true;
|
| 102 |
+
updateTimerDisplay(); // Update display mode
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
|
|
|
| 107 |
if (isRunning) {
|
| 108 |
clearInterval(timerInterval);
|
| 109 |
isRunning = false;
|
| 110 |
+
updateTimerDisplay(); // Update display mode
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
|
|
|
| 118 |
// Save reset state
|
| 119 |
localStorage.setItem('timerElapsed', 0);
|
| 120 |
localStorage.setItem('timerRunning', false);
|
| 121 |
+
updateTimerDisplay(); // Update display mode
|
| 122 |
}
|
| 123 |
+
function updateTimer() {
|
|
|
|
| 124 |
elapsedTime = Date.now() - startTime;
|
| 125 |
updateDisplay(elapsedTime);
|
| 126 |
}
|
|
|
|
| 127 |
function updateDisplay(time) {
|
| 128 |
+
elapsedTime = time;
|
| 129 |
+
document.getElementById('live-clock').textContent = formatTime(time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
}
|
| 131 |
// Drag functionality
|
| 132 |
let isDragging = false;
|
|
|
|
| 208 |
document.getElementById('live-clock').textContent = timeStr;
|
| 209 |
document.getElementById('live-date').textContent = dateStr;
|
| 210 |
}
|
| 211 |
+
// Update timer display based on state
|
| 212 |
+
function updateTimerDisplay() {
|
| 213 |
+
if (isRunning || elapsedTime > 0) {
|
| 214 |
+
// Show timer when running or has elapsed time
|
| 215 |
+
document.getElementById('live-clock').textContent = formatTime(elapsedTime);
|
| 216 |
+
document.getElementById('live-date').style.display = 'none';
|
| 217 |
+
} else {
|
| 218 |
+
// Show live clock when timer is not active
|
| 219 |
+
document.getElementById('live-date').style.display = 'block';
|
| 220 |
+
updateLiveClock();
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// Format time function
|
| 225 |
+
function formatTime(time) {
|
| 226 |
+
const totalSeconds = Math.floor(time / 1000);
|
| 227 |
+
const seconds = totalSeconds % 60;
|
| 228 |
+
const minutes = Math.floor((totalSeconds / 60) % 60);
|
| 229 |
+
const hours = Math.floor(totalSeconds / 3600);
|
| 230 |
+
|
| 231 |
+
return [
|
| 232 |
+
hours.toString().padStart(2, '0'),
|
| 233 |
+
minutes.toString().padStart(2, '0'),
|
| 234 |
+
seconds.toString().padStart(2, '0')
|
| 235 |
+
].join(':');
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// Update live clock
|
| 239 |
+
function updateLiveClock() {
|
| 240 |
+
if (!isRunning && elapsedTime === 0) {
|
| 241 |
+
const now = new Date();
|
| 242 |
+
const timeStr = now.toLocaleTimeString('en-US', {
|
| 243 |
+
hour12: false,
|
| 244 |
+
hour: '2-digit',
|
| 245 |
+
minute: '2-digit',
|
| 246 |
+
second: '2-digit'
|
| 247 |
+
});
|
| 248 |
+
const dateStr = now.toLocaleDateString('en-US', {
|
| 249 |
+
weekday: 'short',
|
| 250 |
+
month: 'short',
|
| 251 |
+
day: 'numeric'
|
| 252 |
+
});
|
| 253 |
+
document.getElementById('live-clock').textContent = timeStr;
|
| 254 |
+
document.getElementById('live-date').textContent = dateStr;
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
// Update live clock immediately and every second
|
| 259 |
updateLiveClock();
|
| 260 |
setInterval(updateLiveClock, 1000);
|
| 261 |
+
// Save notes to localStorage
|
| 262 |
const noteInput = document.getElementById('time-note');
|
| 263 |
noteInput.addEventListener('input', (e) => {
|
| 264 |
e.stopPropagation(); // Prevent triggering drag
|
|
|
|
| 288 |
document.getElementById('note-text').textContent = savedNote;
|
| 289 |
widget.classList.add('has-note');
|
| 290 |
}
|
| 291 |
+
// Load timer state from localStorage
|
| 292 |
const savedElapsed = localStorage.getItem('timerElapsed');
|
| 293 |
const savedRunning = localStorage.getItem('timerRunning') === 'true';
|
| 294 |
|
|
|
|
| 298 |
|
| 299 |
if (savedRunning) {
|
| 300 |
startTimer();
|
| 301 |
+
} else {
|
| 302 |
+
updateTimerDisplay(); // Update display mode for stopped timer
|
| 303 |
}
|
| 304 |
} else {
|
| 305 |
// Initialize with stopped state
|
| 306 |
resetTimer();
|
| 307 |
}
|
| 308 |
+
// Save timer state to localStorage when running
|
| 309 |
function saveTimerState() {
|
| 310 |
localStorage.setItem('timerElapsed', elapsedTime);
|
| 311 |
localStorage.setItem('timerRunning', isRunning);
|