// ═══════════════════════════════════════════════════════ // URL Shortener // ═══════════════════════════════════════════════════════ const urlHist = []; async function shortenURL() { const url = document.getElementById('urlInput').value.trim(); if (!url) return setStatus('urlStatus','error','Enter a URL.'); const d = await apiPost('/api/url/shorten', { url }); if (d.success) { document.getElementById('shortUrlLink').href = d.shortUrl; document.getElementById('shortUrlLink').textContent = d.shortUrl; document.getElementById('urlResult').classList.add('visible'); setStatus('urlStatus','success','Shortened ✓'); urlHist.unshift({ short: d.shortUrl, original: url, time: new Date().toLocaleTimeString() }); renderUrlHistory(); } else setStatus('urlStatus','error', d.error); } function copyShortUrl() { copyText(document.getElementById('shortUrlLink').textContent); } function renderUrlHistory() { const c = document.getElementById('urlHistory'); if (!urlHist.length) { c.textContent = 'No links shortened yet.'; return; } c.innerHTML = urlHist.slice(0,10).map(h => `