document.addEventListener('DOMContentLoaded', function(){ const copyBtn = document.getElementById('copy-url'); const vaultLink = document.getElementById('vault-link'); if(copyBtn && vaultLink){ copyBtn.addEventListener('click', async ()=>{ try{ await navigator.clipboard.writeText(vaultLink.href); copyBtn.textContent = 'Copied!'; setTimeout(()=> copyBtn.textContent = 'Copy', 1800); }catch(e){ const ta = document.createElement('textarea'); ta.value = vaultLink.href; document.body.appendChild(ta); ta.select(); try{ document.execCommand('copy'); copyBtn.textContent='Copied!'}catch(err){alert('Copy failed; please copy manually.')} ta.remove(); setTimeout(()=> copyBtn.textContent = 'Copy',1800); } }); } });