Update index.html
Browse files- index.html +27 -47
index.html
CHANGED
|
@@ -89,7 +89,7 @@
|
|
| 89 |
textarea { min-height: 120px; resize: vertical; }
|
| 90 |
textarea:focus, input:focus, select:focus { border-color: var(--accent-primary); background: #fff; }
|
| 91 |
|
| 92 |
-
/* دکمه
|
| 93 |
.btn-main {
|
| 94 |
width: 100%; padding: 16px;
|
| 95 |
background: linear-gradient(135deg, var(--accent-primary), #3b5bdb);
|
|
@@ -97,11 +97,18 @@
|
|
| 97 |
font-size: 1.1rem; font-weight: 700; cursor: pointer;
|
| 98 |
display: flex; justify-content: center; align-items: center; gap: 10px;
|
| 99 |
box-shadow: 0 5px 15px var(--accent-glow);
|
| 100 |
-
transition: all 0.
|
| 101 |
}
|
| 102 |
.btn-main:hover {
|
| 103 |
-
transform: translateY(-
|
| 104 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
.btn-main:active { transform: scale(0.98); }
|
| 107 |
.btn-main:disabled { opacity: 0.7; cursor: not-allowed; filter: grayscale(1); }
|
|
@@ -236,7 +243,7 @@
|
|
| 236 |
|
| 237 |
<script>
|
| 238 |
const ACE_SPACE_URL = "https://ace-step-ace-step-v1-5.hf.space/";
|
| 239 |
-
let db;
|
| 240 |
|
| 241 |
// المانها
|
| 242 |
const ideaInput = document.getElementById('ideaInput');
|
|
@@ -268,12 +275,8 @@
|
|
| 268 |
// --- مدیریت پایگاه داده IndexedDB ---
|
| 269 |
function initDB() {
|
| 270 |
const request = indexedDB.open("alphaMusicDB", 1);
|
| 271 |
-
|
| 272 |
request.onerror = (event) => console.error("خطای IndexedDB:", event);
|
| 273 |
-
request.onsuccess = (event) => {
|
| 274 |
-
db = event.target.result;
|
| 275 |
-
loadHistory(); // بارگذاری سوابق پس از اتصال موفق
|
| 276 |
-
};
|
| 277 |
request.onupgradeneeded = (event) => {
|
| 278 |
const db = event.target.result;
|
| 279 |
db.createObjectStore("songs", { keyPath: "id" });
|
|
@@ -282,69 +285,45 @@
|
|
| 282 |
|
| 283 |
async function saveToHistory(idea, lyrics, audioUrl) {
|
| 284 |
try {
|
| 285 |
-
// دریافت فایل صوتی به صورت Blob
|
| 286 |
const response = await fetch(audioUrl);
|
| 287 |
const audioBlob = await response.blob();
|
| 288 |
-
|
| 289 |
const newItem = {
|
| 290 |
-
id: Date.now(), idea
|
| 291 |
date: new Date().toLocaleDateString('fa-IR', { hour: '2-digit', minute: '2-digit' })
|
| 292 |
};
|
| 293 |
-
|
| 294 |
const transaction = db.transaction(["songs"], "readwrite");
|
| 295 |
const store = transaction.objectStore("songs");
|
| 296 |
store.add(newItem);
|
| 297 |
|
| 298 |
-
// مدیریت محدودیت 10 آیتم
|
| 299 |
const countReq = store.count();
|
| 300 |
countReq.onsuccess = () => {
|
| 301 |
if (countReq.result > 10) {
|
| 302 |
-
|
| 303 |
-
cursorReq.onsuccess = (e) => {
|
| 304 |
const cursor = e.target.result;
|
| 305 |
-
if (cursor)
|
| 306 |
-
cursor.delete();
|
| 307 |
-
}
|
| 308 |
};
|
| 309 |
}
|
| 310 |
};
|
| 311 |
-
|
| 312 |
transaction.oncomplete = () => loadHistory();
|
| 313 |
-
|
| 314 |
} catch (error) {
|
| 315 |
console.error("خطا در ذخیره آهنگ:", error);
|
| 316 |
-
alert("خطایی در ذخیره آهنگ در مرورگر رخ داد. ممکن است لینک موقتی باشد.");
|
| 317 |
}
|
| 318 |
}
|
| 319 |
|
| 320 |
function loadHistory() {
|
| 321 |
if (!db) return;
|
| 322 |
-
const
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
allReq.onsuccess = () => {
|
| 327 |
-
const history = allReq.result.sort((a, b) => b.id - a.id); // جدیدترینها اول
|
| 328 |
historyList.innerHTML = '';
|
| 329 |
-
|
| 330 |
if (history.length === 0) {
|
| 331 |
historyList.innerHTML = '<div style="text-align:center; color:#999; padding:20px;">هنوز آهنگی نساختهاید</div>';
|
| 332 |
return;
|
| 333 |
}
|
| 334 |
-
|
| 335 |
history.forEach((item) => {
|
| 336 |
const div = document.createElement('div');
|
| 337 |
div.className = 'history-card';
|
| 338 |
-
div.innerHTML = `
|
| 339 |
-
<div class="h-info">
|
| 340 |
-
<div class="h-icon">🎵</div>
|
| 341 |
-
<div class="h-details">
|
| 342 |
-
<h4>${item.idea.substring(0, 30)}${item.idea.length > 30 ? '...' : ''}</h4>
|
| 343 |
-
<span>${item.date}</span>
|
| 344 |
-
</div>
|
| 345 |
-
</div>
|
| 346 |
-
<div class="h-play">▶ نمایش</div>
|
| 347 |
-
`;
|
| 348 |
div.onclick = () => openHistoryItem(item);
|
| 349 |
historyList.appendChild(div);
|
| 350 |
});
|
|
@@ -355,23 +334,20 @@
|
|
| 355 |
step1.style.display = 'none';
|
| 356 |
historySection.style.display = 'none';
|
| 357 |
|
| 358 |
-
// تبدیل Blob به URL قابل پخش
|
| 359 |
const audioURL = URL.createObjectURL(item.audioBlob);
|
| 360 |
-
|
| 361 |
const headerText = document.getElementById('resultHeaderText');
|
| 362 |
headerText.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> آهنگ آرشیو شده`;
|
| 363 |
headerText.style.color = 'var(--accent-primary)';
|
| 364 |
|
| 365 |
mainDownloadLink.href = audioURL;
|
| 366 |
mainDownloadLink.style.display = 'inline-block';
|
| 367 |
-
playerWrapper.innerHTML = `<audio controls autoplay src="${audioURL}"></audio>`;
|
| 368 |
finalLyricsBox.innerHTML = formatLyrics(item.lyrics);
|
| 369 |
|
| 370 |
finalResult.style.display = 'block';
|
| 371 |
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 372 |
}
|
| 373 |
|
| 374 |
-
// شروع به کار پایگاه داده
|
| 375 |
initDB();
|
| 376 |
|
| 377 |
// --- فرآیند اصلی ساخت آهنگ ---
|
|
@@ -435,12 +411,15 @@
|
|
| 435 |
processedUrls.add(fullUrl);
|
| 436 |
hasResult = true;
|
| 437 |
|
|
|
|
| 438 |
if (processedUrls.size === 1) {
|
| 439 |
mainDownloadLink.href = fullUrl;
|
| 440 |
mainDownloadLink.style.display = 'inline-block';
|
| 441 |
-
saveToHistory(idea, lyrics, fullUrl);
|
| 442 |
}
|
| 443 |
-
|
|
|
|
|
|
|
| 444 |
}
|
| 445 |
|
| 446 |
function traverse(obj) {
|
|
@@ -468,6 +447,7 @@
|
|
| 468 |
|
| 469 |
function formatLyrics(text) { return text.replace(/\[(.*?)\]/g, '<span class="lyrics-tag">[$1]</span>'); }
|
| 470 |
|
|
|
|
| 471 |
const canvas = document.getElementById('music-canvas');
|
| 472 |
const ctx = canvas.getContext('2d');
|
| 473 |
let t = 0;
|
|
|
|
| 89 |
textarea { min-height: 120px; resize: vertical; }
|
| 90 |
textarea:focus, input:focus, select:focus { border-color: var(--accent-primary); background: #fff; }
|
| 91 |
|
| 92 |
+
/* دکمه اصلی زیباتر شده */
|
| 93 |
.btn-main {
|
| 94 |
width: 100%; padding: 16px;
|
| 95 |
background: linear-gradient(135deg, var(--accent-primary), #3b5bdb);
|
|
|
|
| 97 |
font-size: 1.1rem; font-weight: 700; cursor: pointer;
|
| 98 |
display: flex; justify-content: center; align-items: center; gap: 10px;
|
| 99 |
box-shadow: 0 5px 15px var(--accent-glow);
|
| 100 |
+
transition: all 0.25s ease-out;
|
| 101 |
}
|
| 102 |
.btn-main:hover {
|
| 103 |
+
transform: translateY(-3px);
|
| 104 |
+
box-shadow: 0 10px 25px rgba(74, 108, 250, 0.35);
|
| 105 |
+
}
|
| 106 |
+
.btn-main:hover span {
|
| 107 |
+
transform: translateX(-4px); /* حرکت آیکون */
|
| 108 |
+
}
|
| 109 |
+
.btn-main span {
|
| 110 |
+
display: inline-block; /* برای اعمال transform */
|
| 111 |
+
transition: transform 0.25s ease-out;
|
| 112 |
}
|
| 113 |
.btn-main:active { transform: scale(0.98); }
|
| 114 |
.btn-main:disabled { opacity: 0.7; cursor: not-allowed; filter: grayscale(1); }
|
|
|
|
| 243 |
|
| 244 |
<script>
|
| 245 |
const ACE_SPACE_URL = "https://ace-step-ace-step-v1-5.hf.space/";
|
| 246 |
+
let db;
|
| 247 |
|
| 248 |
// المانها
|
| 249 |
const ideaInput = document.getElementById('ideaInput');
|
|
|
|
| 275 |
// --- مدیریت پایگاه داده IndexedDB ---
|
| 276 |
function initDB() {
|
| 277 |
const request = indexedDB.open("alphaMusicDB", 1);
|
|
|
|
| 278 |
request.onerror = (event) => console.error("خطای IndexedDB:", event);
|
| 279 |
+
request.onsuccess = (event) => { db = event.target.result; loadHistory(); };
|
|
|
|
|
|
|
|
|
|
| 280 |
request.onupgradeneeded = (event) => {
|
| 281 |
const db = event.target.result;
|
| 282 |
db.createObjectStore("songs", { keyPath: "id" });
|
|
|
|
| 285 |
|
| 286 |
async function saveToHistory(idea, lyrics, audioUrl) {
|
| 287 |
try {
|
|
|
|
| 288 |
const response = await fetch(audioUrl);
|
| 289 |
const audioBlob = await response.blob();
|
|
|
|
| 290 |
const newItem = {
|
| 291 |
+
id: Date.now(), idea, lyrics, audioBlob,
|
| 292 |
date: new Date().toLocaleDateString('fa-IR', { hour: '2-digit', minute: '2-digit' })
|
| 293 |
};
|
|
|
|
| 294 |
const transaction = db.transaction(["songs"], "readwrite");
|
| 295 |
const store = transaction.objectStore("songs");
|
| 296 |
store.add(newItem);
|
| 297 |
|
|
|
|
| 298 |
const countReq = store.count();
|
| 299 |
countReq.onsuccess = () => {
|
| 300 |
if (countReq.result > 10) {
|
| 301 |
+
store.openCursor().onsuccess = (e) => {
|
|
|
|
| 302 |
const cursor = e.target.result;
|
| 303 |
+
if (cursor) cursor.delete();
|
|
|
|
|
|
|
| 304 |
};
|
| 305 |
}
|
| 306 |
};
|
|
|
|
| 307 |
transaction.oncomplete = () => loadHistory();
|
|
|
|
| 308 |
} catch (error) {
|
| 309 |
console.error("خطا در ذخیره آهنگ:", error);
|
|
|
|
| 310 |
}
|
| 311 |
}
|
| 312 |
|
| 313 |
function loadHistory() {
|
| 314 |
if (!db) return;
|
| 315 |
+
const store = db.transaction(["songs"], "readonly").objectStore("songs");
|
| 316 |
+
store.getAll().onsuccess = (e) => {
|
| 317 |
+
const history = e.target.result.sort((a, b) => b.id - a.id);
|
|
|
|
|
|
|
|
|
|
| 318 |
historyList.innerHTML = '';
|
|
|
|
| 319 |
if (history.length === 0) {
|
| 320 |
historyList.innerHTML = '<div style="text-align:center; color:#999; padding:20px;">هنوز آهنگی نساختهاید</div>';
|
| 321 |
return;
|
| 322 |
}
|
|
|
|
| 323 |
history.forEach((item) => {
|
| 324 |
const div = document.createElement('div');
|
| 325 |
div.className = 'history-card';
|
| 326 |
+
div.innerHTML = `<div class="h-info"><div class="h-icon">🎵</div><div class="h-details"><h4>${item.idea.substring(0, 30)}${item.idea.length > 30 ? '...' : ''}</h4><span>${item.date}</span></div></div><div class="h-play">▶ نمایش</div>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
div.onclick = () => openHistoryItem(item);
|
| 328 |
historyList.appendChild(div);
|
| 329 |
});
|
|
|
|
| 334 |
step1.style.display = 'none';
|
| 335 |
historySection.style.display = 'none';
|
| 336 |
|
|
|
|
| 337 |
const audioURL = URL.createObjectURL(item.audioBlob);
|
|
|
|
| 338 |
const headerText = document.getElementById('resultHeaderText');
|
| 339 |
headerText.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> آهنگ آرشیو شده`;
|
| 340 |
headerText.style.color = 'var(--accent-primary)';
|
| 341 |
|
| 342 |
mainDownloadLink.href = audioURL;
|
| 343 |
mainDownloadLink.style.display = 'inline-block';
|
| 344 |
+
playerWrapper.innerHTML = `<audio controls autoplay src="${audioURL}"></audio>`; // autoplay اضافه شد
|
| 345 |
finalLyricsBox.innerHTML = formatLyrics(item.lyrics);
|
| 346 |
|
| 347 |
finalResult.style.display = 'block';
|
| 348 |
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 349 |
}
|
| 350 |
|
|
|
|
| 351 |
initDB();
|
| 352 |
|
| 353 |
// --- فرآیند اصلی ساخت آهنگ ---
|
|
|
|
| 411 |
processedUrls.add(fullUrl);
|
| 412 |
hasResult = true;
|
| 413 |
|
| 414 |
+
// برای آهنگ اول، دکمه دانلود اصلی را تنظیم و در سابقه ذخیره کن
|
| 415 |
if (processedUrls.size === 1) {
|
| 416 |
mainDownloadLink.href = fullUrl;
|
| 417 |
mainDownloadLink.style.display = 'inline-block';
|
| 418 |
+
saveToHistory(idea, lyrics, fullUrl);
|
| 419 |
}
|
| 420 |
+
|
| 421 |
+
// autoplay برای آهنگ جدید اضافه شد
|
| 422 |
+
playerWrapper.innerHTML += `<div class="audio-item"><audio controls autoplay src="${fullUrl}"></audio></div>`;
|
| 423 |
}
|
| 424 |
|
| 425 |
function traverse(obj) {
|
|
|
|
| 447 |
|
| 448 |
function formatLyrics(text) { return text.replace(/\[(.*?)\]/g, '<span class="lyrics-tag">[$1]</span>'); }
|
| 449 |
|
| 450 |
+
// انیمیشن پسزمینه
|
| 451 |
const canvas = document.getElementById('music-canvas');
|
| 452 |
const ctx = canvas.getContext('2d');
|
| 453 |
let t = 0;
|