Simplify, simplify

This commit is contained in:
Chris 2015-04-13 19:04:01 -06:00
parent fa3666f85d
commit 0fffd1634e
6 changed files with 26 additions and 80 deletions

View File

@ -11,7 +11,6 @@
<script src="js/vapi-common.js"></script> <script src="js/vapi-common.js"></script>
<script src="js/vapi-background.js"></script> <script src="js/vapi-background.js"></script>
<script src="js/background.js"></script> <script src="js/background.js"></script>
<script src="js/xal.js"></script>
<script src="js/async.js"></script> <script src="js/async.js"></script>
<script src="js/utils.js"></script> <script src="js/utils.js"></script>
<script src="js/uritools.js"></script> <script src="js/uritools.js"></script>

View File

@ -84,7 +84,7 @@ AsyncJobManager.prototype.restartTimer = function() {
// TODO: Maybe use chrome.alarms() API when the next job is at more than // TODO: Maybe use chrome.alarms() API when the next job is at more than
// one minute in the future... From reading about it, chrome.alarms() is // one minute in the future... From reading about it, chrome.alarms() is
// smarter in that it will fire the event only when the browser is not // smarter in that it will fire the event only when the browser is not
// too busy. (through XAL to abstract API specificities) // too busy.
if ( when < this.timerWhen ) { if ( when < this.timerWhen ) {
clearTimeout(this.timerId); clearTimeout(this.timerId);
this.timerWhen = when; this.timerWhen = when;

View File

@ -996,7 +996,7 @@ var backupUserData = function(callback) {
µb.restoreBackupSettings.lastBackupFile = filename; µb.restoreBackupSettings.lastBackupFile = filename;
µb.restoreBackupSettings.lastBackupTime = Date.now(); µb.restoreBackupSettings.lastBackupTime = Date.now();
µb.XAL.keyvalSetMany(µb.restoreBackupSettings); µb.keyvalSetMany(µb.restoreBackupSettings);
getLocalData(callback); getLocalData(callback);
}; };
@ -1018,19 +1018,19 @@ var restoreUserData = function(request) {
var onAllRemoved = function() { var onAllRemoved = function() {
// Be sure to adjust `countdown` if adding/removing anything below // Be sure to adjust `countdown` if adding/removing anything below
µb.XAL.keyvalSetOne('version', userData.version); µb.keyvalSetOne('version', userData.version);
µBlock.saveLocalSettings(true); µBlock.saveLocalSettings(true);
µb.XAL.keyvalSetMany(userData.userSettings, onCountdown); µb.keyvalSetMany(userData.userSettings, onCountdown);
µb.XAL.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown); µb.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown);
µb.XAL.keyvalSetOne('netWhitelist', userData.netWhitelist || '', onCountdown); µb.keyvalSetOne('netWhitelist', userData.netWhitelist || '', onCountdown);
// With versions 0.9.2.4-, dynamic rules were saved within the // With versions 0.9.2.4-, dynamic rules were saved within the
// `userSettings` object. No longer the case. // `userSettings` object. No longer the case.
var s = userData.dynamicFilteringString || userData.userSettings.dynamicFilteringString || ''; var s = userData.dynamicFilteringString || userData.userSettings.dynamicFilteringString || '';
µb.XAL.keyvalSetOne('dynamicFilteringString', s, onCountdown); µb.keyvalSetOne('dynamicFilteringString', s, onCountdown);
µb.assets.put('assets/user/filters.txt', userData.userFilters, onCountdown); µb.assets.put('assets/user/filters.txt', userData.userFilters, onCountdown);
µb.XAL.keyvalSetMany({ µb.keyvalSetMany({
lastRestoreFile: request.file || '', lastRestoreFile: request.file || '',
lastRestoreTime: Date.now(), lastRestoreTime: Date.now(),
lastBackupFile: '', lastBackupFile: '',
@ -1044,13 +1044,13 @@ var restoreUserData = function(request) {
// If we are going to restore all, might as well wipe out clean local // If we are going to restore all, might as well wipe out clean local
// storage // storage
µb.XAL.keyvalRemoveAll(onAllRemoved); vAPI.storage.clear(onAllRemoved);
}; };
/******************************************************************************/ /******************************************************************************/
var resetUserData = function() { var resetUserData = function() {
µb.XAL.keyvalRemoveAll(); vAPI.storage.clear(onAllRemoved);
// Keep global counts, people can become quite attached to numbers // Keep global counts, people can become quite attached to numbers
µb.saveLocalSettings(true); µb.saveLocalSettings(true);

View File

@ -140,7 +140,7 @@ var onUserSettingsReady = function(fetched) {
// Remove obsolete setting // Remove obsolete setting
delete userSettings.logRequests; delete userSettings.logRequests;
µb.XAL.keyvalRemoveOne('logRequests'); vAPI.storage.remove('logRequests');
}; };
/******************************************************************************/ /******************************************************************************/

View File

@ -38,6 +38,20 @@
/******************************************************************************/ /******************************************************************************/
µBlock.keyvalSetOne = function(key, val, callback) {
var bin = {};
bin[key] = val;
vAPI.storage.set(bin, callback || this.noopFunc);
};
/******************************************************************************/
µBlock.keyvalSetMany = function(dict, callback) {
vAPI.storage.set(dict, callback || this.noopFunc);
};
/******************************************************************************/
µBlock.saveLocalSettings = function(force) { µBlock.saveLocalSettings = function(force) {
if ( force ) { if ( force ) {
this.localSettingsModifyTime = Date.now(); this.localSettingsModifyTime = Date.now();
@ -70,7 +84,7 @@
/******************************************************************************/ /******************************************************************************/
µBlock.savePermanentFirewallRules = function() { µBlock.savePermanentFirewallRules = function() {
this.XAL.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString()); this.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString());
}; };
/******************************************************************************/ /******************************************************************************/

View File

@ -1,67 +0,0 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
Copyright (C) 2014 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/chrisaljoudi/uBlock
*/
/* global µBlock */
'use strict';
/******************************************************************************/
µBlock.XAL = (function(){
/******************************************************************************/
var exports = {};
var noopFunc = function(){};
/******************************************************************************/
exports.keyvalSetOne = function(key, val, callback) {
var bin = {};
bin[key] = val;
vAPI.storage.set(bin, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalSetMany = function(dict, callback) {
vAPI.storage.set(dict, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalRemoveOne = function(key, callback) {
vAPI.storage.remove(key, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalRemoveAll = function(callback) {
vAPI.storage.clear(callback || noopFunc);
};
/******************************************************************************/
return exports;
/******************************************************************************/
})();