Header Ads

Rakbi Live Championship - Admin Ready

Rakbi Live Championship

Live matches • TV channels
Live Visitors: 0
No affiliate text inside this website.
Rakbi Live Championship • 2025
`; container.appendChild(el); }) attachEvents(); } function attachEvents(){ // likes document.querySelectorAll('.like').forEach(btn=>{ btn.onclick = ()=>{ const id = btn.dataset.id; incrementLike(id); document.getElementById('likecount-'+id).innerText = getLikeCount(id)} }); // post comments document.querySelectorAll('[data-post]').forEach(b=>{ b.onclick = ()=>{ const id=b.getAttribute('data-post'); const inp=document.getElementById('input-'+id); const v=inp.value.trim(); if(!v) return; addComment(id,{user:'You',time:new Date().toLocaleTimeString(),text:v}); inp.value=''; } }); // admin edit/delete document.querySelectorAll('[data-edit]').forEach(b=>{b.onclick=()=>openEditModal(Number(b.dataset.edit))}); document.querySelectorAll('[data-delete]').forEach(b=>{b.onclick=()=>{ if(confirm('Delete this channel?')){ state.channels=state.channels.filter(c=>c.id!==Number(b.dataset.delete)); saveData(state); render(); } }}); } /* ---------- Likes & Comments storage ---------- */ function getLikeCount(id){ return Number(localStorage.getItem('likes_'+id) || '0') } function incrementLike(id){ localStorage.setItem('likes_'+id, String(getLikeCount(id)+1)) } function addComment(id,comment){ const key='comments_'+id; let arr = []; try{arr=JSON.parse(localStorage.getItem(key)||'[]')}catch(e){}; arr.unshift(comment); localStorage.setItem(key,JSON.stringify(arr)); renderComments(id);} function renderComments(id){ const box = document.getElementById('commentbox-'+id); if(!box) return; box.innerHTML=''; let arr=[]; try{arr=JSON.parse(localStorage.getItem('comments_'+id)||'[]')}catch(e){}; arr.slice(0,30).forEach(c=>{ const el=document.createElement('div'); el.className='comment'; el.innerHTML = `${escapeHtml(c.user)} ${escapeHtml(c.time)}
${escapeHtml(c.text)}
`; box.appendChild(el); }); } /* ---------- Visitors animation ---------- */ function updateVisitors(){ const site=document.getElementById('siteVisitor'); const siteVal = rand(3000,5000); site.innerText = 'Live Visitors: ' + siteVal; state.channels.forEach(ch=>{ const v = rand(3000,5000); const el = document.getElementById('vis-'+ch.id); if(el) el.innerText = v; }); } function rand(min,max){return Math.floor(Math.random()*(max-min+1))+min} setInterval(updateVisitors, 5000); // update every 5s /* ---------- Admin (client-side) ---------- */ function isLoggedIn(){ return sessionStorage.getItem('rakbi_logged') === '1' } function setLogged(val){ if(val) sessionStorage.setItem('rakbi_logged','1'); else sessionStorage.removeItem('rakbi_logged'); updateAdminUI(); } function updateAdminUI(){ document.getElementById('adminStatus').innerText = isLoggedIn()? 'Logged in (admin)' : 'Not logged in'; document.getElementById('loginBtn').classList.toggle('hidden', isLoggedIn()); document.getElementById('logoutBtn').classList.toggle('hidden', !isLoggedIn()); document.getElementById('openEditorBtn').classList.toggle('hidden', !isLoggedIn()); document.getElementById('addChannelBtn').classList.toggle('hidden', !isLoggedIn()); render(); } // Login flow document.getElementById('loginBtn').onclick = ()=>{ openModal('

Admin Login

'); document.getElementById('doLogin').onclick = ()=>{ const p=document.getElementById('pass').value; if(p===ADMIN_PASSWORD){ setLogged(true); closeModal(); alert('Logged in as admin'); } else { alert('Wrong password'); }} } document.getElementById('logoutBtn').onclick = ()=>{ if(confirm('Logout?')){ setLogged(false); }} // Open editor panel for bulk edit document.getElementById('openEditorBtn').onclick = ()=>{ const html = `

Edit Channels

`; openModal(html); const list = document.getElementById('editorList'); list.innerHTML=''; state.channels.forEach(ch=>{ const row = document.createElement('div'); row.style.border='1px solid rgba(255,255,255,0.04)'; row.style.padding='8px'; row.style.marginBottom='8px'; row.innerHTML = `
`; list.appendChild(row); }); // attach saves list.querySelectorAll('[data-save]').forEach(b=>{ b.onclick = ()=>{ const id = Number(b.dataset.save); const name = document.getElementById('ed-name-'+id).value.trim(); const img = document.getElementById('ed-img-'+id).value.trim(); const aff = document.getElementById('ed-aff-'+id).value.trim(); const ch = state.channels.find(c=>c.id===id); if(ch){ ch.name = name||ch.name; ch.img = img||ch.img; ch.aff = aff||ch.aff; saveData(state); render(); alert('Saved'); } } }); document.getElementById('closeEditor').onclick = ()=>closeModal(); } // Add channel document.getElementById('addChannelBtn').onclick = ()=>{ openModal('

Add Channel

'); document.getElementById('createChan').onclick = ()=>{ const name=document.getElementById('new-name').value.trim(); const img=document.getElementById('new-img').value.trim(); const aff=document.getElementById('new-aff').value.trim(); if(!name) return alert('Name required'); const id = Date.now(); state.channels.push({id,name,img:img||'https://picsum.photos/800/450',aff:aff||AFFILIATE_URL}); saveData(state); render(); closeModal(); } } // Edit single function openEditModal(id){ const ch = state.channels.find(c=>c.id===id); if(!ch) return; openModal(`

Edit Channel: ${escapeHtml(ch.name)}

`); document.getElementById('saveCh').onclick = ()=>{ ch.name = document.getElementById('u-name').value.trim()||ch.name; ch.img = document.getElementById('u-img').value.trim()||ch.img; ch.aff = document.getElementById('u-aff').value.trim()||ch.aff; saveData(state); render(); closeModal(); } } /* ---------- Modal helpers ---------- */ function openModal(html){ document.getElementById('modalContent').innerHTML = html; document.getElementById('modal').classList.remove('hidden'); } function closeModal(){ document.getElementById('modalContent').innerHTML=''; document.getElementById('modal').classList.add('hidden'); } // close when clicking outside document.getElementById('modal').addEventListener('click', (e)=>{ if(e.target.id==='modal') closeModal(); }); /* ---------- Utilities ---------- */ function escapeHtml(s){return String(s||'').replace(/[&<>"'`]/g, function(c){return {'&':'&','<':'<','>':'>','"':'"',"'":"'",'`':'`'}[c]}) } /* ---------- Init ---------- */ function init(){ render(); updateVisitors(); // initial comments state.channels.forEach(ch=>renderComments(ch.id)); // set admin UI updateAdminUI(); } init(); // save periodically setInterval(()=>saveData(state), 5000);

No comments

Powered by Blogger.