console.log('script.js loaded'); let currentPath = null; let folderModal = null; let selectedFolder = null; let ws = null; // Initialize WebSocket connection function connectWebSocket() { ws = new WebSocket(`ws://${window.location.host}/ws`); ws.onopen = function () { console.log('WebSocket connected'); }; ws.onmessage = function (event) { const status = JSON.parse(event.data); updateIndexingStatus(status); }; ws.onclose = function () { console.log('WebSocket disconnected, attempting to reconnect...'); setTimeout(connectWebSocket, 1000); }; ws.onerror = function (error) { console.error('WebSocket error:', error); }; } // Update indexing progress function updateIndexingStatus(status) { const statusDiv = document.getElementById('indexingStatus'); const progressBar = statusDiv.querySelector('.progress-bar'); const details = document.getElementById('indexingDetails'); if (status.status === 'idle') { // Fade out the status div statusDiv.style.opacity = '0'; setTimeout(() => { statusDiv.style.display = 'none'; statusDiv.style.opacity = '1'; }, 500); return; } // Show and update the status statusDiv.style.display = 'block'; statusDiv.style.opacity = '1'; // Calculate progress percentage const percentage = status.total_files > 0 ? Math.round((status.processed_files / status.total_files) * 100) : 0; progressBar.style.width = `${percentage}%`; progressBar.setAttribute('aria-valuenow', percentage); // Update status text let statusText = `Status: ${status.status}`; if (status.current_file) { statusText += ` | Current file: ${status.current_file}`; } if (status.total_files > 0) { statusText += ` | Progress: ${status.processed_files}/${status.total_files} (${percentage}%)`; } details.textContent = statusText; } // IntersectionObserver for lazy loading images let imageObserver = null; function observeLazyLoadImages() { const lazyLoadImages = document.querySelectorAll('img.lazy-load'); if (imageObserver) { // Disconnect previous observer if any imageObserver.disconnect(); } imageObserver = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; const fullSrc = img.dataset.src; if (fullSrc) { img.src = fullSrc; img.removeAttribute('data-src'); // Remove data-src to prevent re-processing img.classList.remove('lazy-load'); // Remove class to prevent re-observing } observer.unobserve(img); // Stop observing the image once loaded } }); }, { rootMargin: '0px 0px 200px 0px' // Load images 200px before they enter viewport }); lazyLoadImages.forEach(img => { imageObserver.observe(img); }); } // Initialize folder browser async function initFolderBrowser() { folderModal = new bootstrap.Modal(document.getElementById('folderBrowserModal')); await loadFolderContents(); await loadIndexedFolders(); } // Open folder browser modal function openFolderBrowser() { selectedFolder = null; folderModal.show(); loadFolderContents(); } function showDrives(breadcrumb, browser, data) { // Windows drives breadcrumb.innerHTML = '
Add some folders to start indexing your images
An error occurred while searching. Please try again.
An error occurred while processing your image. Please try again.
This may take a few moments
Please check the URL and try again. Make sure it points to a valid image.
Try adjusting your search terms or uploading a different image