Files
martbost 3e0dee517d Network Weekend (Marty 2026-11-17): 2 free post credits a day Fri 11-27 00:00 CT to Tue 12-01 00:00 CT, live VBBShop SKU values on every page and in the chatbot, the network ribbon
weekend.js: the date gate (WEEKEND_NOW test clock), FREE_CREDITS_PER_DAY stays 1. chainskus.js: skus() read every 60 s, so the
$10 pack shows what the contract credits (50 once the owner signs setSku, 40 before or after). netdeals.js + /assets/netweekend.js:
/api/network-deals and the ribbon; the VBB line is built from live values and drops itself if there is nothing true to say.
chatcore render hook, chatbot FACTS/CANNED from live values with a dated weekend fact. qa/weekend.test.mjs 33 pass, chatbot 182, smoke 268.
common.js?v=10, my.js?v=6, packages.js?v=2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:26:05 -06:00

186 lines
16 KiB
JavaScript

// 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(); };
$('outAllBtn').onclick = async () => { $('outAllBtn').disabled = true; await VBB.post('/api/auth/logout-everywhere'); location.reload(); };
let uploaded = '';
function preview(src) { const p = $('preview'); p.innerHTML = src ? '<img alt="Preview" width="125" height="125">' : '125 x 125<br>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();
};
// LinkSpin Banner Spin (2026-11-14, the Downline Banners pattern): pick one of your 125x125 (or 250x250) spins and it posts
$('lsBtn').onclick = async () => {
const pick = $('lsPick'); pick.hidden = false; pick.innerHTML = '<p class="small muted">Looking up your LinkSpin Banner Spins...</p>';
const d = await VBB.getJSON('/api/my/lsspins');
if (d.error) { pick.innerHTML = '<p class="note err small">' + esc(d.error) + '</p>'; return; }
const make = '<a href="https://linkspin.app/links#b" target="_blank" rel="noopener">make one on LinkSpin</a>';
if (!d.account) { pick.innerHTML = '<p class="small">No LinkSpin account holds this wallet yet. Join LinkSpin (free) with the same email as InstantAdPay, link this wallet there, then ' + make + ' (size 125x125).</p>'; return; }
if (!d.spins.length) { pick.innerHTML = '<p class="small">You have no 125x125 Banner Spin yet: ' + make + ' (pick size 125x125), then tap the button again.</p>'; return; }
pick.innerHTML = '<p class="small muted">Tap a Banner Spin to post it to the loop (one credit).</p><div class="row"></div>';
const row = pick.querySelector('.row');
for (const sp of d.spins) {
const bt = document.createElement('button'); bt.className = 'btn sec small'; bt.dataset.spin = sp.id;
bt.textContent = sp.name + ' (' + sp.size + ', ' + sp.banners + ' image' + (sp.banners === 1 ? '' : 's') + (sp.paused ? ', paused' : '') + ')';
bt.disabled = !sp.banners || sp.paused; if (bt.disabled) bt.title = sp.paused ? 'Unpause it on LinkSpin first.' : 'Add an image to it on LinkSpin first.';
bt.onclick = async () => {
row.querySelectorAll('button').forEach(x => { x.disabled = true; }); VBB.status('Posting your Banner Spin...');
const r = await VBB.post('/api/my/banners', { spinId: sp.id });
if (r.error) { VBB.status(r.error, 'err'); row.querySelectorAll('button').forEach(x => { x.disabled = false; }); return; }
pick.hidden = true; pick.innerHTML = '';
VBB.status((r.banner.state === 'loop' ? 'Posted. Your Banner Spin went straight into the loop.' : 'Posted. Your Banner Spin is number ' + r.banner.position + ' in line.')
+ (r.otherSource ? ' It already reports under another LinkSpin source, so its clicks stay there.' : ''), 'ok');
load();
};
row.appendChild(bt);
}
};
$('copyBtn').onclick = () => { $('share').select(); try { navigator.clipboard.writeText($('share').value); } catch (e) { document.execCommand('copy'); } VBB.status('Link copied.', 'ok'); };
const when = t => new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT';
const where = b => b.state === 'down' ? '<span class="pill down">Taken down</span><br>Reason: ' + esc(b.downReason) + '<br><span class="muted">'
+ (b.creditBack ? 'Your post credit was given back.' : 'The post credit was not given back.') + ' It no longer shows anywhere.</span>'
: b.state === 'queued' ? '<span class="pill queued">Waiting</span><br>Number ' + b.position + ' of ' + b.of + ' in line'
: b.state === 'loop' ? '<span class="pill loop">In the loop</span><br>Place ' + b.place + ' of ' + b.of + ', rides out in about ' + b.shiftsToRideOut + ' shift' + (b.shiftsToRideOut === 1 ? '' : 's')
: '<span class="pill cycled">Cycled</span><br>' + (b.cycledAt ? new Date(b.cycledAt).toLocaleString() : '');
// banner look (SKU 3): buy it for a banner that is waiting or in the loop; with the look, edit its hover teaser
let buying = false, editing = false, swapping = false;
// one swap per banner (Marty 2026-11-15): new image and/or link, or another of your Banner Spins. Same checks as a new post.
function swapRow(row, b) {
if (b.swapUsed) { row.innerHTML = '<span class="muted small">Swap used' + (b.swappedAt ? ' on ' + esc(when(b.swappedAt)) : '') + '. Each banner can be swapped once.</span>'; return; }
if (!b.canSwap) return;
row.innerHTML = '<button class="btn sec small">Swap image or link</button>';
row.querySelector('button').onclick = () => openSwap(row, b);
}
function openSwap(row, b) {
swapping = true; let up = ''; const item = row.closest('.item'); if (item) item.classList.add('swapping');
row.innerHTML = '<div class="swap-box"><p class="small"><b>Swap banner #' + b.id + '</b> (one time only). It keeps its place, clicks and progress. Leave a field empty to keep what it has'
+ (b.spin ? '; a Banner Spin swaps to another Banner Spin, or to your own image and link together' : '') + '.</p>'
+ '<div class="field"><label>New image address (https), or upload a file</label><input class="sw-img" placeholder="https://your-site.com/banner.png" autocomplete="off"></div>'
+ '<div class="row"><label class="btn sec small">Upload image<input type="file" class="sw-file" accept="image/png,image/jpeg,image/gif" hidden></label><span class="muted small sw-note"></span></div>'
+ '<div class="field"><label>New target link (https)</label><input class="sw-link" placeholder="https://your-site.com/page" autocomplete="off"></div>'
+ '<div class="row"><button class="btn small sw-go">Swap now</button><button class="btn sec small sw-spin">Use another Banner Spin</button><button class="btn quiet small sw-x">Cancel</button></div><div class="sw-pick"></div></div>';
const q = k => row.querySelector(k);
q('.sw-img').addEventListener('input', () => { up = ''; q('.sw-note').textContent = ''; });
q('.sw-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; }
q('.sw-note').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) { q('.sw-note').textContent = ''; VBB.status(r.error, 'err'); return; }
up = r.img; q('.sw-img').value = ''; q('.sw-note').textContent = 'Uploaded: ' + f.name; VBB.status('');
});
const send = async body => {
row.querySelectorAll('button').forEach(x => { x.disabled = true; }); VBB.status('Checking the new image and link...');
const r = await VBB.post('/api/my/banners/' + b.id + '/swap', body);
if (r.error) { VBB.status(r.error, 'err'); row.querySelectorAll('button').forEach(x => { x.disabled = false; }); return; }
swapping = false; VBB.status('Swapped. Banner #' + b.id + ' keeps its place and now shows the new ' + (body.spinId != null ? 'Banner Spin' : 'image and link') + '.', 'ok'); load();
};
q('.sw-go').onclick = () => {
const img = up || q('.sw-img').value.trim(), link = q('.sw-link').value.trim();
if (!img && !link) return VBB.status('Add a new image, a new link, or both.', 'err');
send({ img, link });
};
q('.sw-x').onclick = () => { swapping = false; if (item) item.classList.remove('swapping'); swapRow(row, b); };
q('.sw-spin').onclick = async () => {
const pick = q('.sw-pick'); pick.innerHTML = '<p class="small muted">Looking up your LinkSpin Banner Spins...</p>';
const d = await VBB.getJSON('/api/my/lsspins');
if (d.error) { pick.innerHTML = '<p class="note err small">' + esc(d.error) + '</p>'; return; }
const list = (d.spins || []).filter(sp => sp.banners && !sp.paused);
if (!d.account || !list.length) { pick.innerHTML = '<p class="small">No 125x125 (or 250x250) Banner Spin with images on your LinkSpin account yet.</p>'; return; }
pick.innerHTML = '<p class="small muted">Tap a Banner Spin to swap to it.</p><div class="row"></div>';
for (const sp of list) {
const bt = document.createElement('button'); bt.className = 'btn sec small'; bt.textContent = sp.name + ' (' + sp.size + ')';
bt.onclick = () => send({ spinId: sp.id }); pick.querySelector('.row').appendChild(bt);
}
};
}
function lookRow(row, b) {
if (b.look) {
row.innerHTML = '<span class="pill look">Banner look</span><input maxlength="40" aria-label="Hover teaser for banner #' + b.id + '"><button class="btn sec small">Save teaser</button>';
const inp = row.querySelector('input'); inp.value = b.teaser; inp.placeholder = b.teaserDefault || 'Your teaser line';
inp.addEventListener('focus', () => { editing = true; }); inp.addEventListener('blur', () => { editing = false; });
row.querySelector('button').onclick = async () => {
const r = await VBB.post('/api/my/banners/' + b.id + '/teaser', { teaser: inp.value });
editing = false; VBB.status(r.error || 'Teaser saved: "' + r.teaser + '" shows when someone points at your banner.', r.error ? 'err' : 'ok');
};
return;
}
if (b.state === 'cycled' || !shopLive) return;
row.innerHTML = '<button class="btn amber small">Add the banner look ($' + (c.lookUsd || 2) + ')</button>';
row.querySelector('button').onclick = async () => {
if (buying) return; buying = true; document.querySelectorAll('.look-row .btn.amber').forEach(x => { x.disabled = true; });
try {
const r = await VBBBuy.run({ sku: c.lookSku || 3, qty: 1, ref: b.id, done: async () => { const m = await VBB.getJSON('/api/my'); return (m.banners || []).some(x => x.id === b.id && x.look); } });
VBB.status(r.credited ? 'Banner #' + b.id + ' now has the look in the loop. Write its teaser line below the banner.' : 'Paid and confirmed. The look appears on banner #' + b.id + ' within a few minutes.', 'ok');
} catch (e) { VBB.status(String(e && e.message || e).slice(0, 400), 'err'); }
finally { buying = false; load(); }
};
}
const shopLive = !!(c.shop && c.shop.live);
async function load() {
if (buying || editing || swapping) return;
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 === 'queued' || b.state === 'loop').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 => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').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 ? ((d.freePerDay || 1) > 1 ? 'Your free credits for today were just added. ' : 'Your free credit for today was just added. ') : d.freeToday ? 'Today\'s free credit is in. ' : '')
+ ((d.freePerDay || 1) > 1 ? 'Network Weekend: ' + d.freePerDay + ' free credits arrive each day you sign in, through Monday 11-30 Central (they bank up to ' : '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; $('lsBtn').disabled = d.credits < 1;
if (d.credits < 1) $('creditNote').textContent += (shopLive ? ' Out of credits: get a pack on the Packages page, or come back tomorrow for a free one.' : '');
$('mine').innerHTML = d.banners.length ? '' : '<p class="muted">No banners yet. Post your first one above.</p>';
for (const b of d.banners) {
const el = document.createElement('div'); el.className = 'item';
el.innerHTML = '<img alt="Banner #' + b.id + '" width="72" height="72"><div class="s">' + where(b) + '<br><a target="_blank" rel="noopener"></a><br><span class="muted">' + VBB.n(b.clicks) + ' clicks</span><div class="look-row"></div><div class="swap-row"></div></div>';
el.querySelector('img').src = b.img; const a = el.querySelector('a'); a.href = b.link; a.textContent = b.link.replace(/^https:\/\//, '').slice(0, 60);
if (b.spin) { a.removeAttribute('href'); a.textContent = 'LinkSpin Banner Spin: ' + b.spin.name; a.insertAdjacentHTML('beforebegin', '<span class="pill spin">Banner Spin</span> '); }
if (b.state === 'down') { el.classList.add('down'); a.removeAttribute('href'); }
else { lookRow(el.querySelector('.look-row'), b); swapRow(el.querySelector('.swap-row'), b); }
$('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 => '<div class="stat"><b>' + esc(x[1]) + '</b><span>' + esc(x[0]) + '</span></div>').join('');
$('rewards').innerHTML = d.rewards.length ? '<table class="t"><tr><th>When</th><th>Banner</th><th class="n">Network ad views</th><th>Status</th></tr>'
+ d.rewards.map(e => '<tr><td>' + esc(new Date(e.at).toLocaleString()) + '</td><td>#' + e.bannerId + '</td><td class="n">' + VBB.n(e.views) + '</td><td>' + (e.status === 'recorded' ? 'Recorded' : esc(e.status)) + '</td></tr>').join('') + '</table>'
: '<p class="muted">No cycles yet. Your first reward appears when one of your banners rides out of the loop.</p>';
}
load(); setInterval(load, 30000);
})();