web-api-manager/config/js/config.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-10-12 19:00:04 +00:00
/*jslint es6: true*/
2017-10-13 22:30:57 +00:00
/*global window, browser, chrome, Vue*/
2017-10-12 19:00:04 +00:00
(function () {
"use strict";
2017-10-13 22:30:57 +00:00
const rootObject = (window.browser || window.chrome);
2017-10-12 19:00:04 +00:00
const doc = window.document;
const standards = window.WEB_API_MANAGER.standards;
const defaultConservativeRules = window.WEB_API_MANAGER.defaults.conservative;
const {storageLib, stateLib} = window.WEB_API_MANAGER;
const defaultDomain = "(default)";
const state = stateLib.generateStateObject(defaultDomain, standards);
const onSettingsLoaded = function (settingsResults) {
let loadedDomainRules;
if (Object.keys(settingsResults).length !== 0) {
loadedDomainRules = settingsResults;
} else {
loadedDomainRules = Object.create(null);
loadedDomainRules[defaultDomain] = defaultConservativeRules;
}
state.setDomainRules(loadedDomainRules);
const vm = new Vue({
el: doc.body,
data: state
});
const updateStoredSettings = function () {
2017-10-13 22:30:57 +00:00
storageLib.set(state.domainRules, function () {
rootObject.runtime.sendMessage(["rulesUpdate", state.domainRules]);
});
2017-10-12 19:00:04 +00:00
};
vm.$watch("selectedStandards", updateStoredSettings);
vm.$watch("domainNames", updateStoredSettings);
};
const onPageLoad = function () {
storageLib.get(onSettingsLoaded);
};
window.onload = onPageLoad;
}());