Skip to content

Instantly share code, notes, and snippets.

@9kopb
Forked from takumakei/qrcode.js
Created September 12, 2016 18:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9kopb/d879d4a6c59e4f44c939e26f03003df6 to your computer and use it in GitHub Desktop.
Save 9kopb/d879d4a6c59e4f44c939e26f03003df6 to your computer and use it in GitHub Desktop.
qrcode.js for the bookmarklet
// bookmarklet: qrcode
//
// javascript:void((function(d){var s=BOOKMARKLETSCRIPT=d.createElement('script');s.type='text/javascript';s.src='https://raw.github.com/gist/1266971/b5e0748c51dd0ffdf4a1abb00d14409a8220b7c2/qrcode.js';d.getElementsByTagName('head')[0].appendChild(s);})(document));
//
try {
(function(d){
var body = d.getElementsByTagName('body')[0];
var add = function(args) {
var target = args.target || body;
var elem = d.createElement(args.tag || 'div');
var style = args.style || {}, id;
for (id in style) {
elem.style[id] = style[id];
}
target.appendChild(elem);
args.init && args.init(elem);
return elem;
};
add({ style: {
position: 'fixed',
left: '0px',
top: '0px',
width: '100%',
height: '100%',
zIndex: '9999'
},
init: function(backpanel) {
backpanel.onclick = function(event) {
backpanel.parentNode.removeChild(backpanel);
};
add({ target: backpanel,
style: {
position: 'fixed',
left: '0px',
top: '0px',
width: '100%',
height: '100%',
'filter': 'alpha(opacity=50)',
'-moz-opacity': '0.5,',
opacity: '0.5',
backgroundColor: '#000'
}
});
var w = 300, h = 300;
var l = (backpanel.clientWidth - w) / 2;
var t = (backpanel.clientHeight - h) / 2;
add({ target: backpanel,
style: {
position: 'fixed',
left: l + 'px',
top: t + 'px',
width: w + 'px',
height: h + 'px',
backgroundColor: '#fff'
},
init: function(div) {
add({ target: div,
tag: 'img',
style: {
width: '100%',
height: '100%'
},
init: function(img) {
img.src = 'http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl='+encodeURIComponent(window.location.href);
}
});
add({ target: div,
style: {
color: '#fff',
'text-align': 'right',
'font-size': '75%'
},
init: function(ver) {
ver.innerHTML = 'bookmarklet:qrcode v0.0.5';
}
});
}
});
}
});
})(document);
} finally {
if (typeof BOOKMARKLETSCRIPT !== 'undefined') {
BOOKMARKLETSCRIPT.parentNode.removeChild(BOOKMARKLETSCRIPT);
delete BOOKMARKLETSCRIPT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment