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;
|
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) {
|
2017-10-23 05:59:12 +00:00
|
|
|
storageObject.sync.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-21 15:49:56 +00:00
|
|
|
if (!loadedValues ||
|
2017-10-15 04:23:40 +00:00
|
|
|
!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;
|
2017-10-23 05:59:12 +00:00
|
|
|
storageObject.sync.set(valueToStore, callback);
|
2017-10-12 19:00:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
window.WEB_API_MANAGER.storageLib = {
|
|
|
|
get,
|
|
|
|
set
|
|
|
|
};
|
2017-10-23 08:29:59 +00:00
|
|
|
}());
|