amalsp commited on
Commit
68697a0
·
verified ·
1 Parent(s): 302a037

Add automatic download for single images

Browse files
Files changed (1) hide show
  1. script.js +21 -1
script.js CHANGED
@@ -20,7 +20,27 @@ document.getElementById('imageForm').addEventListener('submit', function(e) {
20
  return;
21
  }
22
 
23
- // Generate image links
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  const title = document.createElement('h2');
25
  title.textContent = 'Generated Image Links:';
26
  title.style.marginTop = '20px';
 
20
  return;
21
  }
22
 
23
+ // Special case: if imageCount is 1, download immediately
24
+ if (imageCount === 1) {
25
+ // Create a temporary anchor element
26
+ const a = document.createElement('a');
27
+ a.href = baseUrl;
28
+ a.download = ''; // This triggers download behavior
29
+ document.body.appendChild(a);
30
+ a.click();
31
+ document.body.removeChild(a);
32
+
33
+ // Show success message
34
+ const successMsg = document.createElement('p');
35
+ successMsg.textContent = 'Image download initiated!';
36
+ successMsg.style.color = '#28a745';
37
+ successMsg.style.fontWeight = 'bold';
38
+ successMsg.style.marginTop = '15px';
39
+ resultsDiv.appendChild(successMsg);
40
+ return;
41
+ }
42
+
43
+ // Generate image links for multiple images
44
  const title = document.createElement('h2');
45
  title.textContent = 'Generated Image Links:';
46
  title.style.marginTop = '20px';