Spaces:
Running
Running
Download web_app/index.html from H3y-sam/Telegram-Bot: direct link, hf CLI and curl.
- Browser
- Download file 16.4 kB
-
https://huggingface.co/spaces/H3y-sam/Telegram-Bot/resolve/main/web_app/index.html
- Command line
-
hf download hf://spaces/H3y-sam/Telegram-Bot/web_app/index.html
-
curl -L -o index.html https://huggingface.co/spaces/H3y-sam/Telegram-Bot/resolve/main/web_app/index.html
16.4 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"/> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | |
| <title>CrazyLearners Bot Dashboard</title> | |
| <script src="https://telegram.org/js/telegram-web-app.js"></script> | |
| <style> | |
| :root { | |
| --bg: #0f0f1a; | |
| --card: #1a1a2e; | |
| --border: #2a2a4a; | |
| --accent: #7c3aed; | |
| --accent2: #06b6d4; | |
| --green: #22c55e; | |
| --red: #ef4444; | |
| --yellow: #f59e0b; | |
| --text: #e2e8f0; | |
| --muted: #64748b; | |
| --radius: 12px; | |
| } | |
| * { box-sizing: border-box; margin: 0; padding: 0; } | |
| body { | |
| background: var(--bg); | |
| color: var(--text); | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; | |
| min-height: 100vh; | |
| padding-bottom: 30px; | |
| } | |
| /* ββ Header ββ */ | |
| .header { | |
| background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e3a5f 100%); | |
| padding: 20px 16px 16px; | |
| text-align: center; | |
| border-bottom: 1px solid var(--border); | |
| } | |
| .header h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; } | |
| .header h1 span { color: var(--accent2); } | |
| .header p { font-size: 12px; color: var(--muted); margin-top: 4px; } | |
| .status-dot { | |
| display: inline-block; width: 8px; height: 8px; | |
| background: var(--green); border-radius: 50%; | |
| margin-right: 5px; animation: pulse 2s infinite; | |
| } | |
| @keyframes pulse { | |
| 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } | |
| } | |
| /* ββ Tabs ββ */ | |
| .tabs { | |
| display: flex; background: var(--card); | |
| border-bottom: 1px solid var(--border); | |
| overflow-x: auto; scrollbar-width: none; | |
| } | |
| .tabs::-webkit-scrollbar { display: none; } | |
| .tab { | |
| flex: 1; min-width: 80px; padding: 12px 8px; text-align: center; | |
| font-size: 12px; font-weight: 600; color: var(--muted); | |
| cursor: pointer; border-bottom: 2px solid transparent; | |
| transition: all 0.2s; white-space: nowrap; | |
| } | |
| .tab.active { color: var(--accent2); border-bottom-color: var(--accent2); } | |
| /* ββ Sections ββ */ | |
| .section { display: none; padding: 16px; } | |
| .section.active { display: block; } | |
| /* ββ Cards ββ */ | |
| .card { | |
| background: var(--card); border-radius: var(--radius); | |
| border: 1px solid var(--border); margin-bottom: 12px; overflow: hidden; | |
| } | |
| .card-header { | |
| display: flex; align-items: center; justify-content: space-between; | |
| padding: 14px 16px; border-bottom: 1px solid var(--border); | |
| cursor: pointer; | |
| } | |
| .card-header .title { font-weight: 700; font-size: 14px; } | |
| .card-header .subtitle { font-size: 11px; color: var(--muted); margin-top: 2px; } | |
| .card-header .badge { | |
| font-size: 10px; padding: 3px 8px; border-radius: 20px; | |
| font-weight: 600; | |
| } | |
| .badge-active { background: #14532d; color: var(--green); } | |
| .badge-paused { background: #7c2020; color: var(--red); } | |
| /* ββ Content Type Rows ββ */ | |
| .ct-list { padding: 4px 0; } | |
| .ct-row { | |
| display: flex; align-items: center; justify-content: space-between; | |
| padding: 10px 16px; border-bottom: 1px solid var(--border); | |
| transition: background 0.15s; | |
| } | |
| .ct-row:last-child { border-bottom: none; } | |
| .ct-row:active { background: rgba(124,58,237,0.08); } | |
| .ct-info { flex: 1; } | |
| .ct-name { font-size: 13px; font-weight: 500; } | |
| .ct-time { font-size: 11px; color: var(--muted); margin-top: 2px; } | |
| /* ββ Toggle Switch ββ */ | |
| .toggle { | |
| position: relative; width: 44px; height: 24px; flex-shrink: 0; | |
| } | |
| .toggle input { opacity: 0; width: 0; height: 0; } | |
| .toggle-track { | |
| position: absolute; top: 0; left: 0; right: 0; bottom: 0; | |
| background: #374151; border-radius: 12px; cursor: pointer; | |
| transition: background 0.25s; | |
| } | |
| .toggle-track::before { | |
| content: ""; position: absolute; | |
| width: 18px; height: 18px; border-radius: 50%; | |
| background: white; top: 3px; left: 3px; | |
| transition: transform 0.25s; | |
| box-shadow: 0 1px 3px rgba(0,0,0,0.4); | |
| } | |
| .toggle input:checked + .toggle-track { background: var(--accent); } | |
| .toggle input:checked + .toggle-track::before { transform: translateX(20px); } | |
| .toggle.loading .toggle-track { opacity: 0.5; pointer-events: none; } | |
| /* ββ Stats Grid ββ */ | |
| .stats-grid { | |
| display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; | |
| } | |
| .stat-card { | |
| background: var(--card); border: 1px solid var(--border); | |
| border-radius: var(--radius); padding: 14px; text-align: center; | |
| } | |
| .stat-value { font-size: 28px; font-weight: 800; } | |
| .stat-label { font-size: 11px; color: var(--muted); margin-top: 4px; } | |
| .stat-card.accent { border-color: var(--accent); } | |
| .stat-card.accent2 { border-color: var(--accent2); } | |
| .stat-card.green { border-color: var(--green); } | |
| .stat-card.yellow { border-color: var(--yellow); } | |
| /* ββ Schedule Table ββ */ | |
| .sched-row { | |
| display: flex; align-items: center; padding: 10px 16px; | |
| border-bottom: 1px solid var(--border); | |
| } | |
| .sched-row:last-child { border-bottom: none; } | |
| .sched-time { | |
| font-size: 13px; font-weight: 700; color: var(--accent2); | |
| width: 52px; flex-shrink: 0; | |
| } | |
| .sched-label { font-size: 13px; flex: 1; } | |
| .sched-channels { font-size: 10px; color: var(--muted); } | |
| /* ββ Loading / Error ββ */ | |
| .loading-text { text-align: center; color: var(--muted); padding: 40px; font-size: 14px; } | |
| .spinner { | |
| width: 24px; height: 24px; border: 3px solid var(--border); | |
| border-top-color: var(--accent2); border-radius: 50%; | |
| animation: spin 0.8s linear infinite; margin: 0 auto 12px; | |
| } | |
| @keyframes spin { to { transform: rotate(360deg); } } | |
| /* ββ Toast ββ */ | |
| .toast { | |
| position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); | |
| background: #1e293b; border: 1px solid var(--border); | |
| color: var(--text); padding: 10px 18px; border-radius: 8px; | |
| font-size: 13px; opacity: 0; transition: opacity 0.3s; | |
| pointer-events: none; z-index: 999; white-space: nowrap; | |
| } | |
| .toast.show { opacity: 1; } | |
| /* ββ Expand arrow ββ */ | |
| .arrow { transition: transform 0.2s; font-size: 12px; color: var(--muted); } | |
| .arrow.open { transform: rotate(180deg); } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="header"> | |
| <h1>π <span>CrazyLearners</span> Bot</h1> | |
| <p><span class="status-dot"></span>Live Dashboard</p> | |
| </div> | |
| <div class="tabs"> | |
| <div class="tab active" onclick="switchTab('channels')">π‘ Channels</div> | |
| <div class="tab" onclick="switchTab('schedule')">π Schedule</div> | |
| <div class="tab" onclick="switchTab('stats')">π Stats</div> | |
| </div> | |
| <!-- CHANNELS TAB --> | |
| <div id="tab-channels" class="section active"> | |
| <div id="channels-content" class="loading-text"> | |
| <div class="spinner"></div>Loading channels... | |
| </div> | |
| </div> | |
| <!-- SCHEDULE TAB --> | |
| <div id="tab-schedule" class="section"> | |
| <div id="schedule-content" class="loading-text"> | |
| <div class="spinner"></div>Loading schedule... | |
| </div> | |
| </div> | |
| <!-- STATS TAB --> | |
| <div id="tab-stats" class="section"> | |
| <div id="stats-content" class="loading-text"> | |
| <div class="spinner"></div>Loading stats... | |
| </div> | |
| </div> | |
| <div class="toast" id="toast"></div> | |
| <script> | |
| // ββ API base (bot runs on HF Space) ββ | |
| const API_BASE = 'https://h3y-sam-telegram-bot.hf.space'; | |
| // ββ Telegram Mini App init ββ | |
| const tg = window.Telegram?.WebApp; | |
| if (tg) { tg.ready(); tg.expand(); } | |
| // ββ Content type metadata ββ | |
| const CT_LABELS = { | |
| pyq_question: "π PYQ Question", | |
| formula_sheet: "π Formula Sheet", | |
| short_notes: "π Short Notes", | |
| mnemonic: "π§ Memory Tricks", | |
| concept_recap: "π Concept Recap", | |
| mock_question: "π― Daily Mock", | |
| motivational: "π Night Motivation", | |
| mcq_session: "π§ͺ MCQ Poll Session", | |
| }; | |
| const CT_TIMES = { | |
| pyq_question: "7:00 AM", | |
| formula_sheet: "9:00 AM", | |
| short_notes: "12:00 PM", | |
| mnemonic: "3:00 PM", | |
| concept_recap: "6:00 PM", | |
| mock_question: "8:00 PM", | |
| motivational: "10:00 PM", | |
| mcq_session: "8:00 PM", | |
| }; | |
| let state = null; | |
| let openChannels = {}; | |
| // ββ Fetch data from API ββ | |
| async function fetchStatus() { | |
| try { | |
| const r = await fetch(`${API_BASE}/api/status`); | |
| if (!r.ok) throw new Error('API error'); | |
| return await r.json(); | |
| } catch (e) { | |
| return null; | |
| } | |
| } | |
| async function toggleContentType(chKey, ct, el) { | |
| el.classList.add('loading'); | |
| try { | |
| const r = await fetch(`${API_BASE}/api/toggle/${chKey}/${ct}`, { method: 'POST' }); | |
| const d = await r.json(); | |
| const enabled = d.enabled; | |
| el.querySelector('input').checked = enabled; | |
| showToast(enabled ? `β ${CT_LABELS[ct] || ct} enabled` : `βΈοΈ ${CT_LABELS[ct] || ct} paused`); | |
| // Update state | |
| if (state?.channels?.[chKey]) { | |
| if (!state.channels[chKey].disabled_content_types) state.channels[chKey].disabled_content_types = []; | |
| if (enabled) { | |
| state.channels[chKey].disabled_content_types = state.channels[chKey].disabled_content_types.filter(x => x !== ct); | |
| } else { | |
| if (!state.channels[chKey].disabled_content_types.includes(ct)) | |
| state.channels[chKey].disabled_content_types.push(ct); | |
| } | |
| } | |
| } catch(e) { | |
| showToast('β Failed β check bot logs'); | |
| } | |
| el.classList.remove('loading'); | |
| } | |
| async function toggleChannel(chKey, btn) { | |
| btn.disabled = true; | |
| try { | |
| const r = await fetch(`${API_BASE}/api/toggle-channel/${chKey}`, { method: 'POST' }); | |
| const d = await r.json(); | |
| showToast(d.active ? `β ${d.label} resumed` : `βΈοΈ ${d.label} paused`); | |
| renderChannels(); // re-render | |
| } catch(e) { | |
| showToast('β Failed'); | |
| } | |
| btn.disabled = false; | |
| } | |
| // ββ Render: Channels ββ | |
| function renderChannels() { | |
| const el = document.getElementById('channels-content'); | |
| if (!state) { el.innerHTML = '<p class="loading-text">β οΈ Could not load data. Is the bot running?</p>'; return; } | |
| const channels = state.channels || {}; | |
| let html = ''; | |
| for (const [key, cfg] of Object.entries(channels)) { | |
| const active = cfg.active !== false; | |
| const disabled = cfg.disabled_content_types || []; | |
| const mcqOnly = disabled.length >= 6; | |
| const open = openChannels[key] || false; | |
| html += ` | |
| <div class="card"> | |
| <div class="card-header" onclick="toggleOpen('${key}')"> | |
| <div> | |
| <div class="title">${cfg.label || key}</div> | |
| <div class="subtitle">${cfg.id || ''} Β· ${mcqOnly ? 'MCQ Only' : 'Full Content'}</div> | |
| </div> | |
| <div style="display:flex;align-items:center;gap:8px"> | |
| <span class="badge ${active ? 'badge-active' : 'badge-paused'}">${active ? 'Active' : 'Paused'}</span> | |
| <span class="arrow ${open ? 'open' : ''}" id="arrow-${key}">βΌ</span> | |
| </div> | |
| </div> | |
| ${open ? ` | |
| <div class="ct-list"> | |
| ${Object.entries(CT_LABELS).map(([ct, label]) => { | |
| const enabled = !disabled.includes(ct); | |
| return ` | |
| <div class="ct-row"> | |
| <div class="ct-info"> | |
| <div class="ct-name">${label}</div> | |
| <div class="ct-time">${CT_TIMES[ct] || 'β'} IST</div> | |
| </div> | |
| <label class="toggle" id="toggle-${key}-${ct}"> | |
| <input type="checkbox" ${enabled ? 'checked' : ''} | |
| onchange="toggleContentType('${key}','${ct}',document.getElementById('toggle-${key}-${ct}'))"> | |
| <div class="toggle-track"></div> | |
| </label> | |
| </div>`; | |
| }).join('')} | |
| <div style="padding:12px 16px"> | |
| <button onclick="toggleChannel('${key}',this)" | |
| style="width:100%;padding:10px;border-radius:8px;border:1px solid var(--border); | |
| background:${active ? '#7c2020' : '#14532d'};color:white;font-weight:600; | |
| cursor:pointer;font-size:13px"> | |
| ${active ? 'βΈοΈ Pause All Posts' : 'βΆοΈ Resume All Posts'} | |
| </button> | |
| </div> | |
| </div>` : ''} | |
| </div>`; | |
| } | |
| el.innerHTML = html; | |
| } | |
| function toggleOpen(key) { | |
| openChannels[key] = !openChannels[key]; | |
| renderChannels(); | |
| } | |
| // ββ Render: Schedule ββ | |
| function renderSchedule() { | |
| const el = document.getElementById('schedule-content'); | |
| if (!state) { el.innerHTML = '<p class="loading-text">β οΈ No data.</p>'; return; } | |
| const schedule = state.schedule || {}; | |
| const channels = state.channels || {}; | |
| const rows = Object.entries(schedule) | |
| .sort((a,b) => (a[1].hour*60+a[1].minute) - (b[1].hour*60+b[1].minute)); | |
| let html = '<div class="card"><div style="padding:4px 0">'; | |
| for (const [ct, timing] of rows) { | |
| const h = String(timing.hour).padStart(2,'0'); | |
| const m = String(timing.minute).padStart(2,'0'); | |
| const activeChans = Object.entries(channels) | |
| .filter(([,c]) => c.active && !(c.disabled_content_types||[]).includes(ct)) | |
| .map(([,c]) => c.label?.split(' ')[0]).join(', '); | |
| html += ` | |
| <div class="sched-row"> | |
| <div class="sched-time">${h}:${m}</div> | |
| <div> | |
| <div class="sched-label">${CT_LABELS[ct] || ct}</div> | |
| <div class="sched-channels">${activeChans || 'β'}</div> | |
| </div> | |
| </div>`; | |
| } | |
| html += '</div></div>'; | |
| el.innerHTML = html; | |
| } | |
| // ββ Render: Stats ββ | |
| function renderStats() { | |
| const el = document.getElementById('stats-content'); | |
| if (!state) { el.innerHTML = '<p class="loading-text">β οΈ No data.</p>'; return; } | |
| const channels = state.channels || {}; | |
| const total = Object.keys(channels).length; | |
| const active = Object.values(channels).filter(c => c.active).length; | |
| const jobs = state.total_jobs || 0; | |
| const users = state.user_count || 0; | |
| el.innerHTML = ` | |
| <div class="stats-grid"> | |
| <div class="stat-card accent"> | |
| <div class="stat-value">${active}/${total}</div> | |
| <div class="stat-label">Active Channels</div> | |
| </div> | |
| <div class="stat-card accent2"> | |
| <div class="stat-value">${jobs}</div> | |
| <div class="stat-label">Scheduled Jobs</div> | |
| </div> | |
| <div class="stat-card green"> | |
| <div class="stat-value">${users}</div> | |
| <div class="stat-label">DM Users</div> | |
| </div> | |
| <div class="stat-card yellow"> | |
| <div class="stat-value">${Object.keys(state.schedule||{}).length}</div> | |
| <div class="stat-label">Content Types</div> | |
| </div> | |
| </div> | |
| <div class="card"> | |
| <div style="padding:14px 16px;border-bottom:1px solid var(--border);font-weight:700;font-size:13px"> | |
| π‘ Channel Overview | |
| </div> | |
| ${Object.entries(channels).map(([key, cfg]) => { | |
| const disabled = cfg.disabled_content_types || []; | |
| const enabled = Object.keys(CT_LABELS).filter(ct => !disabled.includes(ct)); | |
| return ` | |
| <div class="sched-row"> | |
| <div style="flex:1"> | |
| <div class="sched-label">${cfg.label || key}</div> | |
| <div class="sched-channels">${enabled.length} active types Β· ${cfg.id}</div> | |
| </div> | |
| <span class="badge ${cfg.active ? 'badge-active':'badge-paused'}">${cfg.active ? 'On':'Off'}</span> | |
| </div>`; | |
| }).join('')} | |
| </div>`; | |
| } | |
| // ββ Tab switch ββ | |
| function switchTab(name) { | |
| document.querySelectorAll('.tab').forEach((t,i) => { | |
| const names = ['channels','schedule','stats']; | |
| t.classList.toggle('active', names[i] === name); | |
| }); | |
| document.querySelectorAll('.section').forEach(s => s.classList.remove('active')); | |
| document.getElementById(`tab-${name}`).classList.add('active'); | |
| } | |
| // ββ Toast ββ | |
| function showToast(msg) { | |
| const t = document.getElementById('toast'); | |
| t.textContent = msg; | |
| t.classList.add('show'); | |
| setTimeout(() => t.classList.remove('show'), 2500); | |
| } | |
| // ββ Init ββ | |
| async function init() { | |
| state = await fetchStatus(); | |
| renderChannels(); | |
| renderSchedule(); | |
| renderStats(); | |
| } | |
| init(); | |
| setInterval(async () => { | |
| state = await fetchStatus(); | |
| renderSchedule(); | |
| renderStats(); | |
| }, 30000); // refresh every 30s | |
| </script> | |
| </body> | |
| </html> | |