Skip to content

Instantly share code, notes, and snippets.

@brunogama
Forked from lemieuxster/Bookmarkified
Created April 3, 2018 15:56
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 brunogama/fa80584d0fff2cdad84b9098205101e6 to your computer and use it in GitHub Desktop.
Save brunogama/fa80584d0fff2cdad84b9098205101e6 to your computer and use it in GitHub Desktop.
QR Code Bookmarklet
javascript:(function(window, document, undefined) {try {var selectedText = document.getSelection().toString(); if (selectedText === ''){selectedText = window.location.href;} if(selectedText !== ''){var baseQRUrl = 'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + encodeURIComponent(selectedText); window.open(baseQRUrl, '_blank', 'width=400,height=400');}} catch (e) {}})(window, document);
//Opens a window with a QR code for either selected text on the page or the current page URL if no text is selected.
//Bookmarklet-ify it by removing whitespace and prepending javascript:
//Like so: javascript:(function ....)()
(function(window, document, undefined) {
try {
var selectedText = document.getSelection().toString();
if (selectedText === '') {
selectedText = window.location.href;
}
if (selectedText !== '') {
var baseQRUrl = 'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + encodeURIComponent(selectedText);
window.open(baseQRUrl, '_blank', 'width=400,height=400');
}
} catch (e) {
}
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment