|
344 | 344 | li.className = `request-link block p-4 hover:bg-gray-50 ${currentViewId == request.ID ? 'bg-indigo-50 border-l-4 border-indigo-500' : ''}`; |
345 | 345 |
|
346 | 346 | const methodColor = getMethodColor(request.Method); |
347 | | - const timestamp = new Date(request.Timestamp).toLocaleString(); |
| 347 | + const timestamp = formatTime(request.Timestamp); |
348 | 348 |
|
349 | 349 | li.innerHTML = ` |
350 | 350 | <div class="flex justify-between items-center mb-1"> |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 |
|
| 396 | + // Helper function to format time in the same format as server-side formatTime |
| 397 | + function formatTime(dateString) { |
| 398 | + const date = new Date(dateString); |
| 399 | + const year = date.getFullYear(); |
| 400 | + const month = String(date.getMonth() + 1).padStart(2, '0'); |
| 401 | + const day = String(date.getDate()).padStart(2, '0'); |
| 402 | + const hours = String(date.getHours()).padStart(2, '0'); |
| 403 | + const minutes = String(date.getMinutes()).padStart(2, '0'); |
| 404 | + const seconds = String(date.getSeconds()).padStart(2, '0'); |
| 405 | + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| 406 | + } |
| 407 | + |
396 | 408 | // Pagination button event listeners |
397 | 409 | prevPageBtn.addEventListener('click', () => { |
398 | 410 | if (currentPage > 1) { |
|
534 | 546 | setCollapsedState(initiallyCollapsed, true); |
535 | 547 | } |
536 | 548 | }); |
| 549 | + |
| 550 | + // --- Copy button functionality --- |
| 551 | + const copyBodyBtn = document.getElementById('copy-body-btn'); |
| 552 | + if (copyBodyBtn) { |
| 553 | + copyBodyBtn.addEventListener('click', async () => { |
| 554 | + const bodyText = document.getElementById('body-text'); |
| 555 | + if (bodyText) { |
| 556 | + try { |
| 557 | + // Get the text content without HTML tags |
| 558 | + const textToCopy = bodyText.textContent || bodyText.innerText; |
| 559 | + |
| 560 | + // Use the modern clipboard API if available |
| 561 | + if (navigator.clipboard && window.isSecureContext) { |
| 562 | + await navigator.clipboard.writeText(textToCopy); |
| 563 | + } else { |
| 564 | + // Fallback for older browsers or non-HTTPS contexts |
| 565 | + const textArea = document.createElement('textarea'); |
| 566 | + textArea.value = textToCopy; |
| 567 | + textArea.style.position = 'fixed'; |
| 568 | + textArea.style.opacity = '0'; |
| 569 | + document.body.appendChild(textArea); |
| 570 | + textArea.focus(); |
| 571 | + textArea.select(); |
| 572 | + document.execCommand('copy'); |
| 573 | + document.body.removeChild(textArea); |
| 574 | + } |
| 575 | + |
| 576 | + // Visual feedback |
| 577 | + const originalContent = copyBodyBtn.innerHTML; |
| 578 | + copyBodyBtn.innerHTML = ` |
| 579 | + <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> |
| 580 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" /> |
| 581 | + </svg> |
| 582 | + <span data-i18n="copied">${translations[currentLang]['copied']}</span> |
| 583 | + `; |
| 584 | + copyBodyBtn.classList.remove('bg-blue-600', 'hover:bg-blue-700'); |
| 585 | + copyBodyBtn.classList.add('bg-green-600', 'hover:bg-green-700'); |
| 586 | + |
| 587 | + // Reset after 2 seconds |
| 588 | + setTimeout(() => { |
| 589 | + copyBodyBtn.innerHTML = originalContent; |
| 590 | + copyBodyBtn.classList.remove('bg-green-600', 'hover:bg-green-700'); |
| 591 | + copyBodyBtn.classList.add('bg-blue-600', 'hover:bg-blue-700'); |
| 592 | + }, 2000); |
| 593 | + |
| 594 | + } catch (err) { |
| 595 | + console.error('Failed to copy text: ', err); |
| 596 | + // Show error feedback |
| 597 | + const originalContent = copyBodyBtn.innerHTML; |
| 598 | + copyBodyBtn.innerHTML = ` |
| 599 | + <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> |
| 600 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> |
| 601 | + </svg> |
| 602 | + <span>失败</span> |
| 603 | + `; |
| 604 | + copyBodyBtn.classList.remove('bg-blue-600', 'hover:bg-blue-700'); |
| 605 | + copyBodyBtn.classList.add('bg-red-600', 'hover:bg-red-700'); |
| 606 | + |
| 607 | + setTimeout(() => { |
| 608 | + copyBodyBtn.innerHTML = originalContent; |
| 609 | + copyBodyBtn.classList.remove('bg-red-600', 'hover:bg-red-700'); |
| 610 | + copyBodyBtn.classList.add('bg-blue-600', 'hover:bg-blue-700'); |
| 611 | + }, 2000); |
| 612 | + } |
| 613 | + } |
| 614 | + }); |
| 615 | + } |
537 | 616 | }); |
538 | 617 | </script> |
539 | 618 | </body> |
|
0 commit comments