document.addEventListener('DOMContentLoaded', function() { // DOM Elements const dropZone = document.getElementById('drop-zone'); const pdfDropZone = document.getElementById('pdf-drop-zone'); const fileList = document.getElementById('file-list'); const processBtn = document.getElementById('process-btn'); const pdfProcessBtn = document.getElementById('pdf-process-btn'); const transporterSection = document.getElementById('transporter-section'); const transporterStatus = document.getElementById('transporter-status'); const completedSection = document.getElementById('completed-section'); const completedFiles = document.getElementById('completed-files'); // File storage let filesToProcess = []; let currentPdfFile = null; // Initialize Feather Icons feather.replace(); // File type icons mapping const fileTypeIcons = { 'text/plain': 'file-text', 'application/msword': 'file-text', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'file-text', 'image/png': 'image', 'image/jpeg': 'image', 'image/gif': 'image', 'application/pdf': 'file' }; // Supported file types const supportedTypes = [ 'text/plain', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/markdown', 'image/png', 'image/jpeg', 'image/gif' ]; // Setup drag and drop for file upload setupDragAndDrop(dropZone, handleFiles); // Setup drag and drop for PDF upload setupDragAndDrop(pdfDropZone, handlePdfFiles); // Process button event processBtn.addEventListener('click', processFiles); // PDF process button event pdfProcessBtn.addEventListener('click', processPdfFile); // Setup drag and drop functionality function setupDragAndDrop(zone, handler) { zone.addEventListener('dragover', (e) => { e.preventDefault(); zone.classList.add('drop-zone-active'); }); zone.addEventListener('dragleave', () => { zone.classList.remove('drop-zone-active'); }); zone.addEventListener('drop', (e) => { e.preventDefault(); zone.classList.remove('drop-zone-active'); const files = e.dataTransfer.files; handler(files); }); zone.addEventListener('click', () => { const fileInput = document.createElement('input'); fileInput.type = 'file'; fileInput.multiple = true; fileInput.accept = supportedTypes.join(','); fileInput.addEventListener('change', (e) => { handler(e.target.files); }); fileInput.click(); }); } // Handle file selection for document creation function handleFiles(files) { for (let i = 0; i < files.length; i++) { const file = files[i]; // Check if file type is supported if (supportedTypes.includes(file.type) && filesToProcess.length < 30) { // Check for duplicates if (!filesToProcess.some(f => f.name === file.name && f.size === file.size)) { filesToProcess.push(file); renderFileItem(file); } } else if (filesToProcess.length >= 30) { alert('Maximum of 30 files allowed'); break; } } } // Handle PDF file selection function handlePdfFiles(files) { if (files.length > 0) { const file = files[0]; if (file.type === 'application/pdf') { currentPdfFile = file; pdfDropZone.innerHTML = `
${file.name}
${(file.size / 1024 / 1024).toFixed(2)} MB
`; feather.replace(); } else { alert('Please select a PDF file'); } } } // Render file item in the list function renderFileItem(file) { const fileItem = document.createElement('div'); fileItem.className = 'file-item mb-2'; fileItem.dataset.fileName = file.name; const fileType = file.type.split('/')[1] || 'file'; const iconType = fileTypeIcons[file.type] || 'file'; fileItem.innerHTML = `Drag & drop PDF files here or click to browse
Convert PDF to MD or JSON format
`; feather.replace(); transporterSection.classList.add('hidden'); }); } // Simulate transporter animation function simulateTransporterAnimation(callback) { const messages = [ 'Initializing transport sequence...', 'Locking coordinates...', 'Energizing pattern buffer...', 'Dematerializing subject...', 'Transport in progress...', 'Rematerializing at destination...', 'Transport complete!' ]; let index = 0; const interval = setInterval(() => { transporterStatus.textContent = messages[index]; index++; if (index >= messages.length) { clearInterval(interval); setTimeout(callback, 500); } }, 800); // Create sparkle effects createSparkles(20); } // Create sparkle effects function createSparkles(count) { const transporterAnimation = document.getElementById('transporter-animation'); for (let i = 0; i < count; i++) { setTimeout(() => { const sparkle = document.createElement('div'); sparkle.className = 'sparkle'; sparkle.style.left = `${Math.random() * 100}%`; sparkle.style.top = `${Math.random() * 100}%`; sparkle.style.animation = `sparkle 0.8s ease-out`; transporterAnimation.appendChild(sparkle); setTimeout(() => { sparkle.remove(); }, 800); }, i * 100); } } // Add completed file to the display function addCompletedFile(fileName, blob, fileType) { completedSection.classList.remove('hidden'); const fileElement = document.createElement('div'); fileElement.className = 'completed-file'; fileElement.innerHTML = `${fileType}