Skip to content

Instantly share code, notes, and snippets.

@jgarber623
Last active January 31, 2024 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber623/b92ea2f7adf0965c2f28eaca6267362c to your computer and use it in GitHub Desktop.
Save jgarber623/b92ea2f7adf0965c2f28eaca6267362c to your computer and use it in GitHub Desktop.
A bookmarklet that generates a QR Code of the current page's URL and displays it in a <dialog> element (assuming a Content Security Policy doesn't prevent the script from running). Inspired by https://til.therealadam.com/2024/01/31/sneakerneting-urls-to.html.
<a href="javascript:(()=>{const script=document.createElement('script');script.type='module';script.append(document.createTextNode=`import QRCode from 'https://cdn.jsdelivr.net/npm/qrcode@1.5.3/+esm';const dialog=document.createElement('dialog');const img=document.createElement('img');img.src=await QRCode.toDataURL(location.href);dialog.append(img);document.body.append(dialog);dialog.showModal();`);document.body.append(script)})()">Generate QR Code</a>
(() => {
const script = document.createElement("script");
script.type = "module";
script.append(
document.createTextNode = `\
import QRCode from "https://cdn.jsdelivr.net/npm/qrcode@1.5.3/+esm";
const dialog = document.createElement("dialog");
const img = document.createElement("img");
img.src = await QRCode.toDataURL(location.href);
dialog.append(img);
document.body.append(dialog);
dialog.showModal();`
);
document.body.append(script);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment