mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-15 15:32:28 +02:00
code review: fixed reloading of dynamic filtering rules
This commit is contained in:
parent
2e57a37e56
commit
f36880315a
@ -430,7 +430,11 @@ Matrix.prototype.fromObsoleteSelfie = function(selfie) {
|
|||||||
if ( selfie === '' ) {
|
if ( selfie === '' ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var bin = JSON.parse(selfie);
|
var bin = {};
|
||||||
|
try {
|
||||||
|
bin = JSON.parse(selfie);
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
var filters = bin.filters;
|
var filters = bin.filters;
|
||||||
var bits, val;
|
var bits, val;
|
||||||
for ( var hostname in filters ) {
|
for ( var hostname in filters ) {
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
var settingsLoaded = function(store) {
|
var settingsLoaded = function(store) {
|
||||||
µBlock.userSettings = store;
|
µBlock.userSettings = store;
|
||||||
if ( typeof callback === 'function' ) {
|
if ( typeof callback === 'function' ) {
|
||||||
callback(store);
|
callback(µBlock.userSettings);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -651,31 +651,32 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// User settings are in memory
|
// User settings are in memory
|
||||||
var onUserSettingsReady = function(settings) {
|
var onUserSettingsReady = function(userSettings) {
|
||||||
// https://github.com/gorhill/uBlock/issues/426
|
// https://github.com/gorhill/uBlock/issues/426
|
||||||
// Important: block remote fetching for when loading assets at launch
|
// Important: block remote fetching for when loading assets at launch
|
||||||
// time.
|
// time.
|
||||||
µb.assets.allowRemoteFetch = false;
|
µb.assets.allowRemoteFetch = false;
|
||||||
µb.assets.autoUpdate = settings.autoUpdate;
|
µb.assets.autoUpdate = userSettings.autoUpdate;
|
||||||
µb.fromSelfie(onSelfieReady);
|
µb.fromSelfie(onSelfieReady);
|
||||||
µb.mirrors.toggle(settings.experimentalEnabled);
|
µb.mirrors.toggle(userSettings.experimentalEnabled);
|
||||||
µb.contextMenu.toggle(settings.contextMenuEnabled);
|
µb.contextMenu.toggle(userSettings.contextMenuEnabled);
|
||||||
|
µb.dynamicNetFilteringEngine.fromString(userSettings.dynamicFilteringString);
|
||||||
|
|
||||||
// Remove obsolete setting
|
// Remove obsolete setting
|
||||||
delete µb.userSettings.logRequests;
|
delete userSettings.logRequests;
|
||||||
µb.XAL.keyvalRemoveOne('logRequests');
|
µb.XAL.keyvalRemoveOne('logRequests');
|
||||||
|
|
||||||
if ( typeof settings.dynamicFilteringSelfie === 'string' ) {
|
if ( typeof userSettings.dynamicFilteringSelfie === 'string' ) {
|
||||||
if ( settings.dynamicFilteringString === '' && settings.dynamicFilteringSelfie !== '' ) {
|
if ( userSettings.dynamicFilteringString === '' && userSettings.dynamicFilteringSelfie !== '' ) {
|
||||||
µb.dynamicNetFilteringEngine.fromObsoleteSelfie(settings.dynamicFilteringSelfie);
|
µb.dynamicNetFilteringEngine.fromObsoleteSelfie(userSettings.dynamicFilteringSelfie);
|
||||||
µb.userSettings.dynamicFilteringString = µb.dynamicNetFilteringEngine.toString();
|
userSettings.dynamicFilteringString = µb.dynamicNetFilteringEngine.toString();
|
||||||
µb.XAL.keyvalSetOne('dynamicFilteringString', µb.userSettings.dynamicFilteringString);
|
µb.XAL.keyvalSetOne('dynamicFilteringString', userSettings.dynamicFilteringString);
|
||||||
|
|
||||||
// Auto-enable advanced user if there were dynamic rules
|
// Auto-enable advanced user if there were dynamic rules
|
||||||
µb.userSettings.advancedUserEnabled = true;
|
userSettings.advancedUserEnabled = userSettings.dynamicFilteringString !== '';
|
||||||
µb.XAL.keyvalSetOne('advancedUserEnabled', true);
|
µb.XAL.keyvalSetOne('advancedUserEnabled', userSettings.advancedUserEnabled);
|
||||||
}
|
}
|
||||||
delete µb.userSettings.dynamicFilteringSelfie;
|
delete userSettings.dynamicFilteringSelfie;
|
||||||
µb.XAL.keyvalRemoveOne('dynamicFilteringSelfie');
|
µb.XAL.keyvalRemoveOne('dynamicFilteringSelfie');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user