File size: 14,182 Bytes
df1a6b9
94a2397
 
 
 
 
df1a6b9
 
94a2397
 
61339ae
 
461c13e
 
 
 
 
 
 
 
61339ae
4b6e049
461c13e
 
de8e843
4b6e049
 
de8e843
 
4b6e049
 
 
de8e843
 
 
461c13e
 
 
de8e843
 
 
 
 
4b6e049
461c13e
 
 
 
 
4b6e049
94a2397
a06753a
461c13e
 
a06753a
4b6e049
461c13e
 
 
94a2397
df1a6b9
 
461c13e
 
94a2397
61339ae
4b6e049
461c13e
 
 
a06753a
 
461c13e
 
 
 
 
a06753a
 
461c13e
 
a06753a
 
461c13e
61339ae
94a2397
 
df1a6b9
461c13e
 
 
 
 
 
23ec822
 
461c13e
 
5a150cc
461c13e
 
5a150cc
461c13e
 
5a150cc
 
461c13e
 
 
 
94a2397
4b6e049
94a2397
461c13e
5a150cc
 
 
 
5798399
 
 
5a150cc
 
 
 
2531820
5a150cc
61c5e4f
5a150cc
94a2397
5a150cc
 
 
 
 
61c5e4f
5a150cc
 
 
 
 
 
 
f0916fa
 
 
61c5e4f
5a150cc
461c13e
 
 
 
c0442de
61c5e4f
 
5a150cc
f0916fa
61339ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5798399
61339ae
 
 
 
 
 
2c01401
 
 
 
61339ae
461c13e
2531820
461c13e
4b6e049
 
 
de8e843
461c13e
 
 
 
 
 
4b6e049
 
 
 
de8e843
d1460fe
61c5e4f
d1460fe
61c5e4f
 
 
 
d1460fe
 
 
61c5e4f
 
c0442de
61c5e4f
 
 
 
 
 
 
 
 
 
 
 
d1460fe
 
 
 
61c5e4f
94a2397
2531820
 
 
de8e843
 
2531820
de8e843
 
 
 
 
94a2397
2531820
 
 
 
 
 
 
 
 
 
94a2397
 
 
de8e843
 
94a2397
461c13e
f0916fa
 
 
 
 
 
 
 
 
61c5e4f
461c13e
f0916fa
 
461c13e
f0916fa
 
461c13e
f0916fa
 
 
 
5798399
461c13e
f0916fa
 
 
 
 
 
de8e843
 
2c01401
 
 
 
 
61339ae
 
 
 
 
 
2c01401
 
2531820
 
 
 
2c01401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2531820
 
 
 
 
 
 
 
 
 
5a150cc
94a2397
 
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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple 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>
        #timer-widget {
            user-select: none;
            transition: all 0.3s ease;
            width: 180px !important;
            height: 80px !important;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            background: rgba(0, 0, 0, 0.3);
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        }
        #timer-widget.expanded {
            width: 300px !important;
            height: 200px !important;
        }
        #controls-container,
        #note-container {
            display: none;
        }
        #timer-widget.expanded #controls-container,
        #timer-widget.expanded #note-container {
            display: flex;
        }
        #note-text {
            display: none;
            font-size: 0.8rem;
            margin-top: 4px;
            color: rgba(255, 255, 255, 0.7);
            word-break: break-word;
        }
        #timer-widget.has-note #note-text {
            display: block;
        }
        #live-clock {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            color: rgba(255, 255, 255, 0.9);
            font-weight: 300;
            letter-spacing: 1px;
            font-size: 1.8rem;
            cursor: pointer;
        }
        #live-date {
            color: rgba(255, 255, 255, 0.6);
            font-weight: 300;
        }
        #time-note {
            transition: all 0.2s ease;
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        #time-note:focus {
            outline: none;
            background-color: rgba(255, 255, 255, 0.08) !important;
            border-color: rgba(255, 255, 255, 0.2);
        }
        #timer-widget {
            overflow: hidden;
            min-width: 180px;
            min-height: 80px;
            border-radius: 16px;
        }
        .timer-button {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            transition: all 0.2s ease;
        }
        .timer-button:hover {
            background: rgba(255, 255, 255, 0.15);
            border-color: rgba(255, 255, 255, 0.25);
        }
        .timer-button:active {
            transform: scale(0.95);
        }
    </style>
</head>
<body class="bg-gray-900">
    <!-- Draggable Time Widget -->
    <div id="timer-widget" class="fixed bottom-4 right-4 z-50 cursor-move">
        <div class="rounded-xl p-4 text-white h-full flex items-center justify-center">
<div class="flex flex-col items-center" id="timer-content">
                <div id="live-clock">00:00:00</div>
                <div class="text-sm opacity-80 mt-1" id="live-date">Loading...</div>
                <div id="note-text" class="hovered-element">zxcvbnmfjfgiygwyigfiweayhsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssiyglq</div>
<div class="flex space-x-3 mt-4" id="controls-container">
                    <button id="start-btn" class="timer-button px-3 py-2 rounded-full text-green-400 hover:text-green-300">
                        <i class="fas fa-play"></i>
                    </button>
                    <button id="stop-btn" class="timer-button px-3 py-2 rounded-full text-red-400 hover:text-red-300">
                        <i class="fas fa-stop"></i>
                    </button>
                    <button id="reset-btn" class="timer-button px-3 py-2 rounded-full text-blue-400 hover:text-blue-300">
                        <i class="fas fa-undo"></i>
                    </button>
                </div>
</div>
            <div class="mt-4" id="note-container">
                <input type="text" id="time-note" class="text-white text-sm rounded-lg px-3 py-2 w-full" 
placeholder="Add note...">
            </div>
        </div>
    </div>
    <script>
        let timerInterval;
        let isRunning = false;
        let startTime;
        let elapsedTime = 0;
        let isExpanded = false;
        const widget = document.getElementById('timer-widget');
        const liveClock = document.getElementById('live-clock');
        // Timer functions
        function startTimer() {
            if (!isRunning) {
                startTime = Date.now() - elapsedTime;
                timerInterval = setInterval(updateTimer, 10); // More frequent updates for smoother animation
                isRunning = true;
                updateTimerDisplay(); // Update display mode
            }
        }

        function stopTimer() {
            if (isRunning) {
                clearInterval(timerInterval);
                isRunning = false;
                updateTimerDisplay(); // Update display mode
            }
        }

        function resetTimer() {
            stopTimer();
            elapsedTime = 0;
            updateDisplay(0);
            // Save reset state
            localStorage.setItem('timerElapsed', 0);
            localStorage.setItem('timerRunning', false);
            updateTimerDisplay(); // Update display mode
        }
function updateTimer() {
    elapsedTime = Date.now() - startTime;
    updateDisplay(elapsedTime);
}
function updateDisplay(time) {
            elapsedTime = time;
            document.getElementById('live-clock').textContent = formatTime(time);
        }
// Drag functionality
        let isDragging = false;
        let offsetX, offsetY;

        widget.addEventListener('mousedown', (e) => {
            if (e.target === widget || e.target.closest('.cursor-move')) {
                isDragging = true;
                offsetX = e.clientX - widget.getBoundingClientRect().left;
                offsetY = e.clientY - widget.getBoundingClientRect().top;
                widget.style.transition = 'none';
                e.preventDefault();
            }
        });

        document.addEventListener('mousemove', (e) => {
            if (!isDragging) return;
            
            widget.style.left = `${e.clientX - offsetX}px`;
            widget.style.top = `${e.clientY - offsetY}px`;
        });

        document.addEventListener('mouseup', () => {
            isDragging = false;
            widget.style.transition = 'all 0.2s ease';
            
            // Save position to localStorage
            const rect = widget.getBoundingClientRect();
            localStorage.setItem('timerPosition', JSON.stringify({
                left: rect.left,
                top: rect.top
            }));
        });

        // Load saved position
        const savedPosition = localStorage.getItem('timerPosition');
        if (savedPosition) {
            const { left, top } = JSON.parse(savedPosition);
            widget.style.left = `${left}px`;
            widget.style.top = `${top}px`;
        } else {
            // Set default position if no saved position
            widget.style.left = 'calc(100vw - 200px)';
            widget.style.top = 'calc(100vh - 100px)';
        }
        // Toggle expanded state
        liveClock.addEventListener('click', (e) => {
            e.stopPropagation(); // Prevent triggering drag
            isExpanded = !isExpanded;
            widget.classList.toggle('expanded', isExpanded);
            localStorage.setItem('timerExpanded', isExpanded);
        });
// Button event listeners
        document.getElementById('start-btn').addEventListener('click', startTimer);
        document.getElementById('stop-btn').addEventListener('click', stopTimer);
        document.getElementById('reset-btn').addEventListener('click', resetTimer);

        // Load expanded state
        const savedExpanded = localStorage.getItem('timerExpanded') === 'true';
        if (savedExpanded) {
            isExpanded = true;
            widget.classList.add('expanded');
        }
// Update timer display based on state
        function updateTimerDisplay() {
            // Always show timer when timer is active (running or has elapsed time)
            if (isRunning || elapsedTime > 0) {
                document.getElementById('live-clock').textContent = formatTime(elapsedTime);
                document.getElementById('live-date').style.display = 'none';
            } else {
                // Show timer with 00:00:00 when not active
                document.getElementById('live-clock').textContent = '00:00:00';
                document.getElementById('live-date').style.display = 'none';
            }
        }
// Format time function
        function formatTime(time) {
            const totalSeconds = Math.floor(time / 1000);
            const seconds = totalSeconds % 60;
            const minutes = Math.floor((totalSeconds / 60) % 60);
            const hours = Math.floor(totalSeconds / 3600);

            return [
                hours.toString().padStart(2, '0'),
                minutes.toString().padStart(2, '0'),
                seconds.toString().padStart(2, '0')
            ].join(':');
        }
        // Remove live clock functionality entirely
        // Update timer display immediately and every second
        updateTimerDisplay();
        setInterval(updateTimerDisplay, 1000);
// Save notes to localStorage
        const noteInput = document.getElementById('time-note');
        noteInput.addEventListener('input', (e) => {
            e.stopPropagation(); // Prevent triggering drag
            const note = noteInput.value;
            localStorage.setItem('timeNote', note);
            
            if (note.trim()) {
                document.getElementById('note-text').textContent = note;
                widget.classList.add('has-note');
            } else {
                widget.classList.remove('has-note');
            }
        });

        // Prevent note input from triggering drag
        noteInput.addEventListener('mousedown', (e) => {
            e.stopPropagation();
        });

        noteInput.addEventListener('touchstart', (e) => {
            e.stopPropagation();
        });
        // Load and show note if exists
        const savedNote = localStorage.getItem('timeNote');
        if (savedNote) {
            noteInput.value = savedNote;
            document.getElementById('note-text').textContent = savedNote;
            widget.classList.add('has-note');
        }
        // Load timer state from localStorage
        const savedElapsed = localStorage.getItem('timerElapsed');
        const savedRunning = localStorage.getItem('timerRunning') === 'true';
        
        if (savedElapsed) {
            elapsedTime = parseInt(savedElapsed);
            updateDisplay(elapsedTime);
            
            if (savedRunning) {
                startTimer();
            } else {
                updateTimerDisplay(); // Update display mode for stopped timer
            }
        } else {
            // Initialize with stopped state
            resetTimer();
        }
// Save timer state to localStorage when running
        function saveTimerState() {
            localStorage.setItem('timerElapsed', elapsedTime);
            localStorage.setItem('timerRunning', isRunning);
        }

        // Save state every second when running
        setInterval(() => {
            if (isRunning) {
                saveTimerState();
            }
        }, 1000);
// Make sure widget stays visible when minimized
        widget.style.minWidth = '150px';
        widget.style.minHeight = '70px';
        
        // Ensure widget is always draggable and visible
        widget.style.position = 'fixed';
        widget.style.zIndex = '9999';
        
        // Prevent text selection while dragging
        document.addEventListener('selectstart', (e) => {
            if (isDragging) {
                e.preventDefault();
            }
        });
        // Touch support for mobile dragging
        widget.addEventListener('touchstart', (e) => {
            // Don't start drag if clicking on note input or buttons
            if (e.target === noteInput || e.target.closest('button') || e.target.closest('#controls-container') || e.target.closest('#note-container')) {
                return;
            }
            if (e.target === widget || e.target.closest('.cursor-move')) {
                isDragging = true;
                const touch = e.touches[0];
                offsetX = touch.clientX - widget.getBoundingClientRect().left;
                offsetY = touch.clientY - widget.getBoundingClientRect().top;
                widget.style.transition = 'none';
                e.preventDefault();
            }
        });

        document.addEventListener('touchmove', (e) => {
            if (!isDragging) return;
            const touch = e.touches[0];
            widget.style.left = `${touch.clientX - offsetX}px`;
            widget.style.top = `${touch.clientY - offsetY}px`;
            e.preventDefault();
        });

        document.addEventListener('touchend', () => {
            if (isDragging) {
                isDragging = false;
                widget.style.transition = 'all 0.2s ease';
                
                // Save position to localStorage
                const rect = widget.getBoundingClientRect();
                localStorage.setItem('timerPosition', JSON.stringify({
                    left: rect.left,
                    top: rect.top
                }));
            }
        });

        // Prevent button clicks from triggering drag
        document.querySelectorAll('button').forEach(button => {
            button.addEventListener('mousedown', (e) => {
                e.stopPropagation();
            });
            button.addEventListener('touchstart', (e) => {
                e.stopPropagation();
            });
        });
</script>
</body>
</html>