From aa8bd8b9f495844fc9071606a5224f41317981f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Th=C3=A9riault?= Date: Mon, 28 Oct 2019 10:25:27 -0400 Subject: [PATCH] Edit space detection method for random url gen (fixes #3) --- resources/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/script.js b/resources/script.js index 8a863a0..cbd9359 100644 --- a/resources/script.js +++ b/resources/script.js @@ -76,6 +76,13 @@ for (const group in inputs) { const urlInput = inputs[group][0]; urlInput.addEventListener("input", () => { + if (urlInput.value[urlInput.value.length - 1] === " ") { + urlInput.value = randomUrl(); + checkValidity(); + e.preventDefault(); + return; + } + urlInput.value = urlInput.value .replace(/[^0-9A-Za-z]/g, "") .toLowerCase(); @@ -87,13 +94,6 @@ for (const group in inputs) { urlInput.setCustomValidity(""); } }); - urlInput.addEventListener("keyup", (e) => { - if (e.code === "Space") { - urlInput.value = randomUrl(); - checkValidity(); - e.preventDefault(); - } - }); const checkValidity = () => { if (used[group].some((x) => x.id === parseInt(urlInput.value, 36))) {