2017-10-12 19:00:04 +00:00
|
|
|
/*jslint es6: true*/
|
|
|
|
/*global window*/
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2017-10-14 20:24:18 +00:00
|
|
|
const rootObject = window.browser || window.chrome;
|
2017-10-15 04:23:40 +00:00
|
|
|
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.local.get(webApiManagerKeySettingsKey, function (results) {
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-15 04:23:40 +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
|
2017-10-14 21:16:24 +00:00
|
|
|
// a stubbed out one, using an empty blocking rule set.
|
2017-10-15 04:23:40 +00:00
|
|
|
if (!loadedValues ||
|
|
|
|
!loadedValues.domainRules ||
|
|
|
|
Object.keys(loadedValues.domainRules).length === 0) {
|
|
|
|
|
|
|
|
loadedValues = {
|
|
|
|
domainRules: {
|
|
|
|
"(default)": []
|
|
|
|
},
|
|
|
|
shouldLog: false
|
2017-10-14 20:24:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-15 04:23:40 +00:00
|
|
|
callback(loadedValues);
|
2017-10-12 19:00:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const set = function (object, callback) {
|
|
|
|
const valueToStore = {};
|
|
|
|
valueToStore[webApiManagerKeySettingsKey] = object;
|
|
|
|
storageObject.local.set(valueToStore, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.WEB_API_MANAGER.storageLib = {
|
|
|
|
get,
|
|
|
|
set
|
|
|
|
};
|
|
|
|
}());
|