document.querySelectorAll('body.users .ac_choice input[type=radio]') .forEach(elt => elt.onchange = () => fetch(document.body.dataset.editUrl + '.choice', { method: 'PUT', body: new URLSearchParams(new FormData(elt.form)) }) .then(launchNotes) .then(() => sleep(1)) .then(() => fetch(document.body.dataset.editUrl + '.result')) .then(response => response.text()) .then(result => window.location.assign('/users/' + window.location.pathname.split('/')[2] + result)) .catch(error => console.error('Error sending answer', error)))