forked from jeushjazmere/https-github.com-owner-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
517 lines (446 loc) · 13.5 KB
/
Copy pathindex.html
File metadata and controls
517 lines (446 loc) · 13.5 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>World Digital Clock — Multiple Time Zones</title>
<style>
:root {
--bg: #0b1220;
--card: #0f1724;
--accent: #60a5fa;
--muted: #94a3b8;
--glass: rgba(255, 255, 255, 0.03);
--success: #34d399;
}
html, body {
height: 100%;
margin: 0;
font-family: Inter, system-ui, Segoe UI, Roboto, Helvetica, Arial;
background: linear-gradient(180deg, #041025 0%, #071229 100%);
color: #e6eef8;
}
.wrap {
max-width: 1000px;
margin: 28px auto;
padding: 20px;
}
header {
display: flex;
align-items: center;
gap: 16px;
flex-wrap: wrap;
}
h1 {
margin: 0;
font-size: 20px;
}
.controls {
margin-left: auto;
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
.controls input[type="text"] {
padding: 8px 10px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.04);
background: transparent;
color: inherit;
width: 260px;
}
.controls button, .controls .smallBtn {
background: var(--accent);
color: #042033;
border: 0;
padding: 8px 10px;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
}
.smallBtn {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.06);
color: var(--muted);
}
.topline {
display: flex;
gap: 12px;
align-items: center;
margin: 12px 0;
color: var(--muted);
font-size: 13px;
flex-wrap: wrap;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 12px;
margin-top: 16px;
}
.card {
background: linear-gradient(180deg, var(--glass), rgba(255, 255, 255, 0.01));
border: 1px solid rgba(255, 255, 255, 0.03);
padding: 12px;
border-radius: 12px;
box-shadow: 0 6px 20px rgba(2, 6, 23, 0.5);
}
.tz-title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
}
.tz-name {
font-weight: 700;
}
.tz-sub {
color: var(--muted);
font-size: 13px;
margin-top: 6px;
}
.time {
font-family: "SFMono-Regular", ui-monospace, SFMono, Menlo, Monaco, "Roboto Mono", monospace;
font-size: 26px;
margin-top: 10px;
font-weight: 500;
}
.date {
color: var(--muted);
font-size: 13px;
margin-top: 4px;
}
.actions {
display: flex;
gap: 8px;
margin-top: 10px;
}
.actions button {
padding: 6px 8px;
border-radius: 8px;
border: 0;
cursor: pointer;
}
.removeBtn {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.04);
color: var(--muted);
padding: 6px 12px;
font-size: 12px;
transition: all 0.2s;
}
.removeBtn:hover {
background: rgba(239, 68, 68, 0.1);
border-color: rgba(239, 68, 68, 0.3);
color: #fecaca;
}
.add-suggestions {
max-height: 160px;
overflow-y: auto;
margin-top: 6px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.03);
background: rgba(255, 255, 255, 0.01);
padding: 6px;
}
.suggestion {
padding: 8px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
transition: background 0.15s;
}
.suggestion:hover {
background: rgba(96, 165, 250, 0.1);
color: var(--accent);
}
footer {
margin-top: 18px;
color: var(--muted);
font-size: 13px;
}
label.switch {
display: inline-flex;
align-items: center;
gap: 8px;
}
input[type="checkbox"] {
width: 18px;
height: 18px;
cursor: pointer;
}
@media (max-width: 520px) {
.controls input[type="text"] {
width: 140px;
}
.controls {
min-width: 100%;
}
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div>
<h1>⏰ World Digital Clock</h1>
<div class="topline">Live clocks for multiple time zones — updates every second</div>
</div>
<div class="controls">
<input id="tzInput" type="text" placeholder="Add time zone (e.g. Europe/London)" autocomplete="off" />
<button id="addBtn">Add</button>
<button id="addLocalBtn" class="smallBtn">Add Local</button>
<label class="switch" title="Toggle 12 / 24 hour format">
<input id="hourToggle" type="checkbox" />
<span>24-hour</span>
</label>
</div>
</header>
<div id="suggestions" class="add-suggestions" style="display: none"></div>
<div id="grid" class="grid"></div>
<footer>
💡 Tips: Enter a valid IANA timezone name like "America/New_York", "Asia/Tokyo", or "UTC". Your list is saved to your browser.
</footer>
</div>
<script>
(() => {
// Common IANA time zones
const COMMON_ZONES = [
'UTC',
'Europe/London', 'Europe/Paris', 'Europe/Berlin', 'Europe/Moscow',
'America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles', 'America/Sao_Paulo',
'Asia/Tokyo', 'Asia/Shanghai', 'Asia/Hong_Kong', 'Asia/Kolkata', 'Asia/Dubai',
'Australia/Sydney', 'Pacific/Auckland', 'Africa/Johannesburg', 'Africa/Cairo', 'America/Caracas'
];
const grid = document.getElementById('grid');
const tzInput = document.getElementById('tzInput');
const addBtn = document.getElementById('addBtn');
const addLocalBtn = document.getElementById('addLocalBtn');
const hourToggle = document.getElementById('hourToggle');
const suggestionsEl = document.getElementById('suggestions');
// Load from localStorage or use defaults
let zones = JSON.parse(localStorage.getItem('world_clock_zones') || 'null') || ['UTC', 'Europe/London', 'America/New_York'];
let use24 = JSON.parse(localStorage.getItem('world_clock_24') || 'false');
hourToggle.checked = use24;
function saveState() {
localStorage.setItem('world_clock_zones', JSON.stringify(zones));
localStorage.setItem('world_clock_24', JSON.stringify(hourToggle.checked));
}
// Validate timezone using Intl API
function isValidTimeZone(tz) {
try {
Intl.DateTimeFormat(undefined, { timeZone: tz });
return true;
} catch (e) {
return false;
}
}
// Escape HTML to prevent injection
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Safe ID for elements
function safeId(tz) {
return tz.replace(/[^a-z0-9]/gi, '_');
}
// Format time for a given timezone
function formatTime(tz) {
try {
const now = new Date();
const options = {
timeZone: tz,
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hour12: !use24
};
return new Intl.DateTimeFormat(undefined, options).format(now);
} catch (e) {
return 'Invalid TZ';
}
}
// Format date for a given timezone
function formatDate(tz) {
try {
const now = new Date();
const options = {
timeZone: tz,
year: 'numeric',
month: 'short',
day: 'numeric'
};
return new Intl.DateTimeFormat(undefined, options).format(now);
} catch (e) {
return '';
}
}
// Build a card for a timezone
function buildCard(tz) {
const card = document.createElement('div');
card.className = 'card';
card.dataset.tz = tz;
const title = document.createElement('div');
title.className = 'tz-title';
const tzInfo = document.createElement('div');
const tzName = document.createElement('div');
tzName.className = 'tz-name';
tzName.textContent = tz;
const tzSub = document.createElement('div');
tzSub.className = 'tz-sub';
tzSub.id = 'sub-' + safeId(tz);
tzInfo.appendChild(tzName);
tzInfo.appendChild(tzSub);
title.appendChild(tzInfo);
const removeBtn = document.createElement('button');
removeBtn.className = 'removeBtn';
removeBtn.textContent = '✕ Remove';
removeBtn.addEventListener('click', () => {
zones = zones.filter(z => z !== tz);
saveState();
render();
});
title.appendChild(removeBtn);
card.appendChild(title);
const timeEl = document.createElement('div');
timeEl.className = 'time';
timeEl.id = 'time-' + safeId(tz);
timeEl.textContent = '—:—:—';
card.appendChild(timeEl);
const dateEl = document.createElement('div');
dateEl.className = 'date';
dateEl.id = 'date-' + safeId(tz);
card.appendChild(dateEl);
return card;
}
// Update all clock displays
function updateClocks() {
zones.forEach(tz => {
const timeEl = document.getElementById('time-' + safeId(tz));
const dateEl = document.getElementById('date-' + safeId(tz));
const subEl = document.getElementById('sub-' + safeId(tz));
if (timeEl) {
timeEl.textContent = formatTime(tz);
}
if (dateEl) {
dateEl.textContent = formatDate(tz);
}
if (subEl) {
try {
const now = new Date();
const formatter = new Intl.DateTimeFormat(undefined, {
timeZone: tz,
timeZoneName: 'short'
});
const parts = formatter.formatToParts(now);
const tzPart = parts.find(p => p.type === 'timeZoneName');
subEl.textContent = tzPart ? tzPart.value : '';
} catch (e) {
subEl.textContent = '';
}
}
});
}
// Render the grid
function render() {
grid.innerHTML = '';
zones.forEach(tz => {
grid.appendChild(buildCard(tz));
});
updateClocks();
}
// Show suggestions
function showSuggestions(input) {
const filtered = COMMON_ZONES.filter(z => z.toLowerCase().includes(input.toLowerCase()));
suggestionsEl.innerHTML = '';
if (filtered.length === 0) {
suggestionsEl.style.display = 'none';
return;
}
filtered.forEach(tz => {
const suggestion = document.createElement('div');
suggestion.className = 'suggestion';
suggestion.textContent = tz;
suggestion.addEventListener('click', () => {
tzInput.value = '';
addZone(tz);
});
suggestionsEl.appendChild(suggestion);
});
suggestionsEl.style.display = 'block';
}
// Add a timezone
function addZone(tz) {
const trimmed = tz.trim();
if (!trimmed) return;
if (!isValidTimeZone(trimmed)) {
alert(`"${trimmed}" is not a valid timezone. Try "America/New_York" or "Asia/Tokyo".`);
return;
}
if (zones.includes(trimmed)) {
alert(`"${trimmed}" is already added.`);
return;
}
zones.push(trimmed);
saveState();
render();
suggestionsEl.style.display = 'none';
}
// Add local timezone
function addLocalZone() {
try {
const formatter = new Intl.DateTimeFormat(undefined, {
timeZoneName: 'long'
});
const parts = formatter.formatToParts(new Date());
const tzPart = parts.find(p => p.type === 'timeZoneName');
const tzName = tzPart ? tzPart.value : 'UTC';
// Try to find matching IANA name (simplified)
const found = Intl.supportedValuesOf('timeZone').find(tz => {
const fmt = new Intl.DateTimeFormat(undefined, { timeZone: tz, timeZoneName: 'long' });
const parts = fmt.formatToParts(new Date());
const part = parts.find(p => p.type === 'timeZoneName');
return part && part.value === tzName;
});
if (found) {
addZone(found);
} else {
alert('Could not detect your local timezone. Try entering it manually.');
}
} catch (e) {
alert('Could not detect your local timezone. Try entering it manually.');
}
}
// Event listeners
addBtn.addEventListener('click', () => {
addZone(tzInput.value);
tzInput.value = '';
});
addLocalBtn.addEventListener('click', addLocalZone);
tzInput.addEventListener('keypress', e => {
if (e.key === 'Enter') {
addZone(tzInput.value);
tzInput.value = '';
}
});
tzInput.addEventListener('input', e => {
const val = e.target.value.trim();
if (val.length > 0) {
showSuggestions(val);
} else {
suggestionsEl.style.display = 'none';
}
});
hourToggle.addEventListener('change', () => {
saveState();
updateClocks();
});
// Initial render and update every second
render();
setInterval(updateClocks, 1000);
})();
</script>
</body>
</html>