-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtryout.html
189 lines (163 loc) · 5.9 KB
/
tryout.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="A place to try out your QR codes to make sure they work as intended" />
<title>Say Cheese: Tryout</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="stylesheet" href="nav.css">
<link rel="stylesheet" href="global.css">
<style>
main {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding-top: 2rem;
display: flex;
flex-direction: column;
align-items: center;
}
#about,
#upload-text {
text-align: center;
}
#file-upload {
height: 100px;
width: 30%;
margin: 2em;
border: 2px dashed black;
border-radius: .5em;
}
#folder-icon {
height: 50%;
width: 50%;
fill: black;
}
#file-label {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
cursor: pointer;
}
#file-label p {
font-size: .85em;
}
#qr {
height: 100%;
}
#qr-wrapper {
height: 50%;
aspect-ratio: 1;
display: flex;
align-items: center;
flex-direction: column;
color: black;
text-decoration: none;
}
#qr-wrapper[data-empty="false"] {
cursor: pointer;
}
#qr-wrapper h1 {
font-size: 1.5em;
margin: 0;
}
#qr-wrapper[data-empty="true"] h1 {
display: none;
}
#qr-wrapper[data-empty="true"] ~ #copy-option {
display: none;
}
#copy-option {
margin-top: 2em;
display: flex;
flex-direction: column;
align-items: center;
}
#copy-option button {
padding: .5em 1em;
font-size: 1em;
background-color: black;
color: white;
border: none;
cursor: pointer;
}
</style>
<script>
var uri = ""
function handleUpload(input) {
const formData = new FormData()
formData.append("file", input.files[0])
fetch("https://api.qrserver.com/v1/read-qr-code/", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
if (data[0].symbol[0].error) {
alert("Invalid QR code")
} else {
document.getElementById("qr").src = URL.createObjectURL(input.files[0])
const qrData = data[0].symbol[0].data
const qrWrapper = document.getElementById("qr-wrapper")
qrWrapper.setAttribute("data-empty", "false")
qrWrapper.href = qrData
uri = qrData
}
})
.catch(error => {
console.error("Error:", error)
})
}
function copy() {
if (uri) {
navigator.clipboard.writeText(uri)
alert("Copied to clipboard!")
} else {
alert("No QR code to copy!")
}
}
</script>
</head>
<body>
<header>
<div class="navbar">
<a class="navbar-link" href="/index.html">home</a>
<a class="navbar-link" href="/gallery.html">gallery</a>
<a class="navbar-link" href="/tutorial.html">tutorial-ish</a>
</div>
<div class="links">
<a href="https://github.com/commonkestrel/saycheese" target="_blank">
<img src="./static/github-mark.svg" alt="github logo">
</a>
</div>
</header>
<main>
<h1>try out</h1>
<small id="about">try out your QR code to make sure it works! (real programmers DON'T test in prod)</small>
<div id="file-upload">
<label for="file" id="file-label">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"
id="folder-icon">
<path d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"></path>
</svg>
<p id="upload-text">upload your QR code here</p>
</label>
</div>
<input type="file" id="file" accept="image/*" style="display: none;" onchange="handleUpload(this)">
<a id="qr-wrapper" data-empty="true">
<h1>click me!</h1>
<img src="#" alt="your QR code" id="qr" />
</a>
<div id="copy-option">
<button onclick="copy()">...or copy and paste into a new tab in your browser</button>
<small>(do this if your project is a webpage)</small>
</div>
</main>
</body>
</html>