diff --git a/core/messenger.js b/core/messenger.js index 4db9f68b..feafe62e 100644 --- a/core/messenger.js +++ b/core/messenger.js @@ -61,6 +61,32 @@ messenger._handleMessageReceived = function (message, sender, sendResponse) { return MessageResponse.ASYNCHRONOUS; } + + if (topic === 'domain:fetch-is-manipulateDOM') { + + let manipulateDOMRecord = requestAnalyzer.domainsManipulateDOMlist[value]; + sendResponse({'value': Boolean(manipulateDOMRecord)}); + + return MessageResponse.SYNCHRONOUS; + } + + if (topic === 'manipulateDOM:add-domain') { + + stateManager.addDomainToManipulateDOMlist(value).then(function () { + sendResponse({'value': true}); + }); + + return MessageResponse.ASYNCHRONOUS; + } + + if (topic === 'manipulateDOM:remove-domain') { + + stateManager.removeDomainFromManipulateDOMlist(value).then(function () { + sendResponse({'value': true}); + }); + + return MessageResponse.ASYNCHRONOUS; + } }; /** diff --git a/core/request-analyzer.js b/core/request-analyzer.js index 233e5c48..cb808f91 100644 --- a/core/request-analyzer.js +++ b/core/request-analyzer.js @@ -172,6 +172,12 @@ requestAnalyzer._applyWhitelistedDomains = function () { requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {}; }); }; +requestAnalyzer._applyManipulateDOMDomains = function () { + + chrome.storage.local.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) { + requestAnalyzer.manipulateDOMDomains = items.manipulateDOMDomains || {}; + }); +}; /** * Initializations @@ -180,8 +186,11 @@ requestAnalyzer._applyWhitelistedDomains = function () { requestAnalyzer.whitelistedDomains = {}; requestAnalyzer._applyWhitelistedDomains(); +requestAnalyzer.domainsManipulateDOMlist = {}; +requestAnalyzer._applyManipulateDOMDomains(); /** * Event Handlers */ chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains); +chrome.storage.onChanged.addListener(requestAnalyzer._applyManipulateDOMDomains); diff --git a/core/state-manager.js b/core/state-manager.js index f66e7e04..4ddca2ca 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -135,6 +135,29 @@ stateManager.removeDomainFromWhitelist = function (domain) { }); }; +stateManager.addDomainToManipulateDOMlist = function (domain) { + + return new Promise((resolve) => { + + let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOMlist; + domainsManipulateDOM[domain] = true; + + chrome.storage.local.set({domainsManipulateDOM}, resolve); + }); +}; + +stateManager.removeDomainFromManipulateDOMlist = function (domain) { + + return new Promise((resolve) => { + + let domainsManipulateDOM = requestAnalyzer.domainsManipulateDOMlist; + delete domainsManipulateDOM[domain]; + + chrome.storage.local.set({domainsManipulateDOM}, resolve); + }); +}; + + /** * Private Methods */