mirror of https://github.com/gorhill/uBlock.git
this fixes #832
This commit is contained in:
parent
c036bd320f
commit
892913d185
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"adminSettings": {
|
||||
"title": "A valid JSON string compliant with uBO's backup format.",
|
||||
"description": "All entries present will overwrite local settings.",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -66,5 +66,8 @@
|
|||
"http://*/*",
|
||||
"https://*/*"
|
||||
],
|
||||
"short_name": "uBlock₀"
|
||||
"short_name": "uBlock₀",
|
||||
"storage": {
|
||||
"managed_schema": "managed_storage.json"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,19 @@ try {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/531
|
||||
// Storage area dedicated to admin settings. Read-only.
|
||||
|
||||
vAPI.adminStorage = {
|
||||
getItem: function(key, callback) {
|
||||
chrome.storage.managed.get(key, function(store) {
|
||||
callback(store[key] || undefined);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -181,6 +181,20 @@ vAPI.localStorage.init('extensions.' + location.host + '.');
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/531
|
||||
// Storage area dedicated to admin settings. Read-only.
|
||||
|
||||
vAPI.adminStorage = {
|
||||
getItem: function(key, callback) {
|
||||
if ( typeof callback !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
callback(vAPI.localStorage.getItem(key));
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -247,32 +247,35 @@ 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;
|
||||
var onAdminSettingsRestored = function() {
|
||||
// Forbid remote fetching of assets
|
||||
µb.assets.remoteFetchBarrier += 1;
|
||||
|
||||
var fetchableProps = {
|
||||
'compiledMagic': '',
|
||||
'dynamicFilteringString': '',
|
||||
'urlFilteringString': '',
|
||||
'hostnameSwitchesString': '',
|
||||
'lastRestoreFile': '',
|
||||
'lastRestoreTime': 0,
|
||||
'lastBackupFile': '',
|
||||
'lastBackupTime': 0,
|
||||
'netWhitelist': '',
|
||||
'selfie': null,
|
||||
'selfieMagic': '',
|
||||
'version': '0.0.0.0'
|
||||
var fetchableProps = {
|
||||
'compiledMagic': '',
|
||||
'dynamicFilteringString': '',
|
||||
'urlFilteringString': '',
|
||||
'hostnameSwitchesString': '',
|
||||
'lastRestoreFile': '',
|
||||
'lastRestoreTime': 0,
|
||||
'lastBackupFile': '',
|
||||
'lastBackupTime': 0,
|
||||
'netWhitelist': '',
|
||||
'selfie': null,
|
||||
'selfieMagic': '',
|
||||
'version': '0.0.0.0'
|
||||
};
|
||||
|
||||
toFetch(µb.localSettings, fetchableProps);
|
||||
toFetch(µb.userSettings, fetchableProps);
|
||||
toFetch(µb.restoreBackupSettings, fetchableProps);
|
||||
|
||||
vAPI.storage.get(fetchableProps, onFirstFetchReady);
|
||||
};
|
||||
|
||||
toFetch(µb.localSettings, fetchableProps);
|
||||
toFetch(µb.userSettings, fetchableProps);
|
||||
toFetch(µb.restoreBackupSettings, fetchableProps);
|
||||
|
||||
vAPI.storage.get(fetchableProps, onFirstFetchReady);
|
||||
// https://github.com/gorhill/uBlock/issues/531
|
||||
µb.restoreAdminSettings(onAdminSettingsRestored);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -725,69 +725,76 @@
|
|||
// 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);
|
||||
µBlock.restoreAdminSettings = function(callback) {
|
||||
var onRead = function(json) {
|
||||
var µb = µBlock;
|
||||
var data;
|
||||
if ( typeof json === 'string' && json !== '' ) {
|
||||
try {
|
||||
data = JSON.parse(json);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( typeof data !== 'object' || data === null ) {
|
||||
return;
|
||||
}
|
||||
if ( typeof data !== 'object' || data === null ) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var bin = {};
|
||||
var binNotEmpty = false;
|
||||
var bin = {};
|
||||
var binNotEmpty = false;
|
||||
|
||||
if ( typeof data.userSettings === 'object' ) {
|
||||
for ( var name in this.userSettings ) {
|
||||
if ( this.userSettings.hasOwnProperty(name) === false ) {
|
||||
continue;
|
||||
if ( typeof data.userSettings === 'object' ) {
|
||||
for ( var name in µb.userSettings ) {
|
||||
if ( µb.userSettings.hasOwnProperty(name) === false ) {
|
||||
continue;
|
||||
}
|
||||
if ( data.userSettings.hasOwnProperty(name) === false ) {
|
||||
continue;
|
||||
}
|
||||
bin[name] = data.userSettings[name];
|
||||
binNotEmpty = true;
|
||||
}
|
||||
if ( data.userSettings.hasOwnProperty(name) === false ) {
|
||||
continue;
|
||||
}
|
||||
bin[name] = data.userSettings[name];
|
||||
}
|
||||
|
||||
if ( typeof data.filterLists === 'object' ) {
|
||||
bin.remoteBlacklists = data.filterLists;
|
||||
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.netWhitelist === 'string' ) {
|
||||
bin.netWhitelist = data.netWhitelist;
|
||||
binNotEmpty = true;
|
||||
}
|
||||
if ( typeof data.dynamicFilteringString === 'string' ) {
|
||||
bin.dynamicFilteringString = data.dynamicFilteringString;
|
||||
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.urlFilteringString === 'string' ) {
|
||||
bin.urlFilteringString = data.urlFilteringString;
|
||||
binNotEmpty = true;
|
||||
}
|
||||
if ( typeof data.hostnameSwitchesString === 'string' ) {
|
||||
bin.hostnameSwitchesString = data.hostnameSwitchesString;
|
||||
binNotEmpty = true;
|
||||
}
|
||||
|
||||
if ( typeof data.hostnameSwitchesString === 'string' ) {
|
||||
bin.hostnameSwitchesString = data.hostnameSwitchesString;
|
||||
binNotEmpty = true;
|
||||
}
|
||||
if ( binNotEmpty ) {
|
||||
vAPI.storage.set(bin);
|
||||
}
|
||||
|
||||
if ( binNotEmpty ) {
|
||||
vAPI.storage.set(bin);
|
||||
}
|
||||
if ( typeof data.userFilters === 'string' ) {
|
||||
µb.assets.put('assets/user/filters.txt', data.userFilters);
|
||||
}
|
||||
|
||||
if ( typeof data.userFilters === 'string' ) {
|
||||
this.assets.put('assets/user/filters.txt', data.userFilters);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
vAPI.adminStorage.getItem('adminSettings', onRead);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -22,7 +22,7 @@ cp src/*.html $DES/
|
|||
cp platform/chromium/*.js $DES/js/
|
||||
cp -R platform/chromium/img $DES/
|
||||
cp platform/chromium/*.html $DES/
|
||||
cp platform/chromium/manifest.json $DES/
|
||||
cp platform/chromium/*.json $DES/
|
||||
cp LICENSE.txt $DES/
|
||||
|
||||
if [ "$1" = all ]; then
|
||||
|
|
Loading…
Reference in New Issue