// My Banners: sign in (network or wallet), credits, post a banner, banner states, share link, cycle rewards. (async function () { VBB.renderNav('/my'); VBB.renderFooter(); const $ = VBB.$, esc = VBB.esc; const c = await VBB.getConfig().catch(() => ({})); const me = await VBB.getJSON('/api/me'); if (!me.signedIn) { // signed in on InstantAdPay already? one quick hop there and back signs you in here too try { const ss = await VBB.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&via=iap&to=' + encodeURIComponent('/my')); return; } } catch (e) {} $('signin').hidden = false; if (!c.sso) { $('ssoIap').hidden = true; $('ssoLs').hidden = true; } $('signBtn').onclick = async () => { try { VBB.status('Check your wallet for the sign-in message.'); await VBBWallet.signIn(); location.reload(); } catch (e) { VBB.status(String(e && e.message || e).slice(0, 300), 'err'); } }; return; } $('outBtn').onclick = async () => { await VBB.post('/api/auth/logout'); location.reload(); }; let uploaded = ''; function preview(src) { const p = $('preview'); p.innerHTML = src ? 'Preview' : '125 x 125
preview'; if (src) p.querySelector('img').src = src; } $('img').addEventListener('input', () => { uploaded = ''; $('fileNote').textContent = ''; const v = $('img').value.trim(); preview(/^https:\/\//.test(v) ? v : ''); }); $('file').addEventListener('change', async e => { const f = e.target.files[0]; if (!f) return; if (f.size > 100 * 1024) { VBB.status('That file is ' + Math.ceil(f.size / 1024) + ' KB. The limit is 100 KB.', 'err'); return; } $('fileNote').textContent = 'Uploading...'; const r = await VBB.getJSON('/api/my/upload', { method: 'POST', headers: { 'Content-Type': 'application/octet-stream' }, body: f }); e.target.value = ''; if (r.error) { $('fileNote').textContent = ''; VBB.status(r.error, 'err'); return; } uploaded = r.img; $('img').value = ''; $('fileNote').textContent = 'Uploaded: ' + f.name; preview(r.img); VBB.status(''); }); $('postBtn').onclick = async () => { const img = uploaded || $('img').value.trim(); if (!img) return VBB.status('Add an image address or upload a file.', 'err'); $('postBtn').disabled = true; VBB.status('Checking your image and link...'); const r = await VBB.post('/api/my/banners', { img, link: $('link').value.trim() }); $('postBtn').disabled = false; if (r.error) return VBB.status(r.error, 'err'); uploaded = ''; $('img').value = ''; $('link').value = ''; $('fileNote').textContent = ''; preview(''); VBB.status(r.banner.state === 'loop' ? 'Posted. Your banner went straight into the loop.' : 'Posted. Your banner is number ' + r.banner.position + ' in line.', 'ok'); load(); }; $('copyBtn').onclick = () => { $('share').select(); try { navigator.clipboard.writeText($('share').value); } catch (e) { document.execCommand('copy'); } VBB.status('Link copied.', 'ok'); }; const where = b => b.state === 'queued' ? 'Waiting
Number ' + b.position + ' of ' + b.of + ' in line' : b.state === 'loop' ? 'In the loop
Place ' + b.place + ' of ' + b.of + ', rides out in about ' + b.shiftsToRideOut + ' shift' + (b.shiftsToRideOut === 1 ? '' : 's') : 'Cycled
' + (b.cycledAt ? new Date(b.cycledAt).toLocaleString() : ''); async function load() { const d = await VBB.getJSON('/api/my'); if (d.error) return VBB.status(d.error, 'err'); $('dash').hidden = false; $('me').textContent = d.username ? '@' + d.username + ' (' + VBB.short(d.address) + ')' : d.address; const live = d.banners.filter(b => b.state !== 'cycled').length, cyc = d.banners.filter(b => b.state === 'cycled').length; $('stats').innerHTML = [['Post credits', d.credits], ['Banners waiting or in the loop', live], ['Banners cycled', cyc], ['Network ad views earned', VBB.n(d.rewardViews)]] .map(x => '
' + esc(x[1]) + '' + esc(x[0]) + '
').join(''); $('creditNote').textContent = !d.netVerified ? 'Free daily credits are for network members. Sign in through InstantAdPay or LinkSpin, or make a free InstantAdPay account with this wallet, and your free credit arrives each day you sign in. You can have up to ' + d.maxQueued + ' banners waiting at once.' : (d.grantedNow ? 'Your free credit for today was just added. ' : d.freeToday ? 'Today\'s free credit is in. ' : '') + 'One free credit arrives each day you sign in (they bank up to ' + d.freeCreditCap + '). You can have up to ' + d.maxQueued + ' banners waiting at once.'; $('postBtn').disabled = d.credits < 1; if (d.credits < 1) VBB.status('You have used your credits. Come back tomorrow for a free one.'); $('mine').innerHTML = d.banners.length ? '' : '

No banners yet. Post your first one above.

'; for (const b of d.banners) { const el = document.createElement('div'); el.className = 'item'; el.innerHTML = 'Banner #' + b.id + '
' + where(b) + '

' + VBB.n(b.clicks) + ' clicks
'; el.querySelector('img').src = b.img; const a = el.querySelector('a'); a.href = b.link; a.textContent = b.link.replace(/^https:\/\//, '').slice(0, 60); $('mine').appendChild(el); } $('share').value = d.share; $('weekStats').innerHTML = [['Verified visitors you sent this week', d.week.visitors], ['Traffic sources this week', d.week.sources]] .map(x => '
' + esc(x[1]) + '' + esc(x[0]) + '
').join(''); $('rewards').innerHTML = d.rewards.length ? '' + d.rewards.map(e => '').join('') + '
WhenBannerNetwork ad viewsStatus
' + esc(new Date(e.at).toLocaleString()) + '#' + e.bannerId + '' + VBB.n(e.views) + '' + (e.status === 'recorded' ? 'Recorded' : esc(e.status)) + '
' : '

No cycles yet. Your first reward appears when one of your banners rides out of the loop.

'; } load(); setInterval(load, 30000); })();