Spaces:
Sleeping
Sleeping
Download UI.html from Ali112008/Quran_Reels_Generator: direct link, hf CLI and curl.
- Browser
- Download file 192 kB
-
https://huggingface.co/spaces/Ali112008/Quran_Reels_Generator/resolve/main/UI.html
- Command line
-
hf download hf://spaces/Ali112008/Quran_Reels_Generator/UI.html
-
curl -L -o UI.html https://huggingface.co/spaces/Ali112008/Quran_Reels_Generator/resolve/main/UI.html
192 kB
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>ุตุงูุน ุงูุฑููุฒ ุงููุฑุขูู</title>
<meta name="theme-color" content="#0f0f0f">
<meta property="og:title" content="ุตุงูุน ุงูุฑููุฒ ุงููุฑุขูู ๐ฌ">
<meta property="og:description" content="ุฃูุดุฆ ููุฏูููุงุช ูุฑุขููุฉ ุงุญุชุฑุงููุฉ ูู ุซูุงูู">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐จ CSS Variables & Base
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
:root {
/* Dark Theme (Default) */
--bg-primary: #0f0f0f;
--bg-secondary: #1a1a1a;
--bg-card: #1f1f1f;
--bg-input: #2a2a2a;
--text-primary: #ffffff;
--text-secondary: #a0a0a0;
--text-muted: #666666;
--accent: #c9a227;
--accent-light: #e6c458;
--accent-dark: #9a7b1c;
--success: #22c55e;
--danger: #ef4444;
--warning: #f59e0b;
--border: rgba(255,255,255,0.08);
--shadow: 0 4px 24px rgba(0,0,0,0.4);
--radius: 16px;
--radius-sm: 10px;
}
.light-theme {
--bg-primary: #f8f8f8;
--bg-secondary: #ffffff;
--bg-card: #ffffff;
--bg-input: #f0f0f0;
--text-primary: #1a1a1a;
--text-secondary: #555555;
--text-muted: #999999;
--accent: #b8941f;
--accent-light: #d4b030;
--accent-dark: #8a6d15;
--border: rgba(0,0,0,0.08);
--shadow: 0 4px 24px rgba(0,0,0,0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'IBM Plex Sans Arabic', sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100dvh;
transition: background 0.3s, color 0.3s;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ App Container
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.app {
max-width: 480px;
margin: 0 auto;
min-height: 100dvh;
display: flex;
flex-direction: column;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Header
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.header {
padding: 20px 20px 16px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--border);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 44px;
height: 44px;
background: linear-gradient(135deg, var(--accent), var(--accent-light));
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
}
.logo-text h1 {
font-family: 'Amiri', serif;
font-size: 1.4rem;
background: linear-gradient(135deg, var(--accent-light), var(--accent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.logo-text span {
font-size: 0.7rem;
color: var(--text-muted);
}
.header-actions {
display: flex;
gap: 8px;
}
.icon-btn {
width: 42px;
height: 42px;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
background: var(--bg-card);
color: var(--text-secondary);
font-size: 1.1rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.icon-btn:hover {
border-color: var(--accent);
color: var(--accent);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Tabs Navigation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.tabs-nav {
display: flex;
padding: 0 20px;
gap: 4px;
border-bottom: 1px solid var(--border);
background: var(--bg-secondary);
}
.tab-btn {
flex: 1;
padding: 14px 16px;
background: none;
border: none;
color: var(--text-muted);
font-family: inherit;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
position: relative;
transition: color 0.2s;
}
.tab-btn.active {
color: var(--accent);
}
.tab-btn::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background: var(--accent);
border-radius: 2px;
transition: width 0.2s;
}
.tab-btn.active::after {
width: 60%;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Tab Content
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.tab-content {
flex: 1;
overflow-y: auto;
padding: 20px;
}
.tab-panel {
display: none;
animation: fadeIn 0.3s ease;
}
.tab-panel.active {
display: block;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Form Elements
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.form-group {
margin-bottom: 18px;
}
.form-label {
display: block;
font-size: 0.85rem;
font-weight: 500;
color: var(--text-secondary);
margin-bottom: 8px;
}
.form-select, .form-input {
width: 100%;
height: 52px;
padding: 0 16px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
font-family: inherit;
font-size: 1rem;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.form-select:focus, .form-input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.15);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ข Ayah Selection
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.ayah-selector {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 16px;
margin-bottom: 18px;
}
.ayah-selector-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.ayah-selector-title {
font-size: 0.85rem;
font-weight: 500;
color: var(--text-secondary);
}
.ayah-selector-range {
display: flex;
align-items: center;
gap: 8px;
}
.ayah-num-display {
display: flex;
align-items: center;
gap: 6px;
}
.ayah-num-display input {
width: 60px;
height: 44px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text-primary);
font-family: inherit;
font-size: 1.1rem;
font-weight: 700;
text-align: center;
outline: none;
transition: border-color 0.2s;
}
.ayah-num-display input:focus {
border-color: var(--accent);
}
.ayah-num-display button {
width: 36px;
height: 36px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--accent);
font-size: 1.2rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.ayah-num-display button:hover {
background: var(--accent);
color: #000;
}
.ayah-separator {
color: var(--text-muted);
font-size: 0.9rem;
padding: 0 4px;
}
.ayah-label {
font-size: 0.75rem;
color: var(--text-muted);
text-align: center;
margin-top: 4px;
}
.ayah-row {
display: flex;
gap: 12px;
}
.ayah-row .form-group {
flex: 1;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Buttons
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.btn-primary {
width: 100%;
height: 56px;
background: linear-gradient(135deg, var(--accent), var(--accent-light));
border: none;
border-radius: var(--radius-sm);
color: #000;
font-family: inherit;
font-size: 1.05rem;
font-weight: 700;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
transition: transform 0.2s, box-shadow 0.2s;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px rgba(201, 162, 39, 0.3);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-secondary {
flex: 1;
height: 48px;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
font-family: inherit;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: all 0.2s;
}
.btn-secondary:hover {
border-color: var(--accent);
color: var(--accent);
}
.btn-row {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.btn-stop {
background: var(--danger);
border: none;
color: #fff;
}
.btn-stop:hover {
background: #dc2626;
color: #fff;
}
.random-btn {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--accent);
font-size: 0.75rem;
padding: 4px 10px;
cursor: pointer;
transition: all 0.2s;
}
.random-btn:hover {
background: var(--accent);
color: #000;
border-color: var(--accent);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐๏ธ Toggle Switches
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.toggle-group {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
overflow: hidden;
}
.toggle-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
border-bottom: 1px solid var(--border);
}
.toggle-item:last-child {
border-bottom: none;
}
.toggle-info h4 {
font-size: 0.95rem;
font-weight: 500;
margin-bottom: 2px;
}
.toggle-info span {
font-size: 0.75rem;
color: var(--text-muted);
}
.switch {
position: relative;
width: 48px;
height: 26px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.switch-slider {
position: absolute;
inset: 0;
background: var(--bg-input);
border-radius: 26px;
cursor: pointer;
transition: background 0.3s;
}
.switch-slider::before {
content: '';
position: absolute;
width: 20px;
height: 20px;
left: 3px;
bottom: 3px;
background: #fff;
border-radius: 50%;
transition: transform 0.3s;
}
.switch input:checked + .switch-slider {
background: var(--accent);
}
.switch input:checked + .switch-slider::before {
transform: translateX(22px);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Progress Section
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.progress-section {
display: none;
text-align: center;
padding: 30px 20px;
}
.progress-section.active {
display: block;
}
.progress-ring {
width: 140px;
height: 140px;
margin: 0 auto 20px;
position: relative;
}
.progress-ring svg {
transform: rotate(-90deg);
}
.progress-ring circle {
fill: none;
stroke-width: 8;
stroke-linecap: round;
}
.progress-ring .bg {
stroke: var(--bg-input);
}
.progress-ring .fill {
stroke: var(--accent);
stroke-dasharray: 408;
stroke-dashoffset: 408;
transition: stroke-dashoffset 0.5s ease;
}
.progress-percent {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-weight: 700;
color: var(--text-primary);
}
.progress-status {
font-size: 0.95rem;
color: var(--text-secondary);
margin-bottom: 8px;
}
.progress-eta {
font-size: 0.85rem;
color: var(--accent);
font-family: monospace;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Result Section
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.result-section {
display: none;
text-align: center;
}
.result-section.active {
display: block;
}
.result-video {
width: 100%;
border-radius: var(--radius);
background: #000;
margin-bottom: 16px;
}
.result-actions {
display: flex;
gap: 10px;
}
.result-actions .btn-secondary {
flex: 1;
}
.btn-download {
background: var(--success);
border: none;
color: #fff;
}
.btn-download:hover {
background: #16a34a;
color: #fff;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ History Section
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.history-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.history-header h3 {
font-size: 1rem;
font-weight: 600;
}
.history-empty {
text-align: center;
padding: 40px 20px;
color: var(--text-muted);
}
.history-empty-icon {
font-size: 3rem;
margin-bottom: 12px;
opacity: 0.5;
}
.history-item {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 14px;
margin-bottom: 10px;
}
.history-item-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 8px;
}
.history-item-title {
font-weight: 600;
font-size: 0.95rem;
}
.history-item-status {
font-size: 0.85rem;
}
.history-item-meta {
font-size: 0.8rem;
color: var(--text-muted);
margin-bottom: 10px;
}
.history-item-actions {
display: flex;
gap: 8px;
}
.history-item-actions button,
.history-item-actions a {
flex: 1;
height: 38px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text-primary);
font-family: inherit;
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
text-decoration: none;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
transition: all 0.2s;
}
.history-item-actions button:hover,
.history-item-actions a:hover {
border-color: var(--accent);
color: var(--accent);
}
.history-item-actions .btn-delete {
color: var(--danger);
border-color: rgba(239, 68, 68, 0.3);
}
.history-item-actions .btn-delete:hover {
background: rgba(239, 68, 68, 0.1);
border-color: var(--danger);
}
.history-timer {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 8px;
background: rgba(245, 158, 11, 0.1);
border-radius: 6px;
font-size: 0.75rem;
color: var(--warning);
margin-right: 8px;
}
.history-timer.urgent {
background: rgba(239, 68, 68, 0.1);
color: var(--danger);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Settings Panel
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.settings-section {
margin-bottom: 24px;
}
.settings-section h4 {
font-size: 0.85rem;
font-weight: 600;
color: var(--accent);
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid var(--border);
}
.settings-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 0;
border-bottom: 1px solid var(--border);
}
.settings-row:last-child {
border-bottom: none;
}
.settings-label {
font-size: 0.9rem;
color: var(--text-primary);
}
.settings-controls {
display: flex;
align-items: center;
gap: 10px;
}
.color-picker {
width: 36px;
height: 36px;
border: 2px solid var(--border);
border-radius: 8px;
cursor: pointer;
overflow: hidden;
}
.color-picker::-webkit-color-swatch-wrapper {
padding: 0;
}
.color-picker::-webkit-color-swatch {
border: none;
border-radius: 6px;
}
.size-slider {
width: 80px;
height: 4px;
accent-color: var(--accent);
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Toast Notifications
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.toast-container {
position: fixed;
bottom: 100px;
left: 50%;
transform: translateX(-50%);
z-index: 1000;
display: flex;
flex-direction: column;
gap: 8px;
pointer-events: none;
}
.toast {
padding: 12px 20px;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
box-shadow: var(--shadow);
font-size: 0.9rem;
animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
pointer-events: auto;
}
.toast.success {
border-color: var(--success);
color: var(--success);
}
.toast.error {
border-color: var(--danger);
color: var(--danger);
}
@keyframes toastIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
from { opacity: 1; }
to { opacity: 0; }
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ Preview Box (Settings)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.preview-box {
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
border-radius: var(--radius);
padding: 30px 20px;
text-align: center;
margin-bottom: 20px;
position: relative;
overflow: hidden;
}
.preview-box::before {
content: '';
position: absolute;
inset: 0;
background: radial-gradient(circle at 50% 50%, transparent 30%, rgba(0,0,0,0.6) 100%);
pointer-events: none;
}
.preview-ar {
font-family: 'Amiri', serif;
font-size: 1.5rem;
margin-bottom: 10px;
position: relative;
z-index: 1;
}
.preview-en {
font-size: 0.85rem;
color: #ccc;
position: relative;
z-index: 1;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง Advanced Options
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.advanced-toggle {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 12px;
background: var(--bg-card);
border: 1px dashed var(--border);
border-radius: var(--radius-sm);
color: var(--text-muted);
font-size: 0.85rem;
cursor: pointer;
margin-bottom: 16px;
transition: all 0.2s;
}
.advanced-toggle:hover {
border-color: var(--accent);
color: var(--accent);
}
.advanced-options {
display: none;
}
.advanced-options.show {
display: block;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ Responsive
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
@media (max-width: 400px) {
.header {
padding: 16px 16px 12px;
}
.tab-content {
padding: 16px;
}
.logo-text h1 {
font-size: 1.2rem;
}
}
</style>
</head>
<body>
<div class="app">
<!-- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Header
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ -->
<header class="header">
<div class="logo">
<div class="logo-icon">๐ฌ</div>
<div class="logo-text">
<h1>ุตุงูุน ุงูุฑููุฒ ุงููุฑุขูู</h1>
<span>ูุณุฎุฉ ุงูุชูุฑุจู</span>
</div>
</div>
<div class="header-actions">
<button class="icon-btn" onclick="toggleTheme()" id="themeBtn">๐</button>
</div>
</header>
<!-- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Tabs Navigation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ -->
<nav class="tabs-nav">
<button class="tab-btn active" data-tab="main">๐ ุงูุฑุฆูุณูุฉ</button>
<button class="tab-btn" data-tab="batch">๐ฆ ุฏูุนุฉ ู
ุชุนุฏุฏุฉ</button>
<button class="tab-btn" data-tab="history">๐ ุงูุณุฌู</button>
<button class="tab-btn" data-tab="settings">โ๏ธ ุฅุนุฏุงุฏุงุช</button>
<button class="tab-btn" data-tab="autopublish">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="display: inline-block; vertical-align: middle; margin-left: 2px;"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>
ูุดุฑ ุชููุงุฆู
</button>
</nav>
<!-- โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Tab Content
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ -->
<main class="tab-content">
<!-- ๐ Main Tab -->
<div class="tab-panel active" id="main-panel">
<form id="videoForm">
<!-- ุงููุงุฑุฆ -->
<div class="form-group">
<label class="form-label">๐ค ุงููุงุฑุฆ</label>
<select class="form-select" id="reciterSelect"></select>
</div>
<!-- ุงูุณูุฑุฉ -->
<div class="form-group">
<label class="form-label">๐ ุงูุณูุฑุฉ</label>
<select class="form-select" id="surahSelect"></select>
</div>
<!-- ุงูุขูุงุช -->
<div class="ayah-selector">
<div class="ayah-selector-header">
<span class="ayah-selector-title">๐ ูุทุงู ุงูุขูุงุช</span>
<span id="maxAyahHint" style="font-size: 0.75rem; color: var(--text-muted);"></span>
</div>
<div class="ayah-selector-range">
<div class="ayah-num-display">
<button type="button" onclick="adjustAyah('startAyah', -1)">โ</button>
<input type="number" id="startAyah" value="1" min="1" max="286">
<button type="button" onclick="adjustAyah('startAyah', 1)">+</button>
</div>
<span class="ayah-separator">โ</span>
<div class="ayah-num-display">
<button type="button" onclick="adjustAyah('endAyah', -1)">โ</button>
<input type="number" id="endAyah" value="5" min="1" max="286">
<button type="button" onclick="adjustAyah('endAyah', 1)">+</button>
</div>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 6px;">
<span class="ayah-label">ู
ู ุขูุฉ</span>
<span class="ayah-label">ุฅูู ุขูุฉ</span>
</div>
<!-- ุนุฑุถ ุงูููุช ุงูุชูุฑูุจู -->
<div id="estimatedTimeDisplay" style="text-align: center; margin-top: 10px; padding: 8px; background: var(--bg-input); border-radius: 8px; font-size: 0.85rem;">
โฑ๏ธ ุงูููุช ุงูุชูุฑูุจู: <span id="estimatedTime" style="color: var(--accent); font-weight: 600;">--:--</span>
</div>
</div>
<!-- ุฎูุงุฑุงุช ุณุฑูุนุฉ -->
<div class="toggle-group" style="margin-bottom: 18px;">
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชุบููุฑ ุงูุฎูููุฉ ู
ุน ุงูุขูุงุช</h4>
<span>ูู ุขูุฉ ุจุฎูููุฉ ู
ุฎุชููุฉ</span>
</div>
<label class="switch">
<input type="checkbox" id="dynamicBg" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชููุฌ ุงููุต</h4>
<span>ุชุฃุซูุฑ ูุงูุฉ ุญูู ุงููุต</span>
</div>
<label class="switch">
<input type="checkbox" id="useGlow" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชุนุชูู
ุณููู
ุงุฆู</h4>
<span>Vignette effect</span>
</div>
<label class="switch">
<input type="checkbox" id="useVignette" checked>
<span class="switch-slider"></span>
</label>
</div>
</div>
<!-- ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ -->
<div class="advanced-toggle" onclick="toggleAdvanced()">
<span>โก</span>
<span>ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ</span>
</div>
<div class="advanced-options" id="advancedOptions">
<div class="form-group">
<label class="form-label">ุณูุงุณุฉ ุงูููุฏูู (FPS)</label>
<select class="form-select" id="fpsSelect">
<option value="15">๐ 15 FPS - ุณุฑูุน ุฌุฏุงู</option>
<option value="20" selected>โ๏ธ 20 FPS - ู
ุชูุงุฒู</option>
<option value="24">๐ฌ 24 FPS - ุณููู
ุงุฆู</option>
<option value="30">๐ 30 FPS - ุงูุฃูุซุฑ ุณูุงุณุฉ</option>
</select>
</div>
<div class="form-group">
<label class="form-label">ุฌูุฏุฉ ุงูููุฏูู</label>
<select class="form-select" id="qualitySelect">
<option value="720">โก 720p HD - ุงูุฃุณุฑุน</option>
<option value="1080">๐ 1080p FHD</option>
</select>
</div>
<div class="form-group">
<label class="form-label">๐ ุฃุจุนุงุฏ ุงูููุฏูู</label>
<select class="form-select" id="aspectRatio">
<option value="9:16">๐ฑ 9:16 - ุฑููุฒ / ุชูู ุชูู</option>
<option value="1:1">โฌ 1:1 - ุณููุฑ / ุงูุณุชุฌุฑุงู
</option>
<option value="16:9">๐ฅ๏ธ 16:9 - ููุชููุจ</option>
</select>
</div>
<div class="form-group">
<label class="form-label">โ๏ธ ุฎุท ุงูู
ุตุญู</label>
<select class="form-select" id="fontSelect">
<option value="Arabic">Arabic - ุงูุฎุท ุงูุงูุชุฑุงุถู</option>
<option value="Classic">Classic - ููุงุณูู</option>
<option value="Amiri">Amiri - ุฃู
ูุฑู</option>
<option value="Uthmani">Uthmani - ุนุซู
ุงูู</option>
</select>
</div>
<div class="form-group">
<label class="form-label">๐ค ุฎุท ุงูุชุฑุฌู
ุฉ</label>
<select class="form-select" id="fontEnSelect">
<option value="English">English - ุงูุงูุชุฑุงุถู</option>
<option value="Cinzel">Cinzel - ููุงุณููู</option>
<option value="Playfair">Playfair - ุฃููู</option>
<option value="Lora">Lora - ุนุตุฑู</option>
</select>
</div>
<div class="toggle-item" style="border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px;">
<div class="toggle-info">
<h4>ุจุญุซ ุฎูููุฉ ู
ุฎุตุต</h4>
</div>
<label class="switch">
<input type="checkbox" id="useSearch" onchange="toggleSearchInput()">
<span class="switch-slider"></span>
</label>
</div>
<div class="form-group" id="searchInputGroup" style="display: none;">
<input type="text" class="form-input" id="bgQuery" placeholder="ุงูุชุจ: ุจุญุฑุ ุณู
ุงุกุ ุฌุจุงู...">
</div>
</div>
<!-- ุฃุฒุฑุงุฑ ุงูุชุญูู
-->
<div class="btn-row">
<button type="button" class="btn-secondary" onclick="randomize()">๐ฒ ุนุดูุงุฆู</button>
</div>
<button type="submit" class="btn-primary" id="submitBtn">โจ ุฅูุดุงุก ุงูููุฏูู</button>
<button type="button" class="btn-primary btn-stop" id="stopBtn" style="display: none;">๐ ุฅููุงู</button>
</form>
<!-- Progress Section -->
<div class="progress-section" id="progressSection">
<div class="progress-ring">
<svg width="140" height="140">
<circle class="bg" cx="70" cy="70" r="65"></circle>
<circle class="fill" id="progressCircle" cx="70" cy="70" r="65"></circle>
</svg>
<div class="progress-percent" id="progressPercent">0%</div>
</div>
<div class="progress-status" id="progressStatus">ุฌุงุฑู ุงูุชุญุถูุฑ...</div>
<div class="progress-eta" id="progressEta" style="display: none;">
โณ ู
ุชุจูู: <span id="etaTime">--:--</span>
</div>
</div>
<!-- Result Section -->
<div class="result-section" id="resultSection">
<video class="result-video" id="videoPlayer" controls playsinline></video>
<div class="result-actions">
<a class="btn-secondary btn-download" id="downloadLink" download>โฌ๏ธ ุชุญู
ูู</a>
<button class="btn-secondary" onclick="resetForm()">๐ ููุฏูู ุฌุฏูุฏ</button>
</div>
</div>
</div>
<!-- ๐ฆ Batch Tab -->
<div class="tab-panel" id="batch-panel">
<div class="batch-header">
<h3>๐ฆ ุฅูุดุงุก ุฏูุนุฉ ููุฏูููุงุช</h3>
<p style="color: var(--text-muted); font-size: 0.85rem; margin-top: 4px;">
ุฃุถู ููุฏูููุงุช ูููุงุฆู
ุฉ ุซู
ุงุจุฏุฃ ุงูุฅูุดุงุก
</p>
</div>
<!-- ๐ค ุงููุงุฑุฆ -->
<div class="form-group">
<label class="form-label">๐ค ุงููุงุฑุฆ</label>
<select class="form-select" id="batchReciterSelect"></select>
</div>
<!-- ๐ ุงูุณูุฑุฉ -->
<div class="form-group">
<label class="form-label">๐ ุงูุณูุฑุฉ</label>
<select class="form-select" id="batchSurahSelect"></select>
</div>
<!-- ๐ ุงูุขูุงุช -->
<div class="ayah-selector">
<div class="ayah-selector-header">
<span class="ayah-selector-title">๐ ูุทุงู ุงูุขูุงุช</span>
</div>
<div class="ayah-selector-range">
<div class="ayah-num-display">
<button type="button" onclick="adjustBatchAyah('batchStartAyah', -1)">โ</button>
<input type="number" id="batchStartAyah" value="1" min="1">
<button type="button" onclick="adjustBatchAyah('batchStartAyah', 1)">+</button>
</div>
<span class="ayah-separator">โ</span>
<div class="ayah-num-display">
<button type="button" onclick="adjustBatchAyah('batchEndAyah', -1)">โ</button>
<input type="number" id="batchEndAyah" value="5" min="1">
<button type="button" onclick="adjustBatchAyah('batchEndAyah', 1)">+</button>
</div>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 6px;">
<span class="ayah-label">ู
ู ุขูุฉ</span>
<span class="ayah-label">ุฅูู ุขูุฉ</span>
</div>
<!-- ุนุฑุถ ุงูููุช ุงูุชูุฑูุจู ููุฏูุนุฉ -->
<div id="batchEstimatedTimeDisplay" style="text-align: center; margin-top: 10px; padding: 8px; background: var(--bg-input); border-radius: 8px; font-size: 0.85rem;">
โฑ๏ธ ุงูููุช ุงูุชูุฑูุจู: <span id="batchEstimatedTime" style="color: var(--accent); font-weight: 600;">--:--</span>
</div>
</div>
<!-- โจ Effects -->
<div class="toggle-group" style="margin-bottom: 18px;">
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชุบููุฑ ุงูุฎูููุฉ</h4>
<span>ูู ุขูุฉ ุจุฎูููุฉ ู
ุฎุชููุฉ</span>
</div>
<label class="switch">
<input type="checkbox" id="batchDynamicBg" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชููุฌ ุงููุต</h4>
</div>
<label class="switch">
<input type="checkbox" id="batchUseGlow" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชุนุชูู
ุณููู
ุงุฆู</h4>
</div>
<label class="switch">
<input type="checkbox" id="batchUseVignette" checked>
<span class="switch-slider"></span>
</label>
</div>
</div>
<!-- ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ ููุฏูุนุฉ -->
<div class="advanced-toggle" onclick="toggleBatchAdvanced()">
<span>โก</span>
<span>ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ</span>
</div>
<div class="advanced-options" id="batchAdvancedOptions">
<div class="form-group">
<label class="form-label">ุณูุงุณุฉ ุงูููุฏูู (FPS)</label>
<select class="form-select" id="batchFpsSelect">
<option value="15">๐ 15 FPS - ุณุฑูุน ุฌุฏุงู</option>
<option value="20" selected>โ๏ธ 20 FPS - ู
ุชูุงุฒู</option>
<option value="24">๐ฌ 24 FPS - ุณููู
ุงุฆู</option>
<option value="30">๐ 30 FPS - ุงูุฃูุซุฑ ุณูุงุณุฉ</option>
</select>
</div>
<div class="form-group">
<label class="form-label">ุฌูุฏุฉ ุงูููุฏูู</label>
<select class="form-select" id="batchQualitySelect">
<option value="720">โก 720p HD - ุงูุฃุณุฑุน</option>
<option value="1080">๐ 1080p FHD</option>
</select>
</div>
<div class="form-group">
<label class="form-label">๐ ุฃุจุนุงุฏ ุงูููุฏูู</label>
<select class="form-select" id="batchAspectRatio">
<option value="9:16">๐ฑ 9:16 - ุฑููุฒ / ุชูู ุชูู</option>
<option value="1:1">โฌ 1:1 - ุณููุฑ / ุงูุณุชุฌุฑุงู
</option>
<option value="16:9">๐ฅ๏ธ 16:9 - ููุชููุจ</option>
</select>
</div>
<div class="form-group">
<label class="form-label">โ๏ธ ุฎุท ุงูู
ุตุญู</label>
<select class="form-select" id="batchFontSelect">
<option value="Arabic">Arabic - ุงูุฎุท ุงูุงูุชุฑุงุถู</option>
<option value="Classic">Classic - ููุงุณูู</option>
<option value="Amiri">Amiri - ุฃู
ูุฑู</option>
<option value="Uthmani">Uthmani - ุนุซู
ุงูู</option>
</select>
</div>
<div class="form-group">
<label class="form-label">๐ค ุฎุท ุงูุชุฑุฌู
ุฉ</label>
<select class="form-select" id="batchFontEnSelect">
<option value="English">English - ุงูุงูุชุฑุงุถู</option>
<option value="Cinzel">Cinzel - ููุงุณููู</option>
<option value="Playfair">Playfair - ุฃููู</option>
<option value="Lora">Lora - ุนุตุฑู</option>
</select>
</div>
<div class="toggle-item" style="border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px;">
<div class="toggle-info">
<h4>ุจุญุซ ุฎูููุฉ ู
ุฎุตุต</h4>
</div>
<label class="switch">
<input type="checkbox" id="batchUseSearch" onchange="toggleBatchSearchInput()">
<span class="switch-slider"></span>
</label>
</div>
<div class="form-group" id="batchSearchInputGroup" style="display: none;">
<input type="text" class="form-input" id="batchBgQuery" placeholder="ุงูุชุจ: ุจุญุฑุ ุณู
ุงุกุ ุฌุจุงู...">
</div>
</div>
<!-- ๐ค ุงุฎุชูุงุฑ ุงููุฑุงุก ููุนุดูุงุฆู -->
<div class="form-group" style="margin-top: 16px;">
<div style="display: flex; justify-content: space-between; align-items: center; cursor: pointer;" onclick="toggleReciterFilter()">
<label class="form-label" style="margin: 0;">๐ค ูุฑุงุก ุงูุนุดูุงุฆู</label>
<span id="reciterFilterToggle" style="font-size: 1.2rem; transition: transform 0.3s;">โผ</span>
</div>
<div id="reciterFilterSection" style="display: none; margin-top: 12px; padding: 12px; background: var(--bg-input); border-radius: 8px; max-height: 200px; overflow-y: auto;">
<div style="display: flex; gap: 8px; margin-bottom: 10px;">
<button type="button" class="btn-secondary" style="flex: 1; padding: 6px; font-size: 0.75rem;" onclick="selectAllReciters()">ุชุญุฏูุฏ ุงููู</button>
<button type="button" class="btn-secondary" style="flex: 1; padding: 6px; font-size: 0.75rem;" onclick="deselectAllReciters()">ุฅูุบุงุก ุงููู</button>
</div>
<div id="reciterCheckboxes" style="display: flex; flex-direction: column; gap: 6px;">
<!-- ุณูุชู
ู
ูุคูุง ุจุงูุฌุงูุงุณูุฑูุจุช -->
</div>
</div>
</div>
<!-- ุฃุฒุฑุงุฑ ุงูุชุญูู
-->
<div class="btn-row">
<button type="button" class="btn-secondary" onclick="randomizeBatch()">๐ฒ ุนุดูุงุฆู</button>
</div>
<!-- ุฒุฑ ุงูุฅุถุงูุฉ -->
<button type="button" class="btn-primary" onclick="addToBatchList()">
โ ุฅุถุงูุฉ ูููุงุฆู
ุฉ
</button>
<!-- ูุงุฆู
ุฉ ุงูููุฏูููุงุช -->
<div class="batch-list-section" style="margin-top: 24px;">
<div class="history-header" style="margin-bottom: 12px;">
<h4 style="font-size: 0.95rem;">๐ ูุงุฆู
ุฉ ุงูููุฏูููุงุช (<span id="batchCount">0</span>/10)</h4>
<button class="btn-secondary" style="width: auto; height: 32px; padding: 0 10px; font-size: 0.75rem;" onclick="clearBatchList()">๐๏ธ ู
ุณุญ ุงููู</button>
</div>
<div id="batchList" style="max-height: 350px; overflow-y: auto;">
<div class="history-empty" id="batchListEmpty">
<p style="font-size: 0.85rem;">ูู
ุชุชู
ุฅุถุงูุฉ ุฃู ููุฏูููุงุช</p>
</div>
</div>
</div>
<!-- ุงูููุช ุงูููู ููุฏูุนุฉ -->
<div id="batchTotalTimeDisplay" style="text-align: center; margin-top: 16px; padding: 12px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; display: none;">
โฑ๏ธ ุงูููุช ุงูููู ุงูุชูุฑูุจู: <span id="batchTotalTime" style="color: var(--accent); font-weight: 600; font-size: 1.1rem;">--:--</span>
</div>
<!-- ุฒุฑ ุฅูุดุงุก ุงูุฏูุนุฉ -->
<button type="button" class="btn-primary" style="margin-top: 20px; background: linear-gradient(135deg, #22c55e, #16a34a);" onclick="startBatchGeneration()">
๐ ุฅูุดุงุก ุงูุฏูุนุฉ (<span id="batchTotalVideos">0</span> ููุฏูู)
</button>
<!-- ุญุงูุฉ ุงูุฏูุนุฉ -->
<div id="batchStatusSection" style="display: none; margin-top: 20px;">
<div class="progress-section active">
<div class="progress-ring">
<svg width="140" height="140">
<circle class="bg" cx="70" cy="70" r="65"></circle>
<circle class="fill" id="batchProgressCircle" cx="70" cy="70" r="65"></circle>
</svg>
<div class="progress-percent" id="batchProgressPercent">0%</div>
</div>
<div class="progress-status" id="batchProgressStatus">ุฌุงุฑู ุงูุชุญุถูุฑ...</div>
<div id="batchCurrentVideo" style="margin-top: 8px; font-size: 0.9rem; color: var(--accent); display: none;">
๐ฌ <span id="batchCurrentVideoName">--</span>
</div>
<div id="batchRemainingTime" style="margin-top: 6px; font-size: 0.85rem; color: var(--text-muted); display: none;">
โฑ๏ธ ุงูููุช ุงูู
ุชุจูู: <span id="batchRemainingTimeValue" style="color: var(--accent);">--:--</span>
</div>
<div style="margin-top: 12px; font-size: 0.85rem; color: var(--text-muted);">
<span id="batchCompletedCount">0</span> / <span id="batchTotalCount">0</span> ููุฏูู
</div>
<button type="button" class="btn-secondary btn-stop" style="margin-top: 12px;" onclick="cancelBatch()">
๐ ุฅูุบุงุก ุงูุฏูุนุฉ
</button>
</div>
</div>
</div>
<!-- ๐ History Tab -->
<div class="tab-panel" id="history-panel">
<div class="history-header">
<h3>ุณุฌู ุงูููุฏูููุงุช</h3>
<button class="btn-secondary" style="width: auto; height: 36px; padding: 0 12px; font-size: 0.8rem;" onclick="clearAllHistory()">๐๏ธ ู
ุณุญ ุงููู</button>
</div>
<div class="history-empty" id="historyEmpty">
<div class="history-empty-icon">๐</div>
<p>ูุง ุชูุฌุฏ ููุฏูููุงุช ูู ุงูุณุฌู</p>
</div>
<div id="historyList"></div>
</div>
<!-- โ๏ธ Settings Tab -->
<div class="tab-panel" id="settings-panel">
<!-- Preview -->
<div class="preview-box">
<div class="preview-ar" id="previewAr">ุจูุณูู
ู ุงูููููู ุงูุฑููุญูู
ููฐูู ุงูุฑููุญููู
ู</div>
<div class="preview-en" id="previewEn">In the name of Allah, the Entirely Merciful</div>
</div>
<!-- Arabic Settings -->
<div class="settings-section">
<h4>ุงููุต ุงูุนุฑุจู</h4>
<div class="settings-row">
<span class="settings-label">ุงูููู</span>
<div class="settings-controls">
<input type="color" class="color-picker" id="arColor" value="#ffffff" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ุงูุญุฌู
</span>
<div class="settings-controls">
<input type="range" class="size-slider" id="arSize" min="0.5" max="2" step="0.1" value="1" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ููู ุงูุฅุทุงุฑ</span>
<div class="settings-controls">
<input type="color" class="color-picker" id="arOutlineColor" value="#000000" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ุณู
ู ุงูุฅุทุงุฑ</span>
<div class="settings-controls">
<input type="range" class="size-slider" id="arOutlineWidth" min="0" max="10" step="1" value="4" onchange="updatePreview()">
</div>
</div>
</div>
<!-- English Settings -->
<div class="settings-section">
<h4>ุงูุชุฑุฌู
ุฉ ุงูุฅูุฌููุฒูุฉ</h4>
<div class="settings-row">
<span class="settings-label">ุงูููู</span>
<div class="settings-controls">
<input type="color" class="color-picker" id="enColor" value="#FFD700" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ุงูุญุฌู
</span>
<div class="settings-controls">
<input type="range" class="size-slider" id="enSize" min="0.5" max="2" step="0.1" value="1" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ููู ุงูุฅุทุงุฑ</span>
<div class="settings-controls">
<input type="color" class="color-picker" id="enOutlineColor" value="#000000" onchange="updatePreview()">
</div>
</div>
<div class="settings-row">
<span class="settings-label">ุณู
ู ุงูุฅุทุงุฑ</span>
<div class="settings-controls">
<input type="range" class="size-slider" id="enOutlineWidth" min="0" max="10" step="1" value="3" onchange="updatePreview()">
</div>
</div>
</div>
<!-- Pexels Key -->
<div class="settings-section">
<h4>ู
ูุชุงุญ Pexels (ุงุฎุชูุงุฑู)</h4>
<input type="text" class="form-input" id="pexelsKey" placeholder="ุงุชุฑูู ูุงุฑุบุงู ููุงุณุชุฎุฏุงู
ุงูุงูุชุฑุงุถู" style="margin-top: 8px;">
</div>
<button class="btn-primary" onclick="saveAllSettings()" style="margin-top: 10px;">๐พ ุญูุธ ุงูุฅุนุฏุงุฏุงุช</button>
<button class="btn-secondary" onclick="resetAllSettings()" style="margin-top: 10px;">ุงุณุชุนุงุฏุฉ ุงูุงูุชุฑุงุถู</button>
</div>
<!-- ๐ Auto Publish Tab -->
<div class="tab-panel" id="autopublish-panel">
<!-- YouTube Connection Status -->
<div style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between;">
<div style="display: flex; align-items: center; gap: 10px;">
<span style="font-size: 1.5rem;">๐บ</span>
<div>
<div style="font-weight: 600; font-size: 0.95rem;">YouTube</div>
<div id="ap-yt-status" style="font-size: 0.8rem; color: var(--text-muted);">ุฌุงุฑู ุงูุชุญูู...</div>
</div>
</div>
</div>
<!-- Auto Publish Form -->
<div class="settings-section">
<h4>๐ ุฅุนุฏุงุฏุงุช ุงููุดุฑ ุงูุชููุงุฆู</h4>
<!-- ุนุฏุฏ ุงูููุฏูููุงุช -->
<div class="form-group">
<label class="form-label">๐ข ุนุฏุฏ ุงูููุฏูููุงุช (1-500)</label>
<input type="number" class="form-input" id="ap-count" value="10" min="1" max="500" placeholder="ุนุฏุฏ ุงูููุฏูููุงุช">
</div>
<!-- ุงููุฑุงุก -->
<div class="form-group">
<label class="form-label">๐ค ุงููุฑุงุก <span style="font-size: 0.75rem; color: var(--text-muted);">(ุงุฎุชุงุฑ ูุฑุงุก ูุณูุชู
ุงูุงุฎุชูุงุฑ ู
ููู
ุนุดูุงุฆูุงู)</span></label>
<div id="ap-reciters-list" style="max-height: 180px; overflow-y: auto; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px;">
</div>
<div style="display: flex; gap: 8px; margin-top: 6px;">
<button type="button" onclick="apSelectAllReciters()" style="font-size: 0.75rem; color: var(--accent); background: none; border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px; cursor: pointer; font-family: inherit;">ุชุญุฏูุฏ ุงููู</button>
<button type="button" onclick="apDeselectAllReciters()" style="font-size: 0.75rem; color: var(--text-muted); background: none; border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px; cursor: pointer; font-family: inherit;">ุฅูุบุงุก ุงููู</button>
</div>
</div>
<!-- ุงูุฌูุฏุฉ -->
<div class="form-group">
<label class="form-label">๐ ุงูุฌูุฏุฉ</label>
<select class="form-select" id="ap-quality">
<option value="720">โก 720p HD - ุงูุฃุณุฑุน</option>
<option value="1080">๐ 1080p FHD</option>
</select>
</div>
<!-- ู
ุนุฏู ุงูุฅุทุงุฑุงุช -->
<div class="form-group">
<label class="form-label">๐๏ธ ู
ุนุฏู ุงูุฅุทุงุฑุงุช (FPS)</label>
<select class="form-select" id="ap-fps">
<option value="15">๐ 15 FPS - ุณุฑูุน ุฌุฏุงู</option>
<option value="20" selected>โ๏ธ 20 FPS - ู
ุชูุงุฒู</option>
<option value="24">๐ฌ 24 FPS - ุณููู
ุงุฆู</option>
<option value="30">๐ 30 FPS - ุงูุฃูุซุฑ ุณูุงุณุฉ</option>
</select>
</div>
<!-- โจ ุฎูุงุฑุงุช ุจุตุฑูุฉ -->
<div class="toggle-group" style="margin-bottom: 18px;">
<div class="toggle-item">
<div class="toggle-info">
<h4>ุงูุฎูููุงุช ุงูุฏููุงู
ูููุฉ</h4>
<span>ูู ุขูุฉ ุจุฎูููุฉ ู
ุฎุชููุฉ</span>
</div>
<label class="switch">
<input type="checkbox" id="ap-dynamic-bg" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชููุฌ ุงููุต</h4>
<span>ุชุฃุซูุฑ ูุงูุฉ ุญูู ุงููุต</span>
</div>
<label class="switch">
<input type="checkbox" id="ap-use-glow" checked>
<span class="switch-slider"></span>
</label>
</div>
<div class="toggle-item">
<div class="toggle-info">
<h4>ุชุนุชูู
ุณููู
ุงุฆู</h4>
<span>Vignette effect</span>
</div>
<label class="switch">
<input type="checkbox" id="ap-use-vignette" checked>
<span class="switch-slider"></span>
</label>
</div>
</div>
<!-- ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ -->
<div class="advanced-toggle" onclick="toggleApAdvanced()">
<span>โก</span>
<span>ุฎูุงุฑุงุช ู
ุชูุฏู
ุฉ</span>
</div>
<div class="advanced-options" id="apAdvancedOptions">
<div class="form-group">
<label class="form-label">๐ ุฃุจุนุงุฏ ุงูููุฏูู</label>
<select class="form-select" id="ap-aspect-ratio">
<option value="9:16">๐ฑ 9:16 - ุฑููุฒ / ุชูู ุชูู</option>
<option value="1:1">โฌ 1:1 - ุณููุฑ / ุงูุณุชุฌุฑุงู
</option>
<option value="16:9">๐ฅ๏ธ 16:9 - ููุชููุจ</option>
</select>
</div>
<div class="form-group">
<label class="form-label">โ๏ธ ุฎุท ุงูู
ุตุญู</label>
<select class="form-select" id="ap-font-select">
<option value="Arabic">Arabic - ุงูุฎุท ุงูุงูุชุฑุงุถู</option>
<option value="Classic">Classic - ููุงุณูู</option>
<option value="Amiri">Amiri - ุฃู
ูุฑู</option>
<option value="Uthmani">Uthmani - ุนุซู
ุงูู</option>
</select>
</div>
<div class="form-group">
<label class="form-label">๐ค ุฎุท ุงูุชุฑุฌู
ุฉ</label>
<select class="form-select" id="ap-font-en-select">
<option value="English">English - ุงูุงูุชุฑุงุถู</option>
<option value="Cinzel">Cinzel - ููุงุณููู</option>
<option value="Playfair">Playfair - ุฃููู</option>
<option value="Lora">Lora - ุนุตุฑู</option>
</select>
</div>
</div>
</div>
<!-- YouTube Settings -->
<div class="settings-section">
<h4>๐บ ุฅุนุฏุงุฏุงุช YouTube</h4>
<!-- ูุงูุจ ุงูุนููุงู -->
<div class="form-group">
<label class="form-label">๐ ูุงูุจ ุงูุนููุงู</label>
<input type="text" class="form-input" id="ap-title-template" value="ูุฑุขู ูุฑูู
{surah_name} ({ayah_range}) ุจุตูุช ุงููุงุฑุฆ {reciter}" placeholder="ู
ุซุงู: ูุฑุขู ูุฑูู
{surah_name} ({ayah_range})">
<div style="font-size: 0.7rem; color: var(--text-muted); margin-top: 4px;">
ุงูู
ุชุงุญ: {surah_name}, {surah_number}, {ayah_range}, {start_ayah}, {end_ayah}, {reciter}
</div>
</div>
<!-- ูุตู ุงูููุฏูู -->
<div class="form-group">
<label class="form-label">๐ ูุตู ุงูููุฏูู</label>
<textarea class="form-input" id="ap-description" style="height: 80px; padding: 12px 16px; resize: vertical;" placeholder="ูุตู ุงุฎุชูุงุฑู ููููุฏูู...">#ูุฑุงู_ูุฑูู
#ูุฑุงู #quran #fyp #ูุฑุขู_ูุฑูู
_ุฑุงุญุฉ_ููุณูุฉ #shorts</textarea>
</div>
<!-- ุงูุชุงุบุงุช -->
<div class="form-group">
<label class="form-label">๐ท๏ธ ุงูููู
ุงุช ุงูู
ูุชุงุญูุฉ (ู
ูุตููุฉ ุจูุงุตูุฉ)</label>
<input type="text" class="form-input" id="ap-tags" value="ูุฑุขู ูุฑูู
, ุชูุงูุฉ, ุฅุณูุงู
, Quran, ูุฑุขู, ุชูุงูุฉ ูุฑุขููุฉ" placeholder="ูุฑุขู, ุชูุงูุฉ, ุฅุณูุงู
">
</div>
</div>
<!-- Schedule Settings -->
<div class="settings-section">
<h4>๐
ุฅุนุฏุงุฏุงุช ุงูุฌุฏููุฉ</h4>
<!-- ุชูุฒูุน ุนูู -->
<div class="form-group">
<label class="form-label">๐ ุชูุฒูุน ุนูู (ุฃูุงู
)</label>
<input type="number" class="form-input" id="ap-spread-days" value="7" min="1" max="365" placeholder="ุนุฏุฏ ุงูุฃูุงู
">
</div>
<!-- ููุช ุงููุดุฑ -->
<div style="display: flex; gap: 12px;">
<div class="form-group" style="flex: 1;">
<label class="form-label">ู
ู ุงูุณุงุนุฉ</label>
<select class="form-select" id="ap-time-start"></select>
</div>
<div class="form-group" style="flex: 1;">
<label class="form-label">ุฅูู ุงูุณุงุนุฉ</label>
<select class="form-select" id="ap-time-end"></select>
</div>
</div>
</div>
<!-- ุฒุฑ ุจุฏุก ุงููุดุฑ ุงูุชููุงุฆู -->
<button type="button" class="btn-primary" onclick="startAutoPublish()" style="background: linear-gradient(135deg, #dc2626, #ef4444);">
๐ ุงุจุฏุฃ ุงููุดุฑ ุงูุชููุงุฆู
</button>
<!-- Active Auto Publish Progress (hidden by default) -->
<div id="ap-progress-section" style="display: none; margin-top: 24px;">
<div style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; text-align: center; margin-bottom: 16px;">
<!-- Progress Ring -->
<div class="progress-ring" style="margin-bottom: 12px;">
<svg width="140" height="140">
<circle class="bg" cx="70" cy="70" r="65"></circle>
<circle class="fill" id="ap-progress-ring" cx="70" cy="70" r="65" style="stroke-dasharray: 408; stroke-dashoffset: 408; transition: stroke-dashoffset 0.5s ease;"></circle>
</svg>
<div class="progress-percent" id="ap-progress-text">0%</div>
</div>
<!-- Progress Bar -->
<div style="background: var(--bg-input); border-radius: 8px; height: 6px; margin-bottom: 16px; overflow: hidden;">
<div id="ap-progress-bar" style="width: 0%; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-light)); border-radius: 8px; transition: width 0.5s ease;"></div>
</div>
<!-- Status -->
<div id="ap-status-text" style="font-size: 0.95rem; color: var(--text-secondary); margin-bottom: 12px;">ูู ุงูุงูุชุธุงุฑ...</div>
<!-- Current Video Progress -->
<div id="ap-current-video-section" style="display: none; margin-bottom: 12px;">
<div style="font-size: 0.85rem; color: var(--accent); margin-bottom: 6px;">
๐ฌ <span id="ap-current-video-name">--</span>
</div>
<div style="background: var(--bg-input); border-radius: 8px; height: 4px; overflow: hidden;">
<div id="ap-current-video-bar" style="width: 0%; height: 100%; background: var(--success); border-radius: 8px; transition: width 0.3s ease;"></div>
</div>
<div style="font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; text-align: left;" id="ap-current-video-percent">0%</div>
</div>
<!-- Stats Grid -->
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px;">
<div style="background: var(--bg-input); border-radius: 8px; padding: 10px 6px;">
<div style="font-size: 0.7rem; color: var(--text-muted);">ุงููู</div>
<div id="ap-total" style="font-size: 1.1rem; font-weight: 700; color: var(--text-primary);">0</div>
</div>
<div style="background: var(--bg-input); border-radius: 8px; padding: 10px 6px;">
<div style="font-size: 0.7rem; color: var(--text-muted);">ู
ูุชู
ู</div>
<div id="ap-completed" style="font-size: 1.1rem; font-weight: 700; color: var(--success);">0</div>
</div>
<div style="background: var(--bg-input); border-radius: 8px; padding: 10px 6px;">
<div style="font-size: 0.7rem; color: var(--text-muted);">ู
ุฑููุน</div>
<div id="ap-uploaded" style="font-size: 1.1rem; font-weight: 700; color: #60a5fa;">0</div>
</div>
<div style="background: var(--bg-input); border-radius: 8px; padding: 10px 6px;">
<div style="font-size: 0.7rem; color: var(--text-muted);">ูุงุดู</div>
<div id="ap-failed" style="font-size: 1.1rem; font-weight: 700; color: var(--danger);">0</div>
</div>
</div>
<!-- Estimated Time -->
<div style="font-size: 0.85rem; color: var(--accent);">
โฑ๏ธ ู
ุชุจูู: <span id="ap-remaining">--:--</span>
</div>
<!-- Cancel Button -->
<button type="button" id="ap-cancel-btn" class="btn-secondary btn-stop" style="margin-top: 16px;" onclick="cancelAutoPublish()">
๐ ุฅูุบุงุก ุงููุดุฑ ุงูุชููุงุฆู
</button>
<!-- Resume Button (shown when quota_paused) -->
<button type="button" id="ap-resume-btn" class="btn-secondary" style="margin-top: 8px; display: none; background: #ff9800; color: white; border: none; padding: 10px 24px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 0.9rem;" onclick="resumeAutoPublish(currentAutoPublishId)">
โถ๏ธ ุงุณุชุฆูุงู ุงููุดุฑ (ุจุนุฏ ุงุณุชุนุงุฏุฉ ุญุตุฉ YouTube)
</button>
<!-- Quota Info -->
<div id="ap-quota-info" style="display: none; margin-top: 12px; padding: 10px; background: rgba(255,152,0,0.1); border: 1px solid rgba(255,152,0,0.3); border-radius: 8px; font-size: 0.8rem; color: #ff9800;">
โ ๏ธ ููุฐุช ุงูุญุตุฉ ุงูููู
ูุฉ ูู YouTube API (10,000 units). ุงูุญุตุฉ ุชุชุฌุฏุฏ ูู 24 ุณุงุนุฉ. ุงุถุบุท "ุงุณุชุฆูุงู" ูู
ุง ุชุฑุฌุน.
</div>
</div>
<!-- Items List -->
<div style="margin-bottom: 16px;">
<div class="history-header">
<h3 style="font-size: 0.95rem;">๐ ุชูุงุตูู ุงูููุฏูููุงุช</h3>
</div>
<div id="ap-items-list" style="max-height: 400px; overflow-y: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);">
</div>
</div>
</div>
<!-- Previous Auto Publishes -->
<div style="margin-top: 24px;">
<div class="history-header">
<h3>๐ ุณุฌู ุงููุดุฑ ุงูุชููุงุฆู</h3>
</div>
<div id="ap-history-list" style="background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;">
<p style="color: #666; text-align: center; padding: 20px;">ูุง ููุฌุฏ ุณุฌู ุจุนุฏ</p>
</div>
</div>
</div>
</main>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script>
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ฆ State & Config
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
let VERSE_COUNTS = {};
let currentJobId = null;
let pollInterval = null;
let SESSION_ID = null;
const defaultSettings = {
arColor: '#ffffff',
arSize: '1',
arOutlineColor: '#000000',
arOutlineWidth: '4',
enColor: '#FFD700',
enSize: '1',
enOutlineColor: '#000000',
enOutlineWidth: '3'
};
// โ
ุฅุนุฏุงุฏุงุช ุงูููุฏูู ุงูุงูุชุฑุงุถูุฉ
const defaultVideoSettings = {
fontSelect: 'Arabic',
fontEnSelect: 'English',
fpsSelect: '20',
qualitySelect: '720',
aspectRatio: '9:16',
dynamicBg: true,
useGlow: true,
useVignette: true
};
// โ
ุญูุธ ุฅุนุฏุงุฏุงุช ุงูููุฏูู
function saveVideoSettings() {
const settings = {
fontSelect: document.getElementById('fontSelect')?.value || 'Arabic',
fontEnSelect: document.getElementById('fontEnSelect')?.value || 'English',
fpsSelect: document.getElementById('fpsSelect')?.value || '20',
qualitySelect: document.getElementById('qualitySelect')?.value || '720',
aspectRatio: document.getElementById('aspectRatio')?.value || '9:16',
dynamicBg: document.getElementById('dynamicBg')?.checked ?? true,
useGlow: document.getElementById('useGlow')?.checked ?? true,
useVignette: document.getElementById('useVignette')?.checked ?? true
};
localStorage.setItem('quran_video_settings', JSON.stringify(settings));
}
// โ
ุชุญู
ูู ุฅุนุฏุงุฏุงุช ุงูููุฏูู
function loadVideoSettings() {
const saved = JSON.parse(localStorage.getItem('quran_video_settings')) || defaultVideoSettings;
Object.entries(saved).forEach(([key, value]) => {
const el = document.getElementById(key);
if (el) {
if (el.type === 'checkbox') {
el.checked = value;
} else {
el.value = value;
}
}
});
}
// โ
ุญูุธ ุชููุงุฆู ุนูุฏ ุชุบููุฑ ุฃู ุฅุนุฏุงุฏ
function initVideoSettingsAutoSave() {
const settingsIds = ['fontSelect', 'fontEnSelect', 'fpsSelect', 'qualitySelect', 'aspectRatio', 'dynamicBg', 'useGlow', 'useVignette'];
settingsIds.forEach(id => {
const el = document.getElementById(id);
if (el) {
el.addEventListener('change', () => {
saveVideoSettings();
});
}
});
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Session Management
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function getOrCreateSessionId() {
let sessionId = localStorage.getItem('quran_session_id');
const sessionAge = localStorage.getItem('quran_session_age');
const thirtyDays = 30 * 24 * 60 * 60 * 1000;
if (!sessionId || !sessionAge || (Date.now() - parseInt(sessionAge)) > thirtyDays) {
sessionId = 'sess_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
localStorage.setItem('quran_session_id', sessionId);
localStorage.setItem('quran_session_age', Date.now().toString());
console.log('๐ New session created:', sessionId);
}
return sessionId;
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Initialization
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
window.onload = async () => {
SESSION_ID = getOrCreateSessionId();
console.log('๐ฑ Session ID:', SESSION_ID);
initTabs();
loadSettings();
loadVideoSettings(); // โ
ุชุญู
ูู ุฅุนุฏุงุฏุงุช ุงูููุฏูู
initVideoSettingsAutoSave(); // โ
ุญูุธ ุชููุงุฆู
// ุชุญู
ูู ุงูููููุฌ ุงูุฃูู ุนุดุงู VERSE_COUNTS
await loadConfig();
// ุจุนุฏูู ูุนู
ู validation ุจุนุฏ ู
ุง ุงูุจูุงูุงุช ุชุชุญู
ู
initAyahValidation();
await loadHistory();
await checkRunningJob();
// ุชุญุฏูุซ ุงูููุช ุงูุชูุฑูุจู ุนูุฏ ุงูุชุญู
ูู
setTimeout(() => {
updateEstimatedTime();
updateBatchEstimatedTime();
}, 500);
};
function initAyahValidation() {
const startInput = document.getElementById('startAyah');
const endInput = document.getElementById('endAyah');
const surahInput = document.getElementById('surahSelect');
const maxHint = document.getElementById('maxAyahHint');
// ุชุญุฏูุซ ุงูุญุฏ ุงูุฃูุตู ุนูุฏ ุชุบููุฑ ุงูุณูุฑุฉ
const updateMaxAyah = () => {
const surah = parseInt(surahInput?.value) || 1;
const max = VERSE_COUNTS[surah] || 286;
// ุชุญุฏูุซ ุงูู max attribute
if (startInput) startInput.max = max;
if (endInput) endInput.max = max;
// ุนุฑุถ ุชูู
ูุญ ุงูุญุฏ ุงูุฃูุตู
if (maxHint) maxHint.textContent = `(ุนุฏุฏ ุงูุขูุงุช: ${max})`;
// ุชุตุญูุญ ุงูููู
ุงูุญุงููุฉ
if (parseInt(startInput?.value) > max) startInput.value = 1;
if (parseInt(endInput?.value) > max) endInput.value = Math.min(5, max);
};
// ุงูุชุญูู ุงูููุฑู ุฃุซูุงุก ุงููุชุงุจุฉ
const validateOnInput = (input) => {
const surah = parseInt(surahInput?.value) || 1;
const max = VERSE_COUNTS[surah] || 286;
let val = parseInt(input.value) || 1;
if (val < 1) input.value = 1;
if (val > max) {
input.value = max;
showToast(`ูุฐู ุงูุณูุฑุฉ ุจูุง ${max} ุขูุฉ ููุท`, 'error');
}
};
startInput?.addEventListener('input', () => validateOnInput(startInput));
endInput?.addEventListener('input', () => validateOnInput(endInput));
startInput?.addEventListener('blur', () => validateAyahInput('startAyah'));
endInput?.addEventListener('blur', () => validateAyahInput('endAyah'));
startInput?.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
validateAyahInput('startAyah');
endInput.focus();
}
});
endInput?.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
validateAyahInput('endAyah');
}
});
surahInput?.addEventListener('change', () => {
updateMaxAyah();
const max = VERSE_COUNTS[parseInt(surahInput.value)] || 286;
startInput.value = 1;
endInput.value = Math.min(5, max);
validateAyahRange();
});
// ุชุญุฏูุซ ุงูุญุฏ ุงูุฃูุตู ุนูุฏ ุชุญู
ูู ุงูุจูุงูุงุช
setTimeout(updateMaxAyah, 500);
}
function initTabs() {
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
const tabId = btn.dataset.tab;
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
btn.classList.add('active');
document.getElementById(`${tabId}-panel`).classList.add('active');
});
});
}
async function loadConfig() {
try {
const res = await fetch('/api/config');
const data = await res.json();
VERSE_COUNTS = data.verseCounts;
data.surahs.forEach((name, i) => {
surahSelect.add(new Option(`${i + 1}. ${name}`, i + 1));
});
Object.entries(data.reciters).forEach(([name, id]) => {
reciterSelect.add(new Option(name, id));
});
// ุชุญุฏูุซ ุงูุญุฏ ุงูุฃูุตู ููุขูุงุช ุจูุงุกู ุนูู ุงูุณูุฑุฉ ุงูุฃููู
const firstSurahMax = VERSE_COUNTS[1] || 7;
const startAyahInput = document.getElementById('startAyah');
const endAyahInput = document.getElementById('endAyah');
if (startAyahInput) startAyahInput.max = firstSurahMax;
if (endAyahInput) endAyahInput.max = firstSurahMax;
// ุฅุถุงูุฉ event listener ูุชุญุฏูุซ ุงูุญุฏ ุงูุฃูุตู ุนูุฏ ุชุบููุฑ ุงูุณูุฑุฉ
surahSelect.addEventListener('change', function() {
const surah = parseInt(this.value) || 1;
const max = VERSE_COUNTS[surah] || 286;
if (startAyahInput) {
startAyahInput.max = max;
if (parseInt(startAyahInput.value) > max) startAyahInput.value = 1;
}
if (endAyahInput) {
endAyahInput.max = max;
if (parseInt(endAyahInput.value) > max) endAyahInput.value = Math.min(5, max);
}
// ุชุญุฏูุซ ุงูููุช ุงูุชูุฑูุจู
updateEstimatedTime();
});
// ุชุญุฏูุซ ุงูููุช ุงูุชูุฑูุจู
updateEstimatedTime();
} catch (err) {
console.error('Config load error:', err);
showToast('ูุดู ุชุญู
ูู ุงูุฅุนุฏุงุฏุงุช', 'error');
}
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Form Handling
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
document.getElementById('videoForm').addEventListener('submit', async (e) => {
e.preventDefault();
await startGeneration();
});
function adjustAyah(id, delta) {
const input = document.getElementById(id);
const surah = parseInt(surahSelect.value);
const max = VERSE_COUNTS[surah] || 286;
let val = parseInt(input.value) + delta;
if (val < 1) val = 1;
if (val > max) val = max;
input.value = val;
validateAyahRange();
}
function validateAyahInput(id) {
const input = document.getElementById(id);
const surah = parseInt(surahSelect.value);
const max = VERSE_COUNTS[surah] || 286;
let val = parseInt(input.value);
if (isNaN(val) || val < 1) {
val = 1;
}
if (val > max) {
val = max;
showToast(`ูุฐู ุงูุณูุฑุฉ ุจูุง ${max} ุขูุฉ ููุท`, 'error');
}
input.value = val;
validateAyahRange();
}
function validateAyahRange() {
const surah = parseInt(surahSelect.value);
const max = VERSE_COUNTS[surah] || 286;
const start = parseInt(startAyah.value);
const end = parseInt(endAyah.value);
if (start > end) {
endAyah.value = start;
}
if (end > max) {
endAyah.value = max;
}
// ุชุญุฏูุซ ุงูููุช ุงูุชูุฑูุจู
updateEstimatedTime();
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// โฑ๏ธ Estimated Time Calculator (Real Duration from API)
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Cache ูุชุฎุฒูู ู
ุฏุฉ ุงูุขูุงุช
let durationCache = {};
async function fetchEstimatedTime(reciter, surah, startAyah, endAyah) {
// ุฅูุดุงุก ู
ูุชุงุญ ููู cache
const cacheKey = `${reciter}-${surah}-${startAyah}-${endAyah}`;
// ูู ู
ูุฌูุฏ ูู ุงูู cache
if (durationCache[cacheKey]) {
return durationCache[cacheKey];
}
try {
const res = await fetch('/api/estimate-duration', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reciter, surah, startAyah, endAyah })
});
const data = await res.json();
if (data.ok) {
// ุญูุธ ูู ุงูู cache
durationCache[cacheKey] = data;
return data;
}
} catch (err) {
console.error('Duration fetch error:', err);
}
return null;
}
function updateEstimatedTime() {
const reciter = document.getElementById('reciterSelect')?.value;
const surah = parseInt(document.getElementById('surahSelect')?.value) || 1;
const start = parseInt(document.getElementById('startAyah')?.value) || 1;
const end = parseInt(document.getElementById('endAyah')?.value) || 1;
const el = document.getElementById('estimatedTime');
if (el) {
el.textContent = 'โณ ุฌุงุฑู ุงูุญุณุงุจ...';
}
fetchEstimatedTime(reciter, surah, start, end).then(data => {
if (data && data.formatted) {
if (el) {
el.textContent = data.formatted;
}
} else {
if (el) {
el.textContent = '--:--';
}
}
});
}
function updateBatchEstimatedTime() {
const reciter = document.getElementById('batchReciterSelect')?.value;
const surah = parseInt(document.getElementById('batchSurahSelect')?.value) || 1;
const start = parseInt(document.getElementById('batchStartAyah')?.value) || 1;
const end = parseInt(document.getElementById('batchEndAyah')?.value) || 1;
const el = document.getElementById('batchEstimatedTime');
if (el) {
el.textContent = 'โณ ุฌุงุฑู ุงูุญุณุงุจ...';
}
fetchEstimatedTime(reciter, surah, start, end).then(data => {
if (data && data.formatted) {
if (el) {
el.textContent = data.formatted;
}
} else {
if (el) {
el.textContent = '--:--';
}
}
});
}
async function updateBatchTotalTime() {
// ุญุณุงุจ ุงูููุช ุงูููู ููู ุงูููุฏูููุงุช ูู ุงููุงุฆู
ุฉ
const totalTimeDisplay = document.getElementById('batchTotalTimeDisplay');
const totalTimeEl = document.getElementById('batchTotalTime');
if (batchItems.length === 0) {
if (totalTimeDisplay) totalTimeDisplay.style.display = 'none';
return;
}
if (totalTimeDisplay) totalTimeDisplay.style.display = 'block';
if (totalTimeEl) totalTimeEl.textContent = 'โณ ุฌุงุฑู ุงูุญุณุงุจ...';
let totalMs = 0;
for (const item of batchItems) {
const data = await fetchEstimatedTime(item.reciter, item.surah, item.startAyah, item.endAyah);
if (data && data.durationMs) {
totalMs += data.durationMs;
}
}
const totalSeconds = totalMs / 1000;
if (totalTimeEl) {
if (totalSeconds > 0) {
totalTimeEl.textContent = formatDurationLocal(totalSeconds);
} else {
totalTimeEl.textContent = '--:--';
}
}
}
function formatDurationLocal(seconds) {
if (seconds < 60) {
return `${Math.round(seconds)} ุซุงููุฉ`;
} else if (seconds < 3600) {
const mins = Math.floor(seconds / 60);
const secs = Math.round(seconds % 60);
if (secs > 0) {
return `${mins} ุฏ ${secs} ุซ`;
}
return `${mins} ุฏูููุฉ`;
} else {
const hours = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60);
if (mins > 0) {
return `${hours} ุณ ${mins} ุฏ`;
}
return `${hours} ุณุงุนุฉ`;
}
}
function randomize() {
if (reciterSelect.options.length > 0) {
reciterSelect.selectedIndex = Math.floor(Math.random() * reciterSelect.options.length);
}
if (surahSelect.options.length > 0) {
surahSelect.selectedIndex = Math.floor(Math.random() * surahSelect.options.length);
// ุชุญุฏูุซ ุงูู max attribute ููุขูุงุช ุจุนุฏ ุชุบููุฑ ุงูุณูุฑุฉ
surahSelect.dispatchEvent(new Event('change'));
const max = VERSE_COUNTS[parseInt(surahSelect.value)] || 286;
const start = Math.floor(Math.random() * Math.max(1, max - 5)) + 1;
startAyah.value = start;
endAyah.value = Math.min(start + 4, max);
}
updateEstimatedTime();
}
function toggleAdvanced() {
const options = document.getElementById('advancedOptions');
options.classList.toggle('show');
}
function toggleBatchAdvanced() {
const options = document.getElementById('batchAdvancedOptions');
options.classList.toggle('show');
}
function toggleApAdvanced() {
const options = document.getElementById('apAdvancedOptions');
if (options) options.classList.toggle('show');
}
function toggleBatchSearchInput() {
const input = document.getElementById('batchSearchInputGroup');
const checkbox = document.getElementById('batchUseSearch');
input.style.display = checkbox.checked ? 'block' : 'none';
}
function toggleSearchInput() {
const input = document.getElementById('searchInputGroup');
input.style.display = useSearch.checked ? 'block' : 'none';
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ฌ Video Generation
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function startGeneration() {
const style = getStyleSettings();
const payload = {
sessionId: SESSION_ID,
reciter: reciterSelect.value,
surah: parseInt(surahSelect.value),
startAyah: parseInt(startAyah.value),
endAyah: parseInt(endAyah.value),
fps: parseInt(fpsSelect.value),
quality: qualitySelect.value,
aspectRatio: document.getElementById('aspectRatio').value || '9:16',
font: document.getElementById('fontSelect').value || 'Arabic',
fontEn: document.getElementById('fontEnSelect').value || 'English',
dynamicBg: dynamicBg.checked,
useGlow: useGlow.checked,
useVignette: useVignette.checked,
bgQuery: useSearch.checked ? bgQuery.value : '',
pexelsKey: localStorage.getItem('user_pexels_key') || '',
style: style
};
try {
const res = await fetch('/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await res.json();
if (data.ok) {
currentJobId = data.jobId;
showProgress();
startPolling(data.jobId);
} else {
showToast('ูุดู ุจุฏุก ุงูู
ุนุงูุฌุฉ', 'error');
}
} catch (err) {
console.error('Generation error:', err);
showToast('ุญุฏุซ ุฎุทุฃ ูู ุงูุงุชุตุงู', 'error');
}
}
function showProgress() {
document.getElementById('videoForm').style.display = 'none';
document.getElementById('progressSection').classList.add('active');
document.getElementById('resultSection').classList.remove('active');
}
function startPolling(jobId) {
if (pollInterval) clearInterval(pollInterval);
pollInterval = setInterval(async () => {
try {
const res = await fetch(`/api/progress?jobId=${jobId}`);
const data = await res.json();
updateProgress(data);
if (data.status === 'complete') {
clearInterval(pollInterval);
showResult(data);
} else if (data.status === 'error' || data.status === 'cancelled') {
clearInterval(pollInterval);
showToast(data.error || 'ุญุฏุซ ุฎุทุฃ', 'error');
resetForm();
}
} catch (err) {
console.error('Poll error:', err);
}
}, 1500);
}
function updateProgress(data) {
const percent = data.percent || 0;
const circle = document.getElementById('progressCircle');
const circumference = 2 * Math.PI * 65;
circle.style.strokeDashoffset = circumference - (percent / 100) * circumference;
document.getElementById('progressPercent').textContent = `${percent}%`;
document.getElementById('progressStatus').textContent = data.status || 'ุฌุงุฑู ุงูู
ุนุงูุฌุฉ...';
if (data.eta && data.eta !== '--:--') {
document.getElementById('progressEta').style.display = 'block';
document.getElementById('etaTime').textContent = data.eta;
}
}
function showResult(data) {
document.getElementById('progressSection').classList.remove('active');
document.getElementById('resultSection').classList.add('active');
const videoUrl = data.download_url || `/api/download?jobId=${currentJobId}`;
document.getElementById('videoPlayer').src = videoUrl;
document.getElementById('downloadLink').href = videoUrl;
loadHistory();
showToast('ุชู
ุฅูุดุงุก ุงูููุฏูู ุจูุฌุงุญ!', 'success');
}
function resetForm() {
document.getElementById('videoForm').style.display = 'block';
document.getElementById('progressSection').classList.remove('active');
document.getElementById('resultSection').classList.remove('active');
document.getElementById('progressCircle').style.strokeDashoffset = 408;
document.getElementById('progressPercent').textContent = '0%';
currentJobId = null;
}
async function stopGeneration() {
if (!currentJobId) return;
if (confirm('ูู ุชุฑูุฏ ุฅููุงู ุงูู
ุนุงูุฌุฉุ')) {
clearInterval(pollInterval);
await fetch('/api/cancel', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jobId: currentJobId })
});
resetForm();
showToast('ุชู
ุงูุฅููุงู', 'error');
}
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ History
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function loadHistory() {
try {
const res = await fetch(`/api/history?sessionId=${encodeURIComponent(SESSION_ID)}`);
const data = await res.json();
const list = document.getElementById('historyList');
const empty = document.getElementById('historyEmpty');
if (data.ok && data.history && data.history.length > 0) {
empty.style.display = 'none';
list.innerHTML = data.history.map(item => createHistoryItem(item)).join('');
} else {
empty.style.display = 'block';
list.innerHTML = '';
}
} catch (err) {
console.error('History load error:', err);
}
}
function createHistoryItem(item) {
const date = new Date(item.createdAt * 1000);
const dateStr = date.toLocaleDateString('ar-EG') + ' ' + date.toLocaleTimeString('ar-EG', { hour: '2-digit', minute: '2-digit' });
const now = Date.now() / 1000;
const remaining = Math.max(0, 43200 - (now - item.createdAt)); // 12 ุณุงุนุฉ = 43200 ุซุงููุฉ
// ุชูุณูู ุงูููุช ุงูุฐูู
function formatRemaining(secs) {
if (secs < 60) return `${secs} ุซ`;
if (secs < 3600) return `${Math.floor(secs / 60)} ุฏ`;
const hours = Math.floor(secs / 3600);
const mins = Math.floor((secs % 3600) / 60);
return mins > 0 ? `${hours} ุณ ${mins} ุฏ` : `${hours} ุณ`;
}
let timerHtml = '';
if (item.status === 'complete' && remaining > 0) {
const urgent = remaining < 3600; // ุฃูู ู
ู ุณุงุนุฉ = ุนุงุฌู
timerHtml = `<span class="history-timer ${urgent ? 'urgent' : ''}">โฐ ${formatRemaining(remaining)}</span>`;
}
const statusIcon = item.status === 'complete' ? 'โ
' : item.status === 'error' ? 'โ' : 'โณ';
// ุชุฌููุฒ ุจูุงูุงุช ุงููุตู
const surahName = item.surahName || 'ุณูุฑุฉ';
const reciterName = item.reciter || 'ูุงุฑุฆ';
const ayahRange = item.startAyah && item.endAyah ? `(${item.startAyah}-${item.endAyah})` : '';
let actionsHtml = '';
if (item.downloadUrl && remaining > 0) {
actionsHtml = `
<button onclick="previewVideo('${item.downloadUrl}')">โถ๏ธ ุนุฑุถ</button>
<a href="${item.downloadUrl}" download>โฌ๏ธ ุชุญู
ูู</a>
<button onclick="openYoutubeDialog('${item.jobId}', '${item.title?.replace(/'/g, "\\'") || 'ููุฏูู ูุฑุขูู'}', '${reciterName.replace(/'/g, "\\'")}', '${surahName}')" style="background: #ff0000; color: white; border: none;">๐บ ููุชููุจ</button>
<button class="btn-delete" onclick="deleteHistoryItem(${item.id})">๐๏ธ</button>
`;
} else {
actionsHtml = `
<span style="color: var(--text-muted); font-size: 0.85rem;">ุบูุฑ ู
ุชุงุญ</span>
<button class="btn-delete" onclick="deleteHistoryItem(${item.id})">๐๏ธ</button>
`;
}
return `
<div class="history-item" data-id="${item.id}">
<div class="history-item-header">
<span class="history-item-title">${item.title}</span>
<span class="history-item-status">${statusIcon}</span>
</div>
<div class="history-item-meta">
${timerHtml}
๐ค ${item.reciter || 'ุบูุฑ ู
ุญุฏุฏ'} โข ๐บ ${item.quality}p โข ๐ ${dateStr}
</div>
<div class="history-item-actions">
${actionsHtml}
</div>
</div>
`;
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐บ YouTube Integration
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
let youtubeAuthWindow = null;
let currentYoutubeJob = null;
async function checkYoutubeStatus() {
try {
const res = await fetch(`/api/youtube/status?sessionId=${encodeURIComponent(SESSION_ID)}`);
return await res.json();
} catch {
return { configured: false, authorized: false };
}
}
async function openYoutubeDialog(jobId, defaultTitle, reciterName, surahName) {
currentYoutubeJob = jobId;
// ุฅุนุฏุงุฏ ุงููุตู ุงูุงูุชุฑุงุถู
const defaultDescription = `ูุฑุขู ูุฑูู
ุจุตูุช ุงููุงุฑุฆ ${reciterName || 'ูุงุฑุฆ'} ู
ู ุณูุฑุฉ ${surahName || 'ุณูุฑุฉ'}
#ูุฑุงู_ูุฑูู
#ูุฑุงู #quran #fyp #ูุฑุขู_ูุฑูู
_ุฑุงุญุฉ_ููุณูุฉ #ูุฑุขู_ูุฑูู
`;
// ุฅุนุฏุงุฏ ุงูููู
ุงุช ุงูู
ูุชุงุญูุฉ
const defaultTags = 'ูุฑุขู ูุฑูู
, ุชูุงูุฉ, ุฅุณูุงู
, Quran, ูุฑุขู, ุชูุงูุฉ ูุฑุขููุฉ';
// ุงูุชุญูู ู
ู ุญุงูุฉ YouTube
const status = await checkYoutubeStatus();
if (!status.configured) {
showToast('โ ๏ธ ู
ูุฒุฉ ููุชููุจ ุบูุฑ ู
ูุนุฏุฉ. ุชูุงุตู ู
ุน ุงูู
ุทูุฑ.', 'error');
return;
}
if (!status.authorized) {
// ุนุฑุถ ุงูู redirect URI ููู
ุณุชุฎุฏู
if (status.redirectUri) {
console.log('YouTube Redirect URI:', status.redirectUri);
}
// ูุชุญ ูุงูุฐุฉ ุงูู
ุตุงุฏูุฉ
const authRes = await fetch(`/api/youtube/auth-url?sessionId=${encodeURIComponent(SESSION_ID)}`);
const authData = await authRes.json();
if (authData.authUrl) {
showToast('ุณูุชู
ูุชุญ ูุงูุฐุฉ ุงูู
ุตุงุฏูุฉ...', 'success');
youtubeAuthWindow = window.open(authData.authUrl, 'youtube-auth', 'width=500,height=600');
// ุงูุงุณุชู
ุงุน ูุฑุณุงูุฉ ุงููุฌุงุญ
window.addEventListener('message', function ytAuthHandler(e) {
if (e.data.type === 'youtube_auth_success') {
showToast('โ
ุชู
ุฑุจุท ููุชููุจ ุจูุฌุงุญ!', 'success');
window.removeEventListener('message', ytAuthHandler);
// ูุชุญ ุงูู dialog ู
ุฑุฉ ุฃุฎุฑู
setTimeout(() => openYoutubeDialog(jobId, defaultTitle), 500);
}
});
// ุงูุชุญูู ู
ู ุฅุบูุงู ุงููุงูุฐุฉ (ูู ุญุงูุฉ ุงูุฎุทุฃ)
const checkClosed = setInterval(() => {
if (youtubeAuthWindow && youtubeAuthWindow.closed) {
clearInterval(checkClosed);
// ุงูุชุญูู ู
ู ุงูุญุงูุฉ ู
ุฑุฉ ุฃุฎุฑู ุจุนุฏ ุฅุบูุงู ุงููุงูุฐุฉ
setTimeout(async () => {
const newStatus = await checkYoutubeStatus();
if (!newStatus.authorized && newStatus.redirectUri) {
// ุนุฑุถ ุฑุณุงูุฉ ู
ุณุงุนุฏุฉ ููู
ุณุชุฎุฏู
showToast('โ ๏ธ ูุฏ ุชุญุชุงุฌ ูุฅุถุงูุฉ ุงูู Redirect URI ูู Google Cloud Console', 'error', 8000);
console.log('ุฃุถู ูุฐุง URL ูู Google Cloud Console:', newStatus.redirectUri);
}
}, 1000);
}
}, 500);
}
return;
}
// ุนุฑุถ Dialog ุงููุดุฑ
showYoutubeUploadDialog(jobId, defaultTitle, defaultDescription, defaultTags);
}
function showYoutubeUploadDialog(jobId, defaultTitle, defaultDescription, defaultTags) {
// ุฅูุดุงุก ุงูู dialog
// ุญุณุงุจ ุฃูุฑุจ ููุช ููุฌุฏููุฉ (ุจุนุฏ ุณุงุนุฉ ู
ู ุงูุขู)
const now = new Date();
now.setHours(now.getHours() + 1);
const minScheduleTime = now.toISOString().slice(0, 16);
const dialog = document.createElement('div');
dialog.id = 'youtubeDialog';
dialog.innerHTML = `
<div style="position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 9999; display: flex; align-items: center; justify-content: center;">
<div style="background: var(--bg-card); border-radius: 16px; padding: 24px; width: 90%; max-width: 450px; max-height: 90vh; overflow-y: auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
<h3 style="color: #ff0000;">๐บ ูุดุฑ ุนูู ููุชููุจ</h3>
<button onclick="closeYoutubeDialog()" style="background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer;">โ</button>
</div>
<div class="form-group">
<label class="form-label">๐ ุงูุนููุงู</label>
<input type="text" id="ytTitle" class="form-input" value="${defaultTitle}" maxlength="100" placeholder="ุนููุงู ุงูููุฏูู">
</div>
<div class="form-group">
<label class="form-label">๐ ุงููุตู</label>
<textarea id="ytDescription" class="form-input" style="height: 100px; resize: vertical;" placeholder="ูุตู ุงูููุฏูู">${defaultDescription || ''}</textarea>
</div>
<div class="form-group">
<label class="form-label">๐ท๏ธ ุงูููู
ุงุช ุงูู
ูุชุงุญูุฉ (ู
ูุตููุฉ ุจูุงุตูุฉ)</label>
<input type="text" id="ytTags" class="form-input" value="${defaultTags || 'ูุฑุขู, ุชูุงูุฉ, ุฅุณูุงู
, Quran'}" placeholder="ูุฑุขู, ุชูุงูุฉ, ุฅุณูุงู
">
</div>
<div class="form-group">
<label class="form-label">๐ ุงูุฎุตูุตูุฉ</label>
<select id="ytPrivacy" class="form-select" onchange="toggleScheduleOption()">
<option value="unlisted">๐ ุบูุฑ ู
ุฏุฑุฌ (ููุฃุตุฏูุงุก ููุท)</option>
<option value="private">๐ ุฎุงุต</option>
<option value="public">๐ ุนุงู
</option>
<option value="scheduled">๐
ู
ุฌุฏูู (ุนุงู
ูู ููุช ู
ุญุฏุฏ)</option>
</select>
</div>
<div id="scheduleOptions" style="display: none; margin-top: 12px; padding: 16px; background: var(--bg-input); border-radius: 8px;">
<label class="form-label" style="margin-bottom: 8px;">๐ ููุช ุงููุดุฑ ุงูู
ุฌุฏูู</label>
<input type="datetime-local" id="ytScheduleTime" class="form-input" min="${minScheduleTime}" style="width: 100%;">
<p style="font-size: 12px; color: var(--text-muted); margin-top: 8px;">
โ ๏ธ ูุฌุจ ุฃู ูููู ุงูููุช ุนูู ุงูุฃูู ุณุงุนุฉ ู
ู ุงูุขู
</p>
</div>
<div style="margin-top: 20px; display: flex; gap: 10px;">
<button onclick="uploadToYoutube('${jobId}')" class="btn-primary" style="flex: 1;">
<span id="uploadBtnText">๐ค ูุดุฑ ุงูุขู</span>
</button>
<button onclick="closeYoutubeDialog()" class="btn-secondary" style="flex: 1;">
ุฅูุบุงุก
</button>
</div>
<div id="youtubeUploadProgress" style="display: none; margin-top: 16px; text-align: center;">
<div style="color: var(--accent);">โณ ุฌุงุฑู ุงูุฑูุน... ูุฑุฌู ุงูุงูุชุธุงุฑ</div>
</div>
</div>
</div>
`;
document.body.appendChild(dialog);
}
function toggleScheduleOption() {
const privacy = document.getElementById('ytPrivacy')?.value;
const scheduleOptions = document.getElementById('scheduleOptions');
const uploadBtnText = document.getElementById('uploadBtnText');
if (privacy === 'scheduled') {
scheduleOptions.style.display = 'block';
uploadBtnText.textContent = '๐
ุฌุฏููุฉ ุงููุดุฑ';
} else {
scheduleOptions.style.display = 'none';
uploadBtnText.textContent = '๐ค ูุดุฑ ุงูุขู';
}
}
function closeYoutubeDialog() {
const dialog = document.getElementById('youtubeDialog');
if (dialog) dialog.remove();
}
async function uploadToYoutube(jobId) {
const title = document.getElementById('ytTitle')?.value || 'ููุฏูู ูุฑุขูู';
const description = document.getElementById('ytDescription')?.value || '';
const tags = document.getElementById('ytTags')?.value.split(',').map(t => t.trim()).filter(t => t) || [];
let privacyStatus = document.getElementById('ytPrivacy')?.value || 'unlisted';
const scheduleTimeLocal = document.getElementById('ytScheduleTime')?.value || null;
// ุงูุชุญูู ู
ู ููุช ุงูุฌุฏููุฉ
let scheduleTime = null;
if (privacyStatus === 'scheduled') {
if (!scheduleTimeLocal) {
showToast('โ ๏ธ ุงูุฑุฌุงุก ุงุฎุชูุงุฑ ููุช ููุฌุฏููุฉ', 'error');
return;
}
// ุชุญููู ุงูููุช ุงูู
ุญูู ูู ISO string ู
ุน timezone
const scheduledDate = new Date(scheduleTimeLocal);
const now = new Date();
const diffMinutes = (scheduledDate - now) / (1000 * 60);
if (diffMinutes < 15) {
showToast('โ ๏ธ ูุฌุจ ุฃู ูููู ููุช ุงูุฌุฏููุฉ ุจุนุฏ 15 ุฏูููุฉ ุนูู ุงูุฃูู', 'error');
return;
}
// ุชุญููู ูู ISO string (ูุชุถู
ู timezone)
scheduleTime = scheduledDate.toISOString();
console.log('[YouTube] Local time:', scheduleTimeLocal);
console.log('[YouTube] UTC time:', scheduleTime);
// ููุฌุฏููุฉุ ูุฑูุน ุงูููุฏูู ูู scheduled
privacyStatus = 'scheduled';
}
const progressEl = document.getElementById('youtubeUploadProgress');
if (progressEl) progressEl.style.display = 'block';
try {
const res = await fetch('/api/youtube/upload', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: SESSION_ID,
jobId: jobId,
title: title,
description: description,
tags: tags,
privacyStatus: privacyStatus,
scheduleTime: scheduleTime
})
});
const data = await res.json();
if (data.ok) {
closeYoutubeDialog();
if (privacyStatus === 'scheduled') {
showToast('โ
ุชู
ุฌุฏููุฉ ุงูููุฏูู ุจูุฌุงุญ!', 'success');
} else {
showToast('โ
ุชู
ูุดุฑ ุงูููุฏูู ุจูุฌุงุญ!', 'success');
}
// ุนุฑุถ ุฑุงุจุท ุงูููุฏูู
if (data.videoUrl) {
setTimeout(() => {
const message = privacyStatus === 'scheduled'
? `ุชู
ุฌุฏููุฉ ุงูููุฏูู!\n\nุณูููุดุฑ ูู: ${new Date(scheduleTime).toLocaleString('ar-EG')}\n\nูู ุชุฑูุฏ ูุชุญ ุงูููุฏููุ\n${data.videoUrl}`
: `ุชู
ุงููุดุฑ ุจูุฌุงุญ!\n\nูู ุชุฑูุฏ ูุชุญ ุงูููุฏููุ\n${data.videoUrl}`;
if (confirm(message)) {
window.open(data.videoUrl, '_blank');
}
}, 500);
}
} else {
if (data.needsAuth) {
showToast('โ ๏ธ ูุฌุจ ุฑุจุท ุญุณุงุจ ููุชููุจ ุฃููุงู', 'error');
closeYoutubeDialog();
// ุฅุนุงุฏุฉ ุงูู
ุตุงุฏูุฉ
openYoutubeDialog(jobId, title);
} else {
showToast(`โ ${data.error || 'ูุดู ูู ุงูุฑูุน'}`, 'error');
}
}
} catch (err) {
console.error('YouTube upload error:', err);
showToast('โ ูุดู ูู ุงูุงุชุตุงู', 'error');
}
if (progressEl) progressEl.style.display = 'none';
}
async function deleteHistoryItem(id) {
if (!confirm('ุญุฐู ูุฐุง ุงูุนูุตุฑุ')) return;
try {
const res = await fetch(`/api/history/${id}`, { method: 'DELETE' });
const data = await res.json();
if (data.ok) {
document.querySelector(`.history-item[data-id="${id}"]`)?.remove();
if (document.querySelectorAll('.history-item').length === 0) {
document.getElementById('historyEmpty').style.display = 'block';
}
showToast('ุชู
ุงูุญุฐู', 'success');
}
} catch (err) {
showToast('ูุดู ุงูุญุฐู', 'error');
}
}
async function clearAllHistory() {
if (!confirm('ู
ุณุญ ูู ุงูุณุฌูุ ูุง ูู
ูู ุงูุชุฑุงุฌุน.')) return;
try {
const res = await fetch('/api/history/clear', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId: SESSION_ID })
});
const data = await res.json();
if (data.ok) {
document.getElementById('historyList').innerHTML = '';
document.getElementById('historyEmpty').style.display = 'block';
showToast('ุชู
ู
ุณุญ ุงูุณุฌู', 'success');
}
} catch (err) {
showToast('ูุดู ู
ุณุญ ุงูุณุฌู', 'error');
}
}
async function previewVideo(url) {
try {
document.querySelector('[data-tab="main"]').click();
showProgress();
document.getElementById('progressStatus').textContent = 'ุฌุงุฑู ุชุญู
ูู ุงูููุฏูู...';
const res = await fetch(url);
const blob = await res.blob();
const blobUrl = URL.createObjectURL(blob);
document.getElementById('progressSection').classList.remove('active');
document.getElementById('resultSection').classList.add('active');
document.getElementById('videoPlayer').src = blobUrl;
document.getElementById('downloadLink').href = blobUrl;
} catch (err) {
showToast('ูุดู ุชุญู
ูู ุงูููุฏูู', 'error');
resetForm();
}
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// โ๏ธ Settings
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function getStyleSettings() {
return {
arColor: document.getElementById('arColor')?.value || '#ffffff',
arSize: document.getElementById('arSize')?.value || '1',
arOutC: document.getElementById('arOutlineColor')?.value || '#000000',
arOutW: document.getElementById('arOutlineWidth')?.value || '4',
enColor: document.getElementById('enColor')?.value || '#FFD700',
enSize: document.getElementById('enSize')?.value || '1',
enOutC: document.getElementById('enOutlineColor')?.value || '#000000',
enOutW: document.getElementById('enOutlineWidth')?.value || '3'
};
}
function loadSettings() {
const saved = JSON.parse(localStorage.getItem('quran_app_styles_v2')) || defaultSettings;
Object.entries(saved).forEach(([key, value]) => {
const el = document.getElementById(key);
if (el) el.value = value;
});
const pexelsKey = localStorage.getItem('user_pexels_key');
if (pexelsKey) {
document.getElementById('pexelsKey').value = pexelsKey;
}
updatePreview();
}
function updatePreview() {
const ar = document.getElementById('previewAr');
const en = document.getElementById('previewEn');
ar.style.color = document.getElementById('arColor').value;
ar.style.fontSize = `${1.5 * parseFloat(document.getElementById('arSize').value)}rem`;
const arOutline = parseInt(document.getElementById('arOutlineWidth').value) / 5;
ar.style.webkitTextStroke = arOutline > 0 ? `${arOutline}px ${document.getElementById('arOutlineColor').value}` : 'none';
en.style.color = document.getElementById('enColor').value;
en.style.fontSize = `${0.85 * parseFloat(document.getElementById('enSize').value)}rem`;
const enOutline = parseInt(document.getElementById('enOutlineWidth').value) / 5;
en.style.webkitTextStroke = enOutline > 0 ? `${enOutline}px ${document.getElementById('enOutlineColor').value}` : 'none';
}
function saveAllSettings() {
const settings = {};
['arColor', 'arSize', 'arOutlineColor', 'arOutlineWidth',
'enColor', 'enSize', 'enOutlineColor', 'enOutlineWidth'].forEach(key => {
settings[key] = document.getElementById(key).value;
});
localStorage.setItem('quran_app_styles_v2', JSON.stringify(settings));
const pexelsKey = document.getElementById('pexelsKey').value;
if (pexelsKey) {
localStorage.setItem('user_pexels_key', pexelsKey);
} else {
localStorage.removeItem('user_pexels_key');
}
showToast('ุชู
ุญูุธ ุงูุฅุนุฏุงุฏุงุช', 'success');
}
function resetAllSettings() {
if (!confirm('ุงุณุชุนุงุฏุฉ ุงูุฅุนุฏุงุฏุงุช ุงูุงูุชุฑุงุถูุฉุ')) return;
localStorage.removeItem('quran_app_styles_v2');
localStorage.removeItem('user_pexels_key');
document.getElementById('pexelsKey').value = '';
loadSettings();
showToast('ุชู
ุงุณุชุนุงุฏุฉ ุงูุฅุนุฏุงุฏุงุช', 'success');
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐จ Theme
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function toggleTheme() {
document.body.classList.toggle('light-theme');
const isLight = document.body.classList.contains('light-theme');
document.getElementById('themeBtn').textContent = isLight ? 'โ๏ธ' : '๐';
localStorage.setItem('theme', isLight ? 'light' : 'dark');
}
if (localStorage.getItem('theme') === 'light') {
document.body.classList.add('light-theme');
document.getElementById('themeBtn').textContent = 'โ๏ธ';
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Toast Notifications
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function showToast(message, type = 'success') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Check Running Job
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function checkRunningJob() {
try {
const res = await fetch(`/api/my-jobs?status=processing&sessionId=${encodeURIComponent(SESSION_ID)}`);
const data = await res.json();
if (data.ok && data.jobs && data.jobs.length > 0) {
const job = data.jobs[0];
const action = confirm(
`๐ฌ ููุฏูู ููุฏ ุงูู
ุนุงูุฌุฉ!\n` +
`๐ ุงูุชูุฏู
: ${job.percent}%\n\n` +
`ูู ุชุฑูุฏ ู
ุชุงุจุนุชูุ`
);
if (action) {
currentJobId = job.id;
showProgress();
startPolling(job.id);
}
}
} catch (err) {
console.log('No running jobs');
}
}
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ฆ Batch System
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
let batchItems = [];
let currentBatchId = null;
let batchCancelled = false;
let selectedRecitersForRandom = []; // ุงููุฑุงุก ุงูู
ุญุฏุฏูู ููุนุดูุงุฆู
// ๐ค ุฅุฏุงุฑุฉ ูุฑุงุก ุงูุนุดูุงุฆู
function toggleReciterFilter() {
const section = document.getElementById('reciterFilterSection');
const toggle = document.getElementById('reciterFilterToggle');
if (section.style.display === 'none') {
section.style.display = 'block';
toggle.style.transform = 'rotate(180deg)';
} else {
section.style.display = 'none';
toggle.style.transform = 'rotate(0deg)';
}
}
function initReciterCheckboxes() {
const container = document.getElementById('reciterCheckboxes');
const reciterSelect = document.getElementById('batchReciterSelect');
if (!container || !reciterSelect) return;
container.innerHTML = '';
// ุชุญู
ูู ุงูุงุฎุชูุงุฑุงุช ุงูู
ุญููุธุฉ
const saved = localStorage.getItem('selectedRecitersForRandom');
if (saved) {
try {
selectedRecitersForRandom = JSON.parse(saved);
} catch (e) {
selectedRecitersForRandom = [];
}
}
// ุฅูุดุงุก checkboxes
for (let i = 0; i < reciterSelect.options.length; i++) {
const option = reciterSelect.options[i];
const reciterValue = option.value;
const reciterName = option.text;
// ูู ู
ููุด ู
ุญููุธุงุชุ ูุญุฏุฏ ุงููู ุงูุชุฑุงุถูุงู
const isChecked = selectedRecitersForRandom.length === 0 || selectedRecitersForRandom.includes(reciterValue);
const label = document.createElement('label');
label.style.cssText = 'display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 4px; transition: background 0.2s;';
label.innerHTML = `
<input type="checkbox" value="${reciterValue}" ${isChecked ? 'checked' : ''} onchange="updateSelectedReciters()" style="width: 16px; height: 16px; cursor: pointer;">
<span style="font-size: 0.85rem;">${reciterName}</span>
`;
label.onmouseenter = () => label.style.background = 'var(--bg-card)';
label.onmouseleave = () => label.style.background = 'transparent';
container.appendChild(label);
}
// ุชุญุฏูุซ ุงููุงุฆู
ุฉ ุงูู
ุญุฏุฏุฉ
updateSelectedReciters();
}
function updateSelectedReciters() {
const checkboxes = document.querySelectorAll('#reciterCheckboxes input[type="checkbox"]');
selectedRecitersForRandom = [];
checkboxes.forEach(cb => {
if (cb.checked) {
selectedRecitersForRandom.push(cb.value);
}
});
// ุญูุธ ูู localStorage
localStorage.setItem('selectedRecitersForRandom', JSON.stringify(selectedRecitersForRandom));
}
function selectAllReciters() {
const checkboxes = document.querySelectorAll('#reciterCheckboxes input[type="checkbox"]');
checkboxes.forEach(cb => cb.checked = true);
updateSelectedReciters();
}
function deselectAllReciters() {
const checkboxes = document.querySelectorAll('#reciterCheckboxes input[type="checkbox"]');
checkboxes.forEach(cb => cb.checked = false);
updateSelectedReciters();
// ูุงุฒู
ุนูู ุงูุฃูู ูุงุฑุฆ ูุงุญุฏ ูููู ู
ุญุฏุฏ
if (checkboxes.length > 0) {
checkboxes[0].checked = true;
updateSelectedReciters();
}
}
function randomizeBatch() {
const reciterSelect = document.getElementById('batchReciterSelect');
const surahSelect = document.getElementById('batchSurahSelect');
// ๐ฏ ุงุฎุชูุงุฑ ูุงุฑุฆ ุนุดูุงุฆู ู
ู ุงูู
ุญุฏุฏูู ููุท
if (selectedRecitersForRandom.length > 0) {
const randomReciter = selectedRecitersForRandom[Math.floor(Math.random() * selectedRecitersForRandom.length)];
// ุงูุจุญุซ ุนู ุงูู index ูู ุงูู select
for (let i = 0; i < reciterSelect.options.length; i++) {
if (reciterSelect.options[i].value === randomReciter) {
reciterSelect.selectedIndex = i;
break;
}
}
} else if (reciterSelect.options.length > 0) {
reciterSelect.selectedIndex = Math.floor(Math.random() * reciterSelect.options.length);
}
if (surahSelect.options.length > 0) {
surahSelect.selectedIndex = Math.floor(Math.random() * surahSelect.options.length);
const max = VERSE_COUNTS[parseInt(surahSelect.value)] || 286;
const start = Math.floor(Math.random() * Math.max(1, max - 5)) + 1;
document.getElementById('batchStartAyah').value = start;
document.getElementById('batchEndAyah').value = Math.min(start + 4, max);
}
updateBatchEstimatedTime();
}
function adjustBatchAyah(id, delta) {
const input = document.getElementById(id);
const surah = parseInt(document.getElementById('batchSurahSelect').value);
const max = VERSE_COUNTS[surah] || 286;
let val = parseInt(input.value) + delta;
if (val < 1) val = 1;
if (val > max) val = max;
input.value = val;
const start = parseInt(document.getElementById('batchStartAyah').value);
const end = parseInt(document.getElementById('batchEndAyah').value);
if (id === 'batchStartAyah' && start > end) {
document.getElementById('batchEndAyah').value = start;
}
if (id === 'batchEndAyah' && end < start) {
document.getElementById('batchStartAyah').value = end;
}
updateBatchEstimatedTime();
}
const MAX_BATCH_VIDEOS = 10; // ุงูุญุฏ ุงูุฃูุตู ูุนุฏุฏ ุงูููุฏูููุงุช ูู ุงูุฏูุนุฉ
function addToBatchList() {
const reciterSelect = document.getElementById('batchReciterSelect');
const surahSelect = document.getElementById('batchSurahSelect');
// ุงูุชุญูู ู
ู ุงูุญุฏ ุงูุฃูุตู
if (batchItems.length >= MAX_BATCH_VIDEOS) {
showToast(`ุงูุญุฏ ุงูุฃูุตู ูู ${MAX_BATCH_VIDEOS} ููุฏูู ูู ุงูุฏูุนุฉ ุงููุงุญุฏุฉ`, 'error');
return;
}
const reciter = reciterSelect.value;
const reciterName = reciterSelect.options[reciterSelect.selectedIndex]?.text || 'ุบูุฑ ู
ุญุฏุฏ';
const surah = parseInt(surahSelect.value);
const surahName = surahSelect.options[surahSelect.selectedIndex]?.text.replace(/^\d+\.\s*/, '') || 'ุบูุฑ ู
ุญุฏุฏ';
const startAyah = parseInt(document.getElementById('batchStartAyah').value);
const endAyah = parseInt(document.getElementById('batchEndAyah').value);
const exists = batchItems.some(item =>
item.reciter === reciter && item.surah === surah &&
item.startAyah === startAyah && item.endAyah === endAyah
);
if (exists) {
showToast('ูุฐุง ุงูููุฏูู ู
ูุฌูุฏ ุจุงููุนู ูู ุงููุงุฆู
ุฉ', 'error');
return;
}
const effects = {
dynamicBg: document.getElementById('batchDynamicBg').checked,
useGlow: document.getElementById('batchUseGlow').checked,
useVignette: document.getElementById('batchUseVignette').checked
};
// โ
ุฅุนุฏุงุฏุงุช ุงูููุฏูู ุงููุงู
ูุฉ
const videoSettings = {
fps: parseInt(document.getElementById('batchFpsSelect')?.value || 20),
quality: document.getElementById('batchQualitySelect')?.value || '720',
aspectRatio: document.getElementById('batchAspectRatio')?.value || '9:16',
font: document.getElementById('batchFontSelect')?.value || 'Arabic',
fontEn: document.getElementById('batchFontEnSelect')?.value || 'English',
bgQuery: document.getElementById('batchUseSearch')?.checked ? (document.getElementById('batchBgQuery')?.value || '') : ''
};
batchItems.push({
reciter,
reciterName,
surah,
startAyah,
endAyah,
surahName,
effects,
...videoSettings
});
renderBatchList();
showToast(`ุชู
ุช ุงูุฅุถุงูุฉ: ${surahName} (${reciterName})`, 'success');
}
function removeFromBatchList(index) {
batchItems.splice(index, 1);
renderBatchList();
updateBatchTotalVideos();
}
function clearBatchList() {
batchItems = [];
renderBatchList();
updateBatchTotalVideos();
updateBatchTotalTime();
}
function updateBatchTotalVideos() {
document.getElementById('batchTotalVideos').textContent = batchItems.length;
updateBatchTotalTime();
}
function renderBatchList() {
const listEl = document.getElementById('batchList');
const countEl = document.getElementById('batchCount');
countEl.textContent = batchItems.length;
updateBatchTotalVideos();
updateBatchTotalTime();
// ูู ุงููุงุฆู
ุฉ ูุงุถูุฉ
if (batchItems.length === 0) {
listEl.innerHTML = `
<div class="history-empty" id="batchListEmpty">
<p style="font-size: 0.85rem;">ูู
ุชุชู
ุฅุถุงูุฉ ุฃู ููุฏูููุงุช</p>
</div>
`;
return;
}
// ุนุฑุถ ุงูููุฏูููุงุช
listEl.innerHTML = batchItems.map((item, index) => {
const effectsIcons = [];
if (item.effects.dynamicBg) effectsIcons.push('๐ผ๏ธ');
if (item.effects.useGlow) effectsIcons.push('โจ');
if (item.effects.useVignette) effectsIcons.push('๐ญ');
// ู
ุญุงููุฉ ุงูุญุตูู ุนูู ุงูููุช ู
ู ุงูู cache
const cacheKey = `${item.reciter}-${item.surah}-${item.startAyah}-${item.endAyah}`;
const cachedData = durationCache[cacheKey];
const timeStr = cachedData ? cachedData.formatted : 'โณ...';
return `
<div class="batch-item" data-index="${index}" style="
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 10px;
padding: 12px;
margin-bottom: 8px;
display: flex;
justify-content: space-between;
align-items: center;
">
<div style="flex: 1;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div style="font-weight: 600; font-size: 0.95rem;">
๐ ${item.surahName}
</div>
<div style="display: flex; align-items: center; gap: 8px;">
<span class="batch-item-time" data-index="${index}" style="font-size: 0.75rem; color: var(--accent);">โฑ๏ธ ${timeStr}</span>
<span style="font-size: 0.75rem; color: var(--text-muted);">#${index + 1}</span>
</div>
</div>
<div style="font-size: 0.8rem; color: var(--text-muted); margin-top: 4px;">
๐ค ${item.reciterName} โข ุขูุฉ ${item.startAyah} โ ${item.endAyah}
</div>
<div style="font-size: 0.75rem; color: var(--accent); margin-top: 4px;">
${effectsIcons.join(' ')}
</div>
</div>
<button onclick="removeFromBatchList(${index})" style="
background: none;
border: none;
color: var(--danger);
font-size: 1.2rem;
cursor: pointer;
padding: 8px;
">โ</button>
</div>
`}).join('');
// ุชุญุฏูุซ ุฃููุงุช ุงูููุฏูููุงุช ูู ุงูุฎูููุฉ
updateBatchItemTimes();
}
async function updateBatchItemTimes() {
// ุชุญุฏูุซ ููุช ูู ููุฏูู ูู ุงููุงุฆู
ุฉ
for (let i = 0; i < batchItems.length; i++) {
const item = batchItems[i];
const data = await fetchEstimatedTime(item.reciter, item.surah, item.startAyah, item.endAyah);
if (data && data.formatted) {
const timeEl = document.querySelector(`.batch-item-time[data-index="${i}"]`);
if (timeEl) {
timeEl.textContent = `โฑ๏ธ ${data.formatted}`;
}
}
}
}
async function startBatchGeneration() {
if (batchItems.length === 0) {
showToast('ุฃุถู ููุฏูููุงุช ูููุงุฆู
ุฉ ุฃููุงู', 'error');
return;
}
batchCancelled = false;
const payload = {
sessionId: SESSION_ID,
items: batchItems.map(item => ({
surah: item.surah,
startAyah: item.startAyah,
endAyah: item.endAyah,
reciter: item.reciter,
dynamicBg: item.effects?.dynamicBg ?? true,
useGlow: item.effects?.useGlow ?? true,
useVignette: item.effects?.useVignette ?? true,
aspectRatio: item.aspectRatio || '9:16',
font: item.font || 'Arabic',
fontEn: item.fontEn || 'English',
fps: item.fps || 20,
quality: item.quality || '720',
bgQuery: item.bgQuery || ''
})),
pexelsKey: localStorage.getItem('user_pexels_key') || '',
style: getStyleSettings()
};
try {
showToast('ุฌุงุฑู ุฅูุดุงุก ุงูุฏูุนุฉ...', 'success');
const res = await fetch('/api/batch/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const data = await res.json();
if (data.ok) {
currentBatchId = data.batchId;
showToast(`ุชู
ุฅูุดุงุก ุฏูุนุฉ ู
ู ${data.totalJobs} ููุฏูู`, 'success');
const statusSection = document.getElementById('batchStatusSection');
const totalCount = document.getElementById('batchTotalCount');
const completedCount = document.getElementById('batchCompletedCount');
if (statusSection) statusSection.style.display = 'block';
if (totalCount) totalCount.textContent = data.totalJobs;
if (completedCount) completedCount.textContent = 0;
startBatchPolling(data.batchId);
batchItems = [];
renderBatchList();
} else {
showToast(data.error || 'ูุดู ุฅูุดุงุก ุงูุฏูุนุฉ', 'error');
}
} catch (err) {
console.error('Batch creation error:', err);
}
}
function cancelBatch() {
if (!currentBatchId) return;
batchCancelled = true;
fetch('/api/batch/cancel', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ batchId: currentBatchId })
});
showToast('ุชู
ุฅูุบุงุก ุงูุฏูุนุฉ', 'error');
}
let batchPollInterval = null;
let batchRemainingSeconds = 0;
let batchCountdownInterval = null;
let batchLastCompleted = 0;
function startBatchPolling(batchId) {
if (batchPollInterval) clearInterval(batchPollInterval);
stopBatchCountdown();
batchLastCompleted = 0;
batchPollInterval = setInterval(async () => {
if (batchCancelled) {
clearInterval(batchPollInterval);
stopBatchCountdown();
return;
}
try {
const res = await fetch(`/api/batch/status?batchId=${batchId}`);
const data = await res.json();
if (data.ok) {
updateBatchProgress(data.batch);
if (data.batch.status === 'complete' || data.batch.status === 'cancelled') {
clearInterval(batchPollInterval);
stopBatchCountdown();
if (data.batch.status === 'complete') {
showToast(`ุชู
ุฅูุดุงุก ${data.batch.completedJobs} ููุฏูู ุจูุฌุงุญ!`, 'success');
loadHistory();
}
}
}
} catch (err) {
console.error('Batch polling error:', err);
}
}, 2000);
}
function updateBatchProgress(batch) {
const total = batch.totalJobs;
const completed = batch.completedJobs || 0;
const failed = batch.failedJobs || 0;
const percent = total > 0 ? Math.round(((completed + failed) / total) * 100) : 0;
const circle = document.getElementById('batchProgressCircle');
const circumference = 2 * Math.PI * 65;
if (circle) {
circle.style.strokeDashoffset = circumference - (percent / 100) * circumference;
}
document.getElementById('batchProgressPercent').textContent = `${percent}%`;
document.getElementById('batchCompletedCount').textContent = completed + failed;
const statusEl = document.getElementById('batchProgressStatus');
const currentVideoEl = document.getElementById('batchCurrentVideo');
const currentVideoNameEl = document.getElementById('batchCurrentVideoName');
const remainingTimeEl = document.getElementById('batchRemainingTime');
const remainingTimeValueEl = document.getElementById('batchRemainingTimeValue');
if (batch.status === 'running') {
statusEl.textContent = `ุฌุงุฑู ุงูู
ุนุงูุฌุฉ... (${batch.currentJobIndex + 1}/${total})`;
// ุนุฑุถ ุงูููุฏูู ุงูุญุงูู
if (batch.currentVideo) {
currentVideoEl.style.display = 'block';
currentVideoNameEl.textContent = `${batch.currentVideo.surahName} - ุขูุฉ ${batch.currentVideo.ayah}`;
} else {
currentVideoEl.style.display = 'none';
}
// ุนุฑุถ ุงูููุช ุงูู
ุชุจูู (smooth countdown)
if (batch.remainingTime !== null && batch.remainingTime !== undefined) {
const newDone = batch.completedJobs || 0;
if (newDone !== batchLastCompleted) {
batchRemainingSeconds = batch.remainingTime;
batchLastCompleted = newDone;
}
remainingTimeEl.style.display = 'block';
remainingTimeValueEl.textContent = formatTime(batchRemainingSeconds);
startBatchCountdown();
} else {
remainingTimeEl.style.display = 'none';
stopBatchCountdown();
}
} else if (batch.status === 'complete') {
statusEl.textContent = `โ
ุงูุชู
ู!`;
currentVideoEl.style.display = 'none';
remainingTimeEl.style.display = 'none';
stopBatchCountdown();
} else if (batch.status === 'cancelled') {
statusEl.textContent = `โ ๏ธ ุชู
ุงูุฅูุบุงุก`;
currentVideoEl.style.display = 'none';
remainingTimeEl.style.display = 'none';
stopBatchCountdown();
} else if (batch.status === 'pending') {
statusEl.textContent = `โณ ูู ุงูุงูุชุธุงุฑ...`;
currentVideoEl.style.display = 'none';
stopBatchCountdown();
remainingTimeEl.style.display = 'none';
}
}
function formatTime(seconds) {
if (seconds < 60) {
return `${seconds} ุซุงููุฉ`;
}
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
if (mins >= 60) {
const hours = Math.floor(mins / 60);
const remainMins = mins % 60;
return `${hours} ุณุงุนุฉ ${remainMins} ุฏ`;
}
return `${mins} ุฏ ${secs} ุซ`;
}
// Smooth countdown for batch remaining time
function startBatchCountdown() {
stopBatchCountdown();
batchCountdownInterval = setInterval(() => {
if (batchRemainingSeconds > 0) {
batchRemainingSeconds--;
const el = document.getElementById('batchRemainingTimeValue');
if (el) el.textContent = formatTime(batchRemainingSeconds);
}
}, 1000);
}
function stopBatchCountdown() {
if (batchCountdownInterval) {
clearInterval(batchCountdownInterval);
batchCountdownInterval = null;
}
}
function initBatchPage() {
const batchSurahSelect = document.getElementById('batchSurahSelect');
const mainSurahSelect = document.getElementById('surahSelect');
if (batchSurahSelect && mainSurahSelect) {
batchSurahSelect.innerHTML = mainSurahSelect.innerHTML;
batchSurahSelect.addEventListener('change', () => {
const max = VERSE_COUNTS[parseInt(batchSurahSelect.value)] || 286;
document.getElementById('batchStartAyah').value = 1;
document.getElementById('batchEndAyah').value = Math.min(5, max);
});
}
const batchReciterSelect = document.getElementById('batchReciterSelect');
const mainReciterSelect = document.getElementById('reciterSelect');
if (batchReciterSelect && mainReciterSelect) {
batchReciterSelect.innerHTML = mainReciterSelect.innerHTML;
}
// ๐ค ุชููุฆุฉ checkboxes ุงููุฑุงุก ููุนุดูุงุฆู
initReciterCheckboxes();
}
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
if (btn.dataset.tab === 'batch') {
initBatchPage();
}
});
});
async function checkActiveBatch() {
try {
const res = await fetch(`/api/batch/list?sessionId=${encodeURIComponent(SESSION_ID)}`);
const data = await res.json();
if (data.ok && data.batches) {
const activeBatch = data.batches.find(b =>
b.status === 'pending' || b.status === 'running'
);
if (activeBatch) {
currentBatchId = activeBatch.id;
document.getElementById('batchStatusSection').style.display = 'block';
document.getElementById('batchTotalCount').textContent = activeBatch.totalJobs;
startBatchPolling(activeBatch.id);
}
}
} catch (err) {
console.log('No active batches');
}
}
setTimeout(checkActiveBatch, 1000);
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๐ Auto Publish System
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
let currentAutoPublishId = null;
let autoPublishPolling = null;
let apRemainingSeconds = 0; // Live countdown value (decreases every second)
let apCountdownInterval = null; // 1-second timer for smooth countdown
let apLastCompleted = 0; // Last known completed count (to recalculate from server)
let SURAH_NAMES = [];
// Initialize auto-publish page when tab is clicked
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
if (btn.dataset.tab === 'autopublish') {
initAutoPublishPage();
}
});
});
let apRecitersReady = false;
function apSyncRecitersToStorage() {
// Save selected reciters to localStorage (same key as batch export)
const selected = getSelectedReciters();
localStorage.setItem('selectedRecitersForRandom', JSON.stringify(selected));
}
function apSelectAllReciters() {
document.querySelectorAll('#ap-reciters-list input[type=checkbox]').forEach(cb => cb.checked = true);
apSyncRecitersToStorage();
}
function apDeselectAllReciters() {
document.querySelectorAll('#ap-reciters-list input[type=checkbox]').forEach(cb => cb.checked = false);
apSyncRecitersToStorage();
}
function getSelectedReciters() {
const checked = document.querySelectorAll('#ap-reciters-list input[type=checkbox]:checked');
return Array.from(checked).map(cb => cb.value);
}
function initAutoPublishPage() {
// Populate reciters checkbox list from main select
const recitersList = document.getElementById('ap-reciters-list');
const mainReciter = document.getElementById('reciterSelect');
if (recitersList && mainReciter && !apRecitersReady) {
recitersList.innerHTML = '';
// Load saved reciters from localStorage (same source as batch export)
let savedReciters = [];
try {
const saved = localStorage.getItem('selectedRecitersForRandom');
if (saved) savedReciters = JSON.parse(saved);
} catch (e) { savedReciters = []; }
for (let i = 0; i < mainReciter.options.length; i++) {
const opt = mainReciter.options[i];
const label = document.createElement('label');
label.style.cssText = 'display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; transition: background 0.2s;';
label.onmouseover = () => label.style.background = 'rgba(255,255,255,0.05)';
label.onmouseout = () => label.style.background = 'transparent';
// If saved reciters exist, check only those; otherwise check all
const isChecked = savedReciters.length === 0 || savedReciters.includes(opt.value);
label.innerHTML = `<input type="checkbox" value="${opt.value}" ${isChecked ? 'checked' : ''} onchange="apSyncRecitersToStorage()" style="accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer;"> <span>${opt.text}</span>`;
recitersList.appendChild(label);
}
apRecitersReady = true;
}
// Populate hour dropdowns
const timeStart = document.getElementById('ap-time-start');
const timeEnd = document.getElementById('ap-time-end');
if (timeStart && timeStart.options.length === 0) {
for (let h = 0; h < 24; h++) {
const label = h.toString().padStart(2, '0') + ':00';
timeStart.add(new Option(label, h));
timeEnd.add(new Option(label, h));
}
timeStart.value = '14';
timeEnd.value = '22';
}
// Build SURAH_NAMES from main surahSelect
const mainSurah = document.getElementById('surahSelect');
if (mainSurah && mainSurah.options.length > 0 && SURAH_NAMES.length === 0) {
for (let i = 0; i < mainSurah.options.length; i++) {
SURAH_NAMES.push(mainSurah.options[i].text.replace(/^\d+\.\s*/, ''));
}
}
// Check YouTube auth status
checkYouTubeAuth();
// Load auto-publish history
loadAutoPublishList();
// โ
ูู ูุงู ููู batch ุดุบุงู ู
ุญููุธ ูู localStorageุ ูุนุฑุถ ุงูุชูุฏู
const savedApId = localStorage.getItem('activeAutoPublishId');
if (savedApId) {
currentAutoPublishId = savedApId;
startAutoPublishPolling();
}
}
async function startAutoPublish() {
const session = SESSION_ID;
if (!session) return showToast('ูุฑุฌู ุชุญุฏูุซ ุงูุตูุญุฉ', 'error');
// Check YouTube auth first
const ytStatus = await checkYouTubeAuth();
if (!ytStatus.authorized) {
showToast('ูุฑุฌู ุฑุจุท ุญุณุงุจ YouTube ุฃููุงู', 'error');
return;
}
const count = parseInt(document.getElementById('ap-count')?.value || 10);
const selectedReciters = getSelectedReciters();
if (selectedReciters.length === 0) {
showToast('ูุฑุฌู ุงุฎุชูุงุฑ ูุงุฑุฆ ูุงุญุฏ ุนูู ุงูุฃูู', 'error');
return;
}
const quality = document.getElementById('ap-quality')?.value || '720';
const fps = document.getElementById('ap-fps')?.value || '20';
const dynamicBg = document.getElementById('ap-dynamic-bg')?.checked ?? true;
const useGlow = document.getElementById('ap-use-glow')?.checked ?? true;
const useVignette = document.getElementById('ap-use-vignette')?.checked ?? true;
const aspectRatio = document.getElementById('ap-aspect-ratio')?.value || '9:16';
const font = document.getElementById('ap-font-select')?.value || 'Arabic';
const fontEn = document.getElementById('ap-font-en-select')?.value || 'English';
const titleTemplate = document.getElementById('ap-title-template')?.value || 'ูุฑุขู ูุฑูู
{surah_name} ({ayah_range}) ุจุตูุช ุงููุงุฑุฆ {reciter}';
const descriptionTemplate = document.getElementById('ap-description')?.value || '#ูุฑุงู_ูุฑูู
#ูุฑุงู #quran #fyp #ูุฑุขู_ูุฑูู
_ุฑุงุญุฉ_ููุณูุฉ #shorts';
const tags = document.getElementById('ap-tags')?.value?.split(',').map(t => t.trim()).filter(Boolean) || ['ูุฑุขู ูุฑูู
', 'ุชูุงูุฉ', 'ุฅุณูุงู
', 'Quran', 'ูุฑุขู', 'ุชูุงูุฉ ูุฑุขููุฉ'];
const spreadDays = parseInt(document.getElementById('ap-spread-days')?.value || 7);
const timeStart = parseInt(document.getElementById('ap-time-start')?.value || 14);
const timeEnd = parseInt(document.getElementById('ap-time-end')?.value || 22);
try {
showToast('ุฌุงุฑู ุฅูุดุงุก ุงููุดุฑ ุงูุชููุงุฆู...', 'info');
const res = await fetch('/api/auto-publish/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: session,
count, reciters: selectedReciters, quality, fps, dynamicBg,
useGlow, useVignette, aspectRatio, font, fontEn,
titleTemplate, descriptionTemplate, tags,
spreadDays, timeStartHour: timeStart, timeEndHour: timeEnd,
})
});
const data = await res.json();
if (data.ok) {
currentAutoPublishId = data.autoPublishId;
// โ
ุญุณุงุจ ุงูููุช ุงูู
ุชููุน ููุจุงุชุดุงุช ุงููุจูุฑุฉ
let extraInfo = '';
if (data.totalVideos > 6) {
const estSeconds = data.totalVideos * 90; // ~90 ุซุงููุฉ ููู ููุฏูู (ุชุตููุน + ุฑูุน)
const estMinutes = Math.ceil(estSeconds / 60);
if (estMinutes >= 60) {
const hours = Math.floor(estMinutes / 60);
const mins = estMinutes % 60;
extraInfo = ` (ุงูููุช ุงูู
ุชููุน: ~${hours} ุณุงุนุฉ ู ${mins} ุฏูููุฉ)`;
} else {
extraInfo = ` (ุงูููุช ุงูู
ุชููุน: ~${estMinutes} ุฏูููุฉ)`;
}
}
showToast(`ุชู
ุฅูุดุงุก ${data.totalVideos} ููุฏูู - ุฌุงุฑู ุงูู
ุนุงูุฌุฉ${extraInfo}`, 'success');
showAutoPublishProgress();
startAutoPublishPolling();
loadAutoPublishList();
} else {
showToast(data.error || 'ุญุฏุซ ุฎุทุฃ', 'error');
}
} catch (e) {
showToast('ุฎุทุฃ ูู ุงูุงุชุตุงู', 'error');
}
}
async function pollAutoPublishStatus() {
if (!currentAutoPublishId) return;
try {
const res = await fetch(`/api/auto-publish/status?autoPublishId=${currentAutoPublishId}`);
const data = await res.json();
if (data.ok) {
updateAutoPublishUI(data.autoPublish);
if (data.autoPublish.status === 'complete' || data.autoPublish.status === 'cancelled' || data.autoPublish.status === 'error' || data.autoPublish.status === 'quota_paused') {
stopAutoPublishPolling();
if (data.autoPublish.status !== 'quota_paused') {
localStorage.removeItem('activeAutoPublishId');
}
loadAutoPublishList();
}
}
} catch (e) {
console.error('Poll error:', e);
}
}
function startAutoPublishPolling() {
stopAutoPublishPolling();
autoPublishPolling = setInterval(pollAutoPublishStatus, 2000);
pollAutoPublishStatus();
}
function stopAutoPublishPolling() {
if (autoPublishPolling) {
clearInterval(autoPublishPolling);
autoPublishPolling = null;
}
stopApCountdown();
}
function updateAutoPublishUI(ap) {
const totalEl = document.getElementById('ap-total');
const completedEl = document.getElementById('ap-completed');
const uploadedEl = document.getElementById('ap-uploaded');
const failedEl = document.getElementById('ap-failed');
const remainingEl = document.getElementById('ap-remaining');
const statusEl = document.getElementById('ap-status-text');
if (totalEl) totalEl.textContent = ap.totalVideos;
if (completedEl) completedEl.textContent = ap.completedVideos || 0;
if (uploadedEl) uploadedEl.textContent = ap.uploadedVideos || 0;
if (failedEl) failedEl.textContent = ap.failedVideos || 0;
// Find the currently generating item to show per-video progress
let currentItem = null;
if (ap.items) {
currentItem = ap.items.find(item => item.status === 'generating');
}
const currentVideoSection = document.getElementById('ap-current-video-section');
const currentVideoNameEl = document.getElementById('ap-current-video-name');
const currentVideoBarEl = document.getElementById('ap-current-video-bar');
const currentVideoPercentEl = document.getElementById('ap-current-video-percent');
if (currentItem && ap.status === 'running') {
if (currentVideoSection) currentVideoSection.style.display = 'block';
const surahName = SURAH_NAMES?.[currentItem.surah - 1] || `ุณูุฑุฉ ${currentItem.surah}`;
const recName = currentItem.reciterName || currentItem.reciter || '';
const videoName = `${surahName} (${currentItem.startAyah}-${currentItem.endAyah})${recName ? ' ๐ค' + recName : ''}`;
if (currentVideoNameEl) currentVideoNameEl.textContent = videoName;
const itemPercent = currentItem.percent || 0;
if (currentVideoBarEl) currentVideoBarEl.style.width = itemPercent + '%';
if (currentVideoPercentEl) currentVideoPercentEl.textContent = itemPercent + '%';
// Status text shows current video info
if (statusEl) statusEl.textContent = `๐ ุฌุงุฑู ุชุตู
ูู
ุงูููุฏูู (${ap.completedVideos || 0}/${ap.totalVideos})`;
} else if (ap.status === 'running') {
// Running but no currently generating item (maybe uploading)
if (currentVideoSection) currentVideoSection.style.display = 'none';
if (statusEl) statusEl.textContent = `๐ ุฌุงุฑู ุงูู
ุนุงูุฌุฉ (${ap.completedVideos || 0}/${ap.totalVideos})`;
} else {
if (currentVideoSection) currentVideoSection.style.display = 'none';
}
// Calculate remaining time based on actual progress
if (ap.status === 'running') {
const done = (ap.completedVideos || 0) + (ap.failedVideos || 0);
const remainingVideos = ap.totalVideos - done;
// If a video is currently generating, factor in its progress
let effectiveRemaining = remainingVideos;
if (currentItem && currentItem.percent > 0) {
effectiveRemaining = remainingVideos - 1 + (1 - currentItem.percent / 100);
}
// Estimate ~60 seconds per video generation + ~30 seconds per upload
const estimatedRemaining = Math.max(0, Math.round(effectiveRemaining * 90));
if (estimatedRemaining !== apRemainingSeconds || done !== apLastCompleted) {
apRemainingSeconds = estimatedRemaining;
apLastCompleted = done;
}
startApCountdown();
} else {
stopApCountdown();
}
if (remainingEl) remainingEl.textContent = apRemainingSeconds > 0 ? formatAPTime(apRemainingSeconds) : (ap.status !== 'running' ? '--' : '00:00');
const statusMap = {
'pending': 'โณ ูู ุงูุงูุชุธุงุฑ...',
'running': '๐ ุฌุงุฑู ุงูู
ุนุงูุฌุฉ...',
'complete': 'โ
ุงูุชู
ู!',
'cancelled': 'โ ๏ธ ู
ูุบู',
'error': 'โ ุญุฏุซ ุฎุทุฃ',
'quota_paused': 'โธ๏ธ ุชููู ู
ุคูุชุงู (ููุฐ ุญุตุฉ YouTube)'
};
// Only use statusMap for non-running statuses (we set running status above)
if (statusEl && ap.status !== 'running') {
statusEl.textContent = statusMap[ap.status] || ap.status;
}
// โ
ุฅุธูุงุฑ/ุฅุฎูุงุก ุฒุฑ ุงูุงุณุชุฆูุงู ูู
ุนููู
ุงุช ุงูุญุตุฉ
const resumeBtn = document.getElementById('ap-resume-btn');
const quotaInfo = document.getElementById('ap-quota-info');
const cancelBtn = document.getElementById('ap-cancel-btn');
if (resumeBtn) resumeBtn.style.display = ap.status === 'quota_paused' ? 'inline-block' : 'none';
if (quotaInfo) quotaInfo.style.display = ap.status === 'quota_paused' ? 'block' : 'none';
if (cancelBtn) cancelBtn.style.display = (ap.status === 'running' || ap.status === 'pending') ? 'inline-block' : 'none';
showAutoPublishProgress();
// Update items list
const itemsList = document.getElementById('ap-items-list');
if (itemsList && ap.items) {
itemsList.innerHTML = ap.items.map(item => {
const surahName = SURAH_NAMES?.[item.surah - 1] || `ุณูุฑุฉ ${item.surah}`;
const statusBadge = getAPItemStatusBadge(item.status);
const scheduleStr = item.scheduledTime ? formatAPScheduleTime(item.scheduledTime) : '';
const ytLink = item.videoUrl ? `<a href="${item.videoUrl}" target="_blank" style="color: #22c55e; text-decoration: none; font-size: 12px;">YouTube โ</a>` : '';
const reciterName = item.reciterName || item.reciter || '';
const itemPercent = item.status === 'generating' && item.percent > 0 ? ` <span style="color: var(--text-muted); font-size: 10px;">[${item.percent}%]</span>` : '';
return `
<div class="ap-item" style="display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.05);">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="color: #888; font-size: 12px; min-width: 24px;">#${item.position + 1}</span>
<div>
<span style="font-size: 14px;">${surahName} (${item.startAyah}-${item.endAyah})</span>
${reciterName ? `<span style="color: var(--text-muted); font-size: 11px; margin-right: 6px;">๐ค${reciterName}</span>` : ''}
${statusBadge}${itemPercent}
</div>
</div>
<div style="text-align: left; display: flex; align-items: center; gap: 10px;">
<span style="color: #888; font-size: 11px;">${scheduleStr}</span>
${ytLink}
</div>
</div>
`;
}).join('');
}
// Update progress ring and bar based on overall completion
const percent = ap.totalVideos > 0 ? Math.round(((ap.completedVideos || 0) / ap.totalVideos) * 100) : 0;
const progressRing = document.getElementById('ap-progress-ring');
if (progressRing) {
const circumference = 2 * Math.PI * 65;
progressRing.style.strokeDashoffset = circumference - (percent / 100) * circumference;
}
const progressBar = document.getElementById('ap-progress-bar');
if (progressBar) progressBar.style.width = percent + '%';
const progressText = document.getElementById('ap-progress-text');
if (progressText) progressText.textContent = percent + '%';
}
function getAPItemStatusBadge(status) {
const styles = {
'pending': 'background: #374151; color: #9ca3af;',
'generating': 'background: #1e3a5f; color: #60a5fa;',
'generated': 'background: #1a3a2a; color: #4ade80;',
'uploading': 'background: #3b2f1a; color: #fbbf24;',
'published': 'background: #14532d; color: #22c55e;',
'upload_failed': 'background: #3b1a1a; color: #f87171;',
'quota_exceeded': 'background: #4a2000; color: #ff9800;',
'error': 'background: #3b1a1a; color: #f87171;',
};
const labels = {
'pending': 'ุงูุชุธุงุฑ',
'generating': 'ุชุตู
ูู
',
'generated': 'ุฌุงูุฒ',
'uploading': 'ุฑูุน',
'published': 'ู
ูุดูุฑ',
'upload_failed': 'ูุดู ุงูุฑูุน',
'quota_exceeded': 'ููุฐ ุงูุญุตุฉ',
'error': 'ุฎุทุฃ',
};
const style = styles[status] || styles.pending;
const label = labels[status] || status;
return ` <span style="${style} padding: 2px 8px; border-radius: 12px; font-size: 11px;">${label}</span>`;
}
function formatAPScheduleTime(isoStr) {
try {
const d = new Date(isoStr);
return d.toLocaleDateString('ar-EG', { month: 'short', day: 'numeric' }) + ' ' +
d.toLocaleTimeString('ar-EG', { hour: '2-digit', minute: '2-digit' });
} catch {
return isoStr;
}
}
function formatAPTime(seconds) {
if (!seconds || seconds <= 0) return '00:00';
const m = Math.floor(seconds / 60);
const s = seconds % 60;
if (m >= 60) {
const h = Math.floor(m / 60);
const rm = m % 60;
return `${h}:${rm.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
}
return `${m}:${s.toString().padStart(2, '0')}`;
}
// Smooth countdown: ticks every second so the user sees progress
function startApCountdown() {
stopApCountdown();
apCountdownInterval = setInterval(() => {
if (apRemainingSeconds > 0) {
apRemainingSeconds--;
const el = document.getElementById('ap-remaining');
if (el) el.textContent = formatAPTime(apRemainingSeconds);
}
}, 1000);
}
function stopApCountdown() {
if (apCountdownInterval) {
clearInterval(apCountdownInterval);
apCountdownInterval = null;
}
}
function showAutoPublishProgress() {
const progressSection = document.getElementById('ap-progress-section');
if (progressSection) progressSection.style.display = 'block';
}
async function cancelAutoPublish() {
if (!currentAutoPublishId) return;
if (!confirm('ูู ุฃูุช ู
ุชุฃูุฏ ู
ู ุฅูุบุงุก ุงููุดุฑ ุงูุชููุงุฆูุ')) return;
try {
const res = await fetch('/api/auto-publish/cancel', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ autoPublishId: currentAutoPublishId })
});
const data = await res.json();
stopAutoPublishPolling();
localStorage.removeItem('activeAutoPublishId');
if (data.ok) {
showToast('ุชู
ุงูุฅูุบุงุก ุจูุฌุงุญ', 'info');
} else {
showToast(data.error || 'ุญุฏุซ ุฎุทุฃ ูู ุงูุฅูุบุงุก', 'error');
}
loadAutoPublishList();
} catch (e) {
showToast('ุฎุทุฃ ูู ุงูุงุชุตุงู', 'error');
}
}
async function resumeAutoPublish(apId) {
if (!confirm('ูู ุชุฑูุฏ ุงุณุชุฆูุงู ุงููุดุฑ ุงูุชููุงุฆูุ (ุณูุชู
ุฅุนุงุฏุฉ ู
ุญุงููุฉ ุงูุฑูุน ููููุฏูููุงุช ุงููุงุดูุฉ)')) return;
try {
const res = await fetch('/api/auto-publish/resume', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ autoPublishId: apId })
});
const data = await res.json();
if (data.ok) {
currentAutoPublishId = apId;
localStorage.setItem('activeAutoPublishId', apId);
showToast(`ุชู
ุงูุงุณุชุฆูุงู - ุฌุงุฑู ุฅุนุงุฏุฉ ู
ุญุงููุฉ ${data.retried} ููุฏูู`, 'success');
startAutoPublishPolling();
loadAutoPublishList();
} else {
showToast(data.error || 'ุญุฏุซ ุฎุทุฃ', 'error');
}
} catch (e) {
showToast('ุฎุทุฃ ูู ุงูุงุชุตุงู', 'error');
}
}
async function loadAutoPublishList() {
const session = SESSION_ID;
if (!session) return;
try {
const res = await fetch(`/api/auto-publish/list?sessionId=${session}`);
const data = await res.json();
const listEl = document.getElementById('ap-history-list');
if (!listEl) return;
if (!data.ok || !data.batches || data.batches.length === 0) {
listEl.innerHTML = '<p style="color: #666; text-align: center; padding: 20px;">ูุง ููุฌุฏ ุณุฌู ุจุนุฏ</p>';
return;
}
listEl.innerHTML = data.batches.map(b => {
const statusColor = b.status === 'complete' ? '#22c55e' : b.status === 'running' ? '#60a5fa' : b.status === 'cancelled' ? '#f59e0b' : b.status === 'quota_paused' ? '#ff9800' : '#f87171';
const date = new Date(b.createdAt * 1000).toLocaleDateString('ar-EG');
const statusLabel = b.status === 'running' ? '๐ ุฌุงุฑู' : b.status === 'complete' ? 'โ
ู
ูุชู
ู' : b.status === 'cancelled' ? 'โ ๏ธ ู
ูุบู' : b.status === 'quota_paused' ? 'โธ๏ธ ู
ุชููู' : 'โ ุฎุทุฃ';
const resumeBtn = b.status === 'quota_paused' ? `<button onclick="event.stopPropagation(); resumeAutoPublish('${b.id}')" style="background: #ff9800; color: white; border: none; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; font-family: inherit; white-space: nowrap; transition: opacity 0.2s;" onmouseover="this.style.opacity='0.85'" onmouseout="this.style.opacity='1'">โถ๏ธ ุงุณุชุฆูุงู</button>` : '';
return `
<div class="ap-history-item" style="display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.05);">
<div>
<span style="color: ${statusColor}; font-size: 12px;">โ</span>
<span style="margin-right: 8px; font-size: 14px;">${b.totalVideos} ููุฏูู</span>
<span style="color: #888; font-size: 12px;">${date}</span>
<span style="color: ${statusColor}; font-size: 11px; margin-right: 8px;">${statusLabel}</span>
</div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 12px; color: #888;">
โ
${b.completedVideos || 0} | ๐ค ${b.uploadedVideos || 0} | โ ${b.failedVideos || 0}
</span>
${resumeBtn}
<button onclick="event.stopPropagation(); viewAutoPublish('${b.id}')" style="background: var(--accent); color: white; border: none; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; font-family: inherit; white-space: nowrap; transition: opacity 0.2s;" onmouseover="this.style.opacity='0.85'" onmouseout="this.style.opacity='1'">๐ ุนุฑุถ ุงูุชูุฏู
</button>
</div>
</div>
`;
}).join('');
} catch (e) {
console.error('Load AP list error:', e);
}
}
function viewAutoPublish(apId) {
currentAutoPublishId = apId;
localStorage.setItem('activeAutoPublishId', apId);
startAutoPublishPolling();
}
// โ
ูุญุต ุชููุงุฆู ุนูุฏ ุชุญู
ูู ุงูุตูุญุฉ - ูู ููู batch ุดุบุงู ุฃู ู
ุชููู ูุนุฑุถ ุงูุชูุฏู
async function checkActiveAutoPublish() {
try {
const res = await fetch(`/api/auto-publish/list?sessionId=${encodeURIComponent(SESSION_ID)}`);
const data = await res.json();
if (data.ok && data.batches) {
const activeBatch = data.batches.find(b => b.status === 'running' || b.status === 'pending' || b.status === 'quota_paused');
if (activeBatch) {
currentAutoPublishId = activeBatch.id;
localStorage.setItem('activeAutoPublishId', activeBatch.id);
// ูู ุงูุชุงุจ ุฏู ู
ูุชูุญุ ุงุนุฑุถ ุงูุชูุฏู
ู
ุจุงุดุฑุฉ
const panel = document.getElementById('autopublish-panel');
if (panel && panel.style.display !== 'none') {
initAutoPublishPage();
startAutoPublishPolling();
}
return;
}
}
// ูู ู
ููุด batch ุดุบุงูุ ุงู
ุณุญ ุงูู localStorage
localStorage.removeItem('activeAutoPublishId');
} catch (err) {
console.log('No active auto-publish batches');
}
}
// ูุญุต ุชููุงุฆู ุจุนุฏ ุซุงููุฉ
setTimeout(checkActiveAutoPublish, 1500);
async function checkYouTubeAuth() {
const session = SESSION_ID;
try {
const res = await fetch(`/api/youtube/status?sessionId=${encodeURIComponent(session)}`);
const data = await res.json();
updateYouTubeConnectionStatus(data);
return data;
} catch {
return { authorized: false, configured: false };
}
}
function updateYouTubeConnectionStatus(data) {
const statusEl = document.getElementById('ap-yt-status');
if (!statusEl) return;
if (data.authorized) {
statusEl.innerHTML = '<span style="color: #22c55e;">โ
ู
ุชุตู ุจู YouTube</span>';
} else if (data.configured) {
statusEl.innerHTML = '<button onclick="connectYouTube()" style="background: #dc2626; color: white; border: none; padding: 6px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; font-family: inherit;">ุฑุจุท ุญุณุงุจ YouTube</button>';
} else {
statusEl.innerHTML = '<span style="color: #888;">YouTube ุบูุฑ ู
ุชููุฑ (ุชุญุชุงุฌ ุฅุนุฏุงุฏุงุช ุงูุณูุฑูุฑ)</span>';
}
}
let apAuthWindow = null;
async function connectYouTube() {
const session = SESSION_ID;
try {
showToast('ุฌุงุฑู ูุชุญ ูุงูุฐุฉ ุงูู
ุตุงุฏูุฉ...', 'info');
const authRes = await fetch(`/api/youtube/auth-url?sessionId=${encodeURIComponent(session)}`);
const authData = await authRes.json();
if (authData.authUrl) {
apAuthWindow = window.open(authData.authUrl, 'ap-yt-auth', 'width=500,height=600');
} else if (authData.ok && authData.alreadyAuthorized) {
showToast('ุงูุญุณุงุจ ู
ุชุตู ุจุงููุนู', 'info');
checkYouTubeAuth();
return;
} else {
showToast(authData.error || 'ูุดู ูู ุงูุญุตูู ุนูู ุฑุงุจุท ุงูู
ุตุงุฏูุฉ', 'error');
return;
}
// ุงูุงุณุชู
ุงุน ูุฑุณุงูุฉ ุงููุฌุงุญ ู
ู ูุงูุฐุฉ ุงูู
ุตุงุฏูุฉ
function apAuthHandler(e) {
if (e.data?.type === 'youtube_auth_success') {
window.removeEventListener('message', apAuthHandler);
checkYouTubeAuth();
showToast('ุชู
ุฑุจุท YouTube ุจูุฌุงุญ!', 'success');
}
}
window.addEventListener('message', apAuthHandler);
// ู
ุฑุงูุจุฉ ุฅุบูุงู ุงููุงูุฐุฉ ูุฏููุงู
if (apAuthWindow) {
const checkClosed = setInterval(() => {
if (apAuthWindow.closed) {
clearInterval(checkClosed);
window.removeEventListener('message', apAuthHandler);
// ูุชุญูู ู
ุฑุฉ ุชุงููุฉ ุนุดุงู ูู ูุงู ูุฌุญ ูุจู ุงูุฅุบูุงู
checkYouTubeAuth();
}
}, 1000);
}
} catch (err) {
showToast('ุฎุทุฃ ูู ุงูุงุชุตุงู', 'error');
}
}
</script>
</body>
</html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>ุตุงูุน ุงูุฑููุฒ ุงููุฑุขูู</title>
<meta name="theme-color" content="#0f0f0f">
<meta property="og:title" content="ุตุงูุน ุงูุฑููุฒ ุงููุฑุขูู ๐ฌ">
<meta property="og:description" content="ุฃูุดุฆ ููุฏูููุงุช ูุฑุขููุฉ ุงุญุชุฑุงููุฉ ูู ุซูุงูู">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐จ CSS Variables & Base
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
:root {
/* Dark Theme (Default) */
--bg-primary: #0f0f0f;
--bg-secondary: #1a1a1a;
--bg-card: #1f1f1f;
--bg-input: #2a2a2a;
--text-primary: #ffffff;
--text-secondary: #a0a0a0;
--text-muted: #666666;
--accent: #c9a227;
--accent-light: #e6c458;
--accent-dark: #9a7b1c;
--success: #22c55e;
--danger: #ef4444;
--warning: #f59e0b;
--border: rgba(255,255,255,0.08);
--shadow: 0 4px 24px rgba(0,0,0,0.4);
--radius: 16px;
--radius-sm: 10px;
}
.light-theme {
--bg-primary: #f8f8f8;
--bg-secondary: #ffffff;
--bg-card: #ffffff;
--bg-input: #f0f0f0;
--text-primary: #1a1a1a;
--text-secondary: #555555;
--text-muted: #999999;
--accent: #b8941f;
--accent-light: #d4b030;
--accent-dark: #8a6d15;
--border: rgba(0,0,0,0.08);
--shadow: 0 4px 24px rgba(0,0,0,0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'IBM Plex Sans Arabic', sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100dvh;
transition: background 0.3s, color 0.3s;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ App Container
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.app {
max-width: 480px;
margin: 0 auto;
min-height: 100dvh;
display: flex;
flex-direction: column;
}
/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Header
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
.header {
padding: 20px 20px 16px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid var(--border);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 44px;
height: 44px;
background: linear-gradient(135deg, var(--accent), var(--accent-light));
border-radius: 12px;