From 53d96cc88f13c9009f0ef6651141270e4e1ef879 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 30 Mar 2015 08:12:41 -0400 Subject: [PATCH] do not include unused entries in backup --- src/js/messaging.js | 2 +- src/js/storage.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index 05b9ce9ea..98fd3534c 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -980,7 +980,7 @@ var backupUserData = function(callback) { timeStamp: Date.now(), version: vAPI.app.version, userSettings: µb.userSettings, - filterLists: µb.remoteBlacklists, + filterLists: µb.extractSelectedFilterLists(), netWhitelist: µb.stringFromWhitelist(µb.netWhitelist), dynamicFilteringString: µb.permanentFirewall.toString(), hostnameSwitchesString: µb.hnSwitches.toString(), diff --git a/src/js/storage.js b/src/js/storage.js index 8854fe9a0..66ec14390 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -91,6 +91,26 @@ /******************************************************************************/ +// 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)); + + for ( var path in r ) { + if ( r.hasOwnProperty(path) === false ) { + continue; + } + if ( r[path].off !== false ) { + delete r[path]; + } + } + + return r; +}; + +/******************************************************************************/ + µBlock.saveUserFilters = function(content, callback) { return this.assets.put(this.userFiltersPath, content, callback); };