mirror of https://github.com/gorhill/uBlock.git
Minor code review
This commit is contained in:
parent
7bc06fec8c
commit
0b63a4c281
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue