USER
<p> </p>
<style>
:root {
--color-primary: #4CAF50;
--color-white: #ffffff;
--color-gray: #f0f0f0;
--color-black: #000000;
}
/* ریست اولیه */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
background-color: var(--color-gray);
font-family: Arial, sans-serif;
text-align: center;
direction: rtl;
overflow-y: auto; /* برای اسکرول درصورت نیاز (مثلاً کیبورد موبایل) */
overscroll-behavior: none;
}
/* کانتینر آیفریم در حالت عادی */
.iframe-container.normal {
position: relative;
width: 100%;
/* به جای 100vh از 100dvh استفاده میکنیم. */
height: 100dvh;
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: 100dvh;
overflow: hidden;
z-index: 1;
}
.iframe-container.fullscreen iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
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: 9999;
}
.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: var(--color-primary);
transition: width 0.2s ease;
}
.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: var(--color-primary);
color: var(--color-white);
border: none;
border-radius: 5px;
}
#retryButton:hover {
filter: brightness(0.9);
}
/* دکمه نمایش ویدیو (بالا-راست) */
#downloadVideoButton {
position: fixed;
top: 10px;
right: 10px;
z-index: 10001;
background-color: var(--color-primary);
color: var(--color-white);
border: none;
padding: 8px 14px;
cursor: pointer;
font-size: 14px;
border-radius: 5px;
display: none; /* ابتدا مخفی */
}
#downloadVideoButton:hover {
filter: brightness(0.9);
}
/* دکمه مترجم (بالا-چپ) */
#translatorButton {
position: fixed;
top: 10px;
left: 10px;
z-index: 10001;
background-color: var(--color-primary);
color: var(--color-white);
border: none;
padding: 8px 14px;
cursor: pointer;
font-size: 14px;
border-radius: 5px;
display: none; /* ابتدا مخفی */
}
#translatorButton:hover {
filter: brightness(0.9);
}
/* اعلان ساده (تابع createNotification) */
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: var(--color-white);
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: 90%;
max-width: 400px;
max-height: 80vh;
overflow-y: auto;
}
.notification-buttons {
display: flex;
justify-content: center;
margin-top: 20px;
flex-wrap: wrap;
gap: 10px;
}
.notification-buttons button {
background-color: var(--color-primary);
color: var(--color-white);
border: none;
padding: 6px 12px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.notification-buttons button:hover {
filter: brightness(0.9);
}
/* واترمارک نمایشی روی خود پلیر (فقط نمایشی) */
.video-watermark-container {
position: relative;
display: inline-block;
width: 100%;
}
.video-watermark-container video {
width: 100%;
height: auto;
background: #000;
controlsList: nofullscreen;
-webkit-playsinline: true;
playsinline: true;
}
.video-watermark-container video::-webkit-media-controls-fullscreen-button {
display: none;
}
.video-watermark-overlay {
position: absolute;
bottom: 8px;
right: 8px;
background: rgba(0,0,0,0.9);
color: var(--color-white);
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
pointer-events: none;
}
/* ======= استایلهای بخش مترجم (فارسی به انگلیسی) ======= */
.translator-container {
max-width: 300px;
width: 100%;
margin: 0 auto;
text-align: center;
}
.translator-container h2 {
margin-bottom: 20px;
color: #000;
font-size: 18px;
}
.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-top: 4px solid #3498db;
border-radius: 50%;
width: 20px;
height: 20px;
animation: spin 1s linear infinite;
margin: 20px auto;
display: none;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.result {
margin-top: 20px;
padding: 8px;
border-radius: 8px;
min-height: 40px;
font-size: 14px;
color: #000;
white-space: pre-wrap;
word-wrap: break-word;
border: 1px solid #000;
}
.copy-button {
margin-top: 10px;
background-color: #3498db;
border: none;
color: #fff;
padding: 6px 12px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
display: none; /* پیشفرض مخفی */
}
.copy-button:hover {
filter: brightness(0.9);
}
.success-message {
display: none;
margin-top: 10px;
color: #2ecc71;
font-size: 14px;
font-weight: bold;
}
textarea {
width: 100%;
height: 100px;
padding: 8px;
margin-top: 20px;
border-radius: 8px;
border: 1px solid #000;
resize: vertical;
font-size: 14px;
font-family: Arial, sans-serif;
transition: border-color 0.3s;
}
textarea:focus {
border-color: #76c7c0;
outline: none;
}
</style>
<!-- کانتینر اصلی و لودینگ + iframe -->
<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>
<!-- دکمه نمایش ویدیو -->
<p><button id="downloadVideoButton">نمایش ویدیو</button></p>
<!-- دکمه مترجم -->
<p><button id="translatorButton">مترجم 🈯</button></p>
<p>
<script>
// -------------------------------------------------------
// تنظیمات اولیه
// -------------------------------------------------------
const siteURL = 'https://toolful.ai/fa/t/image-to-video-ai';
let videoUrls = [];
let iframeLoadedFlag = false;
let interval, observer;
// المانها
const loadingContainer = document.getElementById('loadingContainer');
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const myIframe = document.getElementById('myIframe');
const downloadVideoButton = document.getElementById('downloadVideoButton');
const translatorButton = document.getElementById('translatorButton');
// کلماتی که نباید مخفی شوند
const exceptions = [
"تصویر به ویدئو",
"متن به ویدئو",
"✨شروع ساخت",
"توضیحات ویدیو⬇️ انگلیسی وارد کنید و یا از مترجم بالا استفاده کنید",
"تصویر خود را بکشید و رها کنید یا برای آپلود کلیک کنید",
"نسبت ابعاد",
"ایجاد",
"فردا بازگردید",
"تصور کنید، ما میسازیمش!",
"این پیشرفت ایجاد",
"ویدیو ساخته شد روی نمایش ویدیو دربالا کلیک کنید"
];
// جایگزینی متنها
const replacementsMap = {
"دستور حرکت": "توضیحات ویدیو⬇️ انگلیسی وارد کنید و یا از مترجم بالا استفاده کنید",
"سهمیه رایگان امروز شما تمام شده است.": "تعداد ساخت ویدیو با این سرور تموم شده امروز از سرور دیگه استفاده کنید ویا"
};
// -------------------------------------------------------
// تابع ساخت اعلان ساده
// -------------------------------------------------------
function createNotification(messageHTML, buttonsArray) {
// حذف اعلانهای قبلی
const oldNotifs = document.querySelectorAll('.notification');
oldNotifs.forEach(notif => notif.remove());
const notificationDiv = document.createElement('div');
notificationDiv.className = 'notification';
notificationDiv.style.display = 'block'; // نمایش اعلان
// محتوای اصلی
const messageWrapper = document.createElement('div');
messageWrapper.innerHTML = messageHTML;
notificationDiv.appendChild(messageWrapper);
// دکمهها
if (buttonsArray && buttonsArray.length > 0) {
const buttonsDiv = document.createElement('div');
buttonsDiv.className = 'notification-buttons';
buttonsArray.forEach(btn => {
const button = document.createElement('button');
button.innerText = btn.text;
button.onclick = () => {
if (btn.onclick) btn.onclick();
if (!btn.preventClose) {
notificationDiv.remove();
}
};
buttonsDiv.appendChild(button);
});
notificationDiv.appendChild(buttonsDiv);
}
document.body.appendChild(notificationDiv);
return notificationDiv;
}
// -------------------------------------------------------
// بارگذاری آیفریم + نمایش پیشرفت نوار
// -------------------------------------------------------
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
let elapsedSeconds = 0;
const totalSeconds = 30; // مدتزمان (ثانیه)
interval = setInterval(() => {
elapsedSeconds++;
const percent = (elapsedSeconds / totalSeconds) * 100;
progressBar.style.width = Math.min(percent, 100) + '%';
// اگر بعد از 30 ثانیه هنوز لود نشده باشد...
if (elapsedSeconds >= totalSeconds) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
const container = document.querySelector('.iframe-container');
container.classList.remove('normal');
container.classList.add('fullscreen');
myIframe.style.display = 'block';
modifyIframeContent();
setupMutationObserver();
checkAndHideElements();
// نمایش دکمهها
downloadVideoButton.style.display = 'inline-block';
translatorButton.style.display = 'inline-block';
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
// تلاش برای دریافت HEAD سایت (چککردن در دسترس بودن)، سپس لود
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
myIframe.src = siteURL;
myIframe.onload = iframeLoaded;
myIframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', () => {
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
myIframe.style.display = 'none';
loadIframe();
startProgress();
});
// آغاز کار
loadIframe();
startProgress();
// -------------------------------------------------------
// مخفی کردن لوگوها و تصاویر ناخواسته
// -------------------------------------------------------
function hideUnwantedAssets(doc) {
try {
// پنهانسازی لینک/لوگوهایی که نمیخواهیم:
const chat100Elems = doc.querySelectorAll('a[href*="chat100.ai"], img[src*="chat100.ai"]');
chat100Elems.forEach(el => {
el.style.display = 'none';
});
const toolfulElems = doc.querySelectorAll(`
img[src*="toolful.ai/logo"],
[href*="toolful.ai/logo"],
[style*="toolful.ai/logo"]
`);
toolfulElems.forEach(el => {
el.style.display = 'none';
});
const videoMakerLinks = doc.querySelectorAll('a[href*="videomaker.me"]');
videoMakerLinks.forEach(link => {
link.style.display = 'none';
});
const lumaLinks = doc.querySelectorAll('a[href*="luma.ai"]');
lumaLinks.forEach(link => {
link.style.display = 'none';
});
// پنهانسازی تصاویری با src مشخص:
const hideImagesSrcs = [
"https://file.aiquickdraw.com/toolfulai/7feca6f3-7aba-4a74-916a-05a930524b4f-screenshot-https://videomaker.me.png",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_408a2c2e8b5412806489327b625b5234.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_84f32a5ec86ba1f23de29fc5cc8a77eb.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_452456d9ae1521e81daa85b4fee96651.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_364573610aa369d9888a397dbe9f15b6.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_e83566f05fe2360b9fc6df88697a824a.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_cdc502844dab8b0cc78fdc96a9d6574b.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_110e5059c9467ea2e8139f8e8777f301.webp",
"https://file.aiquickdraw.com/imgcompressed/img/compressed_15a0f2a3c957a44237b4464e97166e85.webp"
];
hideImagesSrcs.forEach(srcVal => {
const imgs = doc.querySelectorAll(`img[src="${srcVal}"]`);
imgs.forEach(img => {
img.style.display = 'none';
});
});
} catch (e) {
console.error("خطا در hideUnwantedAssets:", e);
}
}
// -------------------------------------------------------
// پنهان/جایگزینکردن متنها
// -------------------------------------------------------
const persianRegex = /[\u0600-\u06FF]+/;
const englishRegex = /[A-Za-z]+/;
function isException(txt) {
return exceptions.some(ex => txt.includes(ex));
}
function hideTextNodes(doc) {
const walker = doc.createTreeWalker(
doc.body,
NodeFilter.SHOW_TEXT,
null,
false
);
let node;
while ((node = walker.nextNode())) {
let content = node.textContent;
if (!content || !content.trim()) continue;
// پنهانسازی متنهای خاص (مثلاً Luma AI یا VideoMaker.me)
const lower = content.toLowerCase();
if (
lower.includes("videomaker.me") ||
lower.includes("luma ai")
) {
if (node.parentElement) {
node.parentElement.style.display = 'none';
}
continue;
}
const hasPersian = persianRegex.test(content);
const hasEnglish = englishRegex.test(content);
// اگر متن حروف فارسی یا انگلیسی دارد...
if (hasPersian || hasEnglish) {
// 1) ابتدا جایگزینیهای تعریفشده را اعمال میکنیم
let replaced = false;
for (const key in replacementsMap) {
if (content.includes(key)) {
node.textContent = content.replace(key, replacementsMap[key]);
replaced = true;
}
}
// 2) اگر جایگزین نبود و متن جزو استثناها هم نبود
if (!replaced && !isException(content)) {
// --- تغییر کلیدی برای عدم مخفیشدن دکمهها ---
const buttonParent = node.parentElement.closest('button');
if (!buttonParent) {
node.parentElement.style.display = 'none';
}
}
}
}
}
// -------------------------------------------------------
// جایگزینی ویدیوها با متن دلخواه
// -------------------------------------------------------
function replaceVideos(doc) {
const vids = doc.querySelectorAll('video');
vids.forEach(v => {
let srcUrl = v.src || '';
if (!srcUrl) {
const srcTag = v.querySelector('source');
if (srcTag && srcTag.src) {
srcUrl = srcTag.src;
}
}
if (srcUrl) {
videoUrls.push(srcUrl);
}
const msg = doc.createElement('div');
msg.textContent = 'ویدیو ساخته شد روی نمایش ویدیو دربالا کلیک کنید';
msg.style.color = 'red';
msg.style.fontWeight = 'bold';
msg.style.padding = '10px';
v.parentElement.replaceChild(msg, v);
});
const ifr = doc.querySelectorAll('iframe[src*="youtube.com"], iframe[src*="youtu.be"], iframe[src*="vimeo.com"]');
ifr.forEach(f => {
videoUrls.push(f.src);
const msg = document.createElement('div');
msg.textContent = 'ویدیو ساخته شد روی نمایش ویدیو دربالا کلیک کنید';
msg.style.color = 'red';
msg.style.fontWeight = 'bold';
msg.style.padding = '10px';
f.parentElement.replaceChild(msg, f);
});
}
// -------------------------------------------------------
// اصلاح محتوای iframe
// -------------------------------------------------------
function modifyIframeContent() {
try {
const doc = myIframe.contentDocument || myIframe.contentWindow.document;
if (!doc) return;
if (observer) observer.disconnect();
hideUnwantedAssets(doc);
hideTextNodes(doc);
replaceVideos(doc);
if (observer) {
observer.observe(doc.body, {
childList: true,
subtree: true
});
}
} catch(e) {
console.error("خطا در اصلاح محتوای iframe:", e);
}
}
function setupMutationObserver() {
try {
const doc = myIframe.contentDocument || myIframe.contentWindow.document;
if (!doc) return;
observer = new MutationObserver(() => {
hideUnwantedAssets(doc);
hideTextNodes(doc);
replaceVideos(doc);
});
observer.observe(doc.body, { childList: true, subtree: true });
} catch(e) {
console.error("خطا در MutationObserver:", e);
}
}
function checkAndHideElements() {
try {
const doc = myIframe.contentDocument || myIframe.contentWindow.document;
if (!doc) return;
hideUnwantedAssets(doc);
hideTextNodes(doc);
replaceVideos(doc);
setTimeout(checkAndHideElements, 500);
} catch(e) {
console.error("خطا در checkAndHideElements:", e);
}
}
// -------------------------------------------------------
// دکمه نمایش ویدیو
// -------------------------------------------------------
downloadVideoButton.addEventListener('click', () => {
if (videoUrls.length === 0) {
alert("هیچ ویدیویی ساخته نشده است.");
return;
}
const firstUrl = videoUrls[0];
const popupHtml = `
<div class="video-watermark-container" style="margin-bottom:10px;">
<video id="popupVideo" controls controlsList="nofullscreen" disablepictureinpicture style="width:100%; background:#000;"></video>
<div class="video-watermark-overlay">aisada.ir</div>
</div>
`;
const notif = createNotification(
popupHtml,
[
{
text: 'دانلود و ذخیره',
onclick: () => {
const popupVideo = document.getElementById('popupVideo');
if (popupVideo) {
popupVideo.pause();
processVideo(popupVideo.src);
}
}
},
{
text: 'بستن',
onclick: () => {
const popupVideo = document.getElementById('popupVideo');
if (popupVideo) popupVideo.pause();
}
}
]
);
const popupVideo = notif.querySelector('#popupVideo');
if (popupVideo) {
popupVideo.src = firstUrl;
}
});
// -------------------------------------------------------
// پردازش ویدیو (ضبط + واترمارک + آپلود)
// -------------------------------------------------------
const VIDEO_BITRATE = 50000000; // ~50Mbps
const FRAME_INTERVAL = 50; // ~20 فریم بر ثانیه
function processVideo(videoUrl) {
// اعلان ساخت لینک
const buildingPopup = createNotification(
'<p style="color:#4CAF50;">در حال ساخت لینک دانلود با کیفیت بالا، لطفاً صبر کنید...</p>',
[]
);
fetch(videoUrl)
.then(r => r.blob())
.then(blob => {
const tmpUrl = URL.createObjectURL(blob);
const vid = document.createElement('video');
vid.src = tmpUrl;
vid.crossOrigin = 'anonymous';
vid.muted = true;
let recordingStarted = false;
let mediaRecorder;
let chunks = [];
vid.onloadedmetadata = function() {
vid.currentTime = 0.1;
vid.play();
};
vid.addEventListener('timeupdate', () => {
if (!recordingStarted && vid.currentTime >= 0.1) {
recordingStarted = true;
const w = vid.videoWidth;
const h = vid.videoHeight;
const canvas = document.createElement('canvas');
canvas.width = w;
canvas.height = h;
const ctx = canvas.getContext('2d');
const stream = canvas.captureStream();
mediaRecorder = new MediaRecorder(stream, {
mimeType: 'video/webm; codecs=vp9',
videoBitsPerSecond: VIDEO_BITRATE
});
mediaRecorder.ondataavailable = e => {
if (e.data.size > 0) {
chunks.push(e.data);
}
};
mediaRecorder.onstop = () => {
const newBlob = new Blob(chunks, { type: 'video/webm' });
chunks = [];
// آپلود روی سرور
const formData = new FormData();
formData.append('video', newBlob, 'downloaded_video.webm');
fetch('https://www.aisada.ir/hamed/upload.php', {
method: 'POST',
body: formData,
mode: 'cors'
})
.then(x => x.json())
.then(data => {
buildingPopup.remove();
if (data.success) {
const c = confirm("ویدیو آماده شد. برای دانلود و ذخیره روی تایید کلیک کنید.");
if (c) {
window.open(data.url, '_blank');
}
} else {
alert("خطا در آپلود ویدیو: " + data.message);
}
})
.catch(err => {
buildingPopup.remove();
console.error("خطا در آپلود ویدیو:", err);
alert("خطا در آپلود ویدیو");
});
};
// مدت زمان ضبط
const recordDuration = (vid.duration - 0.1) * 1000 + 1000;
mediaRecorder.start();
setTimeout(() => {
if (mediaRecorder.state === 'recording') {
mediaRecorder.stop();
}
}, recordDuration);
// رسم واترمارک (نسخه دانلودی)
function drawFrame() {
if (mediaRecorder && mediaRecorder.state === 'recording') {
ctx.drawImage(vid, 0, 0, w, h);
drawWatermark(ctx, {
text: 'aisada.ir',
fontSize: 30,
marginX: 50,
marginY: 30,
width: w,
height: h
});
}
setTimeout(() => {
requestAnimationFrame(drawFrame);
}, FRAME_INTERVAL);
}
function drawWatermark(ctx, { text, fontSize, marginX, marginY, width, height }) {
ctx.font = `bold ${fontSize}px Arial`;
ctx.textAlign = 'right';
const measure = ctx.measureText(text);
const tWidth = measure.width;
const tHeight = fontSize;
// پسزمینه سفید در پایین سمت راست
ctx.fillStyle = 'rgba(255,255,255,1)';
ctx.fillRect(
width - marginX - tWidth - 5,
height - marginY - tHeight,
tWidth + 10,
tHeight + 5
);
// متن سیاه روی پسزمینه سفید
ctx.fillStyle = 'black';
ctx.fillText(text, width - marginX, height - marginY);
}
drawFrame();
}
});
})
.catch(err => {
buildingPopup.remove();
console.error("خطا در دریافت ویدیو:", err);
alert("خطا در پردازش ویدیو");
});
}
// -------------------------------------------------------
// دکمه مترجم
// -------------------------------------------------------
translatorButton.addEventListener('click', () => {
showTranslatorNotification();
});
function showTranslatorNotification() {
const translatorHtml = `
<div class="translator-container">
<h2>مترجم فارسی به انگلیسی</h2>
<div class="spinner" id="spinner"></div>
<div class="result" id="resultText">ترجمه</div>
<button class="copy-button" id="copyButton">کپی متن انگلیسی</button>
<div class="success-message" id="successMessage">متن با موفقیت کپی شد!</div>
<textarea id="inputText" placeholder="متن خود را به فارسی وارد کنید..."></textarea>
</div>
`;
const translatorNotif = createNotification(translatorHtml, [
{
text: 'بستن',
onclick: () => {
// صرفاً اعلان بسته شود
}
}
]);
const inputText = translatorNotif.querySelector('#inputText');
const resultText = translatorNotif.querySelector('#resultText');
const spinnerElement = translatorNotif.querySelector('#spinner');
const copyBtn = translatorNotif.querySelector('#copyButton');
const successMsg = translatorNotif.querySelector('#successMessage');
let timeout;
// لیست محدود کلمات غیر اخلاقی
const forbiddenWords = ['porn','sex','nude','fuck','bitch'];
function detectForbiddenWords(text) {
const pattern = new RegExp(forbiddenWords.join('|'), 'gi');
return pattern.test(text);
}
function handleForbiddenWords() {
alert('محتوای غیرمجاز شناسایی شد!');
inputText.value = '';
resultText.textContent = 'ترجمه';
spinnerElement.style.display = 'none';
copyBtn.style.display = 'none';
}
inputText.addEventListener('input', function() {
const text = inputText.value.trim();
if (timeout) {
clearTimeout(timeout);
}
if (!text) {
resultText.textContent = 'ترجمه';
copyBtn.style.display = 'none';
spinnerElement.style.display = 'none';
return;
}
if (detectForbiddenWords(text)) {
handleForbiddenWords();
return;
}
timeout = setTimeout(() => {
translateText(text);
}, 600);
});
// رویداد paste
inputText.addEventListener('paste', function(event) {
event.preventDefault();
const clipboardData = event.clipboardData || window.clipboardData;
const pastedText = clipboardData.getData('text');
if (detectForbiddenWords(pastedText)) {
handleForbiddenWords();
} else {
const start = inputText.selectionStart;
const end = inputText.selectionEnd;
const before = inputText.value.substring(0, start);
const after = inputText.value.substring(end);
inputText.value = before + pastedText + after;
inputText.selectionStart = inputText.selectionEnd = start + pastedText.length;
if (detectForbiddenWords(inputText.value.trim())) {
handleForbiddenWords();
} else {
timeout = setTimeout(() => {
translateText(inputText.value.trim());
}, 600);
}
}
});
// رویداد drop
inputText.addEventListener('drop', function(event) {
event.preventDefault();
const data = event.dataTransfer.getData('text');
if (detectForbiddenWords(data)) {
handleForbiddenWords();
} else {
const start = inputText.selectionStart;
const end = inputText.selectionEnd;
const before = inputText.value.substring(0, start);
const after = inputText.value.substring(end);
inputText.value = before + data + after;
inputText.selectionStart = inputText.selectionEnd = start + data.length;
if (detectForbiddenWords(inputText.value.trim())) {
handleForbiddenWords();
} else {
timeout = setTimeout(() => {
translateText(inputText.value.trim());
}, 600);
}
}
});
async function translateText(text) {
const endpoint = 'https://api.mymemory.translated.net/get';
const params = new URLSearchParams({
q: text,
langpair: 'fa|en'
});
resultText.textContent = '';
copyBtn.style.display = 'none';
spinnerElement.style.display = 'block';
try {
const response = await fetch(`${endpoint}?${params.toString()}`);
if (!response.ok) {
throw new Error('خطا در سرور ترجمه');
}
const data = await response.json();
spinnerElement.style.display = 'none';
if (data.responseData && data.responseData.translatedText) {
resultText.textContent = data.responseData.translatedText;
copyBtn.style.display = 'inline-block';
} else {
resultText.textContent = 'ترجمه یافت نشد.';
}
} catch (error) {
spinnerElement.style.display = 'none';
resultText.textContent = 'خطا در ترجمه.';
}
}
// کلیک بر دکمه کپی
copyBtn.addEventListener('click', function() {
const translatedText = resultText.textContent.trim();
if (!translatedText || translatedText === 'ترجمه') {
alert('هیچ متنی برای کپی کردن وجود ندارد.');
return;
}
navigator.clipboard.writeText(translatedText)
.then(() => {
successMsg.style.display = 'block';
setTimeout(() => {
successMsg.style.display = 'none';
}, 2000);
})
.catch(err => {
alert('کپی متن موفقیتآمیز نبود.');
});
});
}
</script>
</p> این مترجم از کدوم API استفاده شده؟