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-12 19:00:04 +00:00
|
|
|
const webApiManagerKeySettingsKey = "webApiManagerDomainRules";
|
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
|
|
|
|
|
|
|
let loadedDomainRules = results && results[webApiManagerKeySettingsKey];
|
|
|
|
|
|
|
|
// 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-14 20:24:18 +00:00
|
|
|
if (!loadedDomainRules || Object.keys(loadedDomainRules).length === 0) {
|
|
|
|
loadedDomainRules = {
|
2017-10-14 21:16:24 +00:00
|
|
|
"(default)": []
|
2017-10-14 20:24:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(loadedDomainRules);
|
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
|
|
|
|
};
|
|
|
|
}());
|