Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const urlForm = document.getElementById('urlForm');
+ const previewFrame = document.getElementById('previewFrame');
+ const imagesGrid = document.getElementById('imagesGrid');
+
+ // Device preview settings
+ const deviceSizes = {
+ mobile: { width: '375px', height: '667px' },
+ tablet: { width: '768px', height: '1024px' },
+ desktop: { width: '100%', height: '600px' }
+ };
+
+ urlForm.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ const url = document.getElementById('websiteUrl').value;
+
+ try {
+ // Load website in iframe
+ previewFrame.src = url;
+
+ // Fetch and display images
+ await fetchImages(url);
+ } catch (error) {
+ console.error('Error loading website:', error);
+ alert('Error loading website. Please check the URL and try again.');
+ }
+ });
+
+ // Device preview controls
+ document.querySelectorAll('.device-controls button').forEach(button => {
+ button.addEventListener('click', () => {
+ const device = button.dataset.device;
+ const orientation = button.dataset.orientation;
+
+ if (device) {
+ const size = deviceSizes[device];
+ previewFrame.style.width = size.width;
+ previewFrame.style.height = size.height;
+ }
+
+ if (orientation) {
+ if (orientation === 'landscape') {
+ [previewFrame.style.width, previewFrame.style.height] =
+ [previewFrame.style.height, previewFrame.style.width];
+ }
+ }
+ });
+ });
+
+ async function fetchImages(url) {
+ try {
+ // In a real implementation, this would need a backend service
+ // to fetch and parse the webpage for images
+ const response = await fetch(url);
+ const html = await response.text();
+ const parser = new DOMParser();
+ const doc = parser.parseFromString(html, 'text/html');
+ const images = doc.querySelectorAll('img');
+
+ imagesGrid.innerHTML = '';
+
+ images.forEach(img => {
+ const imgContainer = document.createElement('div');
+ imgContainer.className = 'image-item';
+
+ const imgElement = document.createElement('img');
+ imgElement.src = img.src;
+ imgElement.alt = img.alt;
+
+ const imgInfo = document.createElement('div');
+ imgInfo.className = 'image-info';
+ imgInfo.textContent = `${img.naturalWidth}x${img.naturalHeight}px`;
+
+ imgContainer.appendChild(imgElement);
+ imgContainer.appendChild(imgInfo);
+ imagesGrid.appendChild(imgContainer);
+ });
+ } catch (error) {
+ console.error('Error fetching images:', error);
+ }
+ }
+
+ // Download functionality
+ document.getElementById('downloadAll').addEventListener('click', () => {
+ // In a real implementation, this would create a zip file
+ // containing all images
+ alert('Download functionality would be implemented here');
+ });
+
+ document.getElementById('downloadSelected').addEventListener('click', () => {
+ // In a real implementation, this would create a zip file
+ // containing selected images
+ alert('Download functionality would be implemented here');
+ });
+ });