mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-03 01:29:39 +02:00
ensure no lost "change" events (#307)
This commit is contained in:
parent
e9ed073e42
commit
9e88d0f60d
@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
<div style="margin:1em 0 0 0;">
|
<div style="margin:1em 0 0 0;">
|
||||||
<p><button type="button" id="export" data-i18n="aboutBackupDataButton"></button>
|
<p><button type="button" id="export" data-i18n="aboutBackupDataButton"></button>
|
||||||
<button type="button" id="import" data-i18n="aboutRestoreDataButton"></button>
|
<button type="button" id="import" data-i18n="aboutRestoreDataButton"></button>
|
||||||
|
<input id="restoreFilePicker" type="file" accept="text/plain" style="display:none;">
|
||||||
<p>
|
<p>
|
||||||
<p><button type="button" id="reset" data-i18n="aboutResetDataButton">Start from scratch...</button>
|
<p><button type="button" id="reset" data-i18n="aboutResetDataButton">Start from scratch...</button>
|
||||||
</div>
|
</div>
|
||||||
|
42
js/about.js
42
js/about.js
@ -45,11 +45,7 @@ var exportToFile = function() {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var importFromFile = function() {
|
var handleImportFilePicker = function() {
|
||||||
var input = document.createElement('input');
|
|
||||||
input.setAttribute('type', 'file');
|
|
||||||
input.setAttribute('accept', 'text/plain');
|
|
||||||
|
|
||||||
var fileReaderOnLoadHandler = function() {
|
var fileReaderOnLoadHandler = function() {
|
||||||
var userData;
|
var userData;
|
||||||
try {
|
try {
|
||||||
@ -70,21 +66,26 @@ var importFromFile = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var filePickerOnChangeHandler = function() {
|
var file = this.files[0];
|
||||||
input.removeEventListener('change', filePickerOnChangeHandler);
|
if ( file === undefined || file.name === '' ) {
|
||||||
var file = this.files[0];
|
return;
|
||||||
if ( !file ) {
|
}
|
||||||
return;
|
if ( file.type.indexOf('text') !== 0 ) {
|
||||||
}
|
return;
|
||||||
if ( file.type.indexOf('text') !== 0 ) {
|
}
|
||||||
return;
|
var fr = new FileReader();
|
||||||
}
|
fr.onload = fileReaderOnLoadHandler;
|
||||||
var fr = new FileReader();
|
fr.readAsText(file);
|
||||||
fr.onload = fileReaderOnLoadHandler;
|
};
|
||||||
fr.readAsText(file);
|
|
||||||
};
|
|
||||||
|
|
||||||
input.addEventListener('change', filePickerOnChangeHandler);
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var startImportFilePicker = function() {
|
||||||
|
var input = document.getElementById('restoreFilePicker');
|
||||||
|
// Reset to empty string, this will ensure an change event is properly
|
||||||
|
// triggered if the user pick a file, even if it is the same as the last
|
||||||
|
// one picked.
|
||||||
|
input.value = '';
|
||||||
input.click();
|
input.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,8 +103,9 @@ var resetUserData = function() {
|
|||||||
|
|
||||||
uDom('#aboutVersion').html(chrome.runtime.getManifest().version);
|
uDom('#aboutVersion').html(chrome.runtime.getManifest().version);
|
||||||
uDom('#export').on('click', exportToFile);
|
uDom('#export').on('click', exportToFile);
|
||||||
uDom('#import').on('click', importFromFile);
|
uDom('#import').on('click', startImportFilePicker);
|
||||||
uDom('#reset').on('click', resetUserData);
|
uDom('#reset').on('click', resetUserData);
|
||||||
|
uDom('#restoreFilePicker').on('change', handleImportFilePicker);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user