Last active
August 22, 2019 21:13
-
-
Save dscho/25479c59fb01e64db97097173d51b130 to your computer and use it in GitHub Desktop.
Add QR to https://instant.io/
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
// ==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