Minor code review

This commit is contained in:
Raymond Hill 2023-05-14 10:05:42 -04:00
parent 7bc06fec8c
commit 0b63a4c281
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 12 additions and 11 deletions

View File

@ -181,10 +181,14 @@ async function renderUserFilters(merge = false) {
/******************************************************************************/
function handleImportFilePicker() {
const fileReaderOnLoadHandler = function() {
let content = this.result;
content = uBlockDashboard.mergeNewLines(getEditorText(), content);
function handleImportFilePicker(ev) {
const file = ev.target.files[0];
if ( file === undefined || file.name === '' ) { return; }
if ( file.type.indexOf('text') !== 0 ) { return; }
const fr = new FileReader();
fr.onload = function() {
if ( typeof fr.result !== 'string' ) { return; }
const content = uBlockDashboard.mergeNewLines(getEditorText(), fr.result);
cmEditor.operation(( ) => {
const cmPos = cmEditor.getCursor();
setEditorText(content);
@ -192,14 +196,11 @@ function handleImportFilePicker() {
cmEditor.focus();
});
};
const file = this.files[0];
if ( file === undefined || file.name === '' ) { return; }
if ( file.type.indexOf('text') !== 0 ) { return; }
const fr = new FileReader();
fr.onload = fileReaderOnLoadHandler;
fr.readAsText(file);
}
dom.on('#importFilePicker', 'change', handleImportFilePicker);
function startImportFilePicker() {
const input = qs$('#importFilePicker');
// Reset to empty string, this will ensure an change event is properly
@ -209,6 +210,8 @@ function startImportFilePicker() {
input.click();
}
dom.on('#importUserFiltersFromFile', 'click', startImportFilePicker);
/******************************************************************************/
function exportUserFiltersToFile() {
@ -269,8 +272,6 @@ self.hasUnsavedData = function() {
/******************************************************************************/
// Handle user interaction
dom.on('#importUserFiltersFromFile', 'click', startImportFilePicker);
dom.on('#importFilePicker', 'change', handleImportFilePicker);
dom.on('#exportUserFiltersToFile', 'click', exportUserFiltersToFile);
dom.on('#userFiltersApply', 'click', ( ) => { applyChanges(); });
dom.on('#userFiltersRevert', 'click', revertChanges);