Files
martbost 6616680fc6 WebWorthIt staging: read-only contract + website check (Marty 2026-11-16)
Free check (DeepSeek v4.1 Flash scorecard) and deep report (Opus 5.5) over a generalised
evidence pack from the read-only chain tools; fact gate blocks any address, tx or number not
in the evidence; MySQL store; hub sign-in, sponsor line recorder, vouchers, ad slots in iframes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:54:08 -06:00

98 lines
6.9 KiB
JavaScript

// Front page: the free check form, live progress + result, pricing (staging: payments arrive at launch), vouchers, the staging
// test code, the member share box, and the "Network, checked" table filled from public checks.
(function () {
'use strict';
var $ = WWI.$, esc = WWI.esc;
var live = $('live'), current = null, timer = null;
function setErr(t) { $('formErr').textContent = t || ''; }
function showFree(c) { $('freeLeft').textContent = c.unlocked ? ' Test code active: no daily limit.' : (c.freeLeft != null ? ' Free checks left today: ' + c.freeLeft + ' of ' + c.freePerDay + '.' : ''); }
function credits(c) { var cr = c.credits || {}; $('creditLine').textContent = (cr.deep || cr.free_extra) ? 'On this ' + (c.member ? 'account' : 'browser') + ': ' + (cr.deep || 0) + ' deep report' + (cr.deep === 1 ? '' : 's') + ', ' + (cr.free_extra || 0) + ' extra free check' + (cr.free_extra === 1 ? '' : 's') + '.' : ''; }
function refresh() {
return fetch('/api/config').then(function (r) { return r.json(); }).then(function (c) {
showFree(c); credits(c);
if (c.staging) { $('testBox').classList.remove('hide'); $('testIn').classList.toggle('hide', !!c.unlocked); $('testOn').classList.toggle('hide', !c.unlocked); }
if (c.member && c.member.refLink) { $('shareBox').classList.remove('hide'); $('refLink').value = c.member.refLink; }
if (!c.staging) document.querySelectorAll('[data-buy]').forEach(function (b) { b.textContent = b.getAttribute('data-buy') === 'deep10' ? 'Buy 10 reports' : 'Buy one report'; });
return c;
});
}
function poll(id) {
clearTimeout(timer);
fetch('/api/check/' + id).then(function (r) { return r.json(); }).then(function (v) {
if (v.error && !v.id) { live.innerHTML = '<div class="notice">' + esc(v.error) + '</div>'; return; }
current = v; live.classList.remove('hide'); Render.draw(live, v); wireDeep();
if (v.status === 'done' && !$('liveSlotDone')) { var m = document.createElement('i'); m.id = 'liveSlotDone'; m.hidden = true; live.appendChild(m); WWI.slot($('liveSlot'), 'result', 728, 90); }
if (v.status === 'queued' || v.status === 'running') timer = setTimeout(function () { poll(id); }, 2500);
else refresh();
}).catch(function () { timer = setTimeout(function () { poll(id); }, 5000); });
}
function start(body) {
setErr(''); $('runBtn').disabled = true;
return WWI.post('/api/check', body).then(function (j) {
$('runBtn').disabled = false;
if (!j.id) { setErr(j.error || 'The check could not start.'); return null; }
try { history.replaceState(null, '', '/?c=' + j.id + '#result'); } catch (e) {}
live.classList.remove('hide'); live.innerHTML = '<div class="steps">Starting...</div>'; live.scrollIntoView({ behavior: 'smooth', block: 'start' });
poll(j.id); return j;
}).catch(function () { $('runBtn').disabled = false; setErr('The check could not start. Try again.'); });
}
$('checkForm').addEventListener('submit', function (e) {
e.preventDefault();
var w = $('site').value.trim(), a = $('target').value.trim();
if (!w && !a) return setErr('Fill in a website, a contract address, or both.');
if (a && !/^0x[0-9a-fA-F]{40}$/.test(a)) return setErr('A contract address is 0x followed by 40 letters and numbers.');
start({ website: w, address: a, chain: $('chain').value, kind: 'free' });
});
function wireDeep() {
live.querySelectorAll('[data-deep]').forEach(function (b) {
if (b._w) return; b._w = 1;
b.addEventListener('click', function () {
var msg = live.querySelector('[data-deepmsg]');
b.disabled = true;
WWI.post('/api/check', { website: current.website || '', address: current.address || '', chain: current.chain, kind: 'deep', from: current.id, watch: $('watch').checked }).then(function (j) {
b.disabled = false;
if (!j.id) { msg.textContent = j.error || 'The deep report could not start.'; if (j._status === 402) $('reports').scrollIntoView({ behavior: 'smooth' }); return; }
try { history.replaceState(null, '', '/?c=' + j.id + '#result'); } catch (e) {}
poll(j.id); live.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
});
}
$('redeemBtn').addEventListener('click', function () {
var code = $('voucher').value.trim(); if (!code) return;
WWI.post('/api/redeem', { code: code }).then(function (j) {
$('voucherMsg').textContent = j.ok ? 'Added ' + j.amount + (j.kind === 'deep' ? ' deep report' : ' extra free check') + (j.amount === 1 ? '' : 's') + '.' : (j.error || 'That code did not work.');
refresh();
});
});
$('testBtn').addEventListener('click', function () {
WWI.post('/api/unlock', { code: $('testCode').value.trim() }).then(function (j) { $('testMsg').textContent = j.ok ? 'Unlocked for 30 days on this browser.' : (j.error || 'That code is not right.'); refresh(); });
});
$('lockBtn').addEventListener('click', function () { WWI.post('/api/lock', {}).then(function () { $('testMsg').textContent = 'Locked.'; refresh(); }); });
document.querySelectorAll('[data-test]').forEach(function (b) {
b.addEventListener('click', function () {
WWI.post('/api/test-purchase', { item: b.getAttribute('data-test') }).then(function (j) {
if (!j.ok) { $('testMsg').textContent = j.error || 'Not recorded.'; return; }
var s = j.split || {}; var paid = (s.levels || []).filter(function (l) { return l.username; });
$('testMsg').textContent = 'Recorded (no money moved). Would pay: ' + (paid.length ? paid.map(function (l) { return 'L' + l.level + ' @' + l.username + ' $' + l.usd.toFixed(2); }).join(', ') + ', ' : 'no qualified sponsor, ') + 'company $' + Number(s.company).toFixed(2) + '.';
refresh();
});
});
});
$('copyRef').addEventListener('click', function () { try { navigator.clipboard.writeText($('refLink').value); $('copyRef').textContent = 'Copied'; } catch (e) { $('refLink').select(); } });
var sample = document.querySelector('img[data-sample]'); if (sample) sample.addEventListener('error', function () { sample.remove(); });
// network table: the public deep reports of our own contracts
fetch('/api/network-checks').then(function (r) { return r.json(); }).then(function (j) {
(j.checks || []).forEach(function (c) {
var row = document.querySelector('[data-net="' + c.address + '"]'); if (!row || row._done) return;
if (c.kind !== 'deep' && (j.checks || []).some(function (x) { return x.address === c.address && x.kind === 'deep'; })) return;
row._done = 1;
row.querySelector('[data-score]').innerHTML = '<a style="color:#F0A27F;font-weight:600" href="/c/' + esc(c.id) + '">' + esc(c.grade || 'Report') + (c.overall != null ? ' (' + c.overall + '/100)' : '') + ', full report</a>';
});
}).catch(function () {});
WWI.slot($('heroSlot'), 'hero', 728, 90);
WWI.slot($('howSlot'), 'how', 728, 90);
refresh();
var q = new URLSearchParams(location.search).get('c'); if (q && /^[A-Za-z0-9]{12}$/.test(q)) poll(q);
})();