TOTAL REVENUE
$0.00
Channel
WebApp
Public Channel URL
Verify Channel
App Name
Website URL
Register WebApp
Monetized Assets
Fetching your assets...
`; tg.showPopup({ title: 'Integration Code', message: `Copy this code into your website's tag for ${name}:\n\n${scriptCode}`, buttons: [ {id: 'copy', type: 'default', text: 'Copy Code'}, {id: 'ok', type: 'cancel', text: 'Close'} ] }, (btnId) => { if(btnId === 'copy') { navigator.clipboard.writeText(scriptCode); tg.showAlert("Code copied to clipboard!"); } }); } async function registerAsset(type) { const userId = tg.initDataUnsafe.user?.id || 0; const nameInput = document.getElementById(type === 'channel' ? 'chan-url' : 'web-name'); const urlInput = document.getElementById('web-url'); const btn = document.getElementById(type === 'channel' ? 'btn-chan' : 'btn-web'); const nameValue = nameInput.value.trim(); const urlValue = type === 'webapp' ? urlInput.value.trim() : ''; if(!nameValue) return tg.showAlert("Please fill in the details"); btn.disabled = true; btn.innerText = "Processing..."; try { const endpoint = type === 'channel' ? 'verify_channel.php' : 'process_webapp.php'; const r = await fetch(`${apiBase}/${endpoint}`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ user_id: userId, name: nameValue, url: urlValue, type: type }) }); const res = await r.json(); if(res.success) { if(type === 'channel') { localStorage.setItem('last_channel_url', nameValue); window.location.href = 'verifychannel.html'; } else { // Instantly show the code for WebApps showIntegration(nameValue, res.monetix_id); loadAssets(); // Clear inputs nameInput.value = ''; urlInput.value = ''; } } else { tg.showAlert(res.message || "Error occurred"); } } catch(e) { tg.showAlert("Server connection failed."); } finally { btn.disabled = false; btn.innerText = type === 'channel' ? "Verify Channel" : "Register WebApp"; } } async function loadAssets() { const userId = tg.initDataUnsafe.user?.id || 0; try { const r = await fetch(`${apiBase}/get_data.php?user_id=${userId}`); const res = await r.json(); document.getElementById('revenue').innerText = '$' + (parseFloat(res.revenue) || 0).toFixed(2); const list = document.getElementById('assets-list'); if (res.assets && res.assets.length > 0) { list.innerHTML = res.assets.map(a => { const statusColor = a.status === 'active' ? 'var(--success)' : 'var(--hint-color)'; const isWeb = (a.type.toLowerCase() === 'webapp'); const cpm = a.cpm || "0.00"; return `
${a.name}
${a.status === 'active' ? `
$${cpm} CPM
` : ''}
${a.status}
+$${a.earned || '0.00'}
${ (a.status === 'active' && isWeb) ? `
` : '' }
`; }).join(''); lucide.createIcons(); } else { list.innerHTML = '
No assets added yet.
'; } } catch(e) { document.getElementById('assets-list').innerHTML = '
Failed to load assets.
'; } } loadAssets();