Merge pull request #10 from wanhose/4.1.1

4.1.1
This commit is contained in:
wanhose 2021-07-01 18:03:57 +02:00 committed by GitHub
commit 932407bc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 72 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Do Not Consent", "name": "Do Not Consent",
"version": "4.1.0", "version": "4.1.1",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"icons": { "icons": {

View File

@ -23,66 +23,58 @@ const isValid = (cache) =>
/** /**
* @function disableIcon * @function disableIcon
* @description Disables icon if there is a tab * @description Disables icon
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const disableIcon = (tabId) => { const disableIcon = (tabId) => {
if (tabId) { chrome.browserAction.setIcon({
chrome.browserAction.setIcon({ path: "assets/icons/disabled.png",
path: "assets/icons/disabled.png", tabId,
tabId, });
});
}
}; };
/** /**
* @function disablePopup * @function disablePopup
* @description Disables popup if there is a tab * @description Disables popup
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const disablePopup = (tabId) => { const disablePopup = (tabId) => {
if (tabId) { chrome.browserAction.setPopup({
chrome.browserAction.setPopup({ popup: "",
popup: "", tabId,
tabId, });
});
}
}; };
/** /**
* @function enableIcon * @function enableIcon
* @description Enables icon if there is a tab * @description Enables icon
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const enableIcon = (tabId) => { const enableIcon = (tabId) => {
if (tabId) { chrome.browserAction.setIcon({
chrome.browserAction.setIcon({ path: "assets/icons/enabled.png",
path: "assets/icons/enabled.png", tabId,
tabId, });
});
}
}; };
/** /**
* @function enablePopup * @function enablePopup
* @description Enables popup if there is a tab * @description Enables popup
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const enablePopup = (tabId) => { const enablePopup = (tabId) => {
if (tabId) { chrome.browserAction.setPopup({
chrome.browserAction.setPopup({ popup: "popup.html",
popup: "popup.html", tabId,
tabId, });
});
}
}; };
/** /**
@ -188,15 +180,23 @@ const updateCache = (hostname, state) => {
const updateState = (tabId, state) => { const updateState = (tabId, state) => {
switch (state) { switch (state) {
case "loading": case "loading":
chrome.tabs.insertCSS(tabId, { chrome.tabs.insertCSS(
file: "styles/content.css", tabId,
runAt: "document_start", {
}); file: "styles/content.css",
runAt: "document_start",
},
() => chrome.runtime.lastError
);
break; break;
case "ready": case "ready":
chrome.tabs.removeCSS(tabId, { chrome.tabs.removeCSS(
file: "styles/content.css", tabId,
}); {
file: "styles/content.css",
},
() => chrome.runtime.lastError
);
break; break;
default: default:
break; break;
@ -208,43 +208,40 @@ const updateState = (tabId, state) => {
*/ */
chrome.runtime.onMessage.addListener((request, sender, responseCallback) => { chrome.runtime.onMessage.addListener((request, sender, responseCallback) => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { const hasPermission = !sender.frameId || sender.frameId === 0;
const hasPermission = !sender.frameId || sender.frameId === 0; const tabId = sender.tab.id;
const tab = tabs[0];
const tabId = tab ? tab.id : undefined;
switch (request.type) { switch (request.type) {
case "DISABLE_ICON": case "DISABLE_ICON":
if (hasPermission) disableIcon(tabId); if (hasPermission) disableIcon(tabId);
break; break;
case "DISABLE_POPUP": case "DISABLE_POPUP":
if (hasPermission) disablePopup(tabId); if (hasPermission) disablePopup(tabId);
break; break;
case "ENABLE_ICON": case "ENABLE_ICON":
if (hasPermission) enableIcon(tabId); if (hasPermission) enableIcon(tabId);
break; break;
case "ENABLE_POPUP": case "ENABLE_POPUP":
if (hasPermission) enablePopup(tabId); if (hasPermission) enablePopup(tabId);
break; break;
case "GET_CACHE": case "GET_CACHE":
getCache(request.hostname, responseCallback); getCache(request.hostname, responseCallback);
break; break;
case "GET_LIST": case "GET_LIST":
getList(responseCallback); getList(responseCallback);
break; break;
case "GET_TAB": case "GET_TAB":
getTab(responseCallback); getTab(responseCallback);
break; break;
case "UPDATE_CACHE": case "UPDATE_CACHE":
updateCache(request.hostname, request.state); updateCache(request.hostname, request.state);
break; break;
case "UPDATE_STATE": case "UPDATE_STATE":
if (hasPermission) updateState(tabId, request.state); if (hasPermission) updateState(tabId, request.state);
break; break;
default: default:
break; break;
} }
});
return true; return true;
}); });