// Domains UI functions function renderDnsConflicts() { if (window.genericFilter) window.genericFilter('dns-conflicts'); } function openAddModal() { const modal = document.getElementById('addDomainModal'); if (modal) modal.showModal(); } async function submitAddDomain() { const domainEl = document.getElementById('modal-domain'); const hashEl = document.getElementById('modal-hash'); const sslEl = document.getElementById('modal-ssl'); if (!domainEl || !hashEl) return; const domain = domainEl.value.trim(); const hash = hashEl.value.trim(); const ssl = sslEl ? sslEl.checked : false; try { const response = await fetch('/api/add-domain', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domain, hash, ssl }) }); if (!response.ok) { const errorText = await response.text(); let errorMessage = errorText; // Try to parse as JSON and extract the message try { const errorJson = JSON.parse(errorText); errorMessage = errorJson.message || errorText; } catch (e) { // If not JSON, use the text as-is errorMessage = errorText; } throw new Error(errorMessage); } if (window.showNotification) window.showNotification('Domain added successfully'); const modal = document.getElementById('addDomainModal'); if (modal) modal.close(); domainEl.value = ''; hashEl.value = ''; if (sslEl) sslEl.checked = false; if (window.genericFetch) window.genericFetch('domains', true); } catch (err) { console.error('Failed to add domain:', err); // Display just the error message, not the full error object const errorMessage = err.message || 'An unknown error occurred'; if (window.showNotification) window.showNotification(errorMessage, 'error'); } } function removeDomain(domain) { if (window.showConfirm) { window.showConfirm(`Remove ${domain}?`, async () => { try { const response = await fetch('/api/remove-domain', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domain }) }); if (!response.ok) { throw new Error(await response.text()); } if (window.showNotification) window.showNotification('Domain removed successfully'); if (window.genericFetch) window.genericFetch('domains', true); } catch (err) { console.error('Failed to remove domain:', err); if (window.showNotification) window.showNotification('Failed to remove domain: ' + err.message, 'error'); } }); } } // Domain filter settings functions async function loadDomainFilterSettings() { try { const response = await fetch('/api/domain-filter-settings'); if (response.ok) { const settings = await response.json(); // Apply saved settings to filter dropdowns const consensusEl = document.getElementById('filter-consensus-status'); const hashTypeEl = document.getElementById('filter-hash-type'); const ownershipEl = document.getElementById('filter-ownership'); if (consensusEl && settings.consensusStatus) { consensusEl.value = settings.consensusStatus; } if (hashTypeEl && settings.hashType) { hashTypeEl.value = settings.hashType; } if (ownershipEl && settings.ownership) { ownershipEl.value = settings.ownership; } } } catch (err) { console.log('No saved domain filter settings found, using defaults'); } } async function saveDomainFilterSettings() { try { const consensusEl = document.getElementById('filter-consensus-status'); const hashTypeEl = document.getElementById('filter-hash-type'); const ownershipEl = document.getElementById('filter-ownership'); const settings = { consensusStatus: consensusEl ? consensusEl.value : 'all', hashType: hashTypeEl ? hashTypeEl.value : 'all', ownership: ownershipEl ? ownershipEl.value : 'all' }; const response = await fetch('/api/save-domain-filter-settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(settings) }); if (!response.ok) { console.error('Failed to save domain filter settings'); } } catch (err) { console.error('Error saving domain filter settings:', err); } } window.renderDnsConflicts = renderDnsConflicts; window.openAddModal = openAddModal; window.submitAddDomain = submitAddDomain; window.removeDomain = removeDomain; window.loadDomainFilterSettings = loadDomainFilterSettings; window.saveDomainFilterSettings = saveDomainFilterSettings;