// A packet: the card, Save my ID (network members), whose link a visitor gets, the report button, recent savers, the Spotlight strip. (async function () { const $ = YPB.$, esc = YPB.esc; const id = Number((location.pathname.match(/^\/p\/(\d+)/) || [])[1]); const c = await YPB.getConfig().catch(() => ({})); const d = await YPB.wire('packet', '&id=' + id).catch(() => ({ error: 'x' })); if (d.error || !d.packet) { $('pk').innerHTML = '
' + esc(d.error || 'That packet is not in the Seed Bed right now.') + '
'; return; } const x = d.packet; document.title = x.name + ' | YourProgramBuilder'; $('pk').innerHTML = YPB.packetCard(x, { place: 'packet', extra: 'Link checked ' + esc(YPB.when(x.checkedAt)) + '. Planted ' + esc(YPB.when(x.sownAt)) + (x.planter ? ' by @' + esc(x.planter) : '') + '. ' + YPB.n(x.clicks) + ' verified clicks.' + (x.contract ? ' Contract: ' + esc(x.contract) + '' + (c.explorer ? ' (look it up)' : '') : '') + '
' }); const who = x.linkFallback === null ? '@' + esc(x.linkBy) + '\'s link (the nearest person in your line who saved an ID).' : x.linkFallback === 'planter' ? 'The planter\'s link' + (x.linkBy ? ' (@' + esc(x.linkBy) + ')' : '') + ': nobody in your line has saved an ID yet.' : 'The program\'s home page: no ID saved yet.'; $('linkWho').innerHTML = 'You get ' + who; $('visitBtn').dataset.go = x.id; $('visitBtn').dataset.p = 'packet'; $('visitBtn').href = YPB.goHref(x.id, 'packet'); YPB.decorate(); if (x.recent && x.recent.length) { $('savers').hidden = false; $('saverList').textContent = x.recent.map(n => '@' + n).join(', '); } YPB.spotRow($('spots'), d); const me = await YPB.getJSON('/api/me'); if (!me.signedIn) { $('saveSignin').hidden = false; if (c.joinUrl) $('joinLink').href = c.joinUrl; $('saveSignin').querySelector('a').href = '/sso/start?mode=go&to=' + encodeURIComponent(location.pathname); } else if (x.own) { $('save').querySelector('p').textContent = 'You planted this packet: your ID is the planter\'s ID. Change it on My packets.'; } else { $('saveForm').hidden = false; $('idHint').textContent = 'letters, numbers and . _ - @ + only'; if (d.mySave) { $('refId').value = d.mySave.refId; $('track').checked = d.mySave.track; $('removeBtn').hidden = false; $('saveBtn').textContent = 'Update my ID'; } const send = async refId => { YPB.status('Saving...', ''); const r = await YPB.post('/api/my/save', { packetId: x.id, refId, track: $('track').checked }); if (r.error) return YPB.status(r.error + (r.join ? ' ' : ''), 'err'); if (r.removed) { YPB.status('Your ID was removed from this packet.', 'ok'); $('removeBtn').hidden = true; $('refId').value = ''; return; } YPB.status('Saved. Your link: ' + r.link + '. This packet has ' + r.saves + ' of ' + r.need + ' saved IDs' + (r.review ? ' and is now in the review queue.' : '.'), 'ok'); $('removeBtn').hidden = false; $('saveBtn').textContent = 'Update my ID'; }; $('saveForm').onsubmit = e => { e.preventDefault(); send($('refId').value.trim()); }; $('removeBtn').onclick = () => send(''); } $('reportForm').onsubmit = async e => { e.preventDefault(); const r = await YPB.post('/api/report', { packetId: x.id, reason: $('reason').value, note: $('reportNote').value }); YPB.status(r.error || (r.already ? 'You already reported this packet. Thank you.' : 'Thank you. A person will look at it.'), r.error ? 'err' : 'ok', 'reportStatus'); }; })();