Ads screen in the Control Room shell: buy banner/text/login ads, delivery across viewer, zones and network, earn viewer; login-ad gate after sign-in; member types limited to the three; welcome credits granted from the shell too

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-29 18:11:17 -05:00
parent cfb9ed13d0
commit 274c8fd78c
11 changed files with 198 additions and 10 deletions
+23 -2
View File
@@ -10,13 +10,14 @@ window.CR = (function () {
['links', 'Links', '/links', '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>'],
['pages', 'Pages', '/pages', '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M8 9h8M8 13h6"/>'],
['zones', 'Zones', '/zones', '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 10h18"/>'],
['ads', 'Ads', '/ads', '<path d="M3 11l14-5v12L3 13v-2z"/><path d="M17 8a4 4 0 0 1 0 8"/>'],
['reports', 'Reports', '/reports', '<path d="M4 19V9M10 19V5M16 19v-8M22 19H2"/>'],
['team', 'Team', '/team', '<circle cx="9" cy="8" r="3"/><circle cx="17" cy="9" r="2.5"/><path d="M3 19c0-3 3-5 6-5s6 2 6 5M15 15c3 0 6 1.5 6 4"/>'],
['wallet', 'Wallet', '/wallet', '<rect x="3" y="6" width="18" height="12" rx="2"/><path d="M16 12h3"/>'],
];
// screens not built yet fall back to the classic dashboard pane so nothing is a dead end
const FALLBACK = { pages: '/my#promo', zones: '/my#campaigns', team: '/my#line', wallet: '/my#wallet' };
const BUILT = new Set(['links', 'pages', 'zones', 'reports', 'team', 'wallet']);
const BUILT = new Set(['links', 'pages', 'zones', 'ads', 'reports', 'team', 'wallet']);
let ME = null, toastT;
function toast(msg, bad) { let t = $('crToast'); if (!t) { t = document.createElement('div'); t.id = 'crToast'; t.className = 'toast'; t.setAttribute('role', 'status'); document.body.appendChild(t); } t.textContent = msg; t.style.background = bad ? '#FF7A7A' : ''; t.classList.add('on'); clearTimeout(toastT); toastT = setTimeout(() => t.classList.remove('on'), 2000); }
async function api(path, body) { const r = await (await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) })).json(); if (r.error) throw new Error(r.error); return r; }
@@ -85,6 +86,26 @@ window.CR = (function () {
go.addEventListener('click', step);
host.querySelector('.modal').addEventListener('keydown', e => { if (e.key === 'Enter') step(); });
}
async function requireSession(onReady) { const m = await me(); if (m && m.signedIn) return onReady(m); signInFlow(onReady); }
async function loginAd() {
let seen = false; try { seen = !!sessionStorage.getItem('ls.la'); } catch (e) {}
if (seen) return; try { sessionStorage.setItem('ls.la', '1'); } catch (e) {}
let ad = null; try { ad = (await get('/api/ads/slot?type=login')).ad; } catch (e) { return; }
if (!ad || !ad.targetUrl) return;
await new Promise(done => {
const back = document.createElement('div'); back.className = 'modal-back';
back.innerHTML = '<div class="modal" style="max-width:520px"><div class="muted" style="font:600 11px Manrope,system-ui;letter-spacing:.08em;text-transform:uppercase">Today\'s login sponsor</div>'
+ '<div style="margin:12px 0;text-align:center">' + (ad.imageUrl ? '<img src="' + esc(ad.imageUrl) + '" alt="" style="max-width:100%;height:auto;border:1px solid var(--line)">' : '<div class="panel" style="padding:22px"><b style="font-size:16px">' + esc(ad.title || 'Visit today\'s sponsor') + '</b></div>') + '</div>'
+ '<div class="muted" id="laStatus">Open the ad in a new tab. The timer runs here.</div>'
+ '<div style="display:flex;gap:8px;flex-wrap:wrap;margin-top:12px;align-items:center"><button class="btn pri" type="button" id="laOpen">Open ad</button><span class="mono" id="laTimer" hidden></span><button class="btn" type="button" id="laGo" hidden>Continue</button></div></div>';
document.body.appendChild(back);
back.querySelector('#laOpen').addEventListener('click', () => {
window.open(ad.targetUrl, '_blank'); back.querySelector('#laOpen').disabled = true;
let left = ad.dwell || 10; const t = back.querySelector('#laTimer'); t.hidden = false; t.textContent = left + ' s';
const iv = setInterval(() => { left -= 1; if (left > 0) { t.textContent = left + ' s'; return; } clearInterval(iv); t.textContent = 'done'; back.querySelector('#laStatus').textContent = 'Thanks for the look.'; back.querySelector('#laGo').hidden = false; }, 1000);
});
back.querySelector('#laGo').addEventListener('click', () => { back.remove(); done(); });
});
}
async function requireSession(onReady) { const m = await me(); if (m && m.signedIn) { await loginAd(); return onReady(m); } signInFlow(async r => { await loginAd(); onReady(r); }); }
return { esc, fmt, api, get, copy, dialog, toast, mount, sub, me, requireSession, signInFlow };
})();