mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 01:28:00 +01:00
this fixes #63
This commit is contained in:
parent
c6cb4345f2
commit
544e1215dd
2 changed files with 50 additions and 21 deletions
|
@ -1086,17 +1086,20 @@ var getLocalData = function(callback) {
|
|||
/******************************************************************************/
|
||||
|
||||
var backupUserData = function(callback) {
|
||||
var onUserFiltersReady = function(details) {
|
||||
var userData = {
|
||||
timeStamp: Date.now(),
|
||||
version: vAPI.app.version,
|
||||
userSettings: µb.userSettings,
|
||||
filterLists: µb.extractSelectedFilterLists(),
|
||||
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
||||
dynamicFilteringString: µb.permanentFirewall.toString(),
|
||||
hostnameSwitchesString: µb.hnSwitches.toString(),
|
||||
userFilters: details.content
|
||||
};
|
||||
var userData = {
|
||||
timeStamp: Date.now(),
|
||||
version: vAPI.app.version,
|
||||
userSettings: µb.userSettings,
|
||||
filterLists: {},
|
||||
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
||||
dynamicFilteringString: µb.permanentFirewall.toString(),
|
||||
hostnameSwitchesString: µb.hnSwitches.toString(),
|
||||
userFilters: ''
|
||||
};
|
||||
|
||||
var onSelectedListsReady = function(filterLists) {
|
||||
userData.filterLists = filterLists;
|
||||
|
||||
var now = new Date();
|
||||
var filename = vAPI.i18n('aboutBackupFilename')
|
||||
.replace('{{datetime}}', now.toLocaleString())
|
||||
|
@ -1114,6 +1117,11 @@ var backupUserData = function(callback) {
|
|||
getLocalData(callback);
|
||||
};
|
||||
|
||||
var onUserFiltersReady = function(details) {
|
||||
userData.userFilters = details.content;
|
||||
µb.extractSelectedFilterLists(onSelectedListsReady);
|
||||
};
|
||||
|
||||
µb.assets.get('assets/user/filters.txt', onUserFiltersReady);
|
||||
};
|
||||
|
||||
|
|
|
@ -102,19 +102,40 @@
|
|||
// This will remove all unused filter list entries from
|
||||
// µBlock.remoteBlacklists`. This helps reduce the size of backup files.
|
||||
|
||||
µBlock.extractSelectedFilterLists = function() {
|
||||
var r = JSON.parse(JSON.stringify(this.remoteBlacklists));
|
||||
µBlock.extractSelectedFilterLists = function(callback) {
|
||||
var µb = this;
|
||||
|
||||
for ( var path in r ) {
|
||||
if ( r.hasOwnProperty(path) === false ) {
|
||||
continue;
|
||||
var onBuiltinListsLoaded = function(details) {
|
||||
var builtin;
|
||||
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