this addresses #531

This commit is contained in:
gorhill 2015-07-27 10:10:34 -04:00
parent 8dd21c5f49
commit 2509bceaff
2 changed files with 77 additions and 0 deletions

View File

@ -240,6 +240,9 @@ var fromFetch = function(to, fetched) {
/******************************************************************************/
return function() {
// https://github.com/gorhill/uBlock/issues/531
µb.restoreAdminSettings();
// Forbid remote fetching of assets
µb.assets.remoteFetchBarrier += 1;

View File

@ -719,6 +719,80 @@
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/531
// Overwrite user settings with admin settings if present.
//
// Admin settings match layout of a uBlock backup. Not all data is
// necessarily present, i.e. administrators may removed entries which
// values are left to the user's choice.
µBlock.restoreAdminSettings = function() {
var data = null;
var json = vAPI.localStorage.getItem('adminSettings');
if ( typeof json === 'string' && json !== '' ) {
try {
data = JSON.parse(json);
} catch (ex) {
console.error(ex);
}
}
if ( typeof data !== 'object' || data === null ) {
return;
}
var bin = {};
var binNotEmpty = false;
if ( typeof data.userSettings === 'object' ) {
for ( var name in this.userSettings ) {
if ( this.userSettings.hasOwnProperty(name) === false ) {
continue;
}
if ( data.userSettings.hasOwnProperty(name) === false ) {
continue;
}
bin[name] = data.userSettings[name];
binNotEmpty = true;
}
}
if ( typeof data.filterLists === 'object' ) {
bin.remoteBlacklists = data.filterLists;
binNotEmpty = true;
}
if ( typeof data.netWhitelist === 'string' ) {
bin.netWhitelist = data.netWhitelist;
binNotEmpty = true;
}
if ( typeof data.dynamicFilteringString === 'string' ) {
bin.dynamicFilteringString = data.dynamicFilteringString;
binNotEmpty = true;
}
if ( typeof data.urlFilteringString === 'string' ) {
bin.urlFilteringString = data.urlFilteringString;
binNotEmpty = true;
}
if ( typeof data.hostnameSwitchesString === 'string' ) {
bin.hostnameSwitchesString = data.hostnameSwitchesString;
binNotEmpty = true;
}
if ( binNotEmpty ) {
vAPI.storage.set(bin);
}
if ( typeof data.userFilters === 'string' ) {
this.assets.put('assets/user/filters.txt', data.userFilters);
}
};
/******************************************************************************/
µBlock.updateStartHandler = function(callback) {
var µb = this;
var onListsReady = function(lists) {