mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
this fixes https://github.com/gorhill/uBlock/issues/63
This commit is contained in:
parent
d5465d3159
commit
2ecc81e35b
2 changed files with 51 additions and 21 deletions
|
|
@ -974,16 +974,19 @@ var getLocalData = function(callback) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var backupUserData = function(callback) {
|
var backupUserData = function(callback) {
|
||||||
var onUserFiltersReady = function(details) {
|
var userData = {
|
||||||
var userData = {
|
timeStamp: Date.now(),
|
||||||
timeStamp: Date.now(),
|
version: vAPI.app.version,
|
||||||
version: vAPI.app.version,
|
userSettings: µb.userSettings,
|
||||||
userSettings: µb.userSettings,
|
filterLists: {},
|
||||||
filterLists: µb.extractSelectedFilterLists(),
|
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
||||||
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
dynamicFilteringString: µb.permanentFirewall.toString(),
|
||||||
dynamicFilteringString: µb.permanentFirewall.toString(),
|
userFilters: ''
|
||||||
userFilters: details.content
|
};
|
||||||
};
|
|
||||||
|
var onSelectedListsReady = function(filterLists) {
|
||||||
|
userData.filterLists = filterLists;
|
||||||
|
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var filename = vAPI.i18n('aboutBackupFilename')
|
var filename = vAPI.i18n('aboutBackupFilename')
|
||||||
.replace('{{datetime}}', now.toLocaleString())
|
.replace('{{datetime}}', now.toLocaleString())
|
||||||
|
|
@ -1001,6 +1004,12 @@ var backupUserData = function(callback) {
|
||||||
getLocalData(callback);
|
getLocalData(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var onUserFiltersReady = function(details) {
|
||||||
|
userData.userFilters = details.content;
|
||||||
|
µb.extractSelectedFilterLists(onSelectedListsReady);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
µb.assets.get('assets/user/filters.txt', onUserFiltersReady);
|
µb.assets.get('assets/user/filters.txt', onUserFiltersReady);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1050,7 +1059,7 @@ var restoreUserData = function(request) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var resetUserData = function() {
|
var resetUserData = function() {
|
||||||
vAPI.storage.clear(onAllRemoved);
|
vAPI.storage.clear();
|
||||||
|
|
||||||
// Keep global counts, people can become quite attached to numbers
|
// Keep global counts, people can become quite attached to numbers
|
||||||
µb.saveLocalSettings(true);
|
µb.saveLocalSettings(true);
|
||||||
|
|
|
||||||
|
|
@ -102,19 +102,40 @@
|
||||||
// This will remove all unused filter list entries from
|
// This will remove all unused filter list entries from
|
||||||
// µBlock.remoteBlacklists`. This helps reduce the size of backup files.
|
// µBlock.remoteBlacklists`. This helps reduce the size of backup files.
|
||||||
|
|
||||||
µBlock.extractSelectedFilterLists = function() {
|
µBlock.extractSelectedFilterLists = function(callback) {
|
||||||
var r = JSON.parse(JSON.stringify(this.remoteBlacklists));
|
var µb = this;
|
||||||
|
|
||||||
for ( var path in r ) {
|
var onBuiltinListsLoaded = function(details) {
|
||||||
if ( r.hasOwnProperty(path) === false ) {
|
var builtin;
|
||||||
continue;
|
try {
|
||||||
|
builtin = JSON.parse(details.content);
|
||||||
|
} catch (e) {
|
||||||
|
builtin = {};
|
||||||
}
|
}
|
||||||
if ( r[path].off !== false ) {
|
|
||||||
delete r[path];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
var result = JSON.parse(JSON.stringify(µb.remoteBlacklists));
|
||||||
|
var builtinPath;
|
||||||
|
var defaultState;
|
||||||
|
|
||||||
|
for ( var path in result ) {
|
||||||
|
if ( result.hasOwnProperty(path) === false ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
builtinPath = path.replace(/^assets\/thirdparties\//, '');
|
||||||
|
defaultState = builtin.hasOwnProperty(builtinPath) === false ||
|
||||||
|
builtin[builtinPath].off === true;
|
||||||
|
if ( result[path].off === true && result[path].off === defaultState ) {
|
||||||
|
delete result[path];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/63
|
||||||
|
// Get built-in block lists: this will help us determine whether a
|
||||||
|
// specific list must be included in the result.
|
||||||
|
this.assets.get('assets/ublock/filter-lists.json', onBuiltinListsLoaded);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue