document.addEventListener('DOMContentLoaded', async function() { const user = JSON.parse(localStorage.getItem('user') || 'null'); if (!user) { window.location.href = '/login'; return; } document.getElementById('current-user').textContent = user.username; if (user.role === 'admin') { document.getElementById('admin-section').style.display = ''; } try { const [links, collections, keys] = await Promise.all([ LinkSync.getLinks({ limit: 1 }), LinkSync.getCollections(), LinkSync.getApiKeys(), ]); document.getElementById('link-count').textContent = Array.isArray(links) ? links.length : 0; document.getElementById('collection-count').textContent = Array.isArray(collections) ? collections.length : 0; document.getElementById('api-key-count').textContent = Array.isArray(keys) ? keys.length : 0; } catch (err) { console.error('Failed to load stats:', err); } });