Roshish121 commited on
Commit
f0916fa
·
verified ·
1 Parent(s): 5798399

timer is not working properly and i can't write in note.....Like timer pause play is not working properly....Also i can't now make it only timer

Browse files
Files changed (1) hide show
  1. index.html +39 -14
index.html CHANGED
@@ -93,12 +93,11 @@
93
  let isExpanded = false;
94
  const widget = document.getElementById('timer-widget');
95
  const liveClock = document.getElementById('live-clock');
96
-
97
  // Timer functions
98
  function startTimer() {
99
  if (!isRunning) {
100
  startTime = Date.now() - elapsedTime;
101
- timerInterval = setInterval(updateTimer, 1000);
102
  isRunning = true;
103
  }
104
  }
@@ -114,6 +113,9 @@
114
  stopTimer();
115
  elapsedTime = 0;
116
  updateDisplay(0);
 
 
 
117
  }
118
 
119
  function updateTimer() {
@@ -122,9 +124,10 @@
122
  }
123
 
124
  function updateDisplay(time) {
125
- const seconds = Math.floor((time / 1000) % 60);
126
- const minutes = Math.floor((time / (1000 * 60)) % 60);
127
- const hours = Math.floor((time / (1000 * 60 * 60)) % 24);
 
128
 
129
  const formattedTime = [
130
  hours.toString().padStart(2, '0'),
@@ -134,8 +137,7 @@
134
 
135
  document.getElementById('live-clock').textContent = formattedTime;
136
  }
137
-
138
- // Drag functionality
139
  let isDragging = false;
140
  let offsetX, offsetY;
141
 
@@ -220,10 +222,9 @@
220
  // Update live clock immediately and every second
221
  updateLiveClock();
222
  setInterval(updateLiveClock, 1000);
223
-
224
  // Save notes to localStorage
225
  const noteInput = document.getElementById('time-note');
226
- noteInput.addEventListener('change', () => {
227
  const note = noteInput.value.trim();
228
  localStorage.setItem('timeNote', note);
229
 
@@ -234,8 +235,7 @@
234
  widget.classList.remove('has-note');
235
  }
236
  });
237
-
238
- // Load and show note if exists
239
  const savedNote = localStorage.getItem('timeNote');
240
  if (savedNote) {
241
  noteInput.value = savedNote;
@@ -243,10 +243,35 @@
243
  widget.classList.add('has-note');
244
  }
245
 
246
- // Initialize with stopped state
247
- resetTimer();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
- // Make sure widget stays visible when minimized
 
 
 
 
 
 
250
  widget.style.minWidth = '150px';
251
  widget.style.minHeight = '70px';
252
 
 
93
  let isExpanded = false;
94
  const widget = document.getElementById('timer-widget');
95
  const liveClock = document.getElementById('live-clock');
 
96
  // Timer functions
97
  function startTimer() {
98
  if (!isRunning) {
99
  startTime = Date.now() - elapsedTime;
100
+ timerInterval = setInterval(updateTimer, 100);
101
  isRunning = true;
102
  }
103
  }
 
113
  stopTimer();
114
  elapsedTime = 0;
115
  updateDisplay(0);
116
+ // Save reset state
117
+ localStorage.setItem('timerElapsed', 0);
118
+ localStorage.setItem('timerRunning', false);
119
  }
120
 
121
  function updateTimer() {
 
124
  }
125
 
126
  function updateDisplay(time) {
127
+ const totalSeconds = Math.floor(time / 1000);
128
+ const seconds = totalSeconds % 60;
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'),
 
137
 
138
  document.getElementById('live-clock').textContent = formattedTime;
139
  }
140
+ // Drag functionality
 
141
  let isDragging = false;
142
  let offsetX, offsetY;
143
 
 
222
  // Update live clock immediately and every second
223
  updateLiveClock();
224
  setInterval(updateLiveClock, 1000);
 
225
  // Save notes to localStorage
226
  const noteInput = document.getElementById('time-note');
227
+ noteInput.addEventListener('input', () => {
228
  const note = noteInput.value.trim();
229
  localStorage.setItem('timeNote', note);
230
 
 
235
  widget.classList.remove('has-note');
236
  }
237
  });
238
+ // Load and show note if exists
 
239
  const savedNote = localStorage.getItem('timeNote');
240
  if (savedNote) {
241
  noteInput.value = savedNote;
 
243
  widget.classList.add('has-note');
244
  }
245
 
246
+ // Load timer state from localStorage
247
+ const savedElapsed = localStorage.getItem('timerElapsed');
248
+ const savedRunning = localStorage.getItem('timerRunning') === 'true';
249
+
250
+ if (savedElapsed) {
251
+ elapsedTime = parseInt(savedElapsed);
252
+ updateDisplay(elapsedTime);
253
+
254
+ if (savedRunning) {
255
+ startTimer();
256
+ }
257
+ } else {
258
+ // Initialize with stopped state
259
+ resetTimer();
260
+ }
261
+
262
+ // Save timer state to localStorage when running
263
+ function saveTimerState() {
264
+ localStorage.setItem('timerElapsed', elapsedTime);
265
+ localStorage.setItem('timerRunning', isRunning);
266
+ }
267
 
268
+ // Save state every second when running
269
+ setInterval(() => {
270
+ if (isRunning) {
271
+ saveTimerState();
272
+ }
273
+ }, 1000);
274
+ // Make sure widget stays visible when minimized
275
  widget.style.minWidth = '150px';
276
  widget.style.minHeight = '70px';
277