From 3443f2700c4aa25d9cfb79ab650036997f51a3cf Mon Sep 17 00:00:00 2001 From: Sascha Englert Date: Fri, 29 Aug 2025 23:18:45 +0200 Subject: [PATCH] Add download button for qr code --- i18n.json | 11 +++++++++++ index.html.pre | 3 +++ js/index.js | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/i18n.json b/i18n.json index 589422e..95c241c 100644 --- a/i18n.json +++ b/i18n.json @@ -10,6 +10,17 @@ "pl": "🇵🇱", "tr": "🇹🇷" }, + "download": { + "de": "Herunterladen", + "ch": "Herunterladen", + "en": "Download", + "es": "Descargar", + "fr": "Télécharger", + "gr": "Λήψη", + "it": "Scaricare", + "pl": "Pobierz", + "tr": "İndir" + }, "subtitle": { "de": "Geld überweisen ohne Drittanbieter", "ch": "Gäld überwise ohni Drittparteiä", diff --git a/index.html.pre b/index.html.pre index f90586b..ff67e38 100644 --- a/index.html.pre +++ b/index.html.pre @@ -56,6 +56,9 @@ input[type=number] { -moz-appearance: textfield; } + div#qr-code { + width: fit-content; + } div#qr-code canvas { max-width: 100%; } diff --git a/js/index.js b/js/index.js index 9f92b2c..6eaa91a 100644 --- a/js/index.js +++ b/js/index.js @@ -264,6 +264,27 @@ ${document.querySelector("#purpose input").value} if (document.querySelector("#rememberme").checked) { saveFormData(); } + + // download link + let canvas = document.querySelector("#qr-code canvas") + if (!canvas) { + console.error("Unable to access canvas"); + } else { + canvas.toBlob((blob) => { + let link = document.createElement("a"); + link.className = "button is-fullwidth"; + link.href = URL.createObjectURL(blob); + link.download = "qr-code.png"; + link.innerText = i18n["download"][document.documentElement.lang]; + + let downloadLocation = document.querySelector("#qr-code"); + if (!downloadLocation) { + console.log("Unable to access link container"); + } else { + downloadLocation.appendChild(link); + } + }); + } } }