Skip to content

Commit

Permalink
Fix: Copy the string to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Burgmaier committed Jan 29, 2024
1 parent 5efe7f7 commit 36dd239
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,26 +242,36 @@ selectTag.onchange = function (ev) {

// register context menu function
document.getElementById('btnCopyHex').onclick = function (event) {
let contextMenu = document.getElementById('contextmenu');
let contextMenu = document.getElementById('contextmenu');
let node = contextMenu.node;
const pos = parseInt(node.getAttribute('pos'));
const end = parseInt(node.getAttribute('end'));
const hex = node.asn1.buf2hex(window.derBuffer.subarray(pos, end));
navigator.clipboard.writeText(hex);
contextMenu.style.visibility = 'hidden';
event.stopPropagation();
};
};

document.getElementById('btnCopyString').onclick = function (event) {
let contextMenu = document.getElementById('contextmenu');
let contextMenu = document.getElementById('contextmenu');
let node = contextMenu.node;
const pos = parseInt(node.getAttribute('pos'));
const end = parseInt(node.getAttribute('end'));
// const hex = node.asn1.buf2hex(window.derBuffer.subarray(pos, end));
let result = ASN1.decode(window.derBuffer.subarray(pos, end));
// navigator.clipboard.writeText(hex);
let type = result.typeName();
switch (type) {
case 'UTF8String':
case 'PrintableString':
case 'TeletexString':
case 'VideotexString':
case 'IA5String':
case 'UniversalString':
navigator.clipboard.writeText(result.content());
break;
default: alert('Selected value is not a String!');
}
contextMenu.style.visibility = 'hidden';
event.stopPropagation();
};
};

});

0 comments on commit 36dd239

Please sign in to comment.