-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (94 loc) · 4.32 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
clifford: '#da373d',
}
}
}
}
</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital@0;1&display=swap" rel="stylesheet">
<title>QRCode Generator</title>
<style>
* {
font-family: "Poppins", sans-serif;
}
#spinner {
display: none;
}
#alert{
display: none;
}
</style>
<script src="qrcode.js"></script>
</head>
<body>
<header class="bg-gray-500">
<div class="max-w-5xl m-auto">
<div class="text-xl font-bold text-white text-center p-4">QR Code Generator</div>
</div>
</header>
<main class="bg-gray-200 p-4 flex flex-col justify-center align-center">
<p class="text-center">Enter your URL below to generate a QR Code and download the image.</p>
<form action="" id="url" class="m-auto mt-4 w-full sm:w-1/2 md:w-1/3">
<input type="text" placeholder="Enter your URL" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" id="url_string" />
<div id="alert" class="w-full p-2 my-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400" role="alert">
<svg class="flex-shrink-0 inline w-4 h-4 mr-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
</svg>
<span class="font-medium">Enter a valid URL!</span>
</div>
<button class="mt-3 w-full text-white bg-gradient-to-r from-cyan-300 to-blue-500 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-cyan-300 dark:focus:ring-cyan-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2 block">Generate QR Code</button>
</form>
<div id="spinner" class="relative flex h-3 w-3 mx-auto my-6">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-sky-400 opacity-75"></span>
</div>
</main>
<div id="qrcode" class="mx-auto mt-4 mb-10 w-max"></div>
<footer class="z-40 bg-gray-700 text-center text-white text-lg w-full p-3 fixed bottom-0">© <span id="date"></span> - Thu Rein Soe</footer>
<script>
let qrcode = document.getElementById("qrcode");
let form = document.getElementById("url");
let date = document.getElementById('date');
let url_string = document.getElementById("url_string");
let spinner = document.getElementById("spinner");
let alertElement = document.getElementById("alert");
date.innerHTML = new Date().getFullYear();
const showSpinner = () => {
spinner.style.display = "flex";
}
const hideSpinner = () => {
spinner.style.display = "none";
}
const clearUI = () => {
qrcode.innerHTML = "";
}
form.addEventListener("submit", (e) => {
e.preventDefault();
if(url_string.value == "") {
alertElement.style.display = "block";
return;
}
alertElement.style.display = "none";
clearUI();
showSpinner();
setTimeout(()=> {
hideSpinner();
new QRCode(qrcode, {
text: url_string.value,
});
}, 1500)
})
</script>
</body>
</html>