Varun Hemachandran
Enhance HTML viewer with improved UI, document categories, and built-in PDF viewer
b0f8cf3
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>JFK Document Release 2025</title> | |
| <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"> | |
| <style> | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| line-height: 1.6; | |
| color: #333; | |
| background-color: #f8f9fa; | |
| padding-top: 20px; | |
| padding-bottom: 40px; | |
| } | |
| .container { | |
| max-width: 1200px; | |
| } | |
| .header { | |
| background-color: #fff; | |
| border-radius: 8px; | |
| padding: 20px; | |
| margin-bottom: 20px; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| } | |
| h1 { | |
| color: #212529; | |
| margin-bottom: 15px; | |
| } | |
| .search-container { | |
| margin: 20px 0; | |
| } | |
| .card { | |
| margin-bottom: 20px; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| } | |
| .document-card:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 8px rgba(0,0,0,0.1); | |
| transition: all 0.3s ease; | |
| } | |
| .table { | |
| background-color: #fff; | |
| border-radius: 8px; | |
| overflow: hidden; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| } | |
| .table th { | |
| background-color: #f1f3f5; | |
| border-top: none; | |
| } | |
| .pagination { | |
| justify-content: center; | |
| margin-top: 20px; | |
| } | |
| .document-category { | |
| display: inline-block; | |
| padding: 2px 8px; | |
| border-radius: 4px; | |
| font-size: 12px; | |
| font-weight: 600; | |
| margin-right: 5px; | |
| } | |
| .category-CIA { | |
| background-color: #e3f2fd; | |
| color: #0d6efd; | |
| } | |
| .category-FBI { | |
| background-color: #fff3cd; | |
| color: #ffc107; | |
| } | |
| .category-HSCA { | |
| background-color: #d1e7dd; | |
| color: #198754; | |
| } | |
| .category-Other { | |
| background-color: #f8d7da; | |
| color: #dc3545; | |
| } | |
| .loading { | |
| text-align: center; | |
| padding: 40px; | |
| } | |
| .loading-spinner { | |
| width: 3rem; | |
| height: 3rem; | |
| } | |
| .footer { | |
| margin-top: 30px; | |
| padding: 20px; | |
| background-color: #fff; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| } | |
| #documentViewer { | |
| height: 600px; | |
| width: 100%; | |
| border: none; | |
| } | |
| .modal-xl { | |
| max-width: 90%; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <h1>JFK Document Release 2025</h1> | |
| <p class="lead">Browse and search through declassified documents related to the assassination of President John F. Kennedy.</p> | |
| </div> | |
| <div class="card"> | |
| <div class="card-body"> | |
| <div class="row"> | |
| <div class="col-md-6"> | |
| <div class="input-group mb-3"> | |
| <input type="text" id="search" class="form-control" placeholder="Search documents by name or content..." aria-label="Search documents"> | |
| <button class="btn btn-primary" type="button" onclick="filterDocuments()">Search</button> | |
| </div> | |
| </div> | |
| <div class="col-md-6"> | |
| <div class="d-flex justify-content-end"> | |
| <div class="btn-group" role="group"> | |
| <button type="button" class="btn btn-outline-secondary" onclick="filterByCategory('all')">All</button> | |
| <button type="button" class="btn btn-outline-primary" onclick="filterByCategory('CIA')">CIA</button> | |
| <button type="button" class="btn btn-outline-warning" onclick="filterByCategory('FBI')">FBI</button> | |
| <button type="button" class="btn btn-outline-success" onclick="filterByCategory('HSCA')">HSCA</button> | |
| <button type="button" class="btn btn-outline-danger" onclick="filterByCategory('Other')">Other</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="loading" id="loading"> | |
| <div class="spinner-border loading-spinner text-primary" role="status"> | |
| <span class="visually-hidden">Loading...</span> | |
| </div> | |
| <p class="mt-3">Loading documents...</p> | |
| </div> | |
| <div id="documentsContainer" style="display: none;"> | |
| <table class="table table-hover" id="documents-table"> | |
| <thead> | |
| <tr> | |
| <th scope="col">Document Name</th> | |
| <th scope="col">Category</th> | |
| <th scope="col">Size</th> | |
| <th scope="col">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="documents-list"> | |
| <!-- Documents will be populated here by JavaScript --> | |
| </tbody> | |
| </table> | |
| <nav aria-label="Document pagination"> | |
| <ul class="pagination" id="pagination"> | |
| <!-- Pagination will be populated here by JavaScript --> | |
| </ul> | |
| </nav> | |
| </div> | |
| <!-- Document Viewer Modal --> | |
| <div class="modal fade" id="documentModal" tabindex="-1" aria-labelledby="documentModalLabel" aria-hidden="true"> | |
| <div class="modal-dialog modal-xl modal-dialog-centered"> | |
| <div class="modal-content"> | |
| <div class="modal-header"> | |
| <h5 class="modal-title" id="documentModalLabel">Document Viewer</h5> | |
| <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | |
| </div> | |
| <div class="modal-body"> | |
| <iframe id="documentViewer" title="Document Viewer"></iframe> | |
| </div> | |
| <div class="modal-footer"> | |
| <a id="downloadLink" href="#" class="btn btn-primary" download>Download Document</a> | |
| <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="footer"> | |
| <h4>About this Collection</h4> | |
| <p>This collection contains declassified documents related to the assassination of President John F. Kennedy. | |
| The documents were released by the National Archives and Records Administration (NARA) as part of the JFK Records Act.</p> | |
| <p>The documents follow the National Archives naming convention: <code>104-XXXXX-XXXXX.pdf</code></p> | |
| <p>For more information, visit the <a href="https://github.com/varun-heman/jfk-files-2025" target="_blank">GitHub repository</a>.</p> | |
| </div> | |
| </div> | |
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script> | |
| <script> | |
| // Global variables | |
| let allDocuments = []; | |
| let currentPage = 1; | |
| let documentsPerPage = 20; | |
| let currentCategory = 'all'; | |
| let currentSearch = ''; | |
| // Document modal | |
| const documentModal = new bootstrap.Modal(document.getElementById('documentModal')); | |
| // Function to determine document category based on filename | |
| function getDocumentCategory(fileName) { | |
| if (fileName.includes('104-10')) return 'FBI'; | |
| if (fileName.includes('157-10')) return 'CIA'; | |
| if (fileName.includes('180-10')) return 'HSCA'; | |
| return 'Other'; | |
| } | |
| // Function to format file size | |
| function formatFileSize(bytes) { | |
| if (bytes < 1024) return bytes + ' B'; | |
| if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB'; | |
| return (bytes / (1024 * 1024)).toFixed(2) + ' MB'; | |
| } | |
| // Function to load document list | |
| async function loadDocuments() { | |
| try { | |
| const response = await fetch('https://huggingface.co/api/datasets/varunh/jfk-files-2025/tree/main/data'); | |
| const data = await response.json(); | |
| // Sort files alphabetically | |
| allDocuments = data | |
| .filter(file => file.path.endsWith('.pdf')) | |
| .map(file => { | |
| const fileName = file.path.split('/').pop(); | |
| return { | |
| name: fileName, | |
| path: file.path, | |
| size: file.size || 0, | |
| category: getDocumentCategory(fileName) | |
| }; | |
| }) | |
| .sort((a, b) => a.name.localeCompare(b.name)); | |
| // Hide loading indicator and show documents | |
| document.getElementById('loading').style.display = 'none'; | |
| document.getElementById('documentsContainer').style.display = 'block'; | |
| // Display the documents | |
| displayDocuments(); | |
| } catch (error) { | |
| console.error('Error loading documents:', error); | |
| document.getElementById('loading').innerHTML = ` | |
| <div class="alert alert-danger" role="alert"> | |
| Error loading documents. Please try again later. | |
| </div> | |
| `; | |
| } | |
| } | |
| // Function to display documents with pagination | |
| function displayDocuments() { | |
| // Filter documents based on search and category | |
| let filteredDocuments = allDocuments.filter(doc => { | |
| const matchesSearch = currentSearch === '' || | |
| doc.name.toLowerCase().includes(currentSearch.toLowerCase()); | |
| const matchesCategory = currentCategory === 'all' || | |
| doc.category === currentCategory; | |
| return matchesSearch && matchesCategory; | |
| }); | |
| // Calculate pagination | |
| const totalPages = Math.ceil(filteredDocuments.length / documentsPerPage); | |
| const startIndex = (currentPage - 1) * documentsPerPage; | |
| const endIndex = Math.min(startIndex + documentsPerPage, filteredDocuments.length); | |
| const currentDocuments = filteredDocuments.slice(startIndex, endIndex); | |
| // Display documents | |
| const documentsList = document.getElementById('documents-list'); | |
| documentsList.innerHTML = ''; | |
| if (currentDocuments.length === 0) { | |
| documentsList.innerHTML = ` | |
| <tr> | |
| <td colspan="4" class="text-center">No documents found matching your criteria.</td> | |
| </tr> | |
| `; | |
| return; | |
| } | |
| currentDocuments.forEach(doc => { | |
| const row = document.createElement('tr'); | |
| row.className = 'document-card'; | |
| const nameCell = document.createElement('td'); | |
| nameCell.textContent = doc.name; | |
| const categoryCell = document.createElement('td'); | |
| const categorySpan = document.createElement('span'); | |
| categorySpan.className = `document-category category-${doc.category}`; | |
| categorySpan.textContent = doc.category; | |
| categoryCell.appendChild(categorySpan); | |
| const sizeCell = document.createElement('td'); | |
| sizeCell.textContent = formatFileSize(doc.size); | |
| const actionsCell = document.createElement('td'); | |
| const viewButton = document.createElement('button'); | |
| viewButton.className = 'btn btn-sm btn-primary me-2'; | |
| viewButton.textContent = 'View'; | |
| viewButton.onclick = () => viewDocument(doc); | |
| const downloadLink = document.createElement('a'); | |
| downloadLink.className = 'btn btn-sm btn-outline-secondary'; | |
| downloadLink.href = `https://huggingface.co/datasets/varunh/jfk-files-2025/resolve/main/${doc.path}`; | |
| downloadLink.textContent = 'Download'; | |
| downloadLink.download = doc.name; | |
| actionsCell.appendChild(viewButton); | |
| actionsCell.appendChild(downloadLink); | |
| row.appendChild(nameCell); | |
| row.appendChild(categoryCell); | |
| row.appendChild(sizeCell); | |
| row.appendChild(actionsCell); | |
| documentsList.appendChild(row); | |
| }); | |
| // Update pagination | |
| updatePagination(totalPages); | |
| } | |
| // Function to update pagination controls | |
| function updatePagination(totalPages) { | |
| const pagination = document.getElementById('pagination'); | |
| pagination.innerHTML = ''; | |
| // Previous button | |
| const prevItem = document.createElement('li'); | |
| prevItem.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`; | |
| const prevLink = document.createElement('a'); | |
| prevLink.className = 'page-link'; | |
| prevLink.href = '#'; | |
| prevLink.textContent = 'Previous'; | |
| prevLink.onclick = (e) => { | |
| e.preventDefault(); | |
| if (currentPage > 1) { | |
| currentPage--; | |
| displayDocuments(); | |
| } | |
| }; | |
| prevItem.appendChild(prevLink); | |
| pagination.appendChild(prevItem); | |
| // Page numbers | |
| const maxVisiblePages = 5; | |
| const startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); | |
| const endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); | |
| for (let i = startPage; i <= endPage; i++) { | |
| const pageItem = document.createElement('li'); | |
| pageItem.className = `page-item ${i === currentPage ? 'active' : ''}`; | |
| const pageLink = document.createElement('a'); | |
| pageLink.className = 'page-link'; | |
| pageLink.href = '#'; | |
| pageLink.textContent = i; | |
| pageLink.onclick = (e) => { | |
| e.preventDefault(); | |
| currentPage = i; | |
| displayDocuments(); | |
| }; | |
| pageItem.appendChild(pageLink); | |
| pagination.appendChild(pageItem); | |
| } | |
| // Next button | |
| const nextItem = document.createElement('li'); | |
| nextItem.className = `page-item ${currentPage === totalPages ? 'disabled' : ''}`; | |
| const nextLink = document.createElement('a'); | |
| nextLink.className = 'page-link'; | |
| nextLink.href = '#'; | |
| nextLink.textContent = 'Next'; | |
| nextLink.onclick = (e) => { | |
| e.preventDefault(); | |
| if (currentPage < totalPages) { | |
| currentPage++; | |
| displayDocuments(); | |
| } | |
| }; | |
| nextItem.appendChild(nextLink); | |
| pagination.appendChild(nextItem); | |
| } | |
| // Function to filter documents based on search | |
| function filterDocuments() { | |
| currentSearch = document.getElementById('search').value.toLowerCase(); | |
| currentPage = 1; | |
| displayDocuments(); | |
| } | |
| // Function to filter by category | |
| function filterByCategory(category) { | |
| currentCategory = category; | |
| currentPage = 1; | |
| displayDocuments(); | |
| } | |
| // Function to view document in modal | |
| function viewDocument(doc) { | |
| const viewerUrl = `https://huggingface.co/datasets/varunh/jfk-files-2025/resolve/main/${doc.path}`; | |
| document.getElementById('documentViewer').src = viewerUrl; | |
| document.getElementById('documentModalLabel').textContent = doc.name; | |
| document.getElementById('downloadLink').href = viewerUrl; | |
| documentModal.show(); | |
| } | |
| // Add event listener for search input | |
| document.getElementById('search').addEventListener('keyup', function(event) { | |
| if (event.key === 'Enter') { | |
| filterDocuments(); | |
| } | |
| }); | |
| // Load documents when page loads | |
| window.onload = loadDocuments; | |
| </script> | |
| </body> | |
| </html> | |