From 0fffd1634ea150eef78fec72a8727da39b8de056 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 13 Apr 2015 19:04:01 -0600 Subject: [PATCH] Simplify, simplify --- src/background.html | 1 - src/js/async.js | 2 +- src/js/messaging.js | 18 ++++++------ src/js/start.js | 2 +- src/js/storage.js | 16 ++++++++++- src/js/xal.js | 67 --------------------------------------------- 6 files changed, 26 insertions(+), 80 deletions(-) delete mode 100644 src/js/xal.js diff --git a/src/background.html b/src/background.html index 80faa1108..22de5f3f0 100644 --- a/src/background.html +++ b/src/background.html @@ -11,7 +11,6 @@ - diff --git a/src/js/async.js b/src/js/async.js index c55a77f08..dc8cfa5e1 100644 --- a/src/js/async.js +++ b/src/js/async.js @@ -84,7 +84,7 @@ AsyncJobManager.prototype.restartTimer = function() { // 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 // 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 ) { clearTimeout(this.timerId); this.timerWhen = when; diff --git a/src/js/messaging.js b/src/js/messaging.js index ed8069fe5..93151f731 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -996,7 +996,7 @@ var backupUserData = function(callback) { µb.restoreBackupSettings.lastBackupFile = filename; µb.restoreBackupSettings.lastBackupTime = Date.now(); - µb.XAL.keyvalSetMany(µb.restoreBackupSettings); + µb.keyvalSetMany(µb.restoreBackupSettings); getLocalData(callback); }; @@ -1018,19 +1018,19 @@ var restoreUserData = function(request) { var onAllRemoved = function() { // Be sure to adjust `countdown` if adding/removing anything below - µb.XAL.keyvalSetOne('version', userData.version); + µb.keyvalSetOne('version', userData.version); µBlock.saveLocalSettings(true); - µb.XAL.keyvalSetMany(userData.userSettings, onCountdown); - µb.XAL.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown); - µb.XAL.keyvalSetOne('netWhitelist', userData.netWhitelist || '', onCountdown); + µb.keyvalSetMany(userData.userSettings, onCountdown); + µb.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown); + µb.keyvalSetOne('netWhitelist', userData.netWhitelist || '', onCountdown); // With versions 0.9.2.4-, dynamic rules were saved within the // `userSettings` object. No longer the case. 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.XAL.keyvalSetMany({ + µb.keyvalSetMany({ lastRestoreFile: request.file || '', lastRestoreTime: Date.now(), lastBackupFile: '', @@ -1044,13 +1044,13 @@ var restoreUserData = function(request) { // If we are going to restore all, might as well wipe out clean local // storage - µb.XAL.keyvalRemoveAll(onAllRemoved); + vAPI.storage.clear(onAllRemoved); }; /******************************************************************************/ var resetUserData = function() { - µb.XAL.keyvalRemoveAll(); + vAPI.storage.clear(onAllRemoved); // Keep global counts, people can become quite attached to numbers µb.saveLocalSettings(true); diff --git a/src/js/start.js b/src/js/start.js index 4dfa2d619..bb7129683 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -140,7 +140,7 @@ var onUserSettingsReady = function(fetched) { // Remove obsolete setting delete userSettings.logRequests; - µb.XAL.keyvalRemoveOne('logRequests'); + vAPI.storage.remove('logRequests'); }; /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index 6167e0422..833e84149 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -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) { if ( force ) { this.localSettingsModifyTime = Date.now(); @@ -70,7 +84,7 @@ /******************************************************************************/ µBlock.savePermanentFirewallRules = function() { - this.XAL.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString()); + this.keyvalSetOne('dynamicFilteringString', this.permanentFirewall.toString()); }; /******************************************************************************/ diff --git a/src/js/xal.js b/src/js/xal.js deleted file mode 100644 index b8851f33c..000000000 --- a/src/js/xal.js +++ /dev/null @@ -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; - -/******************************************************************************/ - -})();