// OpenRouter Monitor - Main JavaScript // HTMX Configuration document.addEventListener('DOMContentLoaded', function() { // Configure HTMX to include CSRF token in requests document.body.addEventListener('htmx:configRequest', function(evt) { const csrfToken = document.querySelector('meta[name="csrf-token"]'); if (csrfToken) { evt.detail.headers['X-CSRF-Token'] = csrfToken.content; } }); // Auto-hide alerts after 5 seconds const alerts = document.querySelectorAll('.alert:not(.alert-permanent)'); alerts.forEach(function(alert) { setTimeout(function() { alert.style.opacity = '0'; setTimeout(function() { alert.remove(); }, 300); }, 5000); }); }); // Utility function to format currency function formatCurrency(amount) { return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount); } // Utility function to format date function formatDate(dateString) { return new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }).format(new Date(dateString)); } // Confirmation dialog for destructive actions function confirmAction(message, callback) { if (confirm(message)) { callback(); } }