cookie-dialog-monster/scripts/background.js

81 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* @function disableIcon
* @description Disables icon
*
* @param {string} [tabId]
*/
const disableIcon = (tabId) => {
chrome.browserAction.setIcon({
path: "assets/icon-disabled.png",
tabId: tabId,
});
};
/**
* @function disablePopup
* @description Disables popup
*
* @param {string} [tabId]
*/
const disablePopup = (tabId) => {
chrome.browserAction.setPopup({
popup: "",
tabId: tabId,
});
};
/**
* @function enableIcon
* @description Enables icon
*
* @param {string} [tabId]
*/
const enableIcon = (tabId) => {
chrome.browserAction.setIcon({
path: "assets/icon-enabled.png",
tabId: tabId,
});
};
/**
* @function enablePopup
* @description Enables popup
*
* @param {string} [tabId]
*/
const enablePopup = (tabId) => {
chrome.browserAction.setPopup({
popup: "popup.html",
tabId: tabId,
});
};
/**
* @description Listens to content messages
*/
chrome.runtime.onMessage.addListener((request, sender) => {
2021-04-08 22:13:36 +00:00
const tabId = sender.tab ? sender.tab.id : undefined;
switch (request.type) {
case "DISABLE_ICON":
2021-04-08 22:13:36 +00:00
disableIcon(tabId);
break;
case "DISABLE_POPUP":
2021-04-08 22:13:36 +00:00
disablePopup(tabId);
break;
case "ENABLE_ICON":
2021-04-08 22:13:36 +00:00
enableIcon(tabId);
break;
case "ENABLE_POPUP":
2021-04-08 22:13:36 +00:00
enablePopup(tabId);
break;
default:
break;
}
});