Skip to content

Instantly share code, notes, and snippets.

@git2358
Forked from sv-in/bookmarklet.url
Last active November 1, 2018 05:51
Show Gist options
  • Select an option

  • Save git2358/ebc54e137a321c2c42491293dc198cc3 to your computer and use it in GitHub Desktop.

Select an option

Save git2358/ebc54e137a321c2c42491293dc198cc3 to your computer and use it in GitHub Desktop.
JS: Bookmarklet for displaying QR code of current URL (good for presentations)
javascript:void !function(max,sizes,index,image,size,style){while(index--&&(size=sizes[index])>max);style=image.style,style.position="fixed",style.zIndex=-1>>>1,style.top=style.left="50%",style.marginTop=style.marginLeft=size/-2+"px",style.imageRendering="pixelated",style.mixBlendMode="overlay",image.setAttribute("id","imageQR"),image.setAttribute("onclick","returnfalse;"),image.setAttribute("onmousedown","imageQR.remove()"),image.src="https://chart.apis.google.com/chart?cht=qr&chld=H|0&chs="+size+"x"+size+"&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
style.imageRendering="pixelated",
style.mixBlendMode="overlay",
image.setAttribute("id", "imageQR"), // give QR code an ID tag
image.setAttribute("onclick", "return false;"), // prevent default click
image.setAttribute("onmousedown", "imageQR.remove()"), // uppon click, remove the QR code
image.src="https://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