Last active
December 14, 2015 14:18
-
-
Save findel/5099737 to your computer and use it in GitHub Desktop.
Bookmarklets to give you a QR code for selected HTML or text. Copy each to a bookmark.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: | |
var html = ""; | |
if (typeof window.getSelection != "undefined") { | |
var sel = window.getSelection(); | |
if (sel.rangeCount) { | |
var container = document.createElement("div"); | |
for (var i = 0, len = sel.rangeCount; i < len; ++i) { | |
container.appendChild(sel.getRangeAt(i).cloneContents()); | |
} | |
html = container.innerHTML; | |
} | |
} else if (typeof document.selection != "undefined") { | |
if (document.selection.type == "Text") { | |
html = document.selection.createRange().htmlText; | |
} | |
} | |
window.open('http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + html); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: | |
var selected = ""; | |
if (typeof window.getSelection != "undefined") { | |
selected = window.getSelection(); | |
} else if (typeof document.selection != "undefined") { | |
if (document.selection.type == "Text") { | |
selected = document.selection; | |
} | |
} | |
window.open('http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + selected); |
Added qr-my-text-selection.js for non-HTML selection.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit for the selection code: http://stackoverflow.com/questions/4652734/return-html-from-a-user-selection/4652824#4652824
But just noticed that it's also selecting HTML. Might not want that.