Skip to content

Instantly share code, notes, and snippets.

@NReilingh
Forked from michitux/goQR.js
Created June 17, 2014 19:00
Show Gist options
  • Save NReilingh/9c2b74f89f02ef63a8c3 to your computer and use it in GitHub Desktop.
Save NReilingh/9c2b74f89f02ef63a8c3 to your computer and use it in GitHub Desktop.
/* This bookmarklet tries to find the first selected link and opens the QR code. When no link is selected the current URL is used. */
javascript:(function(){%20function%20openqr(url){window.open('http://api.qrserver.com/v1/create-qr-code/?data='+encodeURIComponent(url)+'&size=700x700&qzone=6');}%20var%20selected,dl,i;%20dl%20=%20document.links;%20if%20(window.getSelection%20&&%20window.getSelection().containsNode)%20{%20/*%20mozilla%20*/%20for(i=0;%20i<dl.length;%20++i)%20{%20if%20(window.getSelection().containsNode(dl[i],%20true))%20{%20selected%20=%20true;%20openqr(dl[i].href);%20break;%20}%20}%20}%20if%20(!selected)%20{%20/*ie,%20or%20mozilla%20with%20no%20links%20selected%20*/%20openqr(document.URL);%20}%20})();
/* This bookmarklet uses the current URL. On some pages the above bookmarklet doesn't work/always uses an unwanted URL. If you experience this issue or don't need selected links try this one. */
javascript:(function(){window.open('http://api.qrserver.com/v1/create-qr-code/?data='+encodeURIComponent(document.URL)+'&size=700x700&qzone=6');})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment