-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkey-manager.html
750 lines (655 loc) · 30.4 KB
/
key-manager.html
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Key Manager</title>
<link href="https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap" rel="stylesheet">
<style>
html {
font-family: 'Poppins', sans-serif;
font-size: 18px;
user-select: none;
color: aliceblue;
background: rgb(63, 47, 60);
background: linear-gradient(45deg, rgba(63, 47, 60, 1) 0%, rgba(17, 17, 17, 1) 10%, rgba(17, 17, 17, 1) 90%, rgba(53, 59, 100, 1) 100%);
min-height: 100vh;
background-repeat: no-repeat;
background-size: cover;
}
body {
max-width: 1000px;
margin: 0 auto;
padding: 20px;
}
.container {
background-color: #222;
border-radius: 10px;
padding: 25px;
box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.5);
transition: 0.2s;
}
.container:hover {
box-shadow: 0px 0px 30px rgba(0, 0, 0, 0.6);
}
h1, h2, h3, h4 {
color: white;
}
button {
padding: 8px 12px;
margin: 5px 0;
border-radius: 10px;
border: none;
background-color: #333;
color: white;
cursor: pointer;
transition: 0.2s;
box-shadow: 5px 5px 3px rgba(0, 0, 0, 0.3);
}
button:hover {
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.6);
background-color: #111;
scale: 1.03;
}
input {
padding: 8px 12px;
margin: 5px 0;
border-radius: 8px;
border: 1px solid #444;
background-color: #333;
color: white;
}
.error {
color: #ff6b6b;
font-size: 14px;
}
.success {
color: #6bff9f;
font-size: 14px;
}
.key-item {
border: 1px solid #444;
padding: 20px;
margin: 15px 0;
border-radius: 8px;
background-color: #2a2a2a;
box-shadow: 5px 5px 3px rgba(0, 0, 0, 0.3);
transition: 0.2s;
}
.key-item:hover {
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.6);
scale: 1.01;
}
.user-list {
margin-top: 10px;
}
.user-item {
display: inline-block;
background-color: #454545;
padding: 4px 8px;
margin: 3px;
border-radius: 6px;
transition: 0.2s;
}
.user-item:hover {
background-color: #555;
}
.remove-user {
cursor: pointer;
color: #ff6b6b;
margin-left: 5px;
display: inline-block;
}
.hidden {
display: none;
}
.actions {
margin-top: 15px;
display: block;
}
#loading {
text-align: center;
margin: 20px;
color: #ccc;
}
.login-box {
text-align: center;
margin: 40px 0;
}
.login-btn {
padding: 12px 24px;
font-size: 18px;
background-color: #333;
transition: 0.2s;
}
.login-btn:hover {
scale: 1.05;
background-color: #111;
}
#create-key-btn {
margin-left: 10px;
padding: 8px 16px;
font-size: 16px;
}
#new-key-price {
width: 100px;
}
.key-value {
word-break: break-all;
color: #6bff9f;
}
.copy-button {
display: inline-block;
cursor: pointer;
background-color: #444;
color: white;
border-radius: 5px;
padding: 3px 8px;
font-size: 14px;
margin-left: 8px;
transition: 0.2s;
}
.copy-button:hover {
background-color: #555;
}
.copied-feedback {
color: #6bff9f;
font-size: 14px;
margin-left: 8px;
opacity: 0;
transition: opacity 0.3s;
}
.copied-feedback.show {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<h1>Key Manager</h1>
<!-- Login Section -->
<div id="login-section" class="login-box">
<h2>Authentication Required</h2>
<button onclick="window.location.href='https://rotur.dev/auth'" class="login-btn">Login</button>
<div id="login-error" class="error"></div>
</div>
<!-- User Info Section -->
<div id="user-info" class="hidden">
<h2>Welcome, <span id="user-name"></span>!</h2>
<button id="logout-btn">Logout</button>
</div>
<!-- Key Management Section -->
<div id="key-management" class="hidden">
<h2>Your Keys</h2>
<div id="loading">Loading your keys...</div>
<div id="keys-list"></div>
<h3>Create New Key</h3>
<div>
<input type="number" id="new-key-price" placeholder="Price (optional)" min="0">
<button id="create-key-btn">Create Key</button>
<div id="create-key-result" class="success"></div>
</div>
</div>
</div>
<!-- Key Item Template -->
<template id="key-template">
<div class="key-item">
<h3>Key: <span class="key-value"></span>
<span class="copy-button">Copy</span>
<span class="copied-feedback">Copied!</span>
</h3>
<p>Creator: <span class="key-creator"></span></p>
<p>Price: <span class="key-price"></span></p>
<div class="key-users">
<h4>Authorized Users:</h4>
<div class="user-list"></div>
<div class="actions">
<input type="text" class="add-user-input" placeholder="Username to add">
<button class="add-user-btn">Add User</button>
</div>
</div>
<div class="actions">
<button class="revoke-key-btn">Revoke Key</button>
<button class="delete-key-btn">Delete Key</button>
<input type="number" class="update-price-input" placeholder="New Price" min="0">
<button class="update-price-btn">Update Price</button>
</div>
<div class="key-message success"></div>
<div class="key-error error"></div>
</div>
</template>
<script>
// Global variables
let authToken = '';
let currentUser = '';
const API_BASE_URL = 'https://social.rotur.dev';
// DOM elements
const loginSection = document.getElementById('login-section');
const userInfoSection = document.getElementById('user-info');
const keyManagementSection = document.getElementById('key-management');
const loginError = document.getElementById('login-error');
const userNameSpan = document.getElementById('user-name');
const keysList = document.getElementById('keys-list');
const loadingIndicator = document.getElementById('loading');
const createKeyResult = document.getElementById('create-key-result');
// Event listeners for page load
document.addEventListener('DOMContentLoaded', () => {
// Check for token in URL parameters (from auth redirect)
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token');
if (token) {
// Token found in URL, use it as auth token
authToken = token;
validateAuthAndFetchUser(token);
// Clean URL by removing the token parameter (for security)
window.history.replaceState({}, document.title, window.location.pathname);
} else {
// Check for stored auth token
const storedAuth = localStorage.getItem('authToken');
const storedUser = localStorage.getItem('username');
if (storedAuth && storedUser) {
authToken = storedAuth;
currentUser = storedUser;
showLoggedInState();
}
}
document.getElementById('logout-btn').addEventListener('click', handleLogout);
document.getElementById('create-key-btn').addEventListener('click', createNewKey);
});
async function validateAuthAndFetchUser(token) {
try {
const response = await fetch(`${API_BASE_URL}/get_user?auth=${encodeURIComponent(token)}`);
const data = await response.json();
if (response.ok) {
currentUser = data.username.toLowerCase();
saveAuthToStorage();
showLoggedInState();
} else {
loginError.textContent = 'Authentication failed. Please try logging in again.';
}
} catch (error) {
loginError.textContent = 'Network error occurred. Please try again.';
console.error('Auth validation error:', error);
}
}
function handleLogout() {
authToken = '';
currentUser = '';
localStorage.removeItem('authToken');
localStorage.removeItem('username');
loginSection.classList.remove('hidden');
userInfoSection.classList.add('hidden');
keyManagementSection.classList.add('hidden');
}
function saveAuthToStorage() {
localStorage.setItem('authToken', authToken);
localStorage.setItem('username', currentUser);
}
function showLoggedInState() {
loginError.textContent = '';
// Update UI
loginSection.classList.add('hidden');
userInfoSection.classList.remove('hidden');
keyManagementSection.classList.remove('hidden');
userNameSpan.textContent = currentUser;
// Fetch user's keys
fetchUserKeys();
}
// Key Management Functions
async function fetchUserKeys() {
loadingIndicator.classList.remove('hidden');
keysList.innerHTML = '';
try {
const response = await fetch(`${API_BASE_URL}/keys/mine?auth=${encodeURIComponent(authToken)}`);
const data = await response.json();
if (response.ok) {
loadingIndicator.classList.add('hidden');
if (data.length === 0) {
keysList.innerHTML = '<p>You don\'t have any keys yet. Create one below!</p>';
return;
}
// Display each key
data.forEach(key => {
renderKeyItem(key);
});
} else {
loadingIndicator.textContent = data.error || 'Failed to load keys';
}
} catch (error) {
loadingIndicator.textContent = 'Network error occurred. Please try again.';
console.error('Fetch keys error:', error);
}
}
function renderKeyItem(key) {
const template = document.getElementById('key-template');
const keyItem = document.importNode(template.content, true);
// Convert creator username to lowercase for consistent comparison
const creatorName = key.creator.toLowerCase();
// Populate key data
const keyValueSpan = keyItem.querySelector('.key-value');
keyValueSpan.textContent = key.key;
keyItem.querySelector('.key-creator').textContent = key.creator;
keyItem.querySelector('.key-price').textContent = key.price || '0';
// Set up copy button functionality
const copyButton = keyItem.querySelector('.copy-button');
const copiedFeedback = keyItem.querySelector('.copied-feedback');
copyButton.addEventListener('click', () => {
navigator.clipboard.writeText(key.key).then(() => {
// Show feedback that the text was copied
copiedFeedback.classList.add('show');
// Hide feedback after 2 seconds
setTimeout(() => {
copiedFeedback.classList.remove('show');
}, 2000);
}).catch(err => {
console.error('Could not copy text: ', err);
const errorDiv = keyItem.querySelector('.key-error');
errorDiv.textContent = 'Failed to copy to clipboard';
// Clear error after 3 seconds
setTimeout(() => {
errorDiv.textContent = '';
}, 3000);
});
});
// Set input default and add data-key attribute to associate it with this specific key
const priceInput = keyItem.querySelector('.update-price-input');
priceInput.value = key.price || '0';
priceInput.setAttribute('data-key', key.key);
// Add data-key attribute to the update button
const updateButton = keyItem.querySelector('.update-price-btn');
updateButton.setAttribute('data-key', key.key);
// Add data-key attribute to the add user input and button
const addUserInput = keyItem.querySelector('.add-user-input');
addUserInput.setAttribute('data-key', key.key);
const addUserButton = keyItem.querySelector('.add-user-btn');
addUserButton.setAttribute('data-key', key.key);
// Add a unique ID to the key item div for easier targeting
const keyItemDiv = keyItem.querySelector('.key-item');
keyItemDiv.id = `key-item-${key.key}`;
keyItemDiv.setAttribute('data-key', key.key);
// Check if current user is the creator (for admin functions visibility)
const isCreator = currentUser.toLowerCase() === creatorName.toLowerCase();
// Populate users
const userList = keyItem.querySelector('.user-list');
if (key.users && key.users.length > 0) {
key.users.forEach(user => {
// Convert each username to lowercase for display
const normalizedUser = user.toLowerCase();
if (normalizedUser === currentUser.toLowerCase()) {
userList.innerHTML += `<span class="user-item">${normalizedUser} (You)</span>`;
return;
}
const userItem = document.createElement('span');
userItem.classList.add('user-item');
// Show remove button for all users when current user is creator
if (isCreator) {
userItem.innerHTML = `${normalizedUser} <span class="remove-user" data-user="${normalizedUser}" data-key="${key.key}">×</span>`;
} else {
userItem.textContent = normalizedUser;
}
userList.appendChild(userItem);
});
} else {
userList.innerHTML = '<p>No users have access to this key.</p>';
}
// Always show the user management UI
const addUserSection = keyItem.querySelector('.key-users .actions');
addUserSection.style.display = 'block';
// Set up event listeners for all buttons
const addUserButtonElem = keyItem.querySelector('.add-user-btn');
addUserButtonElem.addEventListener('click', () => {
addUserToKey(key.key, keyItemDiv);
});
keyItem.querySelector('.revoke-key-btn').addEventListener('click', () => {
revokeKey(key.key, keyItemDiv);
});
keyItem.querySelector('.delete-key-btn').addEventListener('click', () => {
deleteKey(key.key, keyItemDiv);
});
updateButton.addEventListener('click', () => {
updateKeyPrice(key.key, keyItemDiv);
});
// Show/hide administrative functions based on creator status
if (!isCreator) {
keyItem.querySelector('.revoke-key-btn').style.display = 'none';
keyItem.querySelector('.delete-key-btn').style.display = 'none';
updateButton.parentNode.style.display = 'none';
}
// Attach remove user event listeners
setTimeout(() => {
const removeButtons = keyItemDiv.querySelectorAll('.remove-user');
removeButtons.forEach(button => {
button.addEventListener('click', (e) => {
const username = e.target.getAttribute('data-user');
const keyId = e.target.getAttribute('data-key');
removeUserFromKey(keyId, username, keyItemDiv);
});
});
}, 0);
keysList.appendChild(keyItem);
}
async function createNewKey() {
const priceInput = document.getElementById('new-key-price');
const price = priceInput.value ? parseInt(priceInput.value) : 0;
try {
const url = `${API_BASE_URL}/keys/create?auth=${encodeURIComponent(authToken)}${price ? `&price=${price}` : ''}`;
const response = await fetch(url);
const data = await response.json();
if (response.ok) {
createKeyResult.textContent = `Key created successfully: ${data.key}`;
priceInput.value = '';
// Refresh the key list
fetchUserKeys();
// Clear success message after 5 seconds
setTimeout(() => {
createKeyResult.textContent = '';
}, 5000);
} else {
createKeyResult.textContent = data.error || 'Failed to create key';
createKeyResult.classList.remove('success');
createKeyResult.classList.add('error');
}
} catch (error) {
createKeyResult.textContent = 'Network error occurred. Please try again.';
createKeyResult.classList.remove('success');
createKeyResult.classList.add('error');
console.error('Create key error:', error);
}
}
async function addUserToKey(keyId, keyElement) {
// Find the specific input for this key using data-key attribute
const input = keyElement.querySelector(`.add-user-input[data-key="${keyId}"]`);
if (!input) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Error: Could not find username input element';
console.error('Username input element not found for key', keyId);
return;
}
// Convert username to lowercase before processing
const username = input.value.trim().toLowerCase();
if (!username) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Please enter a username';
return;
}
try {
// Since there's no direct endpoint to add a user, we need to use the update endpoint
// First we get the current key users
const response = await fetch(`${API_BASE_URL}/keys/mine?auth=${encodeURIComponent(authToken)}`);
const allKeys = await response.json();
if (!response.ok) {
throw new Error('Failed to fetch key data');
}
const key = allKeys.find(k => k.key === keyId);
if (!key) throw new Error('Key not found');
// Add the new user if they don't exist already (case insensitive check)
const users = key.users || [];
const normalizedUsers = users.map(u => u.toLowerCase());
if (!normalizedUsers.includes(username)) {
users.push(username);
} else {
throw new Error('User already has access to this key');
}
// Update the key with the new users list
const updateData = JSON.stringify({ users });
// The API expects the data as a query parameter, not in the request body
const updateUrl = `${API_BASE_URL}/keys/update/${keyId}?auth=${encodeURIComponent(authToken)}&data=${encodeURIComponent(updateData)}`;
const updateResponse = await fetch(updateUrl);
const updateResult = await updateResponse.json();
if (updateResponse.ok) {
const messageDiv = keyElement.querySelector('.key-message');
messageDiv.textContent = `User ${username} added successfully`;
input.value = '';
// Refresh the key list to show changes
fetchUserKeys();
// Clear success message after 3 seconds
setTimeout(() => {
messageDiv.textContent = '';
}, 3000);
} else {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = updateResult.error || 'Failed to add user';
console.error('API error:', updateResult);
}
} catch (error) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = error.message || 'Error adding user';
console.error('Add user error:', error);
}
}
async function removeUserFromKey(keyId, username, keyElement) {
// Convert username to lowercase for comparison
const normalizedUsername = username.toLowerCase();
const normalizedCurrentUser = currentUser.toLowerCase();
// Get the creator of this key
const allKeys = await fetch(`${API_BASE_URL}/keys/mine?auth=${encodeURIComponent(authToken)}`).then(r => r.json());
const key = allKeys.find(k => k.key === keyId);
if (!key) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = "Could not find key data";
return;
}
// Check if current user is creator
const isCreator = normalizedCurrentUser === key.creator.toLowerCase();
// Only creator can remove users
if (!isCreator) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = "Only the creator can remove users";
return;
}
try {
// Get current key data
const users = key.users || [];
const updatedUsers = users.filter(u => u.toLowerCase() !== normalizedUsername);
// Update the key with the new users list
const updateData = JSON.stringify({ users: updatedUsers });
const updateUrl = `${API_BASE_URL}/keys/update/${keyId}?auth=${encodeURIComponent(authToken)}&data=${encodeURIComponent(updateData)}`;
const updateResponse = await fetch(updateUrl);
const updateResult = await updateResponse.json();
if (updateResponse.ok) {
const messageDiv = keyElement.querySelector('.key-message');
messageDiv.textContent = `User ${normalizedUsername} removed successfully`;
// Refresh the key list to show changes
fetchUserKeys();
// Clear success message after 3 seconds
setTimeout(() => {
messageDiv.textContent = '';
}, 3000);
} else {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = updateResult.error || 'Failed to remove user';
}
} catch (error) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = error.message || 'Error removing user';
console.error('Remove user error:', error);
}
}
async function revokeKey(keyId, keyElement) {
if (!confirm('Are you sure you want to revoke this key? This will remove all users.')) {
return;
}
try {
const url = `${API_BASE_URL}/keys/revoke/${keyId}?auth=${encodeURIComponent(authToken)}`;
const response = await fetch(url);
const data = await response.json();
if (response.ok) {
const messageDiv = keyElement.querySelector('.key-message');
messageDiv.textContent = 'Key revoked successfully';
// Refresh the key list
fetchUserKeys();
} else {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = data.error || 'Failed to revoke key';
}
} catch (error) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Network error occurred. Please try again.';
console.error('Revoke key error:', error);
}
}
async function deleteKey(keyId, keyElement) {
if (!confirm('Are you sure you want to delete this key? This action cannot be undone.')) {
return;
}
try {
const url = `${API_BASE_URL}/keys/delete/${keyId}?auth=${encodeURIComponent(authToken)}`;
const response = await fetch(url);
const data = await response.json();
if (response.ok) {
keyElement.remove();
// Check if there are any keys left
if (keysList.children.length === 0) {
keysList.innerHTML = '<p>You don\'t have any keys. Create one below!</p>';
}
} else {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = data.error || 'Failed to delete key';
}
} catch (error) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Network error occurred. Please try again.';
console.error('Delete key error:', error);
}
}
async function updateKeyPrice(keyId, keyElement) {
// Find the specific price input for this key using the data-key attribute
const input = keyElement.querySelector(`.update-price-input[data-key="${keyId}"]`);
if (!input) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Error: Could not find price input element';
console.error('Price input element not found for key', keyId);
return;
}
const price = input.value ? parseInt(input.value) : 0;
try {
const updateData = JSON.stringify({ price });
const updateUrl = `${API_BASE_URL}/keys/update/${keyId}?auth=${encodeURIComponent(authToken)}&data=${encodeURIComponent(updateData)}`;
const response = await fetch(updateUrl);
const data = await response.json();
if (response.ok) {
const messageDiv = keyElement.querySelector('.key-message');
messageDiv.textContent = 'Price updated successfully';
keyElement.querySelector('.key-price').textContent = price;
// Refresh the key list to ensure we have the latest data
setTimeout(() => {
fetchUserKeys();
}, 1000);
// Clear success message after 3 seconds
setTimeout(() => {
messageDiv.textContent = '';
}, 3000);
} else {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = data.error || 'Failed to update price';
console.error('Update price error:', data);
}
} catch (error) {
const errorDiv = keyElement.querySelector('.key-error');
errorDiv.textContent = 'Network error occurred. Please try again.';
console.error('Update price error:', error);
}
}
</script>
</body>
</html>