Skip to content

Instantly share code, notes, and snippets.

@dscho
Last active August 22, 2019 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscho/25479c59fb01e64db97097173d51b130 to your computer and use it in GitHub Desktop.
Save dscho/25479c59fb01e64db97097173d51b130 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Add QR to instant.io
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Adds a QR code ready for scanning next to the URL once a file is seeded.
// @source https://gist.github.com/dscho/25479c59fb01e64db97097173d51b130
// @updateURL https://gist.github.com/dscho/25479c59fb01e64db97097173d51b130/raw/qr-for-instant.io.user.js
// @downloadURL https://gist.github.com/dscho/25479c59fb01e64db97097173d51b130/raw/qr-for-instant.io.user.js
// @author dscho
// @match https://instant.io/
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js
// ==/UserScript==
(function() {
'use strict';
const makeQR = (e) => {
if (e.hasQR)
return;
e.hasQR = true;
const div = document.createElement('div');
e.parentElement.insertBefore(div, e);
var qr = new QRious({element: div, value: e.href});
e.parentElement.insertBefore(qr.image, e);
};
const selector = 'a[href^="/#"]';
const els = document.querySelectorAll(selector);
Array.prototype.map.call(els, (e) => {
makeQR(e);
});
const observe = (events, observer) => {
events.map((event) => {
if (event.type === 'childList') {
Array.prototype.map.call(event.target.querySelectorAll(selector), (e) => {
makeQR(e);
});
}
});
};
new MutationObserver(observe).observe(document, { attributes: true, childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment