document.addEventListener('DOMContentLoaded', () => { /* ── Create-paste page ── */ const pasteForm = document.getElementById('pasteForm'); const resultBox = document.getElementById('result'); const pasteText = document.getElementById('pasteText'); const charCount = document.getElementById('charCount'); const submitBtn = document.getElementById('submitBtn'); if (pasteText && charCount) { const update = () => { charCount.textContent = pasteText.value.length.toLocaleString(); pasteText.style.height = 'auto'; pasteText.style.height = Math.max(280, pasteText.scrollHeight) + 'px'; }; pasteText.addEventListener('input', update); update(); } if (pasteForm) { pasteForm.addEventListener('submit', async (e) => { e.preventDefault(); if (!pasteText || pasteText.value.trim() === '') { pasteText.focus(); pasteText.style.borderColor = 'var(--error)'; setTimeout(() => pasteText.style.borderColor = '', 1200); return; } submitBtn.classList.add('loading'); submitBtn.querySelector('span').textContent = 'Creating...'; try { const res = await fetch('/index.php?action=save', { method: 'POST', body: new FormData(pasteForm), }); const data = await res.json(); if (!data.success) { showError(data.message || 'Something went wrong.'); return; } const linkInput = document.getElementById('pasteLink'); const viewLink = document.getElementById('viewLink'); linkInput.value = data.url; viewLink.href = data.url; resultBox.removeAttribute('hidden'); resultBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); pasteText.value = ''; if (charCount) charCount.textContent = '0'; } catch { showError('Network error. Please try again.'); } finally { submitBtn.classList.remove('loading'); submitBtn.querySelector('span').textContent = 'Create Secure Link'; } }); function showError(msg) { resultBox.removeAttribute('hidden'); resultBox.style.borderLeftColor = 'var(--error)'; resultBox.innerHTML = `