این کد یک آپلودر تصویر ساده در PHP است که تصاویر ارسالی را روی سرور ذخیره میکند و لینکی به تصویر ذخیرهشده در اختیار کاربر قرار میدهد. در اینجا، بهطور مختصر هر بخش از کد را توضیح میدهم:
مسیر ذخیرهسازی :
php Copy code
$storagePath = __DIR__ . '/storage/';
این خط مسیر پوشهی ذخیرهسازی تصاویر را تعیین میکند که در پوشهی فرعی storage در دایرکتوری جاری قرار دارد.
بررسی وجود پوشه :
php Copy code
if (!is_dir($storagePath)) {
mkdir($storagePath, 0777, true);
}
اگر پوشهی ذخیرهسازی وجود نداشت، آن را با سطح دسترسی 777 ایجاد میکند.
پاسخ پیشفرض :
php Copy code
$response = ['success' => false, 'url' => ''];
یک آرایه بهنام $response تعریف میشود که در ابتدا موفقیت آپلود را false و URL تصویر را خالی تنظیم میکند.
بررسی درخواست POST و وجود فایل :
php Copy code
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
این خطها بررسی میکنند که آیا درخواست از نوع POST بوده و فایل تصویری image آپلود شده است یا نه.
اعتبارسنجی پسوند فایل :
php Copy code
$allowedExtensions = ['png', 'jpg', 'jpeg', 'webp'];
if (!in_array($fileExtension, $allowedExtensions)) {
echo json_encode($response);
exit;
}
این بخش، پسوند فایل آپلودشده را بررسی میکند و در صورتی که پسوند مجاز نباشد، عملیات متوقف میشود.
ایجاد نام منحصربهفرد برای فایل :
php Copy code
$fileName = uniqid() . '.' . $fileExtension;
این خط یک نام منحصربهفرد برای فایل با استفاده از uniqid ایجاد میکند تا از همپوشانی نام فایل جلوگیری شود.
ذخیره فایل و تنظیم پاسخ موفقیتآمیز :
php Copy code
if (move_uploaded_file($file['tmp_name'], $filePath)) {
$response['success'] = true;
$response['url'] = 'https://www.aisada.ir/hamed/storage/' . $fileName;
}
اگر فایل بهطور موفقیتآمیز جابهجا و ذخیره شد، پاسخ به موفقیت تنظیم میشود و URL تصویر ارائه داده میشود.
ارسال پاسخِ JSON به کلاینت :
php Copy code
echo json_encode($response);
در نهایت، پاسخ بهصورت JSON ارسال میشود که شامل وضعیت موفقیتآمیز بودن و URL تصویر آپلودشده (اگر موفقیتآمیز باشد) میباشد.
اگر سوال یا نیازی به بهبودهای خاص در کد دارید، میتوانید آن را مشخص کنید.
این یکی کد منم مثل اون درست کن
Show full message · 378 lines Assistant2024-11-19 14:27 UTC Copy response
به نظر میرسد که شما یک اسکریپت HTML, CSS, و جاوا اسکریپت دارید که به منظور یک رابط کاربری تعاملی و زیباسازی صفحه مورد استفاده قرار میگیرد. قصد دارید این کد را بهبود بخشید همانطور که یک اسکریپت PHP برای آپلود تصویر را بهبود دادید.
با در نظر داشتن ساختار کلی صفحات وب، میتوانید برخی بهبودها یا نکات را در نظر بگیرید:
اثرگذاری CSS :
فشردهسازی و مینیمایز کردن فایلهای CSS برای بهبود سرعت لود صفحه.
اطمینان از استفاده بهینه از مشخصات CSS و اجتناب از تأثیرات سنگین که ممکن است بر عملکرد صفحه تأثیر بگذارد.
جاوا اسکریپت :
بهبود عملکرد و حذف خطوط غیرضروری برای اجرای بهتر.
در نظر گرفتن asynchronous operations برای جلوگیری از بلاک شدن UI.
تأیید اینکه تمام event listeners به صورت بهینه و بدون نشت حافظه اضافه شدهاند.
HTML :
استفاده از تگهای HTML5 و بهرهوری از تگهای معنایی برای بهبود خوانایی و SEO.
اطمینان از درست بودن nesting تگها و اعتبار HTML با استفاده از HTML validator.
دسترسپذیری :
اطمینان از اینکه تجربه کاربری خوبی برای افرادی با ناتوانیهای مختلف ارائه میشود. استفاده از aria-* attributes و عناصر قابل درک توسط screen readers.
امنیت :
اطمینان از امنیت لینکهای ارائه شده با اعمال سیاستهای امنیتی سرور (CSP) و جلوگیری از خطرات XSS.
بارگذاری منابع خارجی :
بررسی این که منابع خارجی (جاوا اسکریپت و CSS) به صورت مطمئن و از منابع معتبر لود میشوند.
در نظر گرفتن CDNها برای بهبود سرعت دانلود و افزایش پایداری.
اگر مورد خاصی جهت بهبود این اسکریپت مدنظر دارید یا نیاز به ویژگیهای دیگر دارید، لطفاً بهطور مشخصتری بیان کنید تا بتوانم به شما کمک کنم.
Assistant2024-11-19 14:28 UTC Copy response
برای ایجاد یک صفحه وب کامل با توجه به جزئیات ارائه شده، میتوانیم HTML، CSS و جاوا اسکریپت را به صورت کامل ادغام کنیم. در این کد، یک رابط کاربری تعاملی برای بارگذاری و مشاهده تصاویر ساخته شده است. در زیر نمونهای از یک صفحه وب کامل که شامل تمامی قطعات مورد نظر است ارائه میشود:
Show full message · 379 lines کد همون باشه فقط یک دکمه دانلود بهش اضافه کن که مثل اون داخل سایت خودم لینک بده و کپی بشه
Assistant2024-11-19 14:34 UTC Copy response
برای اضافه کردن یک دکمه دانلود که بتواند لینکها را کپی کند، میتوانید از جاوا اسکریپت استفاده کنید تا لینکها در کلیپبورد کاربر کپی شوند. در اینجا دکمه دانلودی اضافه میکنیم که پس از کلیک، لینک تصویر را کپی میکند و یک اعلان مبنیبر کپیشدن موفقیتآمیز ارائه میدهد.
کد HTML و جاوا اسکریپت زیر اصلاحشده و شامل دکمه دانلود است:
Show full message · 391 lines کد همون باشه کامل همه چیییییش
Assistant2024-11-19 14:35 UTC Copy response
باشه، بگذارید همه بخشهای کد را با اضافه کردن دکمهای برای کپی کردن لینک دانلود تصویر کامل کنیم. در این کد، دکمهای اضافه میشود که در داخل مودالی که تصاویر را پیشنمایش میکند، برای کپی کردن لینک تصویر استفاده میشود. همچنین اطمینان خواهیم یافت که متن کد از نظر نگارشی کامل و درست است.
Show full message · 389 lines Show full message · 378 lines Assistant2024-11-19 14:38 UTC Copy response
برای اضافه کردن دکمهای که لینک دانلود تصویر را کپی کند، میتوانیم از جاوا اسکریپت برای مدیریت رویداد کلیک این دکمه استفاده کنیم. در اینجا به شما نشان میدهم که چگونه میتوانید دکمه دانلود را بهگونهای تغییر دهید که بهجای دانلود، لینک تصویر را به کلیپبورد کپی کند:
کد HTML کامل با دکمه کپی لینک
Show full message · 410 lines Not yet included in a published release.
a {
display: none;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
margin-top: 0;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#tutorialTitle {
color: red;
}
#einsteinTip {
margin-top: 10px;
font-style: italic;
color: #555;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
code Copy code
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
const downloadButton = document.getElementById('downloadButton');
if (downloadButton) {
downloadButton.addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
}
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
const saveImageButton = document.getElementById('saveImageButton');
saveImageButton.addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
const confirmButton = document.getElementById('confirmButton');
confirmButton.addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
const closeFullscreenButton = document.getElementById('closeFullscreenButton');
closeFullscreenButton.addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
const noImageButton = document.getElementById('noImageButton');
noImageButton.addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
});
</script>
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>بارگذاری و مشاهده تصویر</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: auto;
background-color: #f4f4f9;
font-family: sans-serif;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div id="loader">
<div id="progress">
<div id="bar">0%</div>
</div>
<div>لطفاً صبر کنید...</div>
</div>
<gradio-app src="https://victorestrada-diffusers-image-outpaint.hf.space/"></gradio-app>
<button id="downloadButton">دانلود تصویر 📥</button>
<div class="modal" id="imageModal">
<h3>پیشنمایش تصویر</h3>
<img id="modalImage" alt="Image Preview" />
<button id="nextImageButton">تصویر بعدی ⏭️</button>
<button id="saveImageButton">ذخیره تصویر 💾</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification" id="saveNotification">
<p>برای ذخیره تصویر روی تایید کلیک کنید و بعد از باز شدن تصویر در حالت تمام صفحه از صفحه اسکرین شات بگیرید و بعدا برش دهید.</p>
<button id="confirmButton">تایید ✅</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification error" id="noImageNotification">
<p>هیچ تصویر ساخته شده ای یافت نشد.</p>
<button id="noImageButton">باشه</button>
</div>
<div class="fullscreen-overlay" id="fullscreenOverlay">
<img id="fullscreenImage" class="fullscreen-image" />
<button class="close-fullscreen" id="closeFullscreenButton">❌</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function modifyText() {
document.querySelectorAll('body *').forEach(element => {
element.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
const replacements = {
'Examples': 'نمونهها',
'Expected Ratio': 'اندازه مورد انتظار',
'Prompt': 'متن',
'Optional': 'انگلیسی وارد کنید و یا خالی بزارید.',
'Generate': 'شروع ساخت',
'Diffusers Image Outpaint': 'ابزار فوق پیشرفته گسترش تصاویر',
'Drop an image...': 'با نرمافزار هوش مصنوعی',
'Input Image': 'تصویر ورودی',
'Alignment': 'تراز',
'Advanced settings': 'تنظیمات پیشرفته',
'Middle': 'وسط',
'Left': 'چپ',
'Right': 'راست',
'Top': 'بالا',
'Bottom': 'پایین',
'Width': 'عرض',
'Steps': 'مراحل',
'Height': 'ارتفاع',
'Mask': 'ماسک',
'Overlap': 'همپوشانی',
'Resize input image': 'تغییر اندازه تصویر ورودی',
'Loading': 'در حال بارگذاری'
};
for (const [original, replacement] of Object.entries(replacements)) {
if (node.nodeValue.includes(original)) {
node.nodeValue = node.nodeValue.replace(original, replacement);
}
}
}
});
});
}
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
document.getElementById('downloadButton').addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
document.getElementById('saveImageButton').addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
document.getElementById('confirmButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
document.getElementById('closeFullscreenButton').addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
document.getElementById('noImageButton').addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
});
</script>
</body>
</html>
توضیحات:
HTML : ساختار صفحه و چیدمان عناصر تعیین شده است.
CSS : ظاهر و استایل عناصر توسط استایلهای داخلی صفحه تعریف شدهاند.
آزمایش متنی : تبدیل متون به کمک جاوا اسکریپت برای پشتیبانی از زبان فارسی و بومیسازی برخی از متنهای موجود در رابط کاربری برنامه.
جاوا اسکریپت : برای تعامل کاربری و مدیریت بروز رسانی داینامیک صفحه از DOM manipulation و event handling استفاده شده است.
این کد نمونه کامل و پایهای از یک صفحه وب است که قابلیت بهبود و گسترش دارد. لطفاً مطمئن شوید که از لینکهای صحیح و قابلاعتماد برای منابع خارجی استفاده میکنید.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>بارگذاری و مشاهده تصویر</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: auto;
background-color: #f4f4f9;
font-family: sans-serif;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div id="loader">
<div id="progress">
<div id="bar">0%</div>
</div>
<div>لطفاً صبر کنید...</div>
</div>
<gradio-app src="https://victorestrada-diffusers-image-outpaint.hf.space/"></gradio-app>
<button id="downloadButton">دانلود تصویر 📥</button>
<div class="modal" id="imageModal">
<h3>پیشنمایش تصویر</h3>
<img id="modalImage" alt="Image Preview" />
<button id="nextImageButton">تصویر بعدی ⏭️</button>
<button id="saveImageButton">ذخیره تصویر 💾</button>
<button id="copyLinkButton">کپی لینک 📋</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification" id="saveNotification">
<p>برای ذخیره تصویر روی تایید کلیک کنید و بعد از باز شدن تصویر در حالت تمام صفحه از صفحه اسکرین شات بگیرید و بعدا برش دهید.</p>
<button id="confirmButton">تایید ✅</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification error" id="noImageNotification">
<p>هیچ تصویر ساخته شده ای یافت نشد.</p>
<button id="noImageButton">باشه</button>
</div>
<div class="fullscreen-overlay" id="fullscreenOverlay">
<img id="fullscreenImage" class="fullscreen-image" />
<button class="close-fullscreen" id="closeFullscreenButton">❌</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function modifyText() {
document.querySelectorAll('body *').forEach(element => {
element.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
const replacements = {
'Examples': 'نمونهها',
'Expected Ratio': 'اندازه مورد انتظار',
'Prompt': 'متن',
'Optional': 'انگلیسی وارد کنید و یا خالی بزارید.',
'Generate': 'شروع ساخت',
'Diffusers Image Outpaint': 'ابزار فوق پیشرفته گسترش تصاویر',
'Drop an image...': 'با نرمافزار هوش مصنوعی',
'Input Image': 'تصویر ورودی',
'Alignment': 'تراز',
'Advanced settings': 'تنظیمات پیشرفته',
'Middle': 'وسط',
'Left': 'چپ',
'Right': 'راست',
'Top': 'بالا',
'Bottom': 'پایین',
'Width': 'عرض',
'Steps': 'مراحل',
'Height': 'ارتفاع',
'Mask': 'ماسک',
'Overlap': 'همپوشانی',
'Resize input image': 'تغییر اندازه تصویر ورودی',
'Loading': 'در حال بارگذاری'
};
for (const [original, replacement] of Object.entries(replacements)) {
if (node.nodeValue.includes(original)) {
node.nodeValue = node.nodeValue.replace(original, replacement);
}
}
}
});
});
}
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
document.getElementById('downloadButton').addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
document.getElementById('saveImageButton').addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
document.getElementById('copyLinkButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const imageUrl = modalImage.src;
navigator.clipboard.writeText(imageUrl).then(() => {
alert("لینک تصویر کپی شد!");
}, (err) => {
alert("خطا در هنگام کپی لینک!");
});
});
document.getElementById('confirmButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
document.getElementById('closeFullscreenButton').addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
document.getElementById('noImageButton').addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
});
</script>
</body>
</html>
توضیحات:
دکمه 'کپی لینک' : با کلیک بر روی این دکمه، URL تصویر فعلی در مودال کپی میشود.
تابع navigator.clipboard.writeText : برای کپی کردن متن به کلیپبورد استفاده میشود و در مرورگرهایی که API کلیپبورد را پشتیبانی میکنند، قابل استفاده است.
اعلانها : یک اعلان کوچک برای نمایش موفقیتآمیز بودن کپی اضافه شده است. در صورت عدم موفقیت، یک پیام خطا نمایش داده میشود.
لطفاً از اینکه چه عناصری مورد نیاز هستند یا باید تغییر یابند اطمینان حاصل کنید و بررسی کنید که تمامی مرورگرهای هدف از APIهای استفاده شده پشتیبانی میکنند.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>بارگذاری و مشاهده تصویر</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: auto;
background-color: #f4f4f9;
font-family: sans-serif;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div id="loader">
<div id="progress">
<div id="bar">0%</div>
</div>
<div>لطفاً صبر کنید...</div>
</div>
<gradio-app src="https://victorestrada-diffusers-image-outpaint.hf.space/"></gradio-app>
<button id="downloadButton">دانلود تصویر 📥</button>
<div class="modal" id="imageModal">
<h3>پیشنمایش تصویر</h3>
<img id="modalImage" alt="Image Preview" />
<button id="nextImageButton">تصویر بعدی ⏭️</button>
<button id="saveImageButton">ذخیره تصویر 💾</button>
<button id="copyLinkButton">کپی لینک 📋</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification" id="saveNotification">
<p>برای ذخیره تصویر روی تایید کلیک کنید و بعد از باز شدن تصویر در حالت تمام صفحه از صفحه اسکرین شات بگیرید و بعدا برش دهید.</p>
<button id="confirmButton">تایید ✅</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification error" id="noImageNotification">
<p>هیچ تصویر ساخته شده ای یافت نشد.</p>
<button id="noImageButton">باشه</button>
</div>
<div class="fullscreen-overlay" id="fullscreenOverlay">
<img id="fullscreenImage" class="fullscreen-image" />
<button class="close-fullscreen" id="closeFullscreenButton">❌</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function modifyText() {
document.querySelectorAll('body *').forEach(element => {
element.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
const replacements = {
'Examples': 'نمونهها',
'Expected Ratio': 'اندازه مورد انتظار',
'Prompt': 'متن',
'Optional': 'انگلیسی وارد کنید و یا خالی بزارید.',
'Generate': 'شروع ساخت',
'Diffusers Image Outpaint': 'ابزار فوق پیشرفته گسترش تصاویر',
'Drop an image...': 'با نرمافزار هوش مصنوعی',
'Input Image': 'تصویر ورودی',
'Alignment': 'تراز',
'Advanced settings': 'تنظیمات پیشرفته',
'Middle': 'وسط',
'Left': 'چپ',
'Right': 'راست',
'Top': 'بالا',
'Bottom': 'پایین',
'Width': 'عرض',
'Steps': 'مراحل',
'Height': 'ارتفاع',
'Mask': 'ماسک',
'Overlap': 'همپوشانی',
'Resize input image': 'تغییر اندازه تصویر ورودی',
'Loading': 'در حال بارگذاری'
};
for (const [original, replacement] of Object.entries(replacements)) {
if (node.nodeValue.includes(original)) {
node.nodeValue = node.nodeValue.replace(original, replacement);
}
}
}
});
});
}
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
document.getElementById('downloadButton').addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
document.getElementById('saveImageButton').addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
document.getElementById('copyLinkButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const imageUrl = modalImage.src;
navigator.clipboard.writeText(imageUrl).then(() => {
alert("لینک تصویر کپی شد!");
}, (err) => {
alert("خطا در هنگام کپی لینک!");
});
});
document.getElementById('confirmButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
document.getElementById('closeFullscreenButton').addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
document.getElementById('noImageButton').addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
});
</script>
</body>
</html>
نکات:
دکمههای کپی لینک, ذخیره تصویر, و تصویر بعدی در مودالها اضافه شدهاند.
از API clipboard در جاوا اسکریپت برای کپی کردن لینک تصویر استفاده شده است.
تغییری در بقیه کد ایجاد نشده و مشابه درخواست شما باقی مانده است.
امیدوارم این کد به شما کمک کند تا ویژگی مورد نظر خود را بر روی سایت پیادهسازی کنید. اگر سوال یا نیاز به تغییری دارید، اطلاع دهید.
a {
display: none;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
margin-top: 0;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#tutorialTitle {
color: red;
}
#einsteinTip {
margin-top: 10px;
font-style: italic;
color: #555;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
code Copy code
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
const downloadButton = document.getElementById('downloadButton');
if (downloadButton) {
downloadButton.addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
}
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
const saveImageButton = document.getElementById('saveImageButton');
saveImageButton.addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
const confirmButton = document.getElementById('confirmButton');
confirmButton.addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
const closeFullscreenButton = document.getElementById('closeFullscreenButton');
closeFullscreenButton.addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
const noImageButton = document.getElementById('noImageButton');
noImageButton.addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
});
</script>
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>بارگذاری و مشاهده تصویر</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: auto;
background-color: #f4f4f9;
font-family: sans-serif;
position: relative;
}
a {
display: none;
}
#loader {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #f4f4f9;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
text-align: center;
}
#progress {
width: 80%;
height: 30px;
background-color: #eee;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%;
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.2s ease;
}
gradio-app {
display: flex;
justify-content: center;
align-items: center;
zoom: 0.8;
min-height: 100vh;
margin-top: 0;
}
.modal, .notification {
display: none;
position: fixed;
z-index: 10002;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
color: #333;
max-width: 400px;
width: 90%;
}
.modal img, .notification img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
border-radius: 8px;
}
.modal button, .notification button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin: 5px;
font-size: 16px;
}
.modal button:hover, .notification button:hover {
background-color: #45a049;
}
.close-button {
background-color: #d9534f;
color: white;
}
.close-button:hover {
background-color: #c9302c;
}
#downloadButton {
display: none;
position: fixed;
bottom: 20px;
left: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 10003;
font-size: 16px;
}
#downloadButton:hover {
background-color: #45a049;
}
.fullscreen-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
z-index: 10004;
justify-content: center;
align-items: center;
overflow: hidden;
}
.fullscreen-image {
max-width: 90%;
max-height: 90%;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
.close-fullscreen {
position: absolute;
top: 10px;
right: 10px;
background-color: transparent;
color: white;
font-size: 24px;
border: none;
cursor: pointer;
}
.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
</style>
</head>
<body>
<div id="loader">
<div id="progress">
<div id="bar">0%</div>
</div>
<div>لطفاً صبر کنید...</div>
<div id="einsteinTip">اگر این هوش مصنوعی باز نشد فیلتر شکن تونو روشن کنید</div>
</div>
<gradio-app src="https://victorestrada-diffusers-image-outpaint.hf.space/"></gradio-app>
<button id="downloadButton">کپی لینک تصویر 📋</button>
<div class="modal" id="imageModal">
<h3>پیشنمایش تصویر</h3>
<img id="modalImage" alt="Image Preview" />
<button id="nextImageButton">تصویر بعدی ⏭️</button>
<button id="saveImageButton">ذخیره تصویر 💾</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification" id="saveNotification">
<p>برای ذخیره تصویر روی تایید کلیک کنید و بعد از باز شدن تصویر در حالت تمام صفحه از صفحه اسکرین شات بگیرید و بعدا برش بدید.</p>
<button id="confirmButton">تایید ✅</button>
<button class="close-button">لغو ❌</button>
</div>
<div class="notification error" id="noImageNotification">
<p>هیچ تصویر ساخته شده ای یافت نشد.</p>
<button id="noImageButton">باشه</button>
</div>
<div class="fullscreen-overlay" id="fullscreenOverlay">
<img id="fullscreenImage" class="fullscreen-image" />
<button class="close-fullscreen" id="closeFullscreenButton">❌</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function modifyText() {
document.querySelectorAll('body *').forEach(element => {
element.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
const replacements = {
'Examples': 'نمونه ها',
'Expected Ratio': 'اندازه مورد انتظار',
'Prompt': 'متن',
'Optional': 'انگلیسی وارد کنید و یا خالی بزارید.',
'Generate': 'شروع ساخت',
'Diffusers Image Outpaint': 'ابزار فوق پیشرفته گسترش تصاویر',
'Drop an image you would like to extend, pick your expected ratio and hit شروع ساخت': 'با نرم افزار هوش مصنوعی',
'Input Image': 'تصویر ورودی',
'Alignment': 'تراز',
'Advanced settings': 'تنظیمات پیشرفته',
'Middle': 'وسط',
'Left': 'چپ',
'Right': 'راست',
'Top': 'بالا',
'Bottom': 'پایین',
'Width': 'عرض',
'Steps': 'مراحل',
'Height': 'ارتفاع',
'Mask': 'ماسک',
'Overlap': 'همپوشانی',
'Resize input image': 'تغییر اندازه تصویر ورودی',
'Loading': 'در حال بارگذاری'
};
for (const [original, replacement] of Object.entries(replacements)) {
if (node.nodeValue.includes(original)) {
node.nodeValue = node.nodeValue.replace(original, replacement);
}
}
}
});
});
}
function simulateProgress(callback) {
let progress = 0;
const progressElement = document.getElementById('bar');
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 50);
} else {
callback();
modifyText();
}
}
updateProgress();
}
function showContent() {
document.getElementById('loader').style.display = 'none';
const gradioApp = document.querySelector('gradio-app');
gradioApp.scrollIntoView({ behavior: 'smooth', block: 'start' });
document.getElementById('downloadButton').style.display = 'block';
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp) {
gradioApp.addEventListener('gradio_loaded', showContent);
gradioApp.addEventListener('load', showContent);
setTimeout(showContent, 10000);
} else {
setTimeout(checkIfLoaded, 100);
}
}
checkIfLoaded();
};
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'subtree') {
modifyText();
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
const downloadButton = document.getElementById('downloadButton');
if (downloadButton) {
downloadButton.addEventListener('click', function() {
const images = document.querySelectorAll('gradio-app img[src$=".webp"]');
const ignoredUrl = 'https://victorestrada-diffusers-image-outpaint.hf.space/file=/tmp/gradio/58d27ee015923ff8867291e88910c3b1fc5e49698a7a06372037c6d58cd5452e/example_1.webp';
let imageArray = [];
images.forEach(img => {
if (!img.src.includes(ignoredUrl)) {
imageArray.push(img.src);
}
});
if (imageArray.length > 0) {
let currentIndex = 0;
displayImage(imageArray, currentIndex);
document.getElementById('nextImageButton').onclick = function() {
currentIndex = (currentIndex + 1) % imageArray.length;
displayImage(imageArray, currentIndex);
};
} else {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'block';
}
});
}
function displayImage(imageList, index) {
const modalImage = document.getElementById('modalImage');
modalImage.src = imageList[index];
const imageModal = document.getElementById('imageModal');
imageModal.style.display = 'block';
}
const saveImageButton = document.getElementById('saveImageButton');
saveImageButton.addEventListener('click', function() {
const saveNotification = document.getElementById('saveNotification');
saveNotification.style.display = 'block';
});
const confirmButton = document.getElementById('confirmButton');
confirmButton.addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
const fullscreenImage = document.getElementById('fullscreenImage');
fullscreenImage.src = modalImage.src;
fullscreenOverlay.style.display = 'flex';
document.getElementById('saveNotification').style.display = 'none';
});
const closeFullscreenButton = document.getElementById('closeFullscreenButton');
closeFullscreenButton.addEventListener('click', function() {
const fullscreenOverlay = document.getElementById('fullscreenOverlay');
fullscreenOverlay.style.display = 'none';
});
document.querySelectorAll('.close-button').forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation();
button.closest('.modal, .notification').style.display = 'none';
});
});
const noImageButton = document.getElementById('noImageButton');
noImageButton.addEventListener('click', function() {
const noImageNotification = document.getElementById('noImageNotification');
noImageNotification.style.display = 'none';
});
document.addEventListener('click', function(event) {
if (!event.target.closest('.modal, .notification') && !event.target.matches('#downloadButton')) {
document.querySelectorAll('.modal, .notification').forEach(modal => {
modal.style.display = 'none';
});
}
});
document.getElementById('downloadButton').addEventListener('click', function() {
const modalImage = document.getElementById('modalImage');
if (modalImage.src) {
navigator.clipboard.writeText(modalImage.src).then(() => {
alert("لینک تصویر کپی شد!");
}).catch(err => {
alert("خطا در کپی کردن لینک!");
});
}
});
});
</script>
</body>
</html>
توضیحات:
دکمه کپی لینک : دکمهای برای کپی لینک تصویر در کلیپبورد اضافه شده است.
جاوا اسکریپت : یک رویداد click به دکمه دانلود اضافه شده تا لینک تصویر فعلی که در پیشنمایش قرار دارد، کپی شود.
اعلانها : پیامهای اعلان را نیز اضافه کردیم که به کاربر اطلاع میدهند که لینک تصویر با موفقیت کپی شده یا در کپی کردن آن خطایی رخ داده است.
شما میتوانید این کد را بهصورت مستقیم برای ایجاد صفحهای با قابلیت کپی لینک تصویر در کلیپبورد پیادهسازی کنید. هر زمان که سؤالی داشتید یا نیاز به تغییر دیگری بود، لطفاً بگویید.