Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const generateBtn = document.getElementById('generate-btn');
+ const promptInput = document.getElementById('prompt-input');
+ const imageGallery = document.getElementById('image-gallery');
+
+ // Placeholder for image generation functionality
+ generateBtn.addEventListener('click', function() {
+ const prompt = promptInput.value.trim();
+
+ if (!prompt) {
+ alert('Please enter a description for your image');
+ return;
+ }
+
+ // Simulate image generation (in a real app, this would call an API)
+ generateBtn.disabled = true;
+ generateBtn.textContent = 'Generating...';
+
+ setTimeout(() => {
+ // Create a new image item
+ const newImageItem = document.createElement('div');
+ newImageItem.className = 'gallery-item';
+
+ // Create a unique "generated" image URL based on prompt
+ const placeholderColors = ['6c5ce7', '00cec9', 'fd79a8', 'e17055', '0984e3'];
+ const randomColor = placeholderColors[Math.floor(Math.random() * placeholderColors.length)];
+ const imageUrl = `https://via.placeholder.com/600x400/${randomColor}/ffffff?text=${encodeURIComponent(prompt.substring(0, 30))}`;
+
+ newImageItem.innerHTML = `
+

+ `;
+
+ // Add to the top of the gallery
+ imageGallery.insertBefore(newImageItem, imageGallery.firstChild);
+
+ generateBtn.disabled = false;
+ generateBtn.textContent = 'Generate Image';
+ promptInput.value = '';
+ }, 1500);
+ });
+
+ // Allow pressing Enter to generate
+ promptInput.addEventListener('keypress', function(e) {
+ if (e.key === 'Enter') {
+ generateBtn.click();
+ }
+ });
+ });
+
+ // Helper functions for the buttons
+ function downloadImage(url, filename) {
+ const link = document.createElement('a');
+ link.href = url;
+ link.download = `imagine_${filename || 'image'}.jpg`;
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ }
+
+ function shareImage(url, prompt) {
+ if (navigator.share) {
+ navigator.share({
+ title: 'Check out this AI-generated image',
+ text: `I created this with Imagine: "${prompt}"`,
+ url: url
+ }).catch(err => {
+ console.log('Error sharing:', err);
+ fallbackShare(url);
+ });
+ } else {
+ fallbackShare(url);
+ }
+ }
+
+ function fallbackShare(url) {
+ prompt('Copy this link to share your image:', url);
+ }