1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2024-12-23 00:25:15 +01:00

Fetch or save domain into extension storage (#1)

This commit is contained in:
nobody 2020-05-25 22:30:44 +02:00
parent c7bf456a06
commit 652150d70c
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
3 changed files with 58 additions and 0 deletions

View File

@ -61,6 +61,32 @@ messenger._handleMessageReceived = function (message, sender, sendResponse) {
return MessageResponse.ASYNCHRONOUS; 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;
}
}; };
/** /**

View File

@ -172,6 +172,12 @@ requestAnalyzer._applyWhitelistedDomains = function () {
requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {}; requestAnalyzer.whitelistedDomains = items.whitelistedDomains || {};
}); });
}; };
requestAnalyzer._applyManipulateDOMDomains = function () {
chrome.storage.local.get(Setting.DOMAINS_MANIPULATE_DOM, function (items) {
requestAnalyzer.manipulateDOMDomains = items.manipulateDOMDomains || {};
});
};
/** /**
* Initializations * Initializations
@ -180,8 +186,11 @@ requestAnalyzer._applyWhitelistedDomains = function () {
requestAnalyzer.whitelistedDomains = {}; requestAnalyzer.whitelistedDomains = {};
requestAnalyzer._applyWhitelistedDomains(); requestAnalyzer._applyWhitelistedDomains();
requestAnalyzer.domainsManipulateDOMlist = {};
requestAnalyzer._applyManipulateDOMDomains();
/** /**
* Event Handlers * Event Handlers
*/ */
chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains); chrome.storage.onChanged.addListener(requestAnalyzer._applyWhitelistedDomains);
chrome.storage.onChanged.addListener(requestAnalyzer._applyManipulateDOMDomains);

View File

@ -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 * Private Methods
*/ */