gpt-4o-mini-2024-07-18· openai
from WildChat-4.8M
<p> </p> <style> /* تنظیمات پایه برای body و html / html, body { margin: 0;…
- Usercode
- Assistant
- User
کد کامل یکجا درست کن بفرست
- Assistant
کد کامل یکجا درست کن بفرست
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* حالت عادی */
.iframe-container.normal {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.iframe-container.normal iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
}
/* حالت تمام صفحه */
.iframe-container.fullscreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
.iframe-container.fullscreen iframe {
position: absolute;
top: -76px; /* پنهان کردن ۲ سانتیمتر بالای صفحه (76px) */
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 114px); /* افزایش ارتفاع iframe به اندازه ۲ سانتیمتر بالا و ۱ سانتیمتر پایین */
border: none;
display: block;
}
/* استایلهای مشترک */
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 1s;
}
.error-message {
display: none;
color: red;
margin-top: 20px;
font-size: 16px;
text-align: center;
}
#retryButton {
display: none;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
/* استایل دکمه دانلود */
.download-button {
display: none; /* مخفی کردن اولیه */
width: auto;
height: 25px; /* کاهش ارتفاع */
color: white;
text-align: center;
padding: 2px 8px; /* کاهش فاصله داخلی */
border-radius: 5px;
cursor: pointer;
font-size: 12px; /* کاهش اندازه فونت */
line-height: 20px; /* تنظیم ارتفاع خط */
transition: background-color 0.3s;
position: fixed;
top: 10px;
right: 10px;
z-index: 10001;
text-decoration: none;
background-color: #4CAF50;
}
.download-button:hover {
background-color: #45a049;
}
/* اعلان */
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #ffffff;
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 10003;
display: none;
text-align: center;
width: 300px;
max-height: 80vh;
overflow-y: auto;
}
.notification-buttons {
display: flex;
justify-content: center;
margin-top: 20px;
}
.notification-buttons button {
background-color: #4CAF50;
color: #ffffff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
margin: 0 5px;
}
.notification-buttons button:hover {
background-color: #45a049;
}
.image-item {
margin: 10px 0;
text-align: center;
}
.image-item img {
width: 100px;
height: 100px;
object-fit: cover;
border-radius: 5px;
margin-bottom: 5px;
}
.image-item button {
background-color: #4CAF50;
color: white;
padding: 5px 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
}
.image-item button:hover {
background-color: #45a049;
}
/* Overlay برای مخفی کردن بخشهای اضافی */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 76px; /* ارتفاع ۲ سانتیمتر (76px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
display: none; /* مخفی در حالت عادی */
}
.overlay-bottom {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 38px; /* ارتفاع ۱ سانتیمتر (38px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
display: none; /* مخفی در حالت عادی */
}
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
let interval;
let iframeLoadedFlag = false;
let dataImages = [];
let generatedLinks = [];
// عناصر برای جایگزینی متن
const textsToReplace = [
{
original: "Click and drag on the image.",
replacement: "بعد از اضافه کردن عکس برای تغییر روی چهره لمس کنید. اگه دکمه دانلود عمل نکرد توی گوشی از صفحه عکس بگیرید و بعدا برش بدید برای عملکرد بهتر بطور مثال دست رو که میزارید روی چشم از روی صفحه برندارید و بکشید بالا یا پایین یا راست یا چپ برای نتیجه دلخواه"
},
{
original: "Hugging Face",
replacement: "یک عکس با چهره اضافه کنید"
},
{
original: "Download",
replacement: ""
}
];
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function replaceText(iframeDoc) {
textsToReplace.forEach(item => {
// جستجوی تمام عناصر در iframe
const elements = iframeDoc.querySelectorAll('*');
elements.forEach(el => {
if (el.textContent && el.textContent.trim() === item.original) {
if (item.replacement === "") {
el.style.display = 'none';
} else {
el.textContent = item.replacement;
}
}
});
});
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.classList.remove('normal');
iframeContainer.classList.add('fullscreen');
// نمایش overlayها
document.getElementById('overlayTop').style.display = 'block';
document.getElementById('overlayBottom').style.display = 'block';
// تنظیم iframe به نمایش
document.getElementById('myIframe').style.display = 'block';
// تلاش برای جایگزینی متون
try {
const iframe = document.getElementById('myIframe');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
replaceText(iframeDoc);
} catch (e) {
console.warn('دسترسی به محتوای iframe محدود شده است:', e);
}
// نمایش دکمه دانلود پس از بارگذاری iframe
document.getElementById('downloadButton').style.display = 'block';
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
const iframe = document.getElementById('myIframe');
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
document.getElementById('myIframe').style.display = 'none';
loadIframe();
startProgress();
});
// تنظیم ارتفاع نمایشگر برای متغیر --vh
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
// جلوگیری از باز شدن لینکها در مرورگر (برای لینکهای خارج از iframe)
document.addEventListener('click', function(event) {
if (event.target.tagName === 'A') {
event.preventDefault();
// اینجا میتوانید کد مورد نظر برای مدیریت کلیک روی لینک را قرار دهید
}
});
// عملکرد اسکرول از طریق Overlays
let scrollPosition = 0;
const scrollStep = 100; // میزان اسکرول با هر کلیک
// اسکرول کردن iframe با کلیک بر روی Overlay بالایی
document.getElementById('overlayTop').addEventListener('click', function(e) {
const iframe = document.getElementById('myIframe');
scrollPosition -= scrollStep;
scrollPosition = Math.max(0, scrollPosition);
try {
iframe.contentWindow.scrollTo(0, scrollPosition);
} catch (error) {
console.warn('Unable to scroll iframe content:', error);
}
});
// اسکرول کردن iframe با کلیک بر روی Overlay پایینی
document.getElementById('overlayBottom').addEventListener('click', function(e) {
const iframe = document.getElementById('myIframe');
scrollPosition += scrollStep;
try {
iframe.contentWindow.scrollTo(0, scrollPosition);
} catch (error) {
console.warn('Unable to scroll iframe content:', error);
}
});
// افزودن رویداد کلیک برای دکمه دانلود
document.getElementById('downloadButton').addEventListener('click', handleDownload);
function createNotification(messageText, buttonsArray, contentElements) {
const notificationDiv = document.createElement('div');
notificationDiv.classList.add('notification');
notificationDiv.style.display = 'block';
// پیام
const messageSpan = document.createElement('span');
messageSpan.innerText = messageText;
notificationDiv.appendChild(messageSpan);
// محتوا (مثلاً تصاویر)
if (contentElements && contentElements.length > 0) {
contentElements.forEach(elem => {
notificationDiv.appendChild(elem);
});
}
// دکمهها
if (buttonsArray.length > 0) {
const buttonsDiv = document.createElement('div');
buttonsDiv.classList.add('notification-buttons');
buttonsArray.forEach((btn) => {
const button = document.createElement('button');
button.innerText = btn.text;
button.onclick = () => {
btn.onclick();
if (!btn.preventClose) {
notificationDiv.style.display = 'none';
}
};
buttonsDiv.appendChild(button);
});
notificationDiv.appendChild(buttonsDiv);
}
document.body.appendChild(notificationDiv);
return notificationDiv;
}
function handleDownload(event) {
event.preventDefault();
try {
const iframe = document.getElementById('myIframe');
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) {
alert("نمیتوان به محتوای iframe دسترسی پیدا کرد.");
return;
}
const images = iframeDocument.querySelectorAll('img');
if (images.length === 0) {
alert("هیچ تصویری برای دانلود یافت نشد.");
return;
}
dataImages = [];
images.forEach((img) => {
// نادیده گرفتن تصاویر خاص با استفاده از src
if (!excludeUrls.includes(img.src)) {
dataImages.push(img.src);
}
});
if (dataImages.length === 0) {
alert("هیچ تصویر ساخته شدهای برای دانلود یافت نشد.");
return;
}
// ایجاد عناصر تصویر و دکمه دانلود برای هر تصویر
let contentElements = [];
dataImages.forEach((imageUrl) => {
const imageItem = document.createElement('div');
imageItem.classList.add('image-item');
const imgElement = document.createElement('img');
imgElement.src = imageUrl;
const downloadButton = document.createElement('button');
downloadButton.innerText = 'دانلود و ذخیره';
downloadButton.onclick = () => {
processImage(imageUrl);
};
imageItem.appendChild(imgElement);
imageItem.appendChild(downloadButton);
contentElements.push(imageItem);
});
// نمایش اعلان با تصاویر
const notification = createNotification(
'تصاویر شناساییشده:',
[
{
text: 'بستن',
onclick: () => {
notification.style.display = 'none';
}
}
],
contentElements
);
} catch (error) {
console.error("خطا در شناسایی تصاویر: ", error);
alert("خطایی در شناسایی تصاویر رخ داد.");
}
}
// تابع برای آپلود تصویر به سرور و دریافت لینک
window.processImage = function(imageUrl) {
// نمایش پیام ساخت لینک دانلود
const buildingLinkNotification = createNotification(
'در حال ساخت لینک دانلود، لطفاً صبر کنید...',
[]
);
// بعد از 3 ثانیه اعلان ناپدید میشود
setTimeout(() => {
if (buildingLinkNotification) {
buildingLinkNotification.style.display = 'none';
}
}, 3000);
// تبدیل data URL به blob
function dataURLtoBlob(dataurl) {
let arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {type:mime});
}
const blob = dataURLtoBlob(imageUrl);
// آمادهسازی فرم دیتا
const formData = new FormData();
formData.append('image', blob, 'downloaded_image.png');
// ارسال تصویر به سرور
fetch('https://www.aisada.ir/hamed/upload.php', {
method: 'POST',
body: formData,
mode: 'cors'
})
.then(response => response.json())
.then(data => {
if (buildingLinkNotification) {
buildingLinkNotification.style.display = 'none';
}
if (data.success) {
generatedLinks.push(data.url);
// نمایش پیغام لینک آماده با دکمه دانلود
const downloadMessage = createNotification(
'لینک دانلود تصویر آماده شد.',
[
{
text: 'دانلود',
onclick: () => {
window.open(data.url, '_blank');
}
},
{
text: 'بستن',
onclick: () => {
// بدون عملیات
}
}
]
);
} else {
alert('خطا در آپلود تصویر: ' + data.message);
}
})
.catch(error => {
if (buildingLinkNotification) {
buildingLinkNotification.style.display = 'none';
}
console.error('خطا:', error);
alert('خطا در آپلود تصویر');
});
}
در اینجا کد کامل HTML، CSS و JavaScript شما بهروز شده تا بعد از کلیک بر روی دکمه "دانلود تصویر"، تصاویر شناسایی شده نمایش داده شود و هر تصویر یک دکمه "کپی لینک تصویر" داشته باشد که لینک دانلود تصویر را به کلیپ بورد کپی کند.
تغییرات اصلی کد در قسمت ایجاد اعلان برای نمایش تصاویر شناسایی شده و دکمه "کپی لینک تصویر" اعمال شده است.
<!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 */
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden; /* مخفی کردن اسکرولهای اضافی */
background-color: #f0f0f0; /* رنگ پسزمینه */
font-family: Arial, sans-serif;
}
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* حالت عادی */
.iframe-container.normal {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.iframe-container.normal iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
}
/* حالت تمام صفحه */
.iframe-container.fullscreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
.loading, .error-message, .download-button {
display: none;
}
/* استایلهای دیگر و دکمهها */
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
}
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #ffffff;
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 10003;
display: none;
text-align: center;
width: 300px;
max-height: 80vh;
overflow-y: auto;
}
</style>
</head>
<body>
<p><a href="#" class="download-button" id="downloadButton">دانلود تصویر 📥</a></p>
<div class="iframe-container normal">
<div class="loading" id="loadingContainer">
<div class="loading-message">لطفاً صبر کنید...</div>
<div class="progress"><div class="progress-bar" id="progressBar"></div></div>
<div class="error-message" id="errorMessage">بارگیری زیاد طول کشید.<br />در صورت عدم بارگذاری، فیلترشکن خود را روشن کنید.</div>
<button id="retryButton">بارگذاری مجدد</button>
</div>
<iframe id="myIframe" sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="clipboard-read; clipboard-write"></iframe>
</div>
<script>
const siteURL = 'https://jbilcke-hf-facepoke.hf.space/';
const excludeUrls = [
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png'
];
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
let interval;
let iframeLoadedFlag = false;
let dataImages = [];
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.classList.remove('normal');
iframeContainer.classList.add('fullscreen');
document.getElementById('myIframe').style.display = 'block';
// تلاش برای شناسایی تصاویر
try {
const iframe = document.getElementById('myIframe');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const images = iframeDoc.querySelectorAll('img');
dataImages = [];
images.forEach(img => {
if (!excludeUrls.includes(img.src)) {
dataImages.push(img.src);
}
});
} catch (e) {
console.warn('دسترسی به محتوای iframe محدود شده است:', e);
}
// نمایش دکمه دانلود پس از بارگذاری iframe
document.getElementById('downloadButton').style.display = 'block';
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
const iframe = document.getElementById('myIframe');
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
document.getElementById('myIframe').style.display = 'none';
loadIframe();
startProgress();
});
function createNotification(messageText, contentElements) {
const notificationDiv = document.createElement('div');
notificationDiv.classList.add('notification');
notificationDiv.style.display = 'block';
// پیام
const messageSpan = document.createElement('span');
messageSpan.innerText = messageText;
notificationDiv.appendChild(messageSpan);
// محتوا (تصاویر)
if (contentElements && contentElements.length > 0) {
contentElements.forEach(elem => {
notificationDiv.appendChild(elem);
});
}
document.body.appendChild(notificationDiv);
return notificationDiv;
}
function handleDownload(event) {
event.preventDefault();
if (dataImages.length === 0) {
alert("هیچ تصویری برای دانلود یافت نشد.");
return;
}
// ایجاد عناصر تصویر و دکمه کپی برای هر تصویر
let contentElements = [];
dataImages.forEach((imageUrl) => {
const imageItem = document.createElement('div');
imageItem.classList.add('image-item');
const imgElement = document.createElement('img');
imgElement.src = imageUrl;
const copyLinkButton = document.createElement('button');
copyLinkButton.innerText = 'کپی لینک تصویر';
copyLinkButton.onclick = () => {
navigator.clipboard.writeText(imageUrl).then(() => {
alert('لینک تصویر کپی شد: ' + imageUrl);
}).catch(err => {
console.error('خطا در کپی لینک: ', err);
});
};
imageItem.appendChild(imgElement);
imageItem.appendChild(copyLinkButton);
contentElements.push(imageItem);
});
// نمایش اعلان با تصاویر
createNotification('تصاویر شناساییشده:', contentElements);
}
// تنظیم ارتفاع نمایشگر برای متغیر --vh
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
// افزودن رویداد کلیک برای دکمه دانلود
document.getElementById('downloadButton').addEventListener('click', handleDownload);
</script>
</body>
</html>
handleDownload و ایجاد دکمه "کپی لینک تصویر" انجام شده است.در اینجا کد کامل HTML، CSS و JavaScript به صورت یکجا و کامل برای شما آماده شده است. این کد شامل بارگذاری iframe، شناسایی تصاویر و دکمه "کپی لینک تصویر" است:
<!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 */
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden; /* مخفی کردن اسکرولهای اضافی */
background-color: #f0f0f0; /* رنگ پسزمینه */
font-family: Arial, sans-serif;
}
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* حالت عادی */
.iframe-container.normal {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.iframe-container.normal iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
}
/* حالت تمام صفحه */
.iframe-container.fullscreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 1s;
}
.error-message {
display: none;
color: red;
margin-top: 20px;
font-size: 16px;
text-align: center;
}
#retryButton {
display: none;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
/* استایل دکمه دانلود */
.download-button {
display: none;
width: auto;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
position: fixed;
top: 10px;
right: 10px;
z-index: 10001;
}
.download-button:hover {
background-color: #45a049;
}
/* اعلان */
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #ffffff;
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 10003;
display: none;
text-align: center;
width: 300px;
max-height: 80vh;
overflow-y: auto;
}
.image-item {
margin: 10px 0;
text-align: center;
}
.image-item img {
width: 100px;
height: 100px;
object-fit: cover;
border-radius: 5px;
margin-bottom: 5px;
}
.image-item button {
background-color: #4CAF50;
color: white;
padding: 5px 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
}
.image-item button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<p><a href="#" class="download-button" id="downloadButton">دانلود تصویر 📥</a></p>
<div class="iframe-container normal">
<div class="loading" id="loadingContainer">
<div class="loading-message">لطفاً صبر کنید...</div>
<div class="progress">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="error-message" id="errorMessage">
بارگیری زیاد طول کشید.<br />در صورت عدم بارگذاری، فیلترشکن خود را روشن کنید.
</div>
<button id="retryButton">بارگذاری مجدد</button>
</div>
<iframe id="myIframe" sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="clipboard-read; clipboard-write"></iframe>
</div>
<script>
const siteURL = 'https://jbilcke-hf-facepoke.hf.space/';
const excludeUrls = [
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png'
];
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
let interval;
let iframeLoadedFlag = false;
let dataImages = [];
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.classList.remove('normal');
iframeContainer.classList.add('fullscreen');
// تنظیم iframe به نمایش
document.getElementById('myIframe').style.display = 'block';
// تلاش برای شناسایی تصاویر
try {
const iframe = document.getElementById('myIframe');
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const images = iframeDoc.querySelectorAll('img');
dataImages = [];
images.forEach(img => {
if (!excludeUrls.includes(img.src)) {
dataImages.push(img.src);
}
});
} catch (e) {
console.warn('دسترسی به محتوای iframe محدود شده است:', e);
}
// نمایش دکمه دانلود پس از بارگذاری iframe
document.getElementById('downloadButton').style.display = 'block';
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
const iframe = document.getElementById('myIframe');
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
document.getElementById('myIframe').style.display = 'none';
loadIframe();
startProgress();
});
function createNotification(messageText, contentElements) {
const notificationDiv = document.createElement('div');
notificationDiv.classList.add('notification');
notificationDiv.style.display = 'block';
// پیام
const messageSpan = document.createElement('span');
messageSpan.innerText = messageText;
notificationDiv.appendChild(messageSpan);
// محتوا (تصاویر)
if (contentElements && contentElements.length > 0) {
contentElements.forEach(elem => {
notificationDiv.appendChild(elem);
});
}
document.body.appendChild(notificationDiv);
return notificationDiv;
}
function handleDownload(event) {
event.preventDefault();
if (dataImages.length === 0) {
alert("هیچ تصویری برای دانلود یافت نشد.");
return;
}
// ایجاد عناصر تصویر و دکمه کپی برای هر تصویر
let contentElements = [];
dataImages.forEach((imageUrl) => {
const imageItem = document.createElement('div');
imageItem.classList.add('image-item');
const imgElement = document.createElement('img');
imgElement.src = imageUrl;
const copyLinkButton = document.createElement('button');
copyLinkButton.innerText = 'کپی لینک تصویر';
copyLinkButton.onclick = () => {
navigator.clipboard.writeText(imageUrl).then(() => {
alert('لینک تصویر کپی شد: ' + imageUrl);
}).catch(err => {
console.error('خطا در کپی لینک: ', err);
});
};
imageItem.appendChild(imgElement);
imageItem.appendChild(copyLinkButton);
contentElements.push(imageItem);
});
// نمایش اعلان با تصاویر
createNotification('تصاویر شناساییشده:', contentElements);
}
// تنظیم ارتفاع نمایشگر برای متغیر --vh
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
// افزودن رویداد کلیک برای دکمه دانلود
document.getElementById('downloadButton').addEventListener('click', handleDownload);
</script>
</body>
</html>
fetch وبسایت مشخص شده بارگذاری میشود.با استفاده از این کد، کاربر میتواند به راحتی تصاویر شناسایی شده را مشاهده کند و با کلیک بر روی دکمه مربوطه، لینک آن تصویر را کپی کند.