1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

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

View File

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