Skip to content

Instantly share code, notes, and snippets.

@sv-in
Forked from furf/bookmarklet.url
Created October 16, 2012 10:13
Show Gist options
  • Save sv-in/3898488 to your computer and use it in GitHub Desktop.
Save sv-in/3898488 to your computer and use it in GitHub Desktop.
JS: Bookmarklet for displaying QR code of current URL (good for presentations)
javascript:void !function(e,t,n,r,i,s){while(n--&&(i=t[n])>e);s=r.style,s.position="fixed",s.zIndex=-1>>>1,s.top=s.left="50%",s.marginTop=s.marginLeft=i/-2+"px",r.src="http://chart.apis.google.com/chart?cht=qr&chld=H|0&chs="+i+"x"+i+"&chl="+escape(location)}(Math.min(top.innerHeight,top.innerWidth),[100,150,200,250,300,350,400,500],8,document.body.appendChild(new Image))
void(
!function(max,sizes,index,image,size,style){
while(index--&&(size=sizes[index])>max); // choose largest QR code that will fit
style=image.style, style.position="fixed",
style.zIndex=-1>>>1, // ensure top z-index :)
style.top=style.left="50%", style.marginTop=style.marginLeft=size/-2+"px", // center image on viewport
image.src="http://chart.apis.google.com/chart?cht=qr&chld=H|0&chs="+size+"x"+size+"&chl="+escape(location) // load QR code via Google's Chart API
}(
Math.min(top.innerHeight,top.innerWidth), // max: maximum available viewing area
[100,150,200,250,300,350,400,500], // sizes: optional QR code sizes
8, // index: initial array pointer
document.body.appendChild(new Image) // image: append image to page
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment