document.addEventListener('DOMContentLoaded', function() { const uploadForm = document.getElementById('uploadForm'); const uploadBtn = document.getElementById('uploadBtn'); const btnText = uploadBtn.querySelector('.btn-text'); const loadingSpinner = uploadBtn.querySelector('.loading-spinner'); const resultsSection = document.getElementById('resultsSection'); const resultsContent = document.getElementById('resultsContent'); const clearBtn = document.getElementById('clearBtn'); const filenamesInput = document.getElementById('filenames'); // Form submission handler uploadForm.addEventListener('submit', async function(e) { e.preventDefault(); const filenames = filenamesInput.value.trim(); if (!filenames) { alert('Please enter at least one filename'); return; } // Show loading state setLoadingState(true); try { const formData = new FormData(); formData.append('filenames', filenames); const response = await fetch('/upload', { method: 'POST', body: formData }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const results = await response.text(); displayResults(results); } catch (error) { console.error('Upload error:', error); displayResults(`❌ Error: ${error.message}`); } finally { setLoadingState(false); } }); // Clear results handler clearBtn.addEventListener('click', function() { resultsContent.textContent = ''; resultsSection.style.display = 'none'; }); // Auto-resize textarea filenamesInput.addEventListener('input', function() { this.style.height = 'auto'; this.style.height = Math.min(this.scrollHeight, 200) + 'px'; }); // Functions function setLoadingState(isLoading) { uploadBtn.disabled = isLoading; if (isLoading) { btnText.style.display = 'none'; loadingSpinner.style.display = 'flex'; } else { btnText.style.display = 'flex'; loadingSpinner.style.display = 'none'; } } function displayResults(results) { // Format results with proper styling const formattedResults = formatResults(results); resultsContent.innerHTML = formattedResults; resultsSection.style.display = 'block'; // Scroll to results resultsSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); } function formatResults(results) { if (!results) return 'No results received'; return results.split('\n').map(line => { line = line.trim(); if (!line) return ''; if (line.startsWith('✅')) { return `