// Help desk front end (2026-10-16): the public /support form, the private ticket link page (/support/t/) // and the member Help pane (/my#help). Server side: tickets.js + the /api/support, /api/my/support routes. // Times show in US Central, like the rest of the site's support copy. window.IAPSupport = (function () { const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); const CATS = ['Account & sign-in', 'Wallet & payouts', 'Buying packages', 'Ads & campaigns', 'Earning credits & games', 'Team & referrals', 'Other']; const STATUS = { open: 'Open', waiting_on_member: 'Waiting on you', closed: 'Closed' }; const when = ts => ts ? new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : ''; const linkify = s => esc(s).replace(/(https?:\/\/[^\s<]+[^\s<.,;:!?)\]])/g, '$1'); async function call(path, body, method) { const o = { method: method || (body === undefined ? 'GET' : 'POST'), headers: {} }; if (body !== undefined) { o.headers['Content-Type'] = 'application/json'; o.body = JSON.stringify(body); } const r = await (await fetch(path, o)).json(); if (r.error && !r.challenge) { const e = new Error(r.error); e.data = r; throw e; } return r; } (function css() { if (document.getElementById('supCss')) return; const st = document.createElement('style'); st.id = 'supCss'; st.textContent = '.sup-form label{display:block;font-size:13px;color:var(--muted);margin:12px 0 4px}.sup-form input,.sup-form select,.sup-form textarea{width:100%;box-sizing:border-box}' + '.sup-row{display:flex;gap:10px;align-items:center;justify-content:space-between;padding:12px 4px;border-bottom:1px solid var(--line);cursor:pointer}.sup-row:last-child{border-bottom:0}.sup-row:hover{background:var(--mint-faint)}' + '.sup-row .sr-main{min-width:0;flex:1}.sup-row .sr-sub{font-weight:700;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sup-row .sr-meta{font-size:12px;color:var(--muted)}' + '.sup-st{font-size:11.5px;font-weight:700;border-radius:999px;padding:2px 10px;border:1px solid var(--line-strong);white-space:nowrap}.sup-st.open{color:var(--mint);border-color:var(--mint-line-2)}.sup-st.waiting_on_member{color:var(--gold-2);border-color:var(--gold-line)}.sup-st.closed{color:var(--muted)}' + '.sup-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:var(--amber,#ffb238);margin-right:6px;vertical-align:1px}' + '.sup-msg{border:1px solid var(--line);border-radius:12px;padding:12px 14px;margin:10px 0;background:var(--ground-soft)}.sup-msg.admin{border-color:var(--mint-line);background:var(--mint-faint)}.sup-msg.system{opacity:.8}' + '.sup-msg .sm-head{font-size:12px;color:var(--muted);margin:0 0 6px;display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap}.sup-msg .sm-body{white-space:pre-wrap;word-wrap:break-word;font-size:15px;line-height:1.5}' + '.sup-att{display:flex;gap:8px;margin-top:8px;flex-wrap:wrap}.sup-att img{max-width:160px;max-height:120px;border-radius:8px;border:1px solid var(--line)}' + '.sup-actions{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-top:12px}'; document.head.appendChild(st); })(); const catOptions = sel => CATS.map(c => '' + esc(c) + '').join(''); const AUTHOR = { member: 'You', admin: 'Marty, InstantAdPay support', system: 'InstantAdPay' }; function threadHtml(v) { const t = v.ticket; return '

' + esc(t.subject) + '

' + esc(STATUS[t.status] || t.status) + '
' + '

' + esc(t.ref) + ' · ' + esc(t.category) + ' · opened ' + esc(when(t.created)) + '

' + v.messages.map(m => '
' + esc(AUTHOR[m.author] || m.author) + '' + esc(when(m.created)) + '
' + '
' + linkify(m.body) + '
' + ((m.attachments || []).length ? '
' + m.attachments.map(a => 'attachment').join('') + '
' : '') + '
').join('') + (t.status === 'closed' ? '

This ticket is closed. Write below and it opens again.

' : ''); } function replyBox(id, withAttach) { return '
' + (withAttach ? attachRow(id) : '') + '
'; } // up to 2 screenshots per message, through the member upload path (signed-in only) const attachRow = id => '
'; function wireAttach(id) { const list = []; const inp = document.getElementById(id + 'File'); if (!inp) return () => []; const draw = () => { document.getElementById(id + 'Att').innerHTML = list.map(u => 'screenshot').join(''); }; inp.addEventListener('change', async () => { for (const f of [...inp.files]) { if (list.length >= 2) { IAP.status('Two images per message at most.', 'bad'); break; } try { const r = await (await fetch('/api/my/upload', { method: 'POST', headers: { 'Content-Type': f.type }, body: f })).json(); if (r.error) throw new Error(r.error); if (r.type !== 'image') throw new Error('Images only, please.'); list.push(r.url); draw(); } catch (e) { IAP.status(e.message || 'Upload failed.', 'bad'); } } inp.value = ''; }); return () => list.slice(); // read at send time } // ── member Help pane ── let helpState = { open: null }; async function badge() { try { const r = await call('/api/my/support'); const b = document.getElementById('helpBadge'); if (b) { b.hidden = !r.unread; b.textContent = r.unread > 9 ? '9+' : r.unread; } return r; } catch (e) { return null; } } async function help(paneQ) { const host = document.getElementById('helpBody'); if (!host) return; const want = (/(?:^|&)t=((?:IAP|LS)-\d+)/.exec(paneQ || '') || [])[1]; if (want) return openMine(want); helpState.open = null; host.innerHTML = '

Loading your tickets…

'; let r; try { r = await call('/api/my/support'); } catch (e) { host.innerHTML = '

Could not load your tickets. ' + esc(e.message) + '

'; return; } const b = document.getElementById('helpBadge'); if (b) { b.hidden = !r.unread; b.textContent = r.unread > 9 ? '9+' : r.unread; } host.innerHTML = '

Help and support

' + '

Stuck on something? Send Marty a ticket. He reads every one and replies here, and you get an email when he does. The quickest answers to common questions are in Training and the chat bubble.

' + '' + '

Your tickets

' + r.tickets.length + '
' + (r.tickets.length ? r.tickets.map(t => '
' + (t.unread ? '' : '') + esc(t.subject) + '
' + '
' + esc(t.ref) + ' · ' + esc(t.category) + ' · updated ' + esc(when(t.updated)) + '
' + esc(STATUS[t.status] || t.status) + '
').join('') : '

No tickets yet. When you send one, it shows up here with Marty\'s replies.

') + '
'; host.querySelectorAll('.sup-row').forEach(el => el.addEventListener('click', () => { history.replaceState(null, '', '#help?t=' + el.dataset.ref); openMine(el.dataset.ref); })); document.getElementById('helpNewBtn').addEventListener('click', () => newForm()); if (/(?:^|&)new=1/.test(paneQ || '')) newForm(); } function newForm() { const box = document.getElementById('helpNew'); if (!box) return; box.hidden = false; box.innerHTML = '

New ticket

' + '' + '' + '' + attachRow('hn') + '
'; const atts = wireAttach('hn'); document.getElementById('hnCancel').addEventListener('click', () => { box.hidden = true; box.innerHTML = ''; }); const send = document.getElementById('hnSend'); send.addEventListener('click', async () => { if (send.disabled) return; send.disabled = true; try { const r = await call('/api/my/support', { category: document.getElementById('hnCat').value, subject: document.getElementById('hnSubject').value, body: document.getElementById('hnBody').value, attachments: atts() }); IAP.status('Sent. Your ticket is ' + r.ref + '. Marty will reply here and by email.', 'ok'); history.replaceState(null, '', '#help?t=' + r.ref); openMine(r.ref); } catch (e) { document.getElementById('hnMsg').textContent = e.message; } finally { send.disabled = false; } }); document.getElementById('hnSubject').focus(); } async function openMine(ref) { const host = document.getElementById('helpBody'); if (!host) return; helpState.open = ref; host.innerHTML = '

Loading…

'; let v; try { v = await call('/api/my/support/' + encodeURIComponent(ref)); } catch (e) { host.innerHTML = '

' + esc(e.message) + '

Back to your tickets

'; wireBack(); return; } drawMine(v); badge(); } const wireBack = () => { const a = document.getElementById('helpBack'); if (a) a.addEventListener('click', e => { e.preventDefault(); history.replaceState(null, '', '#help'); help(''); }); }; function drawMine(v) { const host = document.getElementById('helpBody'); host.innerHTML = '

‹ All your tickets

' + threadHtml(v) + '
' + replyBox('hr', true) + '
'; wireBack(); const atts = wireAttach('hr'); const btn = document.getElementById('hrSend'); btn.addEventListener('click', async () => { if (btn.disabled) return; btn.disabled = true; try { const nv = await call('/api/my/support/' + encodeURIComponent(v.ticket.ref) + '/reply', { body: document.getElementById('hrBody').value, attachments: atts() }); drawMine(nv); IAP.status('Reply sent.', 'ok'); } catch (e) { document.getElementById('hrMsg').textContent = e.message; } finally { btn.disabled = false; } }); } // ── public /support page and the private ticket link ── async function page() { const host = document.getElementById('supMain'); if (!host) return; const m = /^\/support\/t\/([A-Za-z0-9_.-]{20,80})$/.exec(location.pathname); if (m) return tokenPage(host, m[1]); let me = null; try { me = await (await fetch('/api/me')).json(); } catch (e) {} const signedIn = !!(me && me.signedIn && me.email); host.innerHTML = (signedIn ? '

You are signed in as ' + esc(me.username ? '@' + me.username : me.email) + '. Your tickets and Marty\'s replies live in Help in your dashboard, which is the easiest place to follow up. This form works too and files the ticket under your account.

' : '') + '
' + '' + (signedIn ? '' : '' + '') + '' + '' + '' + '' + '
' + '
'; const f = document.getElementById('supForm'); f.addEventListener('submit', async e => { e.preventDefault(); const btn = document.getElementById('supSend'); if (btn.disabled) return; btn.disabled = true; const msg = document.getElementById('supMsg'); msg.textContent = 'Sending…'; const val = id => { const el = document.getElementById(id); return el ? el.value : ''; }; try { const g = IAP.guard; await g.formSettled(); let pick = null, r = null; for (let i = 0; i < 4; i++) { r = await call('/api/support', { name: val('supName'), email: val('supEmail'), category: val('supCat'), subject: val('supSubject'), body: val('supBody'), fts: g.FORM_TS, fage: Date.now() - g.FORM_TS, hp_field_x9: g.hpValue(document.getElementById('supHp')), pick }); if (r.challenge) { msg.textContent = ''; pick = await g.iconCheck(document.getElementById('supCheck'), r.challenge, r.error); continue; } break; } if (!r || !r.ok) throw new Error('Could not verify. Refresh the page and try again.'); host.innerHTML = '

Got it. Your ticket is ' + esc(r.ref) + '.

' + '

Marty reads every ticket and replies as soon as he can. ' + (r.member ? 'His reply shows up in Help in your dashboard and in your email.' : 'We just emailed you a private link to this ticket, so you can check on it or add more detail without signing in. If it does not arrive, look in spam or promotions.') + '

' + '

' + (r.member ? 'Open it in Help' : 'View your ticket') + 'Back to InstantAdPay

'; window.scrollTo(0, 0); } catch (err) { msg.textContent = err.message; } finally { btn.disabled = false; } }); } async function tokenPage(host, tok) { const h = document.querySelector('.sectionhead h2'); if (h) h.innerHTML = 'Your support ticket'; host.innerHTML = '

Loading your ticket…

'; let v; try { v = await call('/api/support/t/' + encodeURIComponent(tok)); } catch (e) { host.innerHTML = '

' + esc(e.message) + '

Send a new ticket

'; return; } const draw = v2 => { host.innerHTML = '
' + threadHtml(v2) + '
' + replyBox('tk', false) + '

Keep this link private: anyone with it can read and answer this ticket. Members can also follow up from Help in the dashboard, where screenshots can be attached.

'; const btn = document.getElementById('tkSend'); btn.addEventListener('click', async () => { if (btn.disabled) return; btn.disabled = true; try { const nv = await call('/api/support/t/' + encodeURIComponent(tok) + '/reply', { body: document.getElementById('tkBody').value }); draw(nv); IAP.status('Reply sent. Marty will see it.', 'ok'); } catch (e) { document.getElementById('tkMsg').textContent = e.message; } finally { btn.disabled = false; } }); }; draw(v); } return { help, badge, page, CATS, STATUS, when, esc, linkify }; })(); if (document.getElementById('supMain')) IAPSupport.page();