Merge pages track: link-domain pool with safety checks, page image uploads, form provider labels, Reports pages + zones
This commit is contained in:
+24
-2
@@ -44,8 +44,8 @@
|
||||
});
|
||||
|
||||
// ── panes ──
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', reports: 'Reports', zones: 'Zones', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, reports: loadReports, zones: loadZones, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, settings: loadSettings };
|
||||
const TITLES = { overview: 'Overview', house: 'House ads', campaigns: 'All campaigns', members: 'Members', reports: 'Reports', zones: 'Zones', domains: 'Link domains', traffic: 'Traffic', blog: 'Blog', releases: 'Releases and roadmap', pnl: 'Profit and loss', settings: 'Settings' };
|
||||
const loaders = { overview: loadOverview, house: loadHouse, campaigns: loadCampaigns, members: loadMembers, reports: loadReports, zones: loadZones, domains: loadDomains, traffic: loadTraffic, blog: loadBlog, releases: loadReleases, pnl: loadPnl, settings: loadSettings };
|
||||
function setPane(name) {
|
||||
if (!TITLES[name]) name = 'overview';
|
||||
document.querySelectorAll('.pane').forEach(p => { p.hidden = p.id !== 'pane-' + name; });
|
||||
@@ -488,6 +488,28 @@
|
||||
try { await api('/api/admin/zones/' + b.dataset.znpause, pausing ? { paused: true, note: 'Paused ' + new Date().toLocaleDateString() } : { paused: false, note: '' }, 'POST'); loadZones(); } catch (e) { IAP.status(e.message, 'bad'); }
|
||||
}));
|
||||
}
|
||||
// ── link domains: channel per domain, last safety check, burned flag; check now / clear / pull (2026-10-10) ──
|
||||
async function loadDomains() {
|
||||
const d = await api('/api/admin/domains');
|
||||
const list = d.domains || []; const live = list.filter(x => !x.burned && x.channel !== 'reserve').length, burned = list.filter(x => x.burned).length;
|
||||
$('dmSub').textContent = list.length + ' domain' + (list.length === 1 ? '' : 's') + ' · ' + live + ' live · ' + burned + ' burned';
|
||||
$('dmGsb').textContent = d.gsb ? 'Google Safe Browsing: on' : 'Google Safe Browsing: off (set GSB_API_KEY on the server to turn it on)';
|
||||
const ago = t => t ? new Date(t).toLocaleString() : 'never';
|
||||
const mark = v => v === 'clean' ? '<span style="color:var(--ok,#2e9b5a)">clean</span>' : v === 'flagged' || v === 'listed' ? '<b style="color:var(--bad)">' + v + '</b>' : /^ok:/.test(v || '') ? '<span style="color:var(--ok,#2e9b5a)">answered ' + esc(v.slice(3)) + '</span>' : '<span class="muted">unknown</span>';
|
||||
$('dmTable').innerHTML = '<tr><th>Domain</th><th>Channel</th><th>Safe Browsing</th><th>URIBL</th><th>SURBL</th><th>Reach</th><th>Status</th><th>Last check</th><th></th></tr>'
|
||||
+ (list.length ? list.map(x => '<tr' + (x.burned ? ' style="background:rgba(192,57,43,.08)"' : '') + '><td><b>' + esc(x.host) + '</b></td>'
|
||||
+ '<td><select data-dmch="' + esc(x.host) + '">' + (d.channels || []).map(c => '<option value="' + c + '"' + (c === x.channel ? ' selected' : '') + '>' + esc(d.labels[c] || c) + '</option>').join('') + '</select><br><span class="muted small">' + esc(d.notes[x.channel] || '') + '</span></td>'
|
||||
+ '<td>' + mark(x.gsb) + '</td><td>' + mark(x.uribl) + '</td><td>' + mark(x.surbl) + '</td><td>' + mark(x.reach) + '</td>'
|
||||
+ '<td>' + (x.burned ? '<b style="color:var(--bad)">BURNED</b><br><span class="muted small">' + esc(x.reason || '') + (x.burnedAt ? ' · ' + ago(x.burnedAt) : '') + '</span>' : x.channel === 'reserve' ? '<span class="muted">held in reserve</span>' : '<span style="color:var(--ok,#2e9b5a)">live</span>') + '</td>'
|
||||
+ '<td>' + ago(x.checkedAt) + '</td>'
|
||||
+ '<td class="act" style="white-space:nowrap"><button type="button" class="btn small ghost" data-dmcheck="' + esc(x.host) + '">Check now</button> ' + (x.burned ? '<button type="button" class="btn small sec" data-dmclear="' + esc(x.host) + '">Clear burn</button>' : '<button type="button" class="btn small sec" data-dmburn="' + esc(x.host) + '">Pull</button>') + '</td></tr>').join('')
|
||||
: '<tr><td colspan="9" class="muted">No link domains yet. Add them to the linkDomains site setting (comma list) first.</td></tr>');
|
||||
document.querySelectorAll('[data-dmch]').forEach(sel => sel.addEventListener('change', async () => { try { await api('/api/admin/domains', { action: 'channel', domain: sel.dataset.dmch, channel: sel.value }); IAP.status('Channel saved: ' + sel.dataset.dmch + ' is now ' + sel.value + '.', 'ok'); loadDomains(); } catch (e) { IAP.status(e.message, 'bad'); } }));
|
||||
document.querySelectorAll('[data-dmcheck]').forEach(b => b.addEventListener('click', busy(b, async () => { const r = await api('/api/admin/domains', { action: 'check', domain: b.dataset.dmcheck }); const x = r.domain || {}; IAP.status(b.dataset.dmcheck + ': Safe Browsing ' + x.gsb + ', URIBL ' + x.uribl + ', SURBL ' + x.surbl + ', reach ' + x.reach + (x.burned ? ' · BURNED' : ''), x.burned ? 'bad' : 'ok'); loadDomains(); })));
|
||||
document.querySelectorAll('[data-dmclear]').forEach(b => b.addEventListener('click', busy(b, async () => { await api('/api/admin/domains', { action: 'clear', domain: b.dataset.dmclear }); IAP.status(b.dataset.dmclear + ' is back in the pool.', 'ok'); loadDomains(); })));
|
||||
document.querySelectorAll('[data-dmburn]').forEach(b => b.addEventListener('click', busy(b, async () => { await api('/api/admin/domains', { action: 'burn', domain: b.dataset.dmburn, reason: 'pulled by admin ' + new Date().toLocaleDateString() }); IAP.status(b.dataset.dmburn + ' pulled from the pool.', 'ok'); loadDomains(); })));
|
||||
}
|
||||
$('dmCheckAll').addEventListener('click', busy($('dmCheckAll'), async () => { IAP.status('Checking every domain…', 'ok'); const r = await api('/api/admin/domains', { action: 'check' }); const bad = (r.domains || []).filter(x => x.burned).length; IAP.status('Checked ' + (r.results || []).length + ' domains' + (bad ? ', ' + bad + ' burned' : ', none burned') + '.', bad ? 'bad' : 'ok'); loadDomains(); }));
|
||||
// ── traffic: referring domains / sources, landing pages, angles, by day ──
|
||||
let trfDays = 30;
|
||||
document.querySelectorAll('#trfRange [data-days]').forEach(b => b.addEventListener('click', () => { trfDays = Number(b.dataset.days); document.querySelectorAll('#trfRange [data-days]').forEach(x => x.classList.toggle('on', x === b)); loadTraffic().catch(e => IAP.status(e.message, 'bad')); }));
|
||||
|
||||
@@ -2,12 +2,48 @@
|
||||
(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: [] };
|
||||
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;
|
||||
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);
|
||||
@@ -45,7 +81,13 @@
|
||||
$('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>').join('');
|
||||
$('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 });
|
||||
|
||||
@@ -32,6 +32,27 @@
|
||||
const best = (s.hours || []).map((n, i) => [n, i]).sort((a, b) => b[0] - a[0]).slice(0, 3).filter(x => x[0]).map(x => x[1] + ':00');
|
||||
$('hourNote').textContent = best.length ? 'Busiest hours (UTC): ' + best.join(', ') + '. Hour rules per link come next.' : 'No clicks yet.';
|
||||
$('convRows').innerHTML = kv(s.conversions || [], 0);
|
||||
// -- Pages and Zones (2026-10-10): one bar per Central day in the range (empty days are zero), totals, per-item table
|
||||
const dayBars = (barsId, axisId, rows, f, g, empty) => {
|
||||
const map = {}; (rows || []).forEach(r => { map[r.day] = r; });
|
||||
const ser = keys.map(k => ({ day: k, a: map[k] ? f(map[k]) : 0, b: map[k] ? g(map[k]) : 0 }));
|
||||
const max = Math.max(1, ...ser.map(x => Math.max(x.a, x.b))); const any = ser.some(x => x.a || x.b);
|
||||
const el = $(barsId); el.style.gridTemplateColumns = 'repeat(' + keys.length + ',minmax(0,1fr))'; el.classList.add('stack');
|
||||
el.innerHTML = ser.map(x => '<i class="' + (x.a ? '' : 'dim') + '" style="height:' + Math.round(x.a / max * 100) + '%" title="' + x.day + ' · ' + x.a + ' / ' + x.b + '">' + (x.b ? '<b style="height:' + Math.round(x.b / x.a * 100 || 0) + '%"></b>' : '') + '</i>').join('');
|
||||
$(axisId).innerHTML = any ? '<span>' + keys[0] + '</span><span>' + keys[Math.floor(keys.length / 2)] + '</span><span>' + keys[keys.length - 1] + '</span>' : '<span class="muted">' + empty + '</span>';
|
||||
};
|
||||
const mini = rows => rows.map(([k, v]) => '<div class="m"><span class="k">' + esc(k) + '</span><span class="v">' + v + '</span></div>').join('');
|
||||
const pg = s.pages || { byDay: [], byPage: [] };
|
||||
// bar = views, inner bar = leads (leads as a share of that day's views; a day with leads but no views still shows)
|
||||
dayBars('pgBars', 'pgAxis', pg.byDay, d => Math.max(d.views, d.leads), d => d.leads, 'no page views yet');
|
||||
$('pgBars').querySelectorAll('i b').forEach(b => { b.style.background = 'var(--sig)'; });
|
||||
$('pgTiles').innerHTML = mini([['Views', fmt(pg.views)], ['Unique', fmt(pg.uniques)], ['Clicks through', fmt(pg.clicks)], ['Leads', fmt(pg.leads)]]);
|
||||
$('pgRows').innerHTML = (pg.byPage || []).length ? pg.byPage.map(x => '<div class="rw"><a href="/pages" style="text-decoration:none;color:var(--ink)"><b>' + esc(x.title) + '</b><br><span class="mono muted" style="font-size:11px">' + esc(x.type) + ' · ' + (x.status === 'published' ? '<span class="ok">live</span>' : 'draft') + '</span></a><span class="r num">' + fmt(x.views) + '</span><span class="r num">' + fmt(x.uniques) + '</span><span class="r num">' + fmt(x.clicks) + '</span><span class="r num">' + fmt(x.leads) + '</span></div>').join('') : '<div class="rw"><span class="muted">No pages yet. <a href="/pages">Make one</a>.</span></div>';
|
||||
const zn = s.zones || { byDay: [], byZone: [] };
|
||||
// bar = all views, lighter inner share = the ones that were NOT viewable
|
||||
dayBars('znBars', 'znAxis', zn.byDay, d => d.views, d => d.views - d.viewable, 'no zone views yet');
|
||||
$('znTiles').innerHTML = mini([['Views', fmt(zn.views)], ['Viewable', fmt(zn.viewable) + (zn.views ? ' <small class="muted" style="font-size:11px">' + Math.round(zn.viewable / zn.views * 100) + '%</small>' : '')], ['Clicks', fmt(zn.clicks)], ['Credits earned', fmt(zn.credits)]]);
|
||||
$('znRows').innerHTML = (zn.byZone || []).length ? zn.byZone.map(x => '<div class="rw"><a href="/zones" style="text-decoration:none;color:var(--ink)"><b>' + esc(x.name) + '</b><br><span class="mono muted" style="font-size:11px">' + esc(x.site) + ' · ' + esc(x.size) + (x.paused ? ' · <span class="warn">paused</span>' : x.active ? '' : ' · off') + '</span></a><span class="r num">' + fmt(x.views) + '</span><span class="r num">' + fmt(x.viewable) + (x.viewablePct != null ? ' <span class="muted" style="font-size:10px">' + x.viewablePct + '%</span>' : '') + '</span><span class="r num">' + fmt(x.clicks) + '</span><span class="r num">' + fmt(x.credits) + '</span></div>').join('') : '<div class="rw"><span class="muted">No zones yet. <a href="/zones">Add one</a>.</span></div>';
|
||||
}
|
||||
CR.requireSession(load);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user