// My packets (the member dashboard): sign in (network account through the hub, or wallet), my packet (status, link check, sprout // meter, edit / remove), dormant old programs to confirm, the planting form with the AI writer, my saved IDs, Spotlights and earnings. (async function () { const $ = YPB.$, esc = YPB.esc; YPB.wire('other').catch(() => {}); const c = await YPB.getConfig().catch(() => ({})); const me = await YPB.getJSON('/api/me'); const qs = new URLSearchParams(location.search); if (!me.signedIn) { try { const ss = await YPB.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&to=' + encodeURIComponent(location.pathname + location.search)); return; } } catch (e) {} $('signin').hidden = false; if (c.joinUrl) $('joinLink').href = c.joinUrl; $('walletBtn').onclick = async () => { try { YPB.status('Check your wallet for the sign-in message.', '', 'status'); await YPBWallet.signIn(); location.reload(); } catch (e) { YPB.status(String(e && e.message || e).slice(0, 300), 'err'); } }; return; } $('dash').hidden = false; $('logout').onclick = async () => { await YPB.post('/api/auth/logout'); location.reload(); }; $('logoutAll').onclick = async () => { $('logoutAll').disabled = true; await YPB.post('/api/auth/logout-everywhere'); location.reload(); }; const tabs = document.querySelectorAll('[data-tab]'); const show = t => { tabs.forEach(b => b.setAttribute('aria-pressed', String(b.dataset.tab === t))); document.querySelectorAll('[data-pane]').forEach(p => { p.hidden = p.dataset.pane !== t; }); }; tabs.forEach(b => { b.onclick = () => show(b.dataset.tab); }); show(['plant', 'saved', 'spot'].includes(qs.get('tab')) ? qs.get('tab') : 'packets'); (c.cats || []).forEach(k => { const o = document.createElement('option'); o.value = k.id; o.textContent = k.name; $('cat').appendChild(o); }); $('cat').value = '0'; const costPicked = () => document.querySelector('input[name=cost]:checked').value; document.querySelectorAll('input[name=cost]').forEach(r => { r.onchange = () => { $('costRow').hidden = costPicked() !== 'paid'; }; }); let d = null; const CHECK = { green: 'Link check green', yellow: 'Link check yellow: waiting for a person', red: 'Link check red: not shown' }; const stageTag = x => x.stage === 'review' ? 'In review' : x.stage === 'approved' ? 'Transplanted' : x.stage === 'rejected' ? 'Not added this time' : ''; function packetBox(x) { const pctv = Math.min(100, Math.round(100 * x.saves / x.need)); const notes = x.check && x.check.why && x.check.why.length ? '
Check notes: ' + esc(x.check.why.join('; ')) + '
' : ''; return 'Note: ' + esc(x.decidedNote) + '
' : '') + '' + YPB.n(x.views) + ' verified views, ' + YPB.n(x.clicks) + ' verified clicks' + (x.spotlight ? ', Spotlight ' + YPB.n(x.spotlight.delivered) + ' / ' + YPB.n(x.spotlight.views) + ' views' : '') + '
' + 'Nothing planted yet. Plant a program.
'; document.querySelectorAll('[data-go-tab]').forEach(a => { a.onclick = e => { e.preventDefault(); show(a.dataset.goTab); }; }); document.querySelectorAll('[data-edit]').forEach(b => { b.onclick = () => edit(d.packets.find(x => x.id === Number(b.dataset.edit))); }); document.querySelectorAll('[data-remove]').forEach(b => { b.onclick = async () => { b.disabled = true; const r = await YPB.post('/api/my/packet/remove', { id: Number(b.dataset.remove) }); if (r.error) { b.disabled = false; return YPB.status(r.error, 'err'); } load(); }; }); if (d.dormant && d.dormant.length) { $('dormant').hidden = false; $('dormant').innerHTML = 'Your programs from the old YourProgramBuilderConfirming opens the planting form with your old link: put {id} where your ID goes, then plant it. It counts as your packet.
'; document.querySelectorAll('[data-dorm]').forEach(b => { b.onclick = () => { const x = d.dormant.find(y => y.id === Number(b.dataset.dorm)); reset(); $('dormantId').value = x.id; $('url').value = x.url; $('name').value = x.name; $('plantTitle').textContent = 'Confirm your old program'; show('plant'); }; }); } else $('dormant').hidden = true; $('savedRows').innerHTML = d.saved.length ? d.saved.map(s => 'Put your referral link in the first box first.
'; return; } $('aiWrite').disabled = true; box.innerHTML = 'Reading the program page...
'; const r = await YPB.post('/api/my/adwriter', { url }); $('aiWrite').disabled = false; if (r.error) { box.innerHTML = '' + esc(r.error) + '
'; return; } box.innerHTML = r.options.map((o, i) => '').join('') + '' + (r.left != null ? r.left + ' writes left today. ' : '') + 'Pick one, then change any words you like.
'; box.querySelectorAll('[data-ai]').forEach(b => { b.onclick = () => { const o = r.options[Number(b.dataset.ai)]; $('name').value = String(o.headline || '').slice(0, 40); if (o.line) $('desc').value = String(o.line).slice(0, 200); }; }); }; } await load(); })();