Update index.html
Browse files- index.html +211 -177
index.html
CHANGED
|
@@ -53,7 +53,7 @@
|
|
| 53 |
.free-badge { background: linear-gradient(45deg, #6c757d, #495057); color: white; box-shadow: 0 4px 10px rgba(108, 117, 125, 0.3); }
|
| 54 |
.paid-badge { background: linear-gradient(45deg, var(--premium-color), #ffca2c); color: #333; box-shadow: 0 4px 10px var(--premium-glow); }
|
| 55 |
|
| 56 |
-
/* انیمیشن
|
| 57 |
@keyframes slideUpFadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
|
| 58 |
.usage-info-container { margin-top: 1rem; }
|
| 59 |
.usage-info-line { opacity: 0; animation: slideUpFadeIn 0.7s ease-out forwards; }
|
|
@@ -82,12 +82,16 @@
|
|
| 82 |
.upload-area.file-selected.is-playing .icon-play { opacity: 0; transform: translate(-50%, -50%) scale(0); }
|
| 83 |
.upload-area.file-selected.is-playing .icon-pause { opacity: 1; transform: translate(-50%, -50%) scale(1); }
|
| 84 |
|
| 85 |
-
/* ---
|
| 86 |
.solver-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; } .solver-card { position: relative; cursor: pointer; } .solver-card input { display: none; } .solver-content { display: flex; align-items: center; padding: 12px 15px; border: 2px solid var(--border-color); border-radius: 16px; background: white; transition: all 0.3s ease; } .solver-icon { width: 40px; height: 40px; background: #f1f5f9; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 1.1rem; margin-left: 12px; transition: 0.3s; } .solver-text h6 { margin: 0; font-weight: 700; font-size: 0.9rem; color: var(--text-dark); } .solver-text p { margin: 0; font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; } .check-circle { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #cbd5e1; margin-right: auto; transition: 0.3s; display: flex; align-items: center; justify-content: center; } .check-circle::after { content: '\f00c'; font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 10px; color: white; opacity: 0; transform: scale(0); transition: 0.2s; } .solver-card input:checked + .solver-content { border-color: var(--primary-color); background: #f5f3ff; } .solver-card input:checked + .solver-content .solver-icon { background: var(--primary-color); color: white; } .solver-card input:checked + .solver-content .check-circle { background: var(--primary-color); border-color: var(--primary-color); } .solver-card input:checked + .solver-content .check-circle::after { opacity: 1; transform: scale(1); } .denoise-card { cursor: pointer; display: block; margin-bottom: 20px; } .denoise-card input { display: none; } .denoise-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; border: 2px solid var(--border-color); border-radius: 50px; background: white; transition: 0.3s; } .denoise-left { display: flex; align-items: center; gap: 10px; } .denoise-ico { width: 35px; height: 35px; border-radius: 50%; background: #f1f5f9; color: #64748b; display: flex; align-items: center; justify-content: center; transition: 0.4s; } .denoise-toggle { width: 40px; height: 22px; background: #cbd5e1; border-radius: 20px; position: relative; transition: 0.3s; } .denoise-toggle::after { content: ''; position: absolute; width: 16px; height: 16px; background: white; border-radius: 50%; top: 3px; left: 3px; transform: translateX(0); transition: 0.3s; } .denoise-card input:checked + .denoise-inner { border-color: #10b981; background: #ecfdfdf5; } .denoise-card input:checked + .denoise-inner .denoise-ico { background: #10b981; color: white; transform: rotate(360deg); } .denoise-card input:checked + .denoise-inner .denoise-toggle { background: #10b981; } .denoise-card input:checked + .denoise-inner .denoise-toggle::after { transform: translateX(18px); } .slider-group { background: #f8fafc; border-radius: 16px; padding: 15px; margin-bottom: 15px; } .slider-label { display: flex; justify-content: space-between; font-weight: 700; font-size: 0.85rem; color: #334155; margin-bottom: 8px; } .slider-desc { font-size: 0.75rem; color: #64748b; margin-top: 8px; line-height: 1.5; background: rgba(255,255,255,0.5); padding: 6px; border-radius: 6px; } input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 20px; width: 20px; border-radius: 50%; background: var(--primary-color); cursor: pointer; margin-top: -8px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); } input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #cbd5e1; border-radius: 10px; }
|
|
|
|
|
|
|
| 87 |
.btn-magic { background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%); color: white; border: none; padding: 15px; border-radius: 16px; font-weight: 800; width: 100%; font-size: 1.1rem; box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.4); transition: 0.3s; } .btn-magic:hover { transform: translateY(-2px); box-shadow: 0 15px 35px -5px rgba(79, 70, 229, 0.5); } .btn-magic:disabled { filter: grayscale(1); opacity: 0.7; cursor: not-allowed; }
|
| 88 |
.history-card { background: white; border-radius: 20px; border: 1px solid #e2e8f0; overflow: hidden; transition: all 0.3s ease; box-shadow: 0 5px 20px -5px rgba(0,0,0,0.05); } .history-card-header { padding: 1.25rem; } .history-card-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; } .history-card-title h6 { font-weight: 800; margin: 0; color: var(--text-dark); } .request-badge { font-size: 0.7rem; font-weight: 700; background: #f1f5f9; color: #64748b; padding: 5px 10px; border-radius: 8px; } .status-description { background: #f8fafc; border: 1px solid #e2e8f0; color: #475569; font-size: 0.85rem; padding: 1rem; border-radius: 12px; margin-bottom: 1.25rem; } .progress-display { text-align: center; margin-bottom: 1rem; } .progress-percentage { font-size: 2.5rem; font-weight: 900; color: var(--primary-color); letter-spacing: -1px; } .progress-bar-custom { height: 10px; background: #e2e8f0; border-radius: 10px; overflow: hidden; width: 100%; } .progress-bar-custom-fill { height: 100%; width: 0%; border-radius: 10px; background: linear-gradient(90deg, var(--secondary-color), var(--primary-color)); transition: width 0.5s ease; } .action-buttons { display: flex; gap: 10px; } .btn-delete-icon { width: 50px; flex-shrink: 0; background: #fee2e2; color: #ef4444; border: none; border-radius: 12px; font-size: 1rem; transition: 0.3s; } .btn-delete-icon:hover { background: #ef4444; color: white; } .btn-status { width: 100%; padding: 10px; font-weight: 700; border-radius: 12px; border: none; font-size: 0.9rem; transition: 0.3s; } .history-card.processing .btn-status { background: #f1f5f9; color: #475569; } .history-card.completed .btn-status { background: var(--secondary-color); color: white; cursor: pointer; } .history-card.failed .btn-status { background: #fecaca; color: #b91c1c; } .history-card.completed .progress-percentage { color: var(--secondary-color); font-size: 1.8rem; } .history-card.failed .progress-percentage { color: #ef4444; }
|
| 89 |
-
.history-card-body { max-height: 0; overflow: hidden; transition: max-height 0.5s ease-out; background: #f8fafc; border-top: 1px solid transparent; padding: 0 1.25rem; } .history-card.expanded { border-color: var(--primary-color); } .history-card.expanded .history-card-body { max-height:
|
| 90 |
.history-separator { border: 0; height: 1px; background: linear-gradient(to right, transparent, #cbd5e1, transparent); margin: 2rem 0; }
|
|
|
|
|
|
|
| 91 |
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 9999; display: none; justify-content: center; align-items: center; padding: 20px; } @keyframes pop { from{transform:scale(0.9)} to{transform:scale(1)} } .modal-box { background: white; padding: 25px; border-radius: 20px; width: 100%; max-width: 320px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.2); animation: pop 0.3s; }
|
| 92 |
@keyframes pulse-premium { 0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(255, 193, 7, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); } } .limit-modal-icon { width: 70px; height: 70px; background: linear-gradient(45deg, var(--premium-color), #ffda77); border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; margin: 0 auto 1.5rem; animation: pulse-premium 2s infinite; } .btn-upgrade { background: linear-gradient(45deg, var(--premium-color), #ffca2c); color: #333; font-weight: 800; border: none; }
|
| 93 |
|
|
@@ -101,7 +105,6 @@
|
|
| 101 |
.queue-status-message i { margin-left: 5px; }
|
| 102 |
|
| 103 |
.mini-player { width: 100%; height: 40px; }
|
| 104 |
-
|
| 105 |
</style>
|
| 106 |
</head>
|
| 107 |
<body>
|
|
@@ -143,7 +146,7 @@
|
|
| 143 |
</div>
|
| 144 |
|
| 145 |
<div class="row g-4 justify-content-center">
|
| 146 |
-
<!-- ستون چپ: فرم -->
|
| 147 |
<div class="col-12 col-lg-6">
|
| 148 |
<div class="glass-card">
|
| 149 |
<form id="uploadForm">
|
|
@@ -157,36 +160,91 @@
|
|
| 157 |
<small class="text-muted" id="fileNameText">کلیک کنید (MP3, WAV)</small>
|
| 158 |
<input type="file" id="srcFile" hidden accept="audio/*" onchange="handleFile(this)">
|
| 159 |
</div>
|
|
|
|
| 160 |
<div class="mt-4">
|
| 161 |
<div class="d-flex align-items-center justify-content-between mb-3 p-3 rounded-4" data-bs-toggle="collapse" data-bs-target="#settingsCollapse" style="cursor:pointer; background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 2px 5px rgba(0,0,0,0.02);">
|
| 162 |
<span class="fw-bold text-dark"><i class="fas fa-sliders-h me-2 text-primary"></i> تنظیمات کیفیت</span>
|
| 163 |
<i class="fas fa-chevron-down text-muted small"></i>
|
| 164 |
</div>
|
| 165 |
<div class="collapse" id="settingsCollapse">
|
| 166 |
-
<!-- فیلد توکن هافینگ فیس -->
|
| 167 |
-
<div class="mb-3 px-2">
|
| 168 |
-
<label class="fw-bold text-secondary mb-1 small" for="hfToken">توکن Hugging Face (Bearer Token - اختیاری)</label>
|
| 169 |
-
<input type="password" id="hfToken" placeholder="hf_..." class="form-control rounded-4 border-2" style="font-size: 0.9rem; font-family: monospace; text-align: left; direction: ltr;">
|
| 170 |
-
<div class="text-muted mt-1" style="font-size: 0.7rem;">اگر اسپیس با محدودیت ترافیک مواجه شد یا خصوصی بود، توکن خود را وارد کنید.</div>
|
| 171 |
-
</div>
|
| 172 |
-
|
| 173 |
<h6 class="fw-bold text-secondary mb-2 small px-2">الگوریتم پردازش (Solver)</h6>
|
| 174 |
<div class="solver-grid">
|
| 175 |
-
<label class="solver-card">
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
</div>
|
|
|
|
| 179 |
<h6 class="fw-bold text-secondary mb-2 small px-2 mt-3">حذف نویز</h6>
|
| 180 |
-
<label class="denoise-card">
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
</div>
|
| 184 |
</div>
|
| 185 |
-
|
|
|
|
| 186 |
</form>
|
| 187 |
</div>
|
| 188 |
</div>
|
| 189 |
-
|
|
|
|
| 190 |
<div class="col-12 col-lg-5">
|
| 191 |
<div class="glass-card">
|
| 192 |
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
@@ -203,8 +261,8 @@
|
|
| 203 |
|
| 204 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 205 |
<script>
|
| 206 |
-
const STORAGE_KEY = '
|
| 207 |
-
const DB_NAME = '
|
| 208 |
const DB_VERSION = 1;
|
| 209 |
const STORE_NAME = 'original_audio';
|
| 210 |
const PREMIUM_PAGE_ID = '1149636';
|
|
@@ -212,13 +270,13 @@
|
|
| 212 |
|
| 213 |
let db;
|
| 214 |
let userSubscriptionStatus = 'free';
|
| 215 |
-
const activePolls = new Set();
|
| 216 |
|
| 217 |
const uploadArea = document.getElementById('dropZone');
|
| 218 |
const iconBox = uploadArea.querySelector('.icon-box');
|
| 219 |
const previewAudio = document.getElementById('previewAudio');
|
| 220 |
let previewAudioBlobUrl = null;
|
| 221 |
|
|
|
|
| 222 |
function initDB() {
|
| 223 |
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
| 224 |
request.onerror = (event) => console.error("Database error:", event.target.errorCode);
|
|
@@ -226,13 +284,7 @@
|
|
| 226 |
db = event.target.result;
|
| 227 |
cleanupOldFiles();
|
| 228 |
renderHistory();
|
| 229 |
-
|
| 230 |
-
const jobs = getJobs();
|
| 231 |
-
for (const id in jobs) {
|
| 232 |
-
if (jobs[id].status === 'processing') {
|
| 233 |
-
pollResultsForJob(id, jobs[id].hf_token || '');
|
| 234 |
-
}
|
| 235 |
-
}
|
| 236 |
};
|
| 237 |
request.onupgradeneeded = (event) => {
|
| 238 |
let db = event.target.result;
|
|
@@ -250,6 +302,7 @@
|
|
| 250 |
const saveJob = (data) => { const jobs = getJobs(); jobs[data.job_id] = data; localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs)); };
|
| 251 |
const getAudioDuration = (file) => new Promise((resolve) => { const audio = document.createElement('audio'); audio.onloadedmetadata = () => { resolve(audio.duration); URL.revokeObjectURL(audio.src); }; audio.src = URL.createObjectURL(file); });
|
| 252 |
|
|
|
|
| 253 |
async function handleFile(input) {
|
| 254 |
const file = input.files[0];
|
| 255 |
if (file) {
|
|
@@ -275,17 +328,13 @@
|
|
| 275 |
previewAudio.onpause = () => uploadArea.classList.remove('is-playing');
|
| 276 |
previewAudio.onended = () => uploadArea.classList.remove('is-playing');
|
| 277 |
|
| 278 |
-
//
|
| 279 |
-
async function uploadAudioFile(file
|
| 280 |
const formData = new FormData();
|
| 281 |
formData.append('files', file);
|
| 282 |
|
| 283 |
-
const headers = {};
|
| 284 |
-
if (token) headers['Authorization'] = `Bearer ${token}`;
|
| 285 |
-
|
| 286 |
const response = await fetch('https://opera8-resemble-enhance.hf.space/gradio_api/upload', {
|
| 287 |
method: 'POST',
|
| 288 |
-
headers: headers,
|
| 289 |
body: formData
|
| 290 |
});
|
| 291 |
|
|
@@ -304,14 +353,10 @@
|
|
| 304 |
};
|
| 305 |
}
|
| 306 |
|
| 307 |
-
|
| 308 |
-
async function startProcessing(payload, token) {
|
| 309 |
-
const headers = { 'Content-Type': 'application/json' };
|
| 310 |
-
if (token) headers['Authorization'] = `Bearer ${token}`;
|
| 311 |
-
|
| 312 |
const response = await fetch(`https://opera8-resemble-enhance.hf.space/gradio_api/call/v2/_fn`, {
|
| 313 |
method: 'POST',
|
| 314 |
-
headers:
|
| 315 |
body: JSON.stringify(payload)
|
| 316 |
});
|
| 317 |
|
|
@@ -324,7 +369,7 @@
|
|
| 324 |
return result.event_id;
|
| 325 |
}
|
| 326 |
|
| 327 |
-
//
|
| 328 |
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
|
| 329 |
e.preventDefault();
|
| 330 |
const srcFile = document.getElementById('srcFile').files[0];
|
|
@@ -332,14 +377,13 @@
|
|
| 332 |
|
| 333 |
const btn = document.getElementById('submitBtn');
|
| 334 |
btn.disabled = true;
|
| 335 |
-
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i> در حال آپلود...';
|
| 336 |
-
|
| 337 |
-
const token = document.getElementById('hfToken').value.trim();
|
| 338 |
|
| 339 |
try {
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
|
|
|
| 343 |
const payload = {
|
| 344 |
path: fileData,
|
| 345 |
solver: document.querySelector('input[name="solver"]:checked').value,
|
|
@@ -347,61 +391,45 @@
|
|
| 347 |
tau: parseFloat(document.getElementById('tau').value),
|
| 348 |
denoising: document.getElementById('denoising').checked
|
| 349 |
};
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
| 354 |
job_id: eventId,
|
| 355 |
timestamp: new Date().toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }),
|
| 356 |
fileName: srcFile.name,
|
| 357 |
status: 'processing',
|
| 358 |
progress: 0,
|
| 359 |
-
|
| 360 |
-
|
| 361 |
};
|
| 362 |
-
|
|
|
|
| 363 |
saveFileToDB(eventId, srcFile);
|
| 364 |
-
saveJob(
|
| 365 |
renderHistory();
|
|
|
|
| 366 |
btn.disabled = false;
|
| 367 |
-
btn.innerHTML = 'شروع
|
| 368 |
resetUploadArea();
|
| 369 |
-
|
| 370 |
-
//
|
| 371 |
-
|
|
|
|
| 372 |
} catch (err) {
|
| 373 |
-
alert("خطا: " + err.message);
|
| 374 |
btn.disabled = false;
|
| 375 |
-
btn.innerHTML = 'شروع
|
| 376 |
}
|
| 377 |
});
|
| 378 |
|
| 379 |
-
// --- پیگیری
|
| 380 |
-
function
|
| 381 |
-
|
| 382 |
-
activePolls.add(eventId);
|
| 383 |
-
|
| 384 |
-
const headers = {};
|
| 385 |
-
if (token) headers['Authorization'] = `Bearer ${token}`;
|
| 386 |
-
|
| 387 |
-
const updateState = (updater) => {
|
| 388 |
-
const jobs = getJobs();
|
| 389 |
-
if (jobs[eventId]) {
|
| 390 |
-
updater(jobs[eventId]);
|
| 391 |
-
saveJob(jobs[eventId]);
|
| 392 |
-
if (jobs[eventId].status !== 'processing') {
|
| 393 |
-
renderHistory();
|
| 394 |
-
} else {
|
| 395 |
-
updateProgressBarDOM(eventId, jobs[eventId].progress, jobs[eventId].stage_msg);
|
| 396 |
-
}
|
| 397 |
-
}
|
| 398 |
-
};
|
| 399 |
-
|
| 400 |
-
fetch(`https://opera8-resemble-enhance.hf.space/gradio_api/call/_fn/${eventId}`, { headers })
|
| 401 |
.then(async response => {
|
| 402 |
if (!response.ok) {
|
| 403 |
-
|
| 404 |
-
throw new Error(`خطا در پیگیری وضعیت: ${response.status} - ${errText}`);
|
| 405 |
}
|
| 406 |
|
| 407 |
const reader = response.body.getReader();
|
|
@@ -415,7 +443,7 @@
|
|
| 415 |
|
| 416 |
buffer += decoder.decode(value, { stream: true });
|
| 417 |
const lines = buffer.split("\n");
|
| 418 |
-
buffer = lines.pop();
|
| 419 |
|
| 420 |
for (const line of lines) {
|
| 421 |
const trimmed = line.trim();
|
|
@@ -426,93 +454,92 @@
|
|
| 426 |
let data;
|
| 427 |
try { data = JSON.parse(dataStr); } catch (e) { data = dataStr; }
|
| 428 |
|
|
|
|
|
|
|
|
|
|
| 429 |
if (currentEvent === "complete") {
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
return;
|
|
|
|
| 445 |
} else if (currentEvent === "error") {
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
job.stage_msg = 'خطا در حین پردازش مدل صوتی';
|
| 450 |
-
});
|
| 451 |
-
activePolls.delete(eventId);
|
| 452 |
return;
|
|
|
|
| 453 |
} else {
|
|
|
|
| 454 |
if (typeof data === 'object' && data.stage) {
|
| 455 |
-
let
|
| 456 |
-
if (data.stage === '
|
| 457 |
-
|
| 458 |
-
} else {
|
| 459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
}
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
});
|
| 466 |
}
|
|
|
|
|
|
|
| 467 |
}
|
| 468 |
}
|
| 469 |
}
|
| 470 |
}
|
| 471 |
})
|
| 472 |
.catch(err => {
|
| 473 |
-
console.error(err);
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
});
|
| 481 |
}
|
| 482 |
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
const jobs = getJobs(); let changed = false;
|
| 486 |
for (const id in jobs) {
|
| 487 |
if (jobs[id].status === 'processing') {
|
| 488 |
-
|
| 489 |
-
if (jobs[id].progress < 95) {
|
| 490 |
-
jobs[id].progress += 1; changed = true;
|
| 491 |
-
updateProgressBarDOM(id, jobs[id].progress, jobs[id].stage_msg);
|
| 492 |
-
}
|
| 493 |
}
|
| 494 |
}
|
| 495 |
-
|
| 496 |
-
}, 3000);
|
| 497 |
|
| 498 |
-
function updateProgressBarDOM(id, percent
|
| 499 |
const bar = document.getElementById(`progress-fill-${id}`);
|
| 500 |
const text = document.getElementById(`progress-text-${id}`);
|
| 501 |
if (bar) bar.style.width = `${percent}%`;
|
| 502 |
-
if (text) text.innerHTML = `${percent}%`;
|
| 503 |
-
|
| 504 |
-
const messageEl = document.getElementById(`queue-message-${id}`);
|
| 505 |
-
if (messageEl) {
|
| 506 |
-
if (stageMsg) {
|
| 507 |
-
messageEl.innerHTML = `<i class="fas fa-hourglass-half fa-spin-pulse" style="--fa-animation-duration: 2s;"></i> ${stageMsg}`;
|
| 508 |
-
messageEl.classList.add('visible');
|
| 509 |
-
} else {
|
| 510 |
-
messageEl.classList.remove('visible');
|
| 511 |
-
}
|
| 512 |
-
}
|
| 513 |
}
|
| 514 |
|
| 515 |
-
// --- رندر لیست
|
| 516 |
function renderHistory() {
|
| 517 |
const list = document.getElementById('historyList');
|
| 518 |
const jobs = Object.values(getJobs()).reverse();
|
|
@@ -528,24 +555,24 @@
|
|
| 528 |
let title, description, percentageText, buttonText, buttonAction, buttonIcon;
|
| 529 |
|
| 530 |
if (job.status === 'processing') {
|
| 531 |
-
title = 'در حال بهبود صدا';
|
| 532 |
-
description = '
|
| 533 |
percentageText = `${job.progress || 0}%`;
|
| 534 |
buttonText = 'در حال پیگیری...';
|
| 535 |
buttonIcon = '<i class="fas fa-clock me-2"></i>';
|
| 536 |
buttonAction = '';
|
| 537 |
} else if (job.status === 'completed') {
|
| 538 |
-
title = 'بهبود صدا تکمیل شد';
|
| 539 |
description = `نام فایل اصلی: <strong>${job.fileName}</strong>`;
|
| 540 |
percentageText = 'تکمیل شد';
|
| 541 |
-
buttonText = 'نمایش فایلها';
|
| 542 |
buttonIcon = '<i class="fas fa-play-circle me-2"></i>';
|
| 543 |
buttonAction = `onclick="toggleHistoryItem('${job.job_id}')"`;
|
| 544 |
} else {
|
| 545 |
-
title = 'خطا در
|
| 546 |
-
description = '
|
| 547 |
percentageText = 'خطا';
|
| 548 |
-
buttonText = 'خطا';
|
| 549 |
buttonIcon = '<i class="fas fa-exclamation-triangle me-2"></i>';
|
| 550 |
buttonAction = '';
|
| 551 |
}
|
|
@@ -560,8 +587,8 @@
|
|
| 560 |
<div class="status-description">${description}</div>
|
| 561 |
<div class="progress-display">
|
| 562 |
<div class="progress-percentage" id="progress-text-${job.job_id}">${percentageText}</div>
|
| 563 |
-
<div class="queue-status-message
|
| 564 |
-
<i class="fas fa-hourglass-half fa-spin-pulse" style="--fa-animation-duration: 2s;"></i>
|
| 565 |
</div>
|
| 566 |
<div class="progress-bar-custom">
|
| 567 |
<div class="progress-bar-custom-fill" id="progress-fill-${job.job_id}" style="width: ${job.progress || 0}%"></div>
|
|
@@ -572,7 +599,7 @@
|
|
| 572 |
<button class="btn-status" ${buttonAction}>${buttonIcon} ${buttonText}</button>
|
| 573 |
</div>
|
| 574 |
</div>
|
| 575 |
-
${job.status === 'completed' ? `<div class="history-card-body"
|
| 576 |
</div>
|
| 577 |
${index < jobs.length - 1 ? '<hr class="history-separator">' : ''}
|
| 578 |
`;
|
|
@@ -589,29 +616,36 @@
|
|
| 589 |
});
|
| 590 |
return `
|
| 591 |
<div class="audio-player-wrapper">
|
| 592 |
-
<small class="d-block fw-bold text-muted mb-1" style="font-size:0.8rem">فایل اصلی:</small>
|
| 593 |
<audio controls id="original-audio-${job.job_id}" class="mini-player"></audio>
|
| 594 |
</div>
|
| 595 |
<div class="audio-player-wrapper mt-3">
|
| 596 |
-
<small class="d-block fw-bold text-info mb-1" style="font-size:0.8rem">
|
| 597 |
-
<audio controls src="${job.denoised_url
|
| 598 |
-
<button type="button" class="btn btn-sm btn-outline-info w-100 mt-2 rounded-pill fw-bold btn-download-via-postmessage" data-audiourl="${job.denoised_url || ''}">
|
| 599 |
-
<i class="fas fa-download me-1"></i> دانلود فایل کاهش نویز شده
|
| 600 |
-
</button>
|
| 601 |
</div>
|
| 602 |
<div class="audio-player-wrapper mt-3">
|
| 603 |
-
<small class="d-block fw-bold text-success mb-1" style="font-size:0.8rem">
|
| 604 |
-
<audio controls src="${job.enhanced_url
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
</div>
|
| 609 |
`;
|
| 610 |
}
|
| 611 |
|
| 612 |
function toggleHistoryItem(id) { document.getElementById(`history-${id}`).classList.toggle('expanded'); }
|
| 613 |
|
| 614 |
-
// --- مدیریت مودالها ---
|
| 615 |
let deleteId = null;
|
| 616 |
function openDeleteModal(id) { deleteId = id; document.getElementById('deleteModal').style.display = 'flex'; }
|
| 617 |
function closeModal() { document.getElementById('deleteModal').style.display = 'none'; deleteId = null; }
|
|
@@ -630,9 +664,10 @@
|
|
| 630 |
renderHistory();
|
| 631 |
closeModal();
|
| 632 |
};
|
|
|
|
| 633 |
document.getElementById('upgradeFromModalBtn').onclick = () => { parent.postMessage({ type: 'NAVIGATE_TO_PREMIUM', payload: { url: PREMIUM_URL } }, '*'); };
|
| 634 |
|
| 635 |
-
// ---
|
| 636 |
function isUserPaid(userObject) { return userObject && userObject.isLogin && userObject.accessible_pages && (userObject.accessible_pages.includes(PREMIUM_PAGE_ID) || userObject.accessible_pages.includes(parseInt(PREMIUM_PAGE_ID))); }
|
| 637 |
|
| 638 |
function updateSubscriptionBadge(status) {
|
|
@@ -660,22 +695,21 @@
|
|
| 660 |
}
|
| 661 |
});
|
| 662 |
|
| 663 |
-
// مدیریت دانلود و ارسال پیام به برنامه اندروید
|
| 664 |
document.getElementById('historyList').addEventListener('click', (e) => {
|
| 665 |
const downloadButton = e.target.closest('.btn-download-via-postmessage');
|
| 666 |
if(downloadButton) {
|
| 667 |
e.preventDefault();
|
| 668 |
-
const audioUrl = downloadButton.dataset.
|
| 669 |
if(audioUrl) {
|
| 670 |
parent.postMessage({ type: 'INITIATE_DOWNLOAD_FROM_URL', payload: { audioUrl: audioUrl } }, '*');
|
| 671 |
-
const
|
| 672 |
-
downloadButton.innerHTML = '<i class="fas fa-check me-1"></i> ارسال
|
| 673 |
-
setTimeout(() => { downloadButton.innerHTML =
|
| 674 |
}
|
| 675 |
}
|
| 676 |
});
|
| 677 |
|
| 678 |
-
// ---
|
| 679 |
initDB();
|
| 680 |
parent.postMessage({ type: 'REQUEST_USER_STATUS' }, '*');
|
| 681 |
</script>
|
|
|
|
| 53 |
.free-badge { background: linear-gradient(45deg, #6c757d, #495057); color: white; box-shadow: 0 4px 10px rgba(108, 117, 125, 0.3); }
|
| 54 |
.paid-badge { background: linear-gradient(45deg, var(--premium-color), #ffca2c); color: #333; box-shadow: 0 4px 10px var(--premium-glow); }
|
| 55 |
|
| 56 |
+
/* انیمیشن برای محدودیتها */
|
| 57 |
@keyframes slideUpFadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
|
| 58 |
.usage-info-container { margin-top: 1rem; }
|
| 59 |
.usage-info-line { opacity: 0; animation: slideUpFadeIn 0.7s ease-out forwards; }
|
|
|
|
| 82 |
.upload-area.file-selected.is-playing .icon-play { opacity: 0; transform: translate(-50%, -50%) scale(0); }
|
| 83 |
.upload-area.file-selected.is-playing .icon-pause { opacity: 1; transform: translate(-50%, -50%) scale(1); }
|
| 84 |
|
| 85 |
+
/* --- تنظیمات الگوریتم و نویز --- */
|
| 86 |
.solver-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 20px; } .solver-card { position: relative; cursor: pointer; } .solver-card input { display: none; } .solver-content { display: flex; align-items: center; padding: 12px 15px; border: 2px solid var(--border-color); border-radius: 16px; background: white; transition: all 0.3s ease; } .solver-icon { width: 40px; height: 40px; background: #f1f5f9; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 1.1rem; margin-left: 12px; transition: 0.3s; } .solver-text h6 { margin: 0; font-weight: 700; font-size: 0.9rem; color: var(--text-dark); } .solver-text p { margin: 0; font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; } .check-circle { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #cbd5e1; margin-right: auto; transition: 0.3s; display: flex; align-items: center; justify-content: center; } .check-circle::after { content: '\f00c'; font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 10px; color: white; opacity: 0; transform: scale(0); transition: 0.2s; } .solver-card input:checked + .solver-content { border-color: var(--primary-color); background: #f5f3ff; } .solver-card input:checked + .solver-content .solver-icon { background: var(--primary-color); color: white; } .solver-card input:checked + .solver-content .check-circle { background: var(--primary-color); border-color: var(--primary-color); } .solver-card input:checked + .solver-content .check-circle::after { opacity: 1; transform: scale(1); } .denoise-card { cursor: pointer; display: block; margin-bottom: 20px; } .denoise-card input { display: none; } .denoise-inner { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; border: 2px solid var(--border-color); border-radius: 50px; background: white; transition: 0.3s; } .denoise-left { display: flex; align-items: center; gap: 10px; } .denoise-ico { width: 35px; height: 35px; border-radius: 50%; background: #f1f5f9; color: #64748b; display: flex; align-items: center; justify-content: center; transition: 0.4s; } .denoise-toggle { width: 40px; height: 22px; background: #cbd5e1; border-radius: 20px; position: relative; transition: 0.3s; } .denoise-toggle::after { content: ''; position: absolute; width: 16px; height: 16px; background: white; border-radius: 50%; top: 3px; left: 3px; transform: translateX(0); transition: 0.3s; } .denoise-card input:checked + .denoise-inner { border-color: #10b981; background: #ecfdfdf5; } .denoise-card input:checked + .denoise-inner .denoise-ico { background: #10b981; color: white; transform: rotate(360deg); } .denoise-card input:checked + .denoise-inner .denoise-toggle { background: #10b981; } .denoise-card input:checked + .denoise-inner .denoise-toggle::after { transform: translateX(18px); } .slider-group { background: #f8fafc; border-radius: 16px; padding: 15px; margin-bottom: 15px; } .slider-label { display: flex; justify-content: space-between; font-weight: 700; font-size: 0.85rem; color: #334155; margin-bottom: 8px; } .slider-desc { font-size: 0.75rem; color: #64748b; margin-top: 8px; line-height: 1.5; background: rgba(255,255,255,0.5); padding: 6px; border-radius: 6px; } input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 20px; width: 20px; border-radius: 50%; background: var(--primary-color); cursor: pointer; margin-top: -8px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); } input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #cbd5e1; border-radius: 10px; }
|
| 87 |
+
|
| 88 |
+
/* --- دکمهها و تاریخچه --- */
|
| 89 |
.btn-magic { background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%); color: white; border: none; padding: 15px; border-radius: 16px; font-weight: 800; width: 100%; font-size: 1.1rem; box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.4); transition: 0.3s; } .btn-magic:hover { transform: translateY(-2px); box-shadow: 0 15px 35px -5px rgba(79, 70, 229, 0.5); } .btn-magic:disabled { filter: grayscale(1); opacity: 0.7; cursor: not-allowed; }
|
| 90 |
.history-card { background: white; border-radius: 20px; border: 1px solid #e2e8f0; overflow: hidden; transition: all 0.3s ease; box-shadow: 0 5px 20px -5px rgba(0,0,0,0.05); } .history-card-header { padding: 1.25rem; } .history-card-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; } .history-card-title h6 { font-weight: 800; margin: 0; color: var(--text-dark); } .request-badge { font-size: 0.7rem; font-weight: 700; background: #f1f5f9; color: #64748b; padding: 5px 10px; border-radius: 8px; } .status-description { background: #f8fafc; border: 1px solid #e2e8f0; color: #475569; font-size: 0.85rem; padding: 1rem; border-radius: 12px; margin-bottom: 1.25rem; } .progress-display { text-align: center; margin-bottom: 1rem; } .progress-percentage { font-size: 2.5rem; font-weight: 900; color: var(--primary-color); letter-spacing: -1px; } .progress-bar-custom { height: 10px; background: #e2e8f0; border-radius: 10px; overflow: hidden; width: 100%; } .progress-bar-custom-fill { height: 100%; width: 0%; border-radius: 10px; background: linear-gradient(90deg, var(--secondary-color), var(--primary-color)); transition: width 0.5s ease; } .action-buttons { display: flex; gap: 10px; } .btn-delete-icon { width: 50px; flex-shrink: 0; background: #fee2e2; color: #ef4444; border: none; border-radius: 12px; font-size: 1rem; transition: 0.3s; } .btn-delete-icon:hover { background: #ef4444; color: white; } .btn-status { width: 100%; padding: 10px; font-weight: 700; border-radius: 12px; border: none; font-size: 0.9rem; transition: 0.3s; } .history-card.processing .btn-status { background: #f1f5f9; color: #475569; } .history-card.completed .btn-status { background: var(--secondary-color); color: white; cursor: pointer; } .history-card.failed .btn-status { background: #fecaca; color: #b91c1c; } .history-card.completed .progress-percentage { color: var(--secondary-color); font-size: 1.8rem; } .history-card.failed .progress-percentage { color: #ef4444; }
|
| 91 |
+
.history-card-body { max-height: 0; overflow: hidden; transition: max-height 0.5s ease-out; background: #f8fafc; border-top: 1px solid transparent; padding: 0 1.25rem; } .history-card.expanded { border-color: var(--primary-color); } .history-card.expanded .history-card-body { max-height: 500px; border-top-color: #e2e8f0; padding: 1.25rem; overflow-y: auto; } @keyframes slideInFadeUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } } .audio-player-wrapper { opacity: 0; animation: slideInFadeUp 0.5s forwards; } .history-card.expanded .audio-player-wrapper:nth-child(2) { animation-delay: 0.1s; }
|
| 92 |
.history-separator { border: 0; height: 1px; background: linear-gradient(to right, transparent, #cbd5e1, transparent); margin: 2rem 0; }
|
| 93 |
+
|
| 94 |
+
/* --- مودالها --- */
|
| 95 |
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 9999; display: none; justify-content: center; align-items: center; padding: 20px; } @keyframes pop { from{transform:scale(0.9)} to{transform:scale(1)} } .modal-box { background: white; padding: 25px; border-radius: 20px; width: 100%; max-width: 320px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.2); animation: pop 0.3s; }
|
| 96 |
@keyframes pulse-premium { 0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(255, 193, 7, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); } } .limit-modal-icon { width: 70px; height: 70px; background: linear-gradient(45deg, var(--premium-color), #ffda77); border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; margin: 0 auto 1.5rem; animation: pulse-premium 2s infinite; } .btn-upgrade { background: linear-gradient(45deg, var(--premium-color), #ffca2c); color: #333; font-weight: 800; border: none; }
|
| 97 |
|
|
|
|
| 105 |
.queue-status-message i { margin-left: 5px; }
|
| 106 |
|
| 107 |
.mini-player { width: 100%; height: 40px; }
|
|
|
|
| 108 |
</style>
|
| 109 |
</head>
|
| 110 |
<body>
|
|
|
|
| 146 |
</div>
|
| 147 |
|
| 148 |
<div class="row g-4 justify-content-center">
|
| 149 |
+
<!-- ستون چپ: فرم تنظیمات و آپلود -->
|
| 150 |
<div class="col-12 col-lg-6">
|
| 151 |
<div class="glass-card">
|
| 152 |
<form id="uploadForm">
|
|
|
|
| 160 |
<small class="text-muted" id="fileNameText">کلیک کنید (MP3, WAV)</small>
|
| 161 |
<input type="file" id="srcFile" hidden accept="audio/*" onchange="handleFile(this)">
|
| 162 |
</div>
|
| 163 |
+
|
| 164 |
<div class="mt-4">
|
| 165 |
<div class="d-flex align-items-center justify-content-between mb-3 p-3 rounded-4" data-bs-toggle="collapse" data-bs-target="#settingsCollapse" style="cursor:pointer; background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 2px 5px rgba(0,0,0,0.02);">
|
| 166 |
<span class="fw-bold text-dark"><i class="fas fa-sliders-h me-2 text-primary"></i> تنظیمات کیفیت</span>
|
| 167 |
<i class="fas fa-chevron-down text-muted small"></i>
|
| 168 |
</div>
|
| 169 |
<div class="collapse" id="settingsCollapse">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
<h6 class="fw-bold text-secondary mb-2 small px-2">الگوریتم پردازش (Solver)</h6>
|
| 171 |
<div class="solver-grid">
|
| 172 |
+
<label class="solver-card">
|
| 173 |
+
<input type="radio" name="solver" value="Midpoint" checked>
|
| 174 |
+
<div class="solver-content">
|
| 175 |
+
<div class="solver-icon"><i class="fas fa-balance-scale"></i></div>
|
| 176 |
+
<div class="solver-text flex-grow-1 mx-2">
|
| 177 |
+
<h6>Midpoint (پیشنهادی)</h6>
|
| 178 |
+
<p>بهترین تعادل بین سرعت و کیفیت.</p>
|
| 179 |
+
</div>
|
| 180 |
+
<div class="check-circle"></div>
|
| 181 |
+
</div>
|
| 182 |
+
</label>
|
| 183 |
+
<label class="solver-card">
|
| 184 |
+
<input type="radio" name="solver" value="RK4">
|
| 185 |
+
<div class="solver-content">
|
| 186 |
+
<div class="solver-icon"><i class="fas fa-microscope"></i></div>
|
| 187 |
+
<div class="solver-text flex-grow-1 mx-2">
|
| 188 |
+
<h6>RK4 (دقیق)</h6>
|
| 189 |
+
<p>حداکثر دقت ریاضی، کمی کندتر.</p>
|
| 190 |
+
</div>
|
| 191 |
+
<div class="check-circle"></div>
|
| 192 |
+
</div>
|
| 193 |
+
</label>
|
| 194 |
+
<label class="solver-card">
|
| 195 |
+
<input type="radio" name="solver" value="Euler">
|
| 196 |
+
<div class="solver-content">
|
| 197 |
+
<div class="solver-icon"><i class="fas fa-bolt"></i></div>
|
| 198 |
+
<div class="solver-text flex-grow-1 mx-2">
|
| 199 |
+
<h6>Euler (سریع)</h6>
|
| 200 |
+
<p>پردازش سریع برای تست اولیه.</p>
|
| 201 |
+
</div>
|
| 202 |
+
<div class="check-circle"></div>
|
| 203 |
+
</div>
|
| 204 |
+
</label>
|
| 205 |
</div>
|
| 206 |
+
|
| 207 |
<h6 class="fw-bold text-secondary mb-2 small px-2 mt-3">حذف نویز</h6>
|
| 208 |
+
<label class="denoise-card">
|
| 209 |
+
<input type="checkbox" id="denoising">
|
| 210 |
+
<div class="denoise-inner">
|
| 211 |
+
<div class="denoise-left">
|
| 212 |
+
<div class="denoise-ico"><i class="fas fa-magic"></i></div>
|
| 213 |
+
<div>
|
| 214 |
+
<div class="fw-bold text-dark small">حذف نویز قبل از بهبود کیفیت</div>
|
| 215 |
+
<div class="text-muted" style="font-size: 0.7rem;">اگر صدای شما دارای نویز پسزمینه زیادی است، تیک بزنید</div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
<div class="denoise-toggle"></div>
|
| 219 |
+
</div>
|
| 220 |
+
</label>
|
| 221 |
+
|
| 222 |
+
<div class="slider-group">
|
| 223 |
+
<div class="slider-label">
|
| 224 |
+
<span>عمق پردازش (NFE)</span>
|
| 225 |
+
<span class="text-primary" id="nfeVal">64</span>
|
| 226 |
+
</div>
|
| 227 |
+
<input type="range" min="1" max="128" step="1" value="64" id="nfe" oninput="document.getElementById('nfeVal').innerText=this.value">
|
| 228 |
+
<div class="slider-desc">عدد بالاتر: کیفیت نهایی بهتر.<br>عدد پایین: سرعت پردازش بالاتر.</div>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<div class="slider-group">
|
| 232 |
+
<div class="slider-label">
|
| 233 |
+
<span>شفافیت و دما (Tau)</span>
|
| 234 |
+
<span class="text-primary" id="tauVal">0.5</span>
|
| 235 |
+
</div>
|
| 236 |
+
<input type="range" min="0" max="1" step="0.01" value="0.5" id="tau" oninput="document.getElementById('tauVal').innerText=this.value">
|
| 237 |
+
<div class="slider-desc">عدد کمتر: صدای طبیعیتر.<br>عدد بیشتر: صدای شفافتر و کریستالی.</div>
|
| 238 |
+
</div>
|
| 239 |
</div>
|
| 240 |
</div>
|
| 241 |
+
|
| 242 |
+
<button type="submit" class="btn-magic" id="submitBtn">شروع فرآیند بهبود صدا</button>
|
| 243 |
</form>
|
| 244 |
</div>
|
| 245 |
</div>
|
| 246 |
+
|
| 247 |
+
<!-- ستون راست: تاریخچه و وضعیت کارهای ارسالشده -->
|
| 248 |
<div class="col-12 col-lg-5">
|
| 249 |
<div class="glass-card">
|
| 250 |
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
|
|
| 261 |
|
| 262 |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 263 |
<script>
|
| 264 |
+
const STORAGE_KEY = 'sada_resemble_embedded_v2';
|
| 265 |
+
const DB_NAME = 'SadaAudioDB_v2';
|
| 266 |
const DB_VERSION = 1;
|
| 267 |
const STORE_NAME = 'original_audio';
|
| 268 |
const PREMIUM_PAGE_ID = '1149636';
|
|
|
|
| 270 |
|
| 271 |
let db;
|
| 272 |
let userSubscriptionStatus = 'free';
|
|
|
|
| 273 |
|
| 274 |
const uploadArea = document.getElementById('dropZone');
|
| 275 |
const iconBox = uploadArea.querySelector('.icon-box');
|
| 276 |
const previewAudio = document.getElementById('previewAudio');
|
| 277 |
let previewAudioBlobUrl = null;
|
| 278 |
|
| 279 |
+
// --- مدیریت بانک اطلاعاتی محلی مرورگر (IndexedDB) برای حفظ موقت فایل صوتی اصلی ---
|
| 280 |
function initDB() {
|
| 281 |
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
| 282 |
request.onerror = (event) => console.error("Database error:", event.target.errorCode);
|
|
|
|
| 284 |
db = event.target.result;
|
| 285 |
cleanupOldFiles();
|
| 286 |
renderHistory();
|
| 287 |
+
resumeActivePolls();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
};
|
| 289 |
request.onupgradeneeded = (event) => {
|
| 290 |
let db = event.target.result;
|
|
|
|
| 302 |
const saveJob = (data) => { const jobs = getJobs(); jobs[data.job_id] = data; localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs)); };
|
| 303 |
const getAudioDuration = (file) => new Promise((resolve) => { const audio = document.createElement('audio'); audio.onloadedmetadata = () => { resolve(audio.duration); URL.revokeObjectURL(audio.src); }; audio.src = URL.createObjectURL(file); });
|
| 304 |
|
| 305 |
+
// --- بارگیری و اعتبارسنجی فایل انتخاب شده ---
|
| 306 |
async function handleFile(input) {
|
| 307 |
const file = input.files[0];
|
| 308 |
if (file) {
|
|
|
|
| 328 |
previewAudio.onpause = () => uploadArea.classList.remove('is-playing');
|
| 329 |
previewAudio.onended = () => uploadArea.classList.remove('is-playing');
|
| 330 |
|
| 331 |
+
// --- توابع ارتباط مستقیم با API مدل صوتی (Gradio-HuggingFace Space) ---
|
| 332 |
+
async function uploadAudioFile(file) {
|
| 333 |
const formData = new FormData();
|
| 334 |
formData.append('files', file);
|
| 335 |
|
|
|
|
|
|
|
|
|
|
| 336 |
const response = await fetch('https://opera8-resemble-enhance.hf.space/gradio_api/upload', {
|
| 337 |
method: 'POST',
|
|
|
|
| 338 |
body: formData
|
| 339 |
});
|
| 340 |
|
|
|
|
| 353 |
};
|
| 354 |
}
|
| 355 |
|
| 356 |
+
async function startProcessing(payload) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
const response = await fetch(`https://opera8-resemble-enhance.hf.space/gradio_api/call/v2/_fn`, {
|
| 358 |
method: 'POST',
|
| 359 |
+
headers: { 'Content-Type': 'application/json' },
|
| 360 |
body: JSON.stringify(payload)
|
| 361 |
});
|
| 362 |
|
|
|
|
| 369 |
return result.event_id;
|
| 370 |
}
|
| 371 |
|
| 372 |
+
// ارسال فرم صوتی و آغاز فرآیند در بستر شبکه
|
| 373 |
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
|
| 374 |
e.preventDefault();
|
| 375 |
const srcFile = document.getElementById('srcFile').files[0];
|
|
|
|
| 377 |
|
| 378 |
const btn = document.getElementById('submitBtn');
|
| 379 |
btn.disabled = true;
|
| 380 |
+
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i> در حال آپلود و ارسال فایل...';
|
|
|
|
|
|
|
| 381 |
|
| 382 |
try {
|
| 383 |
+
// ۱. بارگذاری محلی مستقیم فایل
|
| 384 |
+
const fileData = await uploadAudioFile(srcFile);
|
| 385 |
+
|
| 386 |
+
// ۲. ساخت اطلاعات ورودی مدل صوتی طبق پارامترهای نامگذاری شده
|
| 387 |
const payload = {
|
| 388 |
path: fileData,
|
| 389 |
solver: document.querySelector('input[name="solver"]:checked').value,
|
|
|
|
| 391 |
tau: parseFloat(document.getElementById('tau').value),
|
| 392 |
denoising: document.getElementById('denoising').checked
|
| 393 |
};
|
| 394 |
+
|
| 395 |
+
// ۳. ایجاد کار جدید در صف پردازش مدل صوتی
|
| 396 |
+
const eventId = await startProcessing(payload);
|
| 397 |
+
|
| 398 |
+
const jobData = {
|
| 399 |
job_id: eventId,
|
| 400 |
timestamp: new Date().toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }),
|
| 401 |
fileName: srcFile.name,
|
| 402 |
status: 'processing',
|
| 403 |
progress: 0,
|
| 404 |
+
denoised_url: '',
|
| 405 |
+
enhanced_url: ''
|
| 406 |
};
|
| 407 |
+
|
| 408 |
+
// ۴. ثبت جزئیات کار صوتی جدید در تاریخچه
|
| 409 |
saveFileToDB(eventId, srcFile);
|
| 410 |
+
saveJob(jobData);
|
| 411 |
renderHistory();
|
| 412 |
+
|
| 413 |
btn.disabled = false;
|
| 414 |
+
btn.innerHTML = 'شروع فرآیند بهبود صدا';
|
| 415 |
resetUploadArea();
|
| 416 |
+
|
| 417 |
+
// ۵. پیگیری زنده فرآیند از سرور
|
| 418 |
+
pollJobStatus(eventId);
|
| 419 |
+
|
| 420 |
} catch (err) {
|
| 421 |
+
alert("خطایی رخ داد: " + err.message);
|
| 422 |
btn.disabled = false;
|
| 423 |
+
btn.innerHTML = 'شروع فرآیند بهبود صدا';
|
| 424 |
}
|
| 425 |
});
|
| 426 |
|
| 427 |
+
// --- مدیریت و پیگیری وضعیت کارهای صوتی از طریق کانال ارتباطی SSE ---
|
| 428 |
+
function pollJobStatus(jobId) {
|
| 429 |
+
fetch(`https://opera8-resemble-enhance.hf.space/gradio_api/call/_fn/${jobId}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
.then(async response => {
|
| 431 |
if (!response.ok) {
|
| 432 |
+
throw new Error(`خطا در ارتباط با سرور: ${response.status}`);
|
|
|
|
| 433 |
}
|
| 434 |
|
| 435 |
const reader = response.body.getReader();
|
|
|
|
| 443 |
|
| 444 |
buffer += decoder.decode(value, { stream: true });
|
| 445 |
const lines = buffer.split("\n");
|
| 446 |
+
buffer = lines.pop();
|
| 447 |
|
| 448 |
for (const line of lines) {
|
| 449 |
const trimmed = line.trim();
|
|
|
|
| 454 |
let data;
|
| 455 |
try { data = JSON.parse(dataStr); } catch (e) { data = dataStr; }
|
| 456 |
|
| 457 |
+
const jobs = getJobs();
|
| 458 |
+
if (!jobs[jobId]) return; // در صورت حذف کار توسط کاربر از تاریخچه
|
| 459 |
+
|
| 460 |
if (currentEvent === "complete") {
|
| 461 |
+
jobs[jobId].status = 'completed';
|
| 462 |
+
jobs[jobId].progress = 100;
|
| 463 |
+
|
| 464 |
+
const resolveUrl = (audioObj) => {
|
| 465 |
+
if (!audioObj) return '';
|
| 466 |
+
if (audioObj.url) return audioObj.url;
|
| 467 |
+
return `https://opera8-resemble-enhance.hf.space/file=${audioObj.path}`;
|
| 468 |
+
};
|
| 469 |
+
|
| 470 |
+
jobs[jobId].denoised_url = resolveUrl(data[0]);
|
| 471 |
+
jobs[jobId].enhanced_url = resolveUrl(data[1]);
|
| 472 |
+
|
| 473 |
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs));
|
| 474 |
+
renderHistory();
|
| 475 |
return;
|
| 476 |
+
|
| 477 |
} else if (currentEvent === "error") {
|
| 478 |
+
jobs[jobId].status = 'failed';
|
| 479 |
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs));
|
| 480 |
+
renderHistory();
|
|
|
|
|
|
|
|
|
|
| 481 |
return;
|
| 482 |
+
|
| 483 |
} else {
|
| 484 |
+
// بهروزرسانی پیشرفت فرضی در حین پردازش سرور
|
| 485 |
if (typeof data === 'object' && data.stage) {
|
| 486 |
+
let progress = jobs[jobId].progress || 10;
|
| 487 |
+
if (data.stage === 'process') {
|
| 488 |
+
progress = Math.min(progress + 20, 90);
|
| 489 |
+
} else if (data.stage === 'pending') {
|
| 490 |
+
progress = Math.min(progress + 5, 40);
|
| 491 |
+
}
|
| 492 |
+
jobs[jobId].progress = progress;
|
| 493 |
+
|
| 494 |
+
const queueMsgEl = document.getElementById(`queue-message-${jobId}`);
|
| 495 |
+
if (queueMsgEl) {
|
| 496 |
+
if (data.queue_size && data.queue_size > 0) {
|
| 497 |
+
queueMsgEl.innerHTML = `<i class="fas fa-hourglass-half fa-spin-pulse"></i> تعداد ${data.queue_size} درخواست قبل از شما در صف است...`;
|
| 498 |
+
queueMsgEl.classList.add('visible');
|
| 499 |
+
} else {
|
| 500 |
+
queueMsgEl.classList.remove('visible');
|
| 501 |
+
}
|
| 502 |
}
|
| 503 |
+
} else {
|
| 504 |
+
let progress = jobs[jobId].progress || 10;
|
| 505 |
+
progress = Math.min(progress + 3, 95);
|
| 506 |
+
jobs[jobId].progress = progress;
|
|
|
|
| 507 |
}
|
| 508 |
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs));
|
| 509 |
+
updateProgressBarDOM(jobId, jobs[jobId].progress);
|
| 510 |
}
|
| 511 |
}
|
| 512 |
}
|
| 513 |
}
|
| 514 |
})
|
| 515 |
.catch(err => {
|
| 516 |
+
console.error("پیگیری با خطا مواجه شد:", err);
|
| 517 |
+
const jobs = getJobs();
|
| 518 |
+
if (jobs[jobId]) {
|
| 519 |
+
jobs[jobId].status = 'failed';
|
| 520 |
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(jobs));
|
| 521 |
+
renderHistory();
|
| 522 |
+
}
|
| 523 |
});
|
| 524 |
}
|
| 525 |
|
| 526 |
+
function resumeActivePolls() {
|
| 527 |
+
const jobs = getJobs();
|
|
|
|
| 528 |
for (const id in jobs) {
|
| 529 |
if (jobs[id].status === 'processing') {
|
| 530 |
+
pollJobStatus(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
}
|
| 532 |
}
|
| 533 |
+
}
|
|
|
|
| 534 |
|
| 535 |
+
function updateProgressBarDOM(id, percent) {
|
| 536 |
const bar = document.getElementById(`progress-fill-${id}`);
|
| 537 |
const text = document.getElementById(`progress-text-${id}`);
|
| 538 |
if (bar) bar.style.width = `${percent}%`;
|
| 539 |
+
if (text && text.innerHTML.includes('%')) text.innerHTML = `${percent}%`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
}
|
| 541 |
|
| 542 |
+
// --- رندر ساختار لیست تاریخچه با ظاهر کاملا هماهنگ ---
|
| 543 |
function renderHistory() {
|
| 544 |
const list = document.getElementById('historyList');
|
| 545 |
const jobs = Object.values(getJobs()).reverse();
|
|
|
|
| 555 |
let title, description, percentageText, buttonText, buttonAction, buttonIcon;
|
| 556 |
|
| 557 |
if (job.status === 'processing') {
|
| 558 |
+
title = 'در حال بهبود کیفیت صدا';
|
| 559 |
+
description = 'سرور صوتی در حال اعمال پردازشها است. میتوانید از صفحه خارج شوید.';
|
| 560 |
percentageText = `${job.progress || 0}%`;
|
| 561 |
buttonText = 'در حال پیگیری...';
|
| 562 |
buttonIcon = '<i class="fas fa-clock me-2"></i>';
|
| 563 |
buttonAction = '';
|
| 564 |
} else if (job.status === 'completed') {
|
| 565 |
+
title = 'بهبود صدا با موفقیت تکمیل شد';
|
| 566 |
description = `نام فایل اصلی: <strong>${job.fileName}</strong>`;
|
| 567 |
percentageText = 'تکمیل شد';
|
| 568 |
+
buttonText = 'نمایش فایلهای نهایی';
|
| 569 |
buttonIcon = '<i class="fas fa-play-circle me-2"></i>';
|
| 570 |
buttonAction = `onclick="toggleHistoryItem('${job.job_id}')"`;
|
| 571 |
} else {
|
| 572 |
+
title = 'خطا در حین فرآیند بهبود صدا';
|
| 573 |
+
description = 'پردازش فایل صوتی شما روی سرور به دلیل خطا ناموفق بود.';
|
| 574 |
percentageText = 'خطا';
|
| 575 |
+
buttonText = 'خطا در پردازش';
|
| 576 |
buttonIcon = '<i class="fas fa-exclamation-triangle me-2"></i>';
|
| 577 |
buttonAction = '';
|
| 578 |
}
|
|
|
|
| 587 |
<div class="status-description">${description}</div>
|
| 588 |
<div class="progress-display">
|
| 589 |
<div class="progress-percentage" id="progress-text-${job.job_id}">${percentageText}</div>
|
| 590 |
+
<div class="queue-status-message" id="queue-message-${job.job_id}">
|
| 591 |
+
<i class="fas fa-hourglass-half fa-spin-pulse" style="--fa-animation-duration: 2s;"></i> درخواست در صف انجام است، لطفاً صبور باشید...
|
| 592 |
</div>
|
| 593 |
<div class="progress-bar-custom">
|
| 594 |
<div class="progress-bar-custom-fill" id="progress-fill-${job.job_id}" style="width: ${job.progress || 0}%"></div>
|
|
|
|
| 599 |
<button class="btn-status" ${buttonAction}>${buttonIcon} ${buttonText}</button>
|
| 600 |
</div>
|
| 601 |
</div>
|
| 602 |
+
${job.status === 'completed' ? `<div class="history-card-body">${getExpandedContent(job)}</div>` : ''}
|
| 603 |
</div>
|
| 604 |
${index < jobs.length - 1 ? '<hr class="history-separator">' : ''}
|
| 605 |
`;
|
|
|
|
| 616 |
});
|
| 617 |
return `
|
| 618 |
<div class="audio-player-wrapper">
|
| 619 |
+
<small class="d-block fw-bold text-muted mb-1" style="font-size:0.8rem">فایل صوتی اصلی شما:</small>
|
| 620 |
<audio controls id="original-audio-${job.job_id}" class="mini-player"></audio>
|
| 621 |
</div>
|
| 622 |
<div class="audio-player-wrapper mt-3">
|
| 623 |
+
<small class="d-block fw-bold text-info mb-1" style="font-size:0.8rem">فایل خروجی کاهش نویز (Denoised Audio):</small>
|
| 624 |
+
<audio controls src="${job.denoised_url}" class="mini-player"></audio>
|
|
|
|
|
|
|
|
|
|
| 625 |
</div>
|
| 626 |
<div class="audio-player-wrapper mt-3">
|
| 627 |
+
<small class="d-block fw-bold text-success mb-1" style="font-size:0.8rem">فایل خروجی بهبودیافته نهایی (Enhanced Audio):</small>
|
| 628 |
+
<audio controls src="${job.enhanced_url}" class="mini-player"></audio>
|
| 629 |
+
</div>
|
| 630 |
+
|
| 631 |
+
<div class="row g-2 mt-3">
|
| 632 |
+
<div class="col-6">
|
| 633 |
+
<button type="button" class="btn btn-sm btn-outline-info w-100 rounded-pill fw-bold btn-download-via-postmessage" data-url="${job.denoised_url}">
|
| 634 |
+
<i class="fas fa-download me-1"></i> دانلود نسخه بدون نویز
|
| 635 |
+
</button>
|
| 636 |
+
</div>
|
| 637 |
+
<div class="col-6">
|
| 638 |
+
<button type="button" class="btn btn-sm btn-success w-100 rounded-pill fw-bold btn-download-via-postmessage" data-url="${job.enhanced_url}">
|
| 639 |
+
<i class="fas fa-download me-1"></i> دانلود نسخه استودیویی
|
| 640 |
+
</button>
|
| 641 |
+
</div>
|
| 642 |
</div>
|
| 643 |
`;
|
| 644 |
}
|
| 645 |
|
| 646 |
function toggleHistoryItem(id) { document.getElementById(`history-${id}`).classList.toggle('expanded'); }
|
| 647 |
|
| 648 |
+
// --- مدیریت فرآیند لغو و مودالهای هشدار ---
|
| 649 |
let deleteId = null;
|
| 650 |
function openDeleteModal(id) { deleteId = id; document.getElementById('deleteModal').style.display = 'flex'; }
|
| 651 |
function closeModal() { document.getElementById('deleteModal').style.display = 'none'; deleteId = null; }
|
|
|
|
| 664 |
renderHistory();
|
| 665 |
closeModal();
|
| 666 |
};
|
| 667 |
+
|
| 668 |
document.getElementById('upgradeFromModalBtn').onclick = () => { parent.postMessage({ type: 'NAVIGATE_TO_PREMIUM', payload: { url: PREMIUM_URL } }, '*'); };
|
| 669 |
|
| 670 |
+
// --- مدیریت دریافت اشتراک و وضعیت کاربر از هسته اندروید ---
|
| 671 |
function isUserPaid(userObject) { return userObject && userObject.isLogin && userObject.accessible_pages && (userObject.accessible_pages.includes(PREMIUM_PAGE_ID) || userObject.accessible_pages.includes(parseInt(PREMIUM_PAGE_ID))); }
|
| 672 |
|
| 673 |
function updateSubscriptionBadge(status) {
|
|
|
|
| 695 |
}
|
| 696 |
});
|
| 697 |
|
|
|
|
| 698 |
document.getElementById('historyList').addEventListener('click', (e) => {
|
| 699 |
const downloadButton = e.target.closest('.btn-download-via-postmessage');
|
| 700 |
if(downloadButton) {
|
| 701 |
e.preventDefault();
|
| 702 |
+
const audioUrl = downloadButton.dataset.url;
|
| 703 |
if(audioUrl) {
|
| 704 |
parent.postMessage({ type: 'INITIATE_DOWNLOAD_FROM_URL', payload: { audioUrl: audioUrl } }, '*');
|
| 705 |
+
const originalText = downloadButton.innerHTML;
|
| 706 |
+
downloadButton.innerHTML = '<i class="fas fa-check me-1"></i> ارسال شد';
|
| 707 |
+
setTimeout(() => { downloadButton.innerHTML = originalText; }, 2000);
|
| 708 |
}
|
| 709 |
}
|
| 710 |
});
|
| 711 |
|
| 712 |
+
// --- فرآیند راهاندازی در ابتدای بارگذاری صفحه ---
|
| 713 |
initDB();
|
| 714 |
parent.postMessage({ type: 'REQUEST_USER_STATUS' }, '*');
|
| 715 |
</script>
|