let requestSent = false; const refreshCaptcha = () => { if (requestSent) return false; requestSent = true; fetch('/captcha-regenerate', {headers: {'X-Requested-With': 'XMLHttpRequest'}}) .then(response => response.text()) .then(data => document.getElementById('captcha-img')?.setAttribute('src', data)) .catch() .finally(() => requestSent = false); };