1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

Support restoring from application/json file

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2853
This commit is contained in:
Raymond Hill 2023-10-10 10:16:55 -04:00
parent 0a18f75897
commit 437453233d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -30,11 +30,23 @@ import { setAccentColor, setTheme } from './theme.js';
const handleImportFilePicker = function() {
const file = this.files[0];
if ( file === undefined || file.name === '' ) { return; }
if ( file.type.indexOf('text') !== 0 ) { return; }
const reportError = ( ) => {
window.alert(i18n$('aboutRestoreDataError'));
};
const expectedFileTypes = [
'text/plain',
'application/json',
];
if ( expectedFileTypes.includes(file.type) === false ) {
return reportError();
}
const filename = file.name;
const fr = new FileReader();
const fileReaderOnLoadHandler = function() {
fr.onload = function() {
let userData;
try {
userData = JSON.parse(this.result);
@ -61,8 +73,7 @@ const handleImportFilePicker = function() {
userData = undefined;
}
if ( userData === undefined ) {
window.alert(i18n$('aboutRestoreDataError'));
return;
return reportError();
}
const time = new Date(userData.timeStamp);
const msg = i18n$('aboutRestoreDataConfirm')
@ -76,8 +87,6 @@ const handleImportFilePicker = function() {
});
};
const fr = new FileReader();
fr.onload = fileReaderOnLoadHandler;
fr.readAsText(file);
};