Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
// fetch("https://api.val.town/v1/express/galligan.generateQR?url={url}"
// QR Code Generator
// 1. Right click on the bookmarks bar and add new bookmark
// 2. Give it any name (Ex: QR Code)
// 3. For the URL, enter the below value
// javascript:void(open('https://api.val.town/v1/express/ramkarthik.generateQR?url='+encodeURIComponent(location.href), 'Open this URL', 'width=200,height=275'))
// 4. Save the bookmark
// 5. When you are on any page, click the newly added bookmark
// It should generate a QR code that you can scan and open on your mobile
export async function generateQR(req, res) {
const url = req.query.url;
res.set("Content-Type", "text/html");
if (!url) {
res.send(
"<html><body>Not a valid URL - " + JSON.stringify(req.query) +
"</body></html>",
);
}
const { qrcode } = await import("https://deno.land/x/qrcode/mod.ts");
const base64Image = await qrcode(url);
res.send(
`<html><body><img src=${base64Image} height="100px" width="100px" /><p style="font-size:10px">QR Code generated using <a href="https://val.town">val.town</a></p><p style="font-size:10px">Built with &#128151; by <a href="https://twitter.com/Ramkarthik">
);
}
// Forked from @ramkarthik.GenerateQR
October 23, 2023