Improve QR, add QR for fingerprint

This commit is contained in:
Yarmo Mackenbach 2021-05-03 12:06:37 +02:00
parent 08ca4d5d25
commit 484b2cb95e
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 21 additions and 3 deletions

View file

@ -146,7 +146,7 @@ class Claim extends HTMLElement {
const button_profileQR = subsection_qr_text.appendChild(document.createElement('button'));
button_profileQR.innerText = `Show profile QR`;
button_profileQR.setAttribute('onClick', `showQR('${claim.matches[0].profile.qr}')`);
button_profileQR.setAttribute('onClick', `showQR('${claim.matches[0].profile.qr}', 'url')`);
}
elContent.appendChild(document.createElement('hr'));

View file

@ -66,6 +66,19 @@ class Key extends HTMLElement {
const profile_link = subsection1_text.appendChild(document.createElement('p'));
profile_link.innerHTML = `Key link: <a href="${data.key.uri}">${data.key.uri}</a>`;
elContent.appendChild(document.createElement('hr'));
// QR Code
const subsection_qr = elContent.appendChild(document.createElement('div'));
subsection_qr.setAttribute('class', 'subsection');
const subsection_qr_icon = subsection_qr.appendChild(document.createElement('img'));
subsection_qr_icon.setAttribute('src', '/static/img/qrcode.png');
const subsection_qr_text = subsection_qr.appendChild(document.createElement('div'));
const button_profileQR = subsection_qr_text.appendChild(document.createElement('button'));
button_profileQR.innerText = `Show OpenPGP fingerprint QR`;
button_profileQR.setAttribute('onClick', `showQR('${data.fingerprint}', 'fingerprint')`);
}
}

View file

@ -132,7 +132,7 @@ const fetchProfileKey = async function() {
}
// Enable QR modal
const showQR = function(input) {
const showQR = function(input, type) {
const qrTarget = document.getElementById('qr');
const qrContext = qrTarget.getContext('2d');
const qrOpts = {
@ -143,7 +143,12 @@ const showQR = function(input) {
};
if (input) {
input = decodeURIComponent(input);
if (type === 'url') {
input = decodeURIComponent(input);
}
if (type === 'fingerprint') {
input = `OPENPGP4FPR:${input.toUpperCase()}`
}
QRCode.toCanvas(qrTarget, input, qrOpts, function(error) {
if (error) {