function renderAliases(data) { const dataContainer = document.getElementById('container'); const template = window.innerWidth > 768 ? Handlebars.compile(defaultTemplate) : Handlebars.compile(responsiveCardTemplate); const html = template({ data: data .sort((a, b) => new Date(a.created) - new Date(b.created)) .map(alias => ({ ...alias, created: new Date(alias.created).toLocaleString() })) }); dataContainer.innerHTML = html; } function createAlias() { const tags = document.getElementById('tags').value?.split(',') || []; fetch('/aliases', { method: 'POST', body: JSON.stringify({ tags }), headers: { 'Content-Type': 'application/json' } }) .then(res => res.json()) .then(data => { renderAliases(data) }) } function deleteAlias(id) { fetch(`/aliases/${id}`, { method: 'DELETE' }) .then(res => res.json()) .then(data => { renderAliases(data) }) } function copyToClipboard(text) { navigator.clipboard.writeText(text) } const defaultTemplate = `
Address | Tags | Created | Action |
---|---|---|---|
{{address}} | {{#each tags}}{{this}} {{/each}} | {{created}} |
Delete
|
{{created}}