mirror of https://github.com/gorhill/uBlock.git
parent
6b7d8e75f4
commit
a81d2a759b
|
@ -75,7 +75,7 @@ var µBlock = (function() { // jshint ignore:line
|
||||||
hiddenSettingsDefault: hiddenSettingsDefault,
|
hiddenSettingsDefault: hiddenSettingsDefault,
|
||||||
hiddenSettings: (function() {
|
hiddenSettings: (function() {
|
||||||
var out = objectAssign({}, hiddenSettingsDefault),
|
var out = objectAssign({}, hiddenSettingsDefault),
|
||||||
json = vAPI.localStorage.getItem('hiddenSettings');
|
json = vAPI.localStorage.getItem('immediateHiddenSettings');
|
||||||
if ( typeof json === 'string' ) {
|
if ( typeof json === 'string' ) {
|
||||||
try {
|
try {
|
||||||
var o = JSON.parse(json);
|
var o = JSON.parse(json);
|
||||||
|
@ -90,6 +90,8 @@ var µBlock = (function() { // jshint ignore:line
|
||||||
catch(ex) {
|
catch(ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove once 1.15.12+ is widespread.
|
||||||
|
vAPI.localStorage.removeItem('hiddenSettings');
|
||||||
return out;
|
return out;
|
||||||
})(),
|
})(),
|
||||||
|
|
||||||
|
|
|
@ -730,7 +730,7 @@ var backupUserData = function(callback) {
|
||||||
version: vAPI.app.version,
|
version: vAPI.app.version,
|
||||||
userSettings: µb.userSettings,
|
userSettings: µb.userSettings,
|
||||||
selectedFilterLists: µb.selectedFilterLists,
|
selectedFilterLists: µb.selectedFilterLists,
|
||||||
hiddenSettingsString: µb.stringFromHiddenSettings(),
|
hiddenSettings: µb.hiddenSettings,
|
||||||
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
netWhitelist: µb.stringFromWhitelist(µb.netWhitelist),
|
||||||
dynamicFilteringString: µb.permanentFirewall.toString(),
|
dynamicFilteringString: µb.permanentFirewall.toString(),
|
||||||
urlFilteringString: µb.permanentURLFiltering.toString(),
|
urlFilteringString: µb.permanentURLFiltering.toString(),
|
||||||
|
@ -764,8 +764,14 @@ var restoreUserData = function(request) {
|
||||||
var onAllRemoved = function() {
|
var onAllRemoved = function() {
|
||||||
µBlock.saveLocalSettings();
|
µBlock.saveLocalSettings();
|
||||||
vAPI.storage.set(userData.userSettings);
|
vAPI.storage.set(userData.userSettings);
|
||||||
µb.hiddenSettingsFromString(userData.hiddenSettingsString || '');
|
var hiddenSettings = userData.hiddenSettings;
|
||||||
|
if ( hiddenSettings instanceof Object === false ) {
|
||||||
|
hiddenSettings = µBlock.hiddenSettingsFromString(
|
||||||
|
userData.hiddenSettingsString || ''
|
||||||
|
);
|
||||||
|
}
|
||||||
vAPI.storage.set({
|
vAPI.storage.set({
|
||||||
|
hiddenSettings: hiddenSettings,
|
||||||
netWhitelist: userData.netWhitelist || '',
|
netWhitelist: userData.netWhitelist || '',
|
||||||
dynamicFilteringString: userData.dynamicFilteringString || '',
|
dynamicFilteringString: userData.dynamicFilteringString || '',
|
||||||
urlFilteringString: userData.urlFilteringString || '',
|
urlFilteringString: userData.urlFilteringString || '',
|
||||||
|
@ -791,12 +797,13 @@ var restoreUserData = function(request) {
|
||||||
// storage
|
// storage
|
||||||
vAPI.cacheStorage.clear();
|
vAPI.cacheStorage.clear();
|
||||||
vAPI.storage.clear(onAllRemoved);
|
vAPI.storage.clear(onAllRemoved);
|
||||||
|
vAPI.localStorage.removeItem('immediateHiddenSettings');
|
||||||
};
|
};
|
||||||
|
|
||||||
var resetUserData = function() {
|
var resetUserData = function() {
|
||||||
vAPI.cacheStorage.clear();
|
vAPI.cacheStorage.clear();
|
||||||
vAPI.storage.clear();
|
vAPI.storage.clear();
|
||||||
vAPI.localStorage.removeItem('hiddenSettings');
|
vAPI.localStorage.removeItem('immediateHiddenSettings');
|
||||||
|
|
||||||
// Keep global counts, people can become quite attached to numbers
|
// Keep global counts, people can become quite attached to numbers
|
||||||
µb.saveLocalSettings();
|
µb.saveLocalSettings();
|
||||||
|
@ -988,7 +995,8 @@ var onMessage = function(request, sender, callback) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'writeHiddenSettings':
|
case 'writeHiddenSettings':
|
||||||
µb.hiddenSettingsFromString(request.content);
|
µb.hiddenSettings = µb.hiddenSettingsFromString(request.content);
|
||||||
|
µb.saveHiddenSettings();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -80,7 +80,48 @@
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// For now, only boolean type is supported.
|
µBlock.loadHiddenSettings = function() {
|
||||||
|
var onLoaded = function(bin) {
|
||||||
|
if ( bin instanceof Object === false ) { return; }
|
||||||
|
var µb = µBlock,
|
||||||
|
hs = bin.hiddenSettings;
|
||||||
|
// Remove following condition once 1.15.12+ is widespread.
|
||||||
|
if (
|
||||||
|
hs instanceof Object === false &&
|
||||||
|
typeof bin.hiddenSettingsString === 'string'
|
||||||
|
) {
|
||||||
|
vAPI.storage.remove('hiddenSettingsString');
|
||||||
|
hs = µBlock.hiddenSettingsFromString(bin.hiddenSettingsString);
|
||||||
|
}
|
||||||
|
if ( hs instanceof Object ) {
|
||||||
|
var hsDefault = µb.hiddenSettingsDefault;
|
||||||
|
for ( var key in hsDefault ) {
|
||||||
|
if (
|
||||||
|
hsDefault.hasOwnProperty(key) &&
|
||||||
|
hs.hasOwnProperty(key) &&
|
||||||
|
typeof hs[key] === typeof hsDefault[key]
|
||||||
|
) {
|
||||||
|
µb.hiddenSettings[key] = hs[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( vAPI.localStorage.getItem('immediateHiddenSettings') === null ) {
|
||||||
|
µb.saveImmediateHiddenSettings();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
vAPI.storage.get(
|
||||||
|
[ 'hiddenSettings', 'hiddenSettingsString'],
|
||||||
|
onLoaded
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
µBlock.saveHiddenSettings = function(callback) {
|
||||||
|
vAPI.storage.set({ hiddenSettings: this.hiddenSettings, callback });
|
||||||
|
this.saveImmediateHiddenSettings();
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.hiddenSettingsFromString = function(raw) {
|
µBlock.hiddenSettingsFromString = function(raw) {
|
||||||
var out = objectAssign({}, this.hiddenSettingsDefault),
|
var out = objectAssign({}, this.hiddenSettingsDefault),
|
||||||
|
@ -114,19 +155,13 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.hiddenSettings = out;
|
return out;
|
||||||
vAPI.localStorage.setItem('hiddenSettings', JSON.stringify(out));
|
|
||||||
vAPI.storage.set({ hiddenSettingsString: this.stringFromHiddenSettings() });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
µBlock.stringFromHiddenSettings = function() {
|
µBlock.stringFromHiddenSettings = function() {
|
||||||
var out = [],
|
var out = [],
|
||||||
keys = Object.keys(this.hiddenSettings).sort(),
|
keys = Object.keys(this.hiddenSettings).sort();
|
||||||
key;
|
for ( var key of keys ) {
|
||||||
for ( var i = 0; i < keys.length; i++ ) {
|
|
||||||
key = keys[i];
|
|
||||||
out.push(key + ' ' + this.hiddenSettings[key]);
|
out.push(key + ' ' + this.hiddenSettings[key]);
|
||||||
}
|
}
|
||||||
return out.join('\n');
|
return out.join('\n');
|
||||||
|
@ -134,6 +169,24 @@
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// These settings must be available immediately on startup, without delay
|
||||||
|
// through the vAPI.localStorage. Add/remove settings as needed.
|
||||||
|
|
||||||
|
µBlock.saveImmediateHiddenSettings = function() {
|
||||||
|
vAPI.localStorage.setItem(
|
||||||
|
'immediateHiddenSettings',
|
||||||
|
JSON.stringify({
|
||||||
|
suspendTabsUntilReady: this.hiddenSettings.suspendTabsUntilReady,
|
||||||
|
userResourcesLocation: this.hiddenSettings.userResourcesLocation
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Do this here to have these hidden settings loaded ASAP.
|
||||||
|
µBlock.loadHiddenSettings();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.savePermanentFirewallRules = function() {
|
µBlock.savePermanentFirewallRules = function() {
|
||||||
this.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString());
|
this.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString());
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue