0a30b1da60
Item 1 (domains.js): every short link domain in linkDomains gets a channel (email / messaging / social / reserve)
via the new linkDomainChannels site setting ("host:channel,..."; default order email, messaging, social, email,
reserve). Checks every 6 h + Admin > Link domains "Check now": Google Safe Browsing v4 when GSB_API_KEY is set
(unknown otherwise), URIBL + SURBL DNS lists (answer = listed, NXDOMAIN = clean, 127.0.0.1 or errors = unknown),
and a TelegramBot-UA reachability probe. Flagged or listed = BURNED: out of domains.live() (no new links or
pages on it, existing /r/ codes still resolve), admin told once via telegramAdminChatId or ADMIN_EMAIL.
State in DATA_DIR/domains.json. New: GET /api/my/link-hosts, GET+POST /api/admin/domains, admin pane.
/api/my/pages now hands out hosts from domains.live().
Item 2 (pages.js, formrestyle.js): POST /api/my/pages/upload (raw image body, multipart, or JSON base64) for
png/jpg/webp up to 2 MB, 50 per member, magic bytes checked, sharp re-encode when installed, stored under
DATA_DIR/uploads/pages/<owner-hash>/<id>.<ext>, served at /u/pages/... immutable for a year; delete via
POST /api/my/pages/images/<id> {remove}. Pages editor: Upload image button beside the image field + a strip of
the member's images. Provider allowlist (17 autoresponders, Sendy by /subscribe path) exposed as `providers`;
the editor says "Recognised: AWeber" or "Unknown provider: plain post to <host>" at paste time; pub() carries
formProvider. Unknown hosts still allowed when parse-or-refuse passes.
Item 3 (zonereport.js, pages.summary): /api/my/reports returns {spins, pages, zones} (spins still spread at the
top level) for the chosen days; Pages and Zones sections on /reports with 30-day bars, totals, per-item tables,
phone width checked. Zone numbers are a read-only view over zones.json (zones.js untouched).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
112 lines
18 KiB
JavaScript
112 lines
18 KiB
JavaScript
// LinkSpin Pages screen: gallery + wizard (scan -> type -> angle -> write) + editor + leads.
|
|
(function () {
|
|
const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog;
|
|
let PAGES = [], SEL = null, SCAN = null, TYPE = 'bridge', HOSTS = [], BASE = '';
|
|
let STYLES = { palettes: [], designs: [], layouts: [], niches: [] }, PROVIDERS = [], IMAGES = [], IMG_MAX = 50, IMG_BYTES = 2 * 1024 * 1024;
|
|
// which autoresponder a pasted form posts to (same list the server keeps in formrestyle.js, handed over as `providers`)
|
|
function providerOf(embed) {
|
|
const f = /<form\b[^>]*>/i.exec(String(embed || '')); if (!f) return null;
|
|
const am = /\baction\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i.exec(f[0]); const action = am ? (am[1] || am[2] || am[3]) : '';
|
|
if (!/^https?:\/\//i.test(action)) return null;
|
|
let u; try { u = new URL(action); } catch (e) { return null; }
|
|
const host = u.hostname.toLowerCase().replace(/^www\./, '');
|
|
for (const pr of PROVIDERS) { const hostHit = (pr.hosts || []).some(h => host === h || host.endsWith('.' + h)); const pathHit = pr.path ? new RegExp(pr.path, 'i').test(u.pathname) : false; if ((pr.hosts && pr.hosts.length && hostHit) || (!(pr.hosts && pr.hosts.length) && pathHit)) return { host, known: true, name: pr.name }; }
|
|
return { host, known: false, name: '' };
|
|
}
|
|
function providerNote(embed) {
|
|
const el = $('providerNote'); if (!el) return; const src = String(embed || '').trim();
|
|
if (!src) { el.hidden = true; el.innerHTML = ''; return; }
|
|
const pr = providerOf(src); el.hidden = false;
|
|
if (!pr) { el.innerHTML = '<span class="warn">No https:// form action found yet.</span> Paste the whole <form> block your provider gives you.'; return; }
|
|
el.innerHTML = pr.known ? '<span class="ok"><span class="dot"></span>Recognised: ' + esc(pr.name) + '</span> <span class="muted">Submissions go to ' + esc(pr.host) + '.</span>'
|
|
: '<span class="warn"><span class="dot"></span>Unknown provider</span> <span class="muted">The form is kept as a plain post to <b>' + esc(pr.host) + '</b>; we cannot vouch for it. It still has to pass the form check when you save.</span>';
|
|
}
|
|
// the member's hosted images: a strip of thumbnails under the image field, click to use, x to delete
|
|
function drawImages() {
|
|
const box = $('imgStrip'); if (!box) return;
|
|
box.innerHTML = (IMAGES.length ? IMAGES.map(i => '<span class="im" data-url="' + esc(i.url) + '" title="Use this image"><img src="' + esc(i.url) + '" alt="" loading="lazy"><button type="button" class="x" data-del="' + i.id + '" title="Delete this image">×</button></span>').join('') : '<span class="muted" style="font-size:11px">No uploads yet. PNG, JPG or WebP up to 2 MB, ' + IMG_MAX + ' per account.</span>')
|
|
+ (IMAGES.length ? '<span class="muted mono" style="font-size:11px;align-self:center">' + IMAGES.length + '/' + IMG_MAX + '</span>' : '');
|
|
box.querySelectorAll('.im').forEach(s => s.addEventListener('click', e => { if (e.target.closest('[data-del]')) return; const f = $('f-image'); if (f) { f.value = s.dataset.url; f.dispatchEvent(new Event('input')); toast('Image URL filled in. Save to keep it.'); } }));
|
|
box.querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', async e => { e.stopPropagation(); if (!await dialog({ title: 'Delete this image?', text: 'Pages that still point at it will show no image.', ok: 'Delete', danger: true })) return; try { const r = await api('/api/my/pages/images/' + b.dataset.del, { remove: true }); IMAGES = r.images || []; drawImages(); } catch (er) { toast(er.message, true); } }));
|
|
}
|
|
async function uploadFile(file) {
|
|
if (!file) return; if (!/^image\/(png|jpeg|webp)$/.test(file.type)) return toast('Use a PNG, JPG or WebP image.', true);
|
|
if (file.size > IMG_BYTES) return toast('That image is over 2 MB. Make it smaller and try again.', true);
|
|
const btn = $('imgUpload'); if (btn) { btn.disabled = true; btn.textContent = 'Uploading…'; }
|
|
try {
|
|
const r = await (await fetch('/api/my/pages/upload', { method: 'POST', headers: { 'Content-Type': file.type }, body: file })).json(); if (r.error) throw new Error(r.error);
|
|
IMAGES.unshift(r.image); drawImages(); const f = $('f-image'); if (f) { f.value = r.image.url; f.dispatchEvent(new Event('input')); } toast('Uploaded. Save to keep it on the page.');
|
|
} catch (e) { toast(e.message, true); }
|
|
if (btn) { btn.disabled = false; btn.textContent = 'Upload image'; }
|
|
}
|
|
CR.mount({ active: 'pages', title: 'Pages', sub: 'loading', actions: '<button class="btn pri" type="button" id="newBtn">+ New page</button>' });
|
|
const pageUrl = p => (BASE || ('https://' + (HOSTS[0] || location.host) + '/p/')) + p.slug;
|
|
async function load(keepSel) {
|
|
let r; try { r = await CR.get('/api/my/pages'); } catch (e) { CR.sub('could not load'); return; }
|
|
PAGES = r.pages || []; HOSTS = r.hosts || []; BASE = r.pageBase || ''; if (r.styles) STYLES = r.styles; PROVIDERS = r.providers || []; IMAGES = r.images || []; if (r.imageMax) IMG_MAX = r.imageMax; if (r.imageBytes) IMG_BYTES = r.imageBytes;
|
|
const pubd = PAGES.filter(p => p.status === 'published').length;
|
|
CR.sub(PAGES.length + ' page' + (PAGES.length === 1 ? '' : 's') + ' · ' + pubd + ' live');
|
|
const views = PAGES.reduce((n, p) => n + p.views, 0), leads = PAGES.reduce((n, p) => n + p.leads, 0), clicks = PAGES.reduce((n, p) => n + p.clicks, 0);
|
|
$('tiles').innerHTML = [['Pages', fmt(PAGES.length)], ['Live', fmt(pubd)], ['Views', fmt(views)], ['Clicks through', fmt(clicks)], ['Leads on your list', fmt(leads)]].map(([k, v], i) => '<div class="tile' + (i === 4 ? ' hi' : '') + '"><span class="k">' + k + '</span><span class="v">' + v + '</span></div>').join('');
|
|
$('gal').innerHTML = PAGES.length ? PAGES.map(p => '<div class="card' + (p.id === SEL ? ' on' : '') + '" data-id="' + p.id + '" role="button" tabindex="0"><div class="thumb"><i class="t"></i><i style="width:55%"></i><i style="width:65%"></i><i class="b"></i></div><div class="cap"><b>' + esc(p.title) + '</b><span class="mono muted" style="font-size:11px">' + p.type + ' · ' + (p.status === 'published' ? '<span class="ok">live</span>' : 'draft') + ' · ' + fmt(p.views) + ' views' + (p.leads ? ' · ' + fmt(p.leads) + ' leads' : '') + '</span></div></div>').join('')
|
|
: '<div class="muted">No pages yet. Scan the page you promote and write your first bridge page in a minute.</div>';
|
|
$('gal').querySelectorAll('.card').forEach(c => { const go = () => openEditor(c.dataset.id); c.addEventListener('click', go); c.addEventListener('keydown', e => { if (e.key === 'Enter') go(); }); });
|
|
try { const L = await CR.get('/api/my/pages/leads'); const rows = L.leads || []; $('leadsBox').hidden = !rows.length; $('leadRows').innerHTML = rows.slice(0, 50).map(l => '<div class="rw"><span><b>' + esc(l.email) + '</b>' + (l.name ? ' <span class="muted">' + esc(l.name) + '</span>' : '') + '</span><span class="muted">' + esc(l.page) + '</span><span class="mono muted" style="font-size:11px">' + new Date(l.ts).toLocaleString() + '</span></div>').join(''); $('leadFoot').textContent = rows.length + ' lead' + (rows.length === 1 ? '' : 's') + ' on your list · yours to export'; } catch (e) {}
|
|
if (keepSel && SEL) openEditor(SEL, true);
|
|
}
|
|
// wizard
|
|
$('types').querySelectorAll('button').forEach(b => b.addEventListener('click', () => { TYPE = b.dataset.t; $('types').querySelectorAll('button').forEach(x => x.classList.toggle('on', x === b)); }));
|
|
$('scanBtn').addEventListener('click', async () => { const url = $('scanUrl').value.trim(); if (!url) return $('scanUrl').focus(); $('scanBtn').disabled = true; $('scanOut').hidden = false; $('scanOut').innerHTML = '<span class="muted">Scanning…</span>'; try { const r = await api('/api/my/pages/scan', { url }); SCAN = r.scan; $('scanOut').innerHTML = '<span class="mono ok" style="font-size:11px">SCANNED · HTTP ' + SCAN.status + '</span><div><b>' + esc(SCAN.title || SCAN.h1 || '(no title)') + '</b></div><div class="muted">' + esc((SCAN.description || '').slice(0, 160)) + '</div>' + (SCAN.image ? '<div class="muted mono" style="font-size:11px">image found</div>' : '') + (SCAN.bullets.length ? '<div class="muted mono" style="font-size:11px">' + SCAN.bullets.length + ' points found</div>' : ''); } catch (e) { SCAN = null; $('scanOut').innerHTML = '<span class="bad">' + esc(e.message) + '</span>'; } $('scanBtn').disabled = false; });
|
|
async function createPage(writeIt) {
|
|
const url = $('scanUrl').value.trim(); const angle = $('angle').value.trim();
|
|
if (!SCAN && url && writeIt) { $('scanBtn').click(); await new Promise(r => setTimeout(r, 2500)); }
|
|
try {
|
|
const r = await api('/api/my/pages', { type: TYPE, title: (SCAN && (SCAN.title || SCAN.h1)) || angle || 'New ' + TYPE + ' page', angle, scan: SCAN || (url ? { url } : null), content: { cta: { url: url, text: TYPE === 'squeeze' ? 'Send me the details' : 'Take a look' }, headline: angle || '' } });
|
|
SEL = r.page.id;
|
|
if (writeIt) { toast('Writing…'); await api('/api/my/pages/' + SEL + '/write', { angle, cta: url }); }
|
|
await load(); openEditor(SEL);
|
|
} catch (e) { toast(e.message, true); }
|
|
}
|
|
$('writeBtn').addEventListener('click', () => createPage(true)); $('blankBtn').addEventListener('click', () => createPage(false));
|
|
$('newBtn').addEventListener('click', () => { $('editor').hidden = true; $('wizard').hidden = false; $('scanUrl').focus(); });
|
|
// editor
|
|
const F = { bridge: [['eyebrow', 'Eyebrow'], ['headline', 'Headline'], ['sub', 'Subhead'], ['body', 'Body, blank line between paragraphs', 'ta'], ['bullets', 'Bullets, one per line', 'ta'], ['bonusTitle', 'Bonus title'], ['bonus', 'Bonus text', 'ta'], ['ctaText', 'Button text'], ['ctaUrl', 'Button link'], ['image', 'Hero image URL'], ['disclaimer', 'Footer line']],
|
|
review: [['eyebrow', 'Eyebrow'], ['headline', 'Headline'], ['rating', 'Rating 1 to 5'], ['sub', 'Subhead'], ['body', 'Review body, blank line between paragraphs', 'ta'], ['pros', 'What works, one per line', 'ta'], ['cons', 'What to know, one per line', 'ta'], ['verdict', 'Verdict'], ['ctaText', 'Button text'], ['ctaUrl', 'Button link'], ['image', 'Hero image URL'], ['disclaimer', 'Footer line']],
|
|
squeeze: [['eyebrow', 'Eyebrow'], ['headline', 'Headline'], ['sub', 'Subhead'], ['bullets', 'What they get, one per line', 'ta'], ['ctaText', 'Button text'], ['ctaUrl', 'Where they go after the form'], ['image', 'Image URL'], ['price', 'Price chip on the split visual, like $17 (optional)'], ['privacy', 'Privacy line'], ['formEmbed', 'Your autoresponder form (optional, plain HTML form only, no JavaScript). Leave empty to capture leads on your LinkSpin list.', 'ta'], ['disclaimer', 'Footer line']] };
|
|
function openEditor(id, quiet) {
|
|
const p = PAGES.find(x => x.id === id); if (!p) return; SEL = id;
|
|
$('gal').querySelectorAll('.card').forEach(c => c.classList.toggle('on', c.dataset.id === id));
|
|
$('wizard').hidden = true; $('editor').hidden = false;
|
|
$('edTitle').textContent = p.title; $('edStatus').innerHTML = p.status === 'published' ? '<span class="ok"><span class="dot"></span>LIVE</span>' : '<span class="warn"><span class="dot"></span>DRAFT</span>';
|
|
$('edPublish').textContent = p.status === 'published' ? 'Unpublish' : 'Publish'; $('edPreview').href = '/p/' + p.slug + '?preview=1';
|
|
$('edUrl').hidden = p.status !== 'published'; $('edUrl').textContent = pageUrl(p);
|
|
const c = p.content || {}; const v = k => k === 'ctaText' ? (c.cta && c.cta.text) || '' : k === 'ctaUrl' ? (c.cta && c.cta.url) || '' : Array.isArray(c[k]) ? c[k].join('\n') : (c[k] == null ? '' : c[k]);
|
|
$('edFields').innerHTML = F[p.type].map(([k, label, ta]) => '<label class="lbl">' + esc(label) + (ta ? '<textarea class="field" id="f-' + k + '">' + esc(v(k)) + '</textarea>' : '<input class="field' + (/Url|image/i.test(k) ? ' mono' : '') + '" id="f-' + k + '" value="' + esc(v(k)) + '">') + '</label>'
|
|
// hosted images: an Upload button beside the image field (this image is the hero on bridge/review and the card image on squeeze) + the member's strip
|
|
+ (k === 'image' ? '<div class="imgrow"><button class="btn sm" type="button" id="imgUpload">Upload image</button><input type="file" id="imgFile" accept="image/png,image/jpeg,image/webp" hidden><span class="muted" style="font-size:11px">PNG, JPG or WebP up to 2 MB. Uploading fills the URL above.</span></div><div class="imgstrip" id="imgStrip"></div>' : '')
|
|
// pasted provider forms: say at paste time which autoresponder the form posts to
|
|
+ (k === 'formEmbed' ? '<div class="muted" id="providerNote" style="font-size:12px" hidden></div>' : '')).join('');
|
|
if ($('imgUpload')) { $('imgUpload').addEventListener('click', () => $('imgFile').click()); $('imgFile').addEventListener('change', () => { uploadFile($('imgFile').files[0]); $('imgFile').value = ''; }); drawImages(); }
|
|
if ($('f-formEmbed')) { const fe = $('f-formEmbed'); const upd = () => providerNote(fe.value); fe.addEventListener('input', upd); fe.addEventListener('paste', () => setTimeout(upd, 0)); upd(); }
|
|
// the Look panel: niche preset, design, colours, layout. Each change saves at once and the gallery/preview refresh.
|
|
const d = p.design || {}; const setLook = async patch => { try { await api('/api/my/pages/' + p.id, patch); load(true); } catch (e) { toast(e.message, true); } };
|
|
const ns = $('niche'); ns.innerHTML = '<option value="">None (set it yourself)</option>' + STYLES.niches.map(n => '<option value="' + n.key + '"' + (d.niche === n.key ? ' selected' : '') + '>' + esc(n.label) + ' \u00b7 ' + esc(n.blurb) + '</option>').join(''); ns.onchange = () => setLook({ niche: ns.value });
|
|
{ const nn = STYLES.niches.find(n => n.key === d.niche); const row = $('heroRow'); if (nn && nn.heroes && nn.heroes.length > 1 && row) { row.hidden = false; $('heroes').innerHTML = nn.heroes.map((u, i) => '<button type="button" data-h="' + i + '" class="' + ((Number(d.hero) || 0) === i ? 'on' : '') + '" title="Hero ' + (i + 1) + '"><img src="' + esc(u) + '" alt="" loading="lazy"></button>').join(''); $('heroes').querySelectorAll('button').forEach(b => b.addEventListener('click', () => setLook({ hero: Number(b.dataset.h) }))); } else if (row) row.hidden = true; }
|
|
$('designs').innerHTML = STYLES.designs.map(x => '<button type="button" data-d="' + x.key + '" class="' + (d.design === x.key ? 'on' : '') + '" title="' + esc(x.blurb) + '">' + esc(x.label) + '</button>').join('');
|
|
$('designs').querySelectorAll('button').forEach(b => b.addEventListener('click', () => setLook({ design: b.dataset.d })));
|
|
$('pal').innerHTML = STYLES.palettes.map(x => '<button type="button" data-p="' + x.key + '" class="' + (d.palette === x.key ? 'on' : '') + '" title="' + esc(x.label + ', ' + x.sub) + '">' + x.swatch.map(col => '<i style="background:' + col + '"></i>').join('') + '</button>').join('');
|
|
$('pal').querySelectorAll('button').forEach(b => b.addEventListener('click', () => setLook({ palette: b.dataset.p })));
|
|
$('layouts').innerHTML = STYLES.layouts.map(x => '<button type="button" data-l="' + x.key + '" class="' + ((d.layout || 'stack') === x.key ? 'on' : '') + '" title="' + esc(x.blurb) + '">' + esc(x.label) + '</button>').join('');
|
|
$('layouts').querySelectorAll('button').forEach(b => b.addEventListener('click', () => setLook({ layout: b.dataset.l })));
|
|
if (!quiet && window.matchMedia('(max-width:900px)').matches) $('side').scrollIntoView({ behavior: 'smooth' });
|
|
}
|
|
function collect(p) { const g = k => { const el = $('f-' + k); return el ? el.value : undefined; }; const c = {}; for (const [k] of F[p.type]) { if (k === 'ctaText' || k === 'ctaUrl') continue; c[k] = g(k); } c.cta = { text: g('ctaText'), url: g('ctaUrl') }; for (const k of ['bullets', 'pros', 'cons']) if (c[k] != null) c[k] = c[k].split('\n'); return c; }
|
|
$('edSave').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; try { await api('/api/my/pages/' + p.id, { content: collect(p), title: ($('f-headline').value || p.title).slice(0, 100) }); toast('Saved'); load(true); } catch (e) { toast(e.message, true); } });
|
|
$('edPublish').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; try { await api('/api/my/pages/' + p.id, { content: collect(p) }); const r = await api('/api/my/pages/' + p.id, { status: p.status === 'published' ? 'draft' : 'published' }); toast(r.page.status === 'published' ? 'Live at ' + pageUrl(r.page) : 'Unpublished'); load(true); } catch (e) { toast(e.message, true); } });
|
|
$('edRewrite').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; const v = await dialog({ title: 'Write again', text: 'A fresh draft from the scan and your angle. Your current text is replaced.', fields: [{ k: 'angle', label: 'Angle', value: p.angle || '' }], ok: 'Write' }); if (!v) return; try { toast('Writing…'); await api('/api/my/pages/' + p.id + '/write', { angle: v.angle }); load(true); } catch (e) { toast(e.message, true); } });
|
|
$('edDelete').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; if (!await dialog({ title: 'Delete ' + p.title + '?', text: 'The page stops answering. Leads already on your list stay.', ok: 'Delete', danger: true })) return; try { await api('/api/my/pages/' + p.id, { remove: true }); SEL = null; $('editor').hidden = true; $('wizard').hidden = false; load(); } catch (e) { toast(e.message, true); } });
|
|
$('edClose').addEventListener('click', () => { $('editor').hidden = true; $('wizard').hidden = false; });
|
|
$('edSpin').addEventListener('click', async () => { const p = PAGES.find(x => x.id === SEL); if (!p) return; if (p.status !== 'published') return toast('Publish the page first.', true); try { const r = await CR.get('/api/my/rotations'); const rots = r.rotations || []; if (!rots.length) { const c = await api('/api/my/rotations', { name: p.title }); await api('/api/my/rotations/' + c.rotation.id + '/dest', { url: pageUrl(p), label: p.title, weight: 10 }); toast('New spin made with this page'); location.href = '/links#' + c.rotation.id; return; } const v = await dialog({ title: 'Which spin?', html: '<label class="lbl">Spin<select class="field" id="dlg-rot">' + rots.map(x => '<option value="' + x.id + '">' + esc(x.name) + '</option>').join('') + '</select></label>', ok: 'Add page' }); if (!v) return; const id = document.getElementById('dlg-rot') ? document.getElementById('dlg-rot').value : rots[0].id; await api('/api/my/rotations/' + id + '/dest', { url: pageUrl(p), label: p.title, weight: 10 }); toast('Added to the spin'); location.href = '/links#' + id; } catch (e) { toast(e.message, true); } });
|
|
CR.requireSession(() => load());
|
|
})();
|