// Blocked domains: AdGuard's top blocked list plus what was blocked recently, and for whom. import { el } from '../ui.js'; import { get } from '../api.js'; import { ago, num, pct, when } from '../fmt.js'; import { adguardProblem, clientLink, domainLink, screen, section, table, fill } from '../common.js'; export function mount(root) { const ui = screen(root, [el('button.btn', { type: 'button', onclick: () => load() }, 'Refresh'), el('span.spacer'), el('a.btn', { href: '/queries?status=blocked' }, 'Blocked queries in the log')]); async function load() { ui.setStatus('Loading…'); try { const b = await get('/api/dns/blocked'); fill(ui.body, el('p.lede', {}, b.num_queries ? `AdGuard Home blocked ${num(b.num_blocked)} of ${num(b.num_queries)} queries (${pct(b.num_blocked / b.num_queries, 1)}) in its stats period.` : 'No AdGuard stats yet.'), el('div.cols', {}, el('div', {}, section('Recently blocked', b.since ? `${num(b.sample)} blocked queries since ${when(b.since)}` : ''), table(['Domain', { text: 'Times', props: { class: 'num' } }, 'Clients', 'Last'], b.recent.map((r) => el('tr', {}, el('td', {}, domainLink(r.domain), r.rule ? el('div.small.muted.mono', {}, r.rule) : null), el('td.num', {}, num(r.count)), el('td', {}, el('div', { style: 'display:grid;gap:2px' }, ...r.clients.slice(0, 4).map((c) => clientLink(c.ip, c.device)), r.clients.length > 4 ? el('span.small.muted', {}, `+${r.clients.length - 4} more`) : null)), el('td.nowrap', {}, ago(r.last)))), { empty: 'Nothing blocked recently.' })), el('div', {}, section('Most blocked', 'AdGuard stats period'), table(['Domain', { text: 'Times', props: { class: 'num' } }], b.top.map((r) => el('tr', {}, el('td', {}, domainLink(r.domain)), el('td.num', {}, num(r.count)))), { empty: 'Nothing yet.' }))), ); ui.setStatus(`${b.recent.length} domains blocked recently`); } catch (err) { fill(ui.body, adguardProblem(err)); ui.setStatus(err.message, 'error'); } } load(); }