Update index.html
Browse files- index.html +87 -3
index.html
CHANGED
|
@@ -270,6 +270,28 @@
|
|
| 270 |
#submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; box-shadow: none; opacity: 0.7; }
|
| 271 |
#submit-btn .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
#result-container { min-height: 250px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); box-shadow: var(--shadow-sm) inset; transition: var(--transition-smooth); display: flex; align-items: center; justify-content: center; flex-direction: column; box-sizing: border-box; }
|
| 274 |
#result-container.loading,
|
| 275 |
#result-container.has-error-guide {
|
|
@@ -2308,7 +2330,6 @@
|
|
| 2308 |
<div class="progress-bar" id="loading-progress-bar"></div>
|
| 2309 |
</div>
|
| 2310 |
</div>`;
|
| 2311 |
-
const resultWrapperHTML = `<div id="result-image-wrapper"><img id="result-image-display" src="" alt="تصویر خلق شده"></div>`;
|
| 2312 |
|
| 2313 |
const startCountdown = (durationInSeconds) => {
|
| 2314 |
stopCountdown();
|
|
@@ -2361,12 +2382,75 @@
|
|
| 2361 |
}
|
| 2362 |
};
|
| 2363 |
|
|
|
|
| 2364 |
const displayResult = (imageUrl) => {
|
| 2365 |
resultContainer.classList.remove('loading', 'has-error-guide');
|
| 2366 |
resultContainer.classList.add('has-content');
|
| 2367 |
-
|
| 2368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2369 |
};
|
|
|
|
| 2370 |
|
| 2371 |
const clearResult = () => {
|
| 2372 |
resultContainer.classList.remove('has-content', 'loading', 'has-error-guide');
|
|
|
|
| 270 |
#submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; box-shadow: none; opacity: 0.7; }
|
| 271 |
#submit-btn .spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
|
| 272 |
|
| 273 |
+
/* === START: NEW STYLE FOR DOWNLOAD BUTTON === */
|
| 274 |
+
.download-button {
|
| 275 |
+
display: flex; align-items: center; justify-content: center; gap: 0.75rem;
|
| 276 |
+
width: 100%; max-width: 280px; margin: 1.5rem auto 0; padding: 0.9rem;
|
| 277 |
+
font-size: 1rem; font-weight: 600;
|
| 278 |
+
background: var(--accent-primary); color: #fff; border: none;
|
| 279 |
+
border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease;
|
| 280 |
+
box-shadow: var(--shadow-md);
|
| 281 |
+
}
|
| 282 |
+
.download-button svg { width: 20px; height: 20px; }
|
| 283 |
+
.download-button:hover:not(:disabled) {
|
| 284 |
+
background: var(--accent-primary-hover);
|
| 285 |
+
transform: translateY(-3px);
|
| 286 |
+
box-shadow: var(--shadow-lg);
|
| 287 |
+
}
|
| 288 |
+
.download-button:disabled {
|
| 289 |
+
background: var(--text-tertiary);
|
| 290 |
+
cursor: not-allowed;
|
| 291 |
+
opacity: 0.8;
|
| 292 |
+
}
|
| 293 |
+
/* === END: NEW STYLE FOR DOWNLOAD BUTTON === */
|
| 294 |
+
|
| 295 |
#result-container { min-height: 250px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); box-shadow: var(--shadow-sm) inset; transition: var(--transition-smooth); display: flex; align-items: center; justify-content: center; flex-direction: column; box-sizing: border-box; }
|
| 296 |
#result-container.loading,
|
| 297 |
#result-container.has-error-guide {
|
|
|
|
| 2330 |
<div class="progress-bar" id="loading-progress-bar"></div>
|
| 2331 |
</div>
|
| 2332 |
</div>`;
|
|
|
|
| 2333 |
|
| 2334 |
const startCountdown = (durationInSeconds) => {
|
| 2335 |
stopCountdown();
|
|
|
|
| 2382 |
}
|
| 2383 |
};
|
| 2384 |
|
| 2385 |
+
// === START: MODIFIED FUNCTION TO ADD DOWNLOAD BUTTON ===
|
| 2386 |
const displayResult = (imageUrl) => {
|
| 2387 |
resultContainer.classList.remove('loading', 'has-error-guide');
|
| 2388 |
resultContainer.classList.add('has-content');
|
| 2389 |
+
|
| 2390 |
+
// Create elements
|
| 2391 |
+
const wrapper = document.createElement('div');
|
| 2392 |
+
wrapper.id = 'result-image-wrapper';
|
| 2393 |
+
wrapper.style.animation = 'fadeIn 0.5s';
|
| 2394 |
+
wrapper.style.textAlign = 'center';
|
| 2395 |
+
|
| 2396 |
+
const img = document.createElement('img');
|
| 2397 |
+
img.id = 'result-image-display';
|
| 2398 |
+
img.src = imageUrl;
|
| 2399 |
+
img.alt = 'تصویر خلق شده';
|
| 2400 |
+
img.style.maxWidth = '100%';
|
| 2401 |
+
img.style.maxHeight = '500px';
|
| 2402 |
+
img.style.objectFit = 'contain';
|
| 2403 |
+
img.style.borderRadius = 'var(--radius-input)';
|
| 2404 |
+
img.style.boxShadow = 'var(--shadow-md)';
|
| 2405 |
+
img.style.border = '1px solid var(--panel-border)';
|
| 2406 |
+
wrapper.appendChild(img);
|
| 2407 |
+
|
| 2408 |
+
const downloadBtn = document.createElement('button');
|
| 2409 |
+
downloadBtn.id = 'download-btn';
|
| 2410 |
+
downloadBtn.className = 'download-button';
|
| 2411 |
+
downloadBtn.innerHTML = `
|
| 2412 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 2413 |
+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
|
| 2414 |
+
<polyline points="7 10 12 15 17 10"/>
|
| 2415 |
+
<line x1="12" y1="15" x2="12" y2="3"/>
|
| 2416 |
+
</svg>
|
| 2417 |
+
<span>دانلود تصویر</span>
|
| 2418 |
+
`;
|
| 2419 |
+
|
| 2420 |
+
// Clear container and append new elements
|
| 2421 |
+
resultContainer.innerHTML = '';
|
| 2422 |
+
resultContainer.appendChild(wrapper);
|
| 2423 |
+
resultContainer.appendChild(downloadBtn);
|
| 2424 |
+
|
| 2425 |
+
// Add event listener for the download button
|
| 2426 |
+
downloadBtn.addEventListener('click', async (event) => {
|
| 2427 |
+
const button = event.currentTarget;
|
| 2428 |
+
const buttonText = button.querySelector('span');
|
| 2429 |
+
const originalText = buttonText.textContent;
|
| 2430 |
+
|
| 2431 |
+
button.disabled = true;
|
| 2432 |
+
buttonText.textContent = 'در حال آمادهسازی...';
|
| 2433 |
+
|
| 2434 |
+
try {
|
| 2435 |
+
const response = await fetch(img.src);
|
| 2436 |
+
const blob = await response.blob();
|
| 2437 |
+
const filename = `generated-image-${Date.now()}.png`;
|
| 2438 |
+
|
| 2439 |
+
window.parent.postMessage({
|
| 2440 |
+
type: 'DOWNLOAD_IMAGE',
|
| 2441 |
+
payload: { blob, filename }
|
| 2442 |
+
}, '*');
|
| 2443 |
+
|
| 2444 |
+
} catch (error) {
|
| 2445 |
+
console.error('Error preparing file for download:', error);
|
| 2446 |
+
alert('خطا در آمادهسازی فایل برای دانلود. لطفاً دوباره تلاش کنید.');
|
| 2447 |
+
} finally {
|
| 2448 |
+
button.disabled = false;
|
| 2449 |
+
buttonText.textContent = originalText;
|
| 2450 |
+
}
|
| 2451 |
+
});
|
| 2452 |
};
|
| 2453 |
+
// === END: MODIFIED FUNCTION ===
|
| 2454 |
|
| 2455 |
const clearResult = () => {
|
| 2456 |
resultContainer.classList.remove('has-content', 'loading', 'has-error-guide');
|