web-api-manager/add-on/lib/storage.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-10-12 19:00:04 +00:00
(function () {
"use strict";
2017-10-14 20:24:18 +00:00
const rootObject = window.browser || window.chrome;
const webApiManagerKeySettingsKey = "webApiManager";
2017-10-14 20:24:18 +00:00
const storageObject = rootObject.storage;
2017-10-12 19:00:04 +00:00
const get = function (callback) {
storageObject.sync.get(webApiManagerKeySettingsKey, function (results) {
2017-10-14 20:24:18 +00:00
let loadedValues = results && results[webApiManagerKeySettingsKey];
2017-10-14 20:24:18 +00:00
// If there are no currently saved domain rules, then create
// a stubbed out one, using an empty blocking rule set.
if (!loadedValues ||
!loadedValues.domainRules ||
Object.keys(loadedValues.domainRules).length === 0) {
loadedValues = {
domainRules: {
"(default)": []
},
shouldLog: false
2017-10-14 20:24:18 +00:00
};
}
callback(loadedValues);
2017-10-12 19:00:04 +00:00
});
};
const set = function (object, callback) {
const valueToStore = {};
valueToStore[webApiManagerKeySettingsKey] = object;
storageObject.sync.set(valueToStore, callback);
2017-10-12 19:00:04 +00:00
};
window.WEB_API_MANAGER.storageLib = {
get,
set
};
}());