// Shared JavaScript across all pages // File upload handling document.addEventListener('DOMContentLoaded', function() { const fileInput = document.getElementById('pdfUpload'); if (fileInput) { fileInput.addEventListener('change', function(e) { const file = e.target.files[0]; if (file) { handleFileUpload(file); } }); } // Drag and drop functionality const uploadZone = document.querySelector('.border-dashed'); if (uploadZone) { uploadZone.addEventListener('dragover', function(e) { e.preventDefault(); this.classList.add('border-indigo-400', 'bg-indigo-50'); }); uploadZone.addEventListener('dragleave', function(e) { e.preventDefault(); this.classList.remove('border-indigo-400', 'bg-indigo-50'); }); uploadZone.addEventListener('drop', function(e) { e.preventDefault(); this.classList.remove('border-indigo-400', 'bg-indigo-50'); const files = e.dataTransfer.files; if (files.length > 0 && files[0].type === 'application/pdf') { handleFileUpload(files[0]); } else { alert('Please upload a valid PDF file.'); } }); } }); async function handleFileUpload(file) { console.log('File selected:', file.name); // Show loading state const uploadZone = document.querySelector('.border-dashed'); if (uploadZone) { uploadZone.innerHTML = `

DeepSeek OCR Processing...

Running advanced neural network analysis

`; try { // Simulate DeepSeek OCR processing with enhanced features const processingTime = Math.random() * 2000 + 1000; // 1-3 seconds await new Promise(resolve => setTimeout(resolve, processingTime)); // Enhanced success message with DeepSeek branding showSuccessMessage(file); } catch (error) { console.error('OCR processing error:', error); showErrorMessage(); } } } async function processWithDeepSeekOCR(file) { // This would be the actual API call to DeepSeek OCR // For demonstration, we're simulating the process const formData = new FormData(); formData.append('pdf', file); try { // Note: In a real implementation, you would use the actual DeepSeek OCR API // const response = await fetch('https://api.deepseek.com/ocr', { // method: 'POST', // body: formData, // headers: { // 'Authorization': 'Bearer YOUR_DEEPSEEK_API_KEY' // }); // const result = await response.json(); // Simulate DeepSeek OCR results return { success: true, extractedText: "Simulated text extraction using DeepSeek AI's advanced OCR capabilities...", confidence: 0.998, processingTime: 1.8, language: 'English', charactersRecognized: Math.floor(Math.random() * 5000) + 1000, compressionRatio: Math.floor(Math.random() * 60) + 30 }; } catch (error) { throw new Error('DeepSeek OCR processing failed'); } } function showErrorMessage() { const uploadZone = document.querySelector('.border-dashed'); if (uploadZone) { uploadZone.innerHTML = `

OCR Processing Failed

Please try again or contact support if the issue persists.

`; feather.replace(); } } function showSuccessMessage(file) { const uploadZone = document.querySelector('.border-dashed'); if (uploadZone) { uploadZone.innerHTML = `

Compression Complete! 🎉

Your PDF has been optimized successfully!

Original size: ${(Math.random() * 5 + 1).toFixed(1)} MB
Compressed size: ${(Math.random() * 2).toFixed(1)} MB
Reduction: ${Math.floor(Math.random() * 60 + 30)}%
`; feather.replace(); } } function resetUpload() { const uploadZone = document.querySelector('.border-dashed'); if (uploadZone) { uploadZone.innerHTML = `

Drop your PDF here

or click to browse your files

`; feather.replace(); // Re-attach event listeners const fileInput = document.getElementById('pdfUpload'); if (fileInput) { fileInput.addEventListener('change', function(e) { const file = e.target.files[0]; if (file) { handleFileUpload(file); } }); } } } // Initialize tooltips and other UI enhancements document.addEventListener('DOMContentLoaded', function() { console.log('PDF Squeeze Pro - OCR Magic Compressor loaded!'); });