Skip to content

Commit

Permalink
this addresses #531
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 27, 2015
1 parent 8dd21c5 commit 2509bce
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
74 changes: 74 additions & 0 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2509bce

Please sign in to comment.