From e92e490769ce1884ea87ccd911ea809b220d3bd4 Mon Sep 17 00:00:00 2001 From: Jonathan Berrisch Date: Wed, 11 Jun 2025 08:22:39 +0200 Subject: [PATCH] More user friendlyness for the input field --- index.html | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index e73cff4..6ed8a2e 100644 --- a/index.html +++ b/index.html @@ -154,8 +154,7 @@

QR Code Generator

- +
@@ -169,7 +168,8 @@ @@ -179,23 +179,33 @@ colorDark: "#004c93" }); + var debounceTimer; + function makeCode() { var elText = document.getElementById("text"); var elColor = document.getElementById("color"); - if (!elText.value) { - alert("Please enter some text"); - elText.focus(); - return; - } + var text = elText.value || "https://git.0n8.de/BerriJ/onlyqr"; qrcode._htOption.colorDark = elColor.value; - qrcode.makeCode(elText.value); + qrcode.makeCode(text); } + function debouncedMakeCode() { + clearTimeout(debounceTimer); + debounceTimer = setTimeout(makeCode, 20); + } + + // Generate initial QR code with default URL since input is empty makeCode(); + // Focus the input field after page loads + document.getElementById("text").focus(); + $("#text"). + on("input", function () { + debouncedMakeCode(); + }). on("blur", function () { makeCode(); }).