2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Messenger
|
2020-06-30 18:41:58 +02:00
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
* (Origin: Decentraleyes)
|
2020-02-27 13:45:29 +01:00
|
|
|
*
|
|
|
|
* @author Thomas Rientjes
|
|
|
|
* @since 2018-05-28
|
2020-06-30 18:41:58 +02:00
|
|
|
*
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-02-26
|
|
|
|
*
|
2020-02-27 13:45:29 +01:00
|
|
|
* @license MPL 2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Messenger
|
|
|
|
*/
|
|
|
|
|
2024-04-28 07:18:40 +02:00
|
|
|
let messenger = {};
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Private Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
messenger._handleMessageReceived = function (message, sender, sendResponse) {
|
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
let topic, value, popup;
|
2020-02-27 13:45:29 +01:00
|
|
|
|
|
|
|
topic = message.topic;
|
|
|
|
value = message.value;
|
2021-03-21 08:07:30 +01:00
|
|
|
popup = {};
|
|
|
|
|
|
|
|
switch (topic) {
|
|
|
|
|
|
|
|
case 'tab:fetch-injections':
|
2023-07-13 09:07:02 +02:00
|
|
|
sendResponse({'value': {
|
|
|
|
'injections': stateManager.tabs[value].injections,
|
|
|
|
'blockedCounter': stateManager.tabs[value].blocked,
|
|
|
|
'missingCounter': stateManager.tabs[value].missing
|
|
|
|
}});
|
2021-03-21 08:07:30 +01:00
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'tab:inject':
|
|
|
|
chrome.tabs.executeScript(value, {
|
|
|
|
'code': `window.addEventListener('load', () => {
|
|
|
|
document.getElementById('domain').value = '${message.url}';
|
|
|
|
});`,
|
2021-08-02 06:27:02 +02:00
|
|
|
'runAt': 'document_idle'
|
2021-03-21 08:07:30 +01:00
|
|
|
});
|
2021-08-02 06:27:02 +02:00
|
|
|
return MessageResponse.SYNCHRONOUS;
|
2021-03-21 08:07:30 +01:00
|
|
|
|
|
|
|
case 'domain:fetch-is-allowlisted':
|
2021-08-07 08:39:10 +02:00
|
|
|
sendResponse({'value': Boolean(helpers.checkAllowlisted(value, requestAnalyzer.allowlistedDomains))});
|
2021-03-21 08:07:30 +01:00
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'domain:fetch-is-manipulateDOM':
|
2021-08-07 08:39:10 +02:00
|
|
|
sendResponse({'value': Boolean(helpers.checkAllowlisted(value, requestAnalyzer.domainsManipulateDOM))});
|
2021-03-21 08:07:30 +01:00
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
case 'domain:fetch-is-google-fonts':
|
|
|
|
sendResponse({'value': Boolean(helpers.checkAllowlisted(value, interceptor.allowedDomainsGoogleFonts))});
|
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
case 'allowlist:add-domain':
|
|
|
|
stateManager.addDomainToAllowlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'allowlist:remove-domain':
|
|
|
|
stateManager.removeDomainFromAllowlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'manipulateDOM:add-domain':
|
|
|
|
stateManager.addDomainToManipulateDOMlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'manipulateDOM:remove-domain':
|
|
|
|
stateManager.removeDomainFromManipulateDOMlist(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
2021-08-13 06:15:10 +02:00
|
|
|
case 'google-fonts:add-domain':
|
|
|
|
stateManager.addDomainToGoogleFontsList(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'google-fonts:remove-domain':
|
|
|
|
stateManager.removeDomainFromGoogleFontsList(value).then(function () {
|
|
|
|
sendResponse({'value': true});
|
|
|
|
});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
|
|
|
|
2021-03-21 08:07:30 +01:00
|
|
|
case 'statistic:delete':
|
|
|
|
storageManager.statistics = {};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'logs:get':
|
|
|
|
sendResponse({'logs': log.data});
|
|
|
|
return MessageResponse.SYNCHRONOUS;
|
|
|
|
|
|
|
|
case 'logs:delete':
|
|
|
|
log.data = [];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'popup:get-data':
|
|
|
|
popup.amountInjected = storageManager.amountInjected;
|
|
|
|
popup.internalStatistics = stateManager.internalStatistics;
|
|
|
|
popup.negateHtmlFilterList = stateManager.getInvertOption;
|
|
|
|
popup.loggingStatus = stateManager.logging;
|
|
|
|
popup.hideDonationButton = stateManager.hideDonationButton;
|
2021-08-13 06:15:10 +02:00
|
|
|
popup.blockGoogleFonts = interceptor.blockGoogleFonts;
|
2021-03-21 08:07:30 +01:00
|
|
|
sendResponse({'data': popup});
|
|
|
|
return MessageResponse.ASYNCHRONOUS;
|
2021-02-21 19:50:41 +01:00
|
|
|
}
|
2020-02-27 13:45:29 +01:00
|
|
|
};
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Event Handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
chrome.runtime.onMessage.addListener(messenger._handleMessageReceived);
|