Update index.html
Browse files- index.html +29 -1
index.html
CHANGED
|
@@ -20,6 +20,11 @@
|
|
| 20 |
background-color: #e8f0fe;
|
| 21 |
border-color: #0b84ff;
|
| 22 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</style>
|
| 24 |
</head>
|
| 25 |
|
|
@@ -42,10 +47,15 @@
|
|
| 42 |
<label id="status"></label>
|
| 43 |
<input id="upload" type="file" accept="image/*" style="display: none;" />
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
<script>
|
| 46 |
const dropZone = document.getElementById('drop-zone');
|
| 47 |
const fileInput = document.getElementById('upload');
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
dropZone.addEventListener('click', () => {
|
| 50 |
fileInput.click();
|
| 51 |
});
|
|
@@ -68,6 +78,24 @@
|
|
| 68 |
const changeEvent = new Event('change', { bubbles: true });
|
| 69 |
fileInput.dispatchEvent(changeEvent);
|
| 70 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
</script>
|
| 72 |
</body>
|
| 73 |
|
|
|
|
| 20 |
background-color: #e8f0fe;
|
| 21 |
border-color: #0b84ff;
|
| 22 |
}
|
| 23 |
+
|
| 24 |
+
#download-button {
|
| 25 |
+
margin-top: 20px;
|
| 26 |
+
display: none;
|
| 27 |
+
}
|
| 28 |
</style>
|
| 29 |
</head>
|
| 30 |
|
|
|
|
| 47 |
<label id="status"></label>
|
| 48 |
<input id="upload" type="file" accept="image/*" style="display: none;" />
|
| 49 |
|
| 50 |
+
<!-- Download Button -->
|
| 51 |
+
<button id="download-button">Download Image</button>
|
| 52 |
+
|
| 53 |
<script>
|
| 54 |
const dropZone = document.getElementById('drop-zone');
|
| 55 |
const fileInput = document.getElementById('upload');
|
| 56 |
+
const downloadButton = document.getElementById('download-button');
|
| 57 |
+
const container = document.getElementById('container');
|
| 58 |
+
|
| 59 |
dropZone.addEventListener('click', () => {
|
| 60 |
fileInput.click();
|
| 61 |
});
|
|
|
|
| 78 |
const changeEvent = new Event('change', { bubbles: true });
|
| 79 |
fileInput.dispatchEvent(changeEvent);
|
| 80 |
});
|
| 81 |
+
// Observe changes to the container's background image
|
| 82 |
+
const observer = new MutationObserver(() => {
|
| 83 |
+
const backgroundImage = container.style.backgroundImage;
|
| 84 |
+
|
| 85 |
+
// Extract the URL from the background-image style
|
| 86 |
+
const match = /url\(["']?([^"']*)["']?\)/.exec(backgroundImage);
|
| 87 |
+
if (match && match[1]) {
|
| 88 |
+
const imageUrl = match[1];
|
| 89 |
+
|
| 90 |
+
// Set the download button href to the background image URL
|
| 91 |
+
downloadButton.setAttribute('href', imageUrl);
|
| 92 |
+
downloadButton.setAttribute('download', 'generated-image.png');
|
| 93 |
+
downloadButton.style.display = 'block';
|
| 94 |
+
}
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
// Configure the observer to watch for attribute changes
|
| 98 |
+
observer.observe(container, { attributes: true, attributeFilter: ['style'] });
|
| 99 |
</script>
|
| 100 |
</body>
|
| 101 |
|