diff --git a/assets/js/captcha.js b/assets/js/captcha.js index 8fd0ace..b9be7e4 100644 --- a/assets/js/captcha.js +++ b/assets/js/captcha.js @@ -1,6 +1,13 @@ 'use strict'; (() => { + // Make 'em work for it! + let doCryptoStuff = window.crypto.subtle.generateKey({ + name: 'RSA-OAEP', + modulusLength: 4096, + publicExponent: new Uint8Array([1, 0, 1]), + hash: 'SHA-512' + }, false, ['encrypt', 'decrypt']); let captchaValue = document .querySelector('label[for="captcha"]') .textContent @@ -8,13 +15,17 @@ let captchaForm = document .querySelector('form[class="form-body"]'); - captchaForm.captcha.value = captchaValue; - // Make 'em work for it - window.crypto.subtle.generateKey({ - name: 'RSA-OAEP', - modulusLength: 4096, - publicExponent: new Uint8Array([1, 0, 1]), - hash: 'SHA-512' - }, false, ['encrypt', 'decrypt']) - .finally(() => captchaForm.submit()); + captchaForm.captcha.readOnly = true; + captchaForm.captcha.value = '⏳'; + + doCryptoStuff + .then(() => { + captchaForm.captcha.value = captchaValue; + captchaForm.submit(); + }) + .catch((err) => { + captchaForm.captcha.value = null; + captchaForm.captcha.readOnly = false; + console.log(err); + }); })();