Files
PageSigner/ui/FileChooser.js
themighty1 bb1cd756cd feat: allow to preview notarization.
Often the user may want to see what the notarization result will look like without
spending time on the 2PC protocol. This adds a "Preview" menu item to allow to do that.
2022-03-08 16:30:30 +03:00

34 lines
1.0 KiB
JavaScript

/* global chrome*/
// class FileChooser create a "choose file" button and sends the chosen file
// to the extension
export class FileChooser{
// show is called by extension's Main.openFileChooser()
show(){
const label = document.getElementById('import_label');
label.style.display = '';
const that = this;
document.getElementById('import').addEventListener('change', function(evt) {
const f = evt.target.files[0];
if (f) {
const reader = new FileReader();
reader.onload = that.onload;
reader.readAsArrayBuffer(f);
}
});
}
onload(e) {
const loader = document.getElementById('loader');
loader.classList.toggle('m-fadeIn');
loader.removeAttribute('hidden');
const import_label = document.getElementById('import_label');
import_label.classList.toggle('m-fadeOut');
chrome.runtime.sendMessage({
destination: 'extension',
message: 'import',
data: Array.from(new Uint8Array(e.target.result))
});
// don't close the window, we reuse it to display html
}
}