Merge pull request #8 from wanhose/4.1.0

4.1.0
This commit is contained in:
wanhose 2021-07-01 15:15:17 +02:00 committed by GitHub
commit c7ce7eb0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 41 deletions

View File

@ -1188,7 +1188,6 @@ div[data-notificationid="cookie"]
.cookies_alert .cookies_alert
.cookie--form .cookie--form
div[class*="cookieDisclaimer"] div[class*="cookieDisclaimer"]
.ot-sdk-show-settings
.basic_features-cookiemessage .basic_features-cookiemessage
.data-protection-notice .data-protection-notice
#CookieReportsButton #CookieReportsButton
@ -12434,3 +12433,4 @@ html[id="facebook"] > body > div.__fb-light-mode
.css-1dbjc4n r-1awozwy r-1m3jxhj r-qo02w8 r-18u37iz r-1d7fvdj r-d9fdf6 r-tvv088 r-13qz1uu .css-1dbjc4n r-1awozwy r-1m3jxhj r-qo02w8 r-18u37iz r-1d7fvdj r-d9fdf6 r-tvv088 r-13qz1uu
.sibbo-layout .sibbo-layout
body > sibbo-cmp-layout body > sibbo-cmp-layout
.cc_banner-wrapper

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Do Not Consent", "name": "Do Not Consent",
"version": "4.0.3", "version": "4.1.0",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"icons": { "icons": {
@ -21,12 +21,11 @@
"content_scripts": [ "content_scripts": [
{ {
"all_frames": true, "all_frames": true,
"css": ["styles/content.css"],
"js": ["scripts/content.js"], "js": ["scripts/content.js"],
"matches": ["http://*/*", "https://*/*"], "matches": ["http://*/*", "https://*/*"],
"run_at": "document_start" "run_at": "document_start"
} }
], ],
"permissions": ["https://raw.githubusercontent.com/*", "storage", "tabs"], "permissions": ["http://*/*", "https://*/*", "storage", "tabs"],
"web_accessible_resources": ["assets/fonts/*", "scripts/*", "styles/*"] "web_accessible_resources": ["assets/fonts/*", "scripts/*", "styles/*"]
} }

View File

@ -23,59 +23,66 @@ const isValid = (cache) =>
/** /**
* @function disableIcon * @function disableIcon
* @description Disables icon * @description Disables icon if there is a tab
* *
* @param {string} [tabId] * @param {string} [tabId]
* @returns {boolean}
*/ */
const disableIcon = (tabId) => { const disableIcon = (tabId) => {
chrome.browserAction.setIcon({ if (tabId) {
path: "assets/icons/disabled.png", chrome.browserAction.setIcon({
tabId, path: "assets/icons/disabled.png",
}); tabId,
});
}
}; };
/** /**
* @function disablePopup * @function disablePopup
* @description Disables popup * @description Disables popup if there is a tab
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const disablePopup = (tabId) => { const disablePopup = (tabId) => {
chrome.browserAction.setPopup({ if (tabId) {
popup: "", chrome.browserAction.setPopup({
tabId, popup: "",
}); tabId,
});
}
}; };
/** /**
* @function enableIcon * @function enableIcon
* @description Enables icon * @description Enables icon if there is a tab
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const enableIcon = (tabId) => { const enableIcon = (tabId) => {
chrome.browserAction.setIcon({ if (tabId) {
path: "assets/icons/enabled.png", chrome.browserAction.setIcon({
tabId, path: "assets/icons/enabled.png",
}); tabId,
});
}
}; };
/** /**
* @function enablePopup * @function enablePopup
* @description Enables popup * @description Enables popup if there is a tab
* *
* @param {string} [tabId] * @param {string} [tabId]
*/ */
const enablePopup = (tabId) => { const enablePopup = (tabId) => {
chrome.browserAction.setPopup({ if (tabId) {
popup: "popup.html", chrome.browserAction.setPopup({
tabId, popup: "popup.html",
}); tabId,
});
}
}; };
/** /**
@ -170,27 +177,54 @@ const updateCache = (hostname, state) => {
}); });
}; };
/**
* @function updateState
* @description Set an extension state
*
* @param {string} [tabId]
* @param {string} [state]
*/
const updateState = (tabId, state) => {
switch (state) {
case "loading":
chrome.tabs.insertCSS(tabId, {
file: "styles/content.css",
runAt: "document_start",
});
break;
case "ready":
chrome.tabs.removeCSS(tabId, {
file: "styles/content.css",
});
break;
default:
break;
}
};
/** /**
* @description Listens to content messages * @description Listens to content messages
*/ */
chrome.runtime.onMessage.addListener((request, sender, responseCallback) => { chrome.runtime.onMessage.addListener((request, sender, responseCallback) => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const hasPermission = !sender.frameId || sender.frameId === 0;
const tab = tabs[0]; const tab = tabs[0];
const tabId = tab.id; const tabId = tab ? tab.id : undefined;
switch (request.type) { switch (request.type) {
case "DISABLE_ICON": case "DISABLE_ICON":
disableIcon(tabId); if (hasPermission) disableIcon(tabId);
break; break;
case "DISABLE_POPUP": case "DISABLE_POPUP":
disablePopup(tabId); if (hasPermission) disablePopup(tabId);
break; break;
case "ENABLE_ICON": case "ENABLE_ICON":
enableIcon(tabId); if (hasPermission) enableIcon(tabId);
break; break;
case "ENABLE_POPUP": case "ENABLE_POPUP":
enablePopup(tabId); if (hasPermission) enablePopup(tabId);
break; break;
case "GET_CACHE": case "GET_CACHE":
getCache(request.hostname, responseCallback); getCache(request.hostname, responseCallback);
@ -204,6 +238,9 @@ chrome.runtime.onMessage.addListener((request, sender, responseCallback) => {
case "UPDATE_CACHE": case "UPDATE_CACHE":
updateCache(request.hostname, request.state); updateCache(request.hostname, request.state);
break; break;
case "UPDATE_STATE":
if (hasPermission) updateState(tabId, request.state);
break;
default: default:
break; break;
} }

View File

@ -59,8 +59,7 @@ const fix = () => {
if (body) body.style.setProperty("overflow-y", "unset", "important"); if (body) body.style.setProperty("overflow-y", "unset", "important");
if (facebook) facebook.style.setProperty("position", "unset", "important"); if (facebook) facebook.style.setProperty("position", "unset", "important");
if (html) html.style.setProperty("overflow-y", "unset", "important"); if (html) html.style.setProperty("overflow-y", "unset", "important");
if (body && !loading) body.style.setProperty("opacity", "1"); if (!loading) dispatch({ state: "ready", type: "UPDATE_STATE" });
if (html && !loading) html.style.setProperty("background-color", "initial");
}; };
/** /**
@ -148,7 +147,7 @@ const runTasks = () => {
fix(); fix();
removeFromCache(); removeFromCache();
if (attempts <= 5) removeFromNetwork(); if (attempts <= 5) removeFromNetwork();
if (document.readyState !== "loading") attempts += 1; if (document.readyState === "complete") attempts += 1;
} }
if (attempts > 20) { if (attempts > 20) {
@ -163,20 +162,17 @@ const runTasks = () => {
dispatch( dispatch(
{ hostname: document.location.hostname, type: "GET_CACHE" }, { hostname: document.location.hostname, type: "GET_CACHE" },
null, null,
async ({ enabled, matches }) => { ({ enabled, matches }) => {
dispatch({ type: "ENABLE_POPUP" }); dispatch({ type: "ENABLE_POPUP" });
if (enabled) { if (enabled) {
dispatch({ state: "loading", type: "UPDATE_STATE" });
selectorsFromCache = matches; selectorsFromCache = matches;
dispatch({ type: "ENABLE_ICON" }); dispatch({ type: "ENABLE_ICON" });
dispatch({ type: "GET_LIST" }, null, async ({ selectors }) => { dispatch({ type: "GET_LIST" }, null, ({ selectors }) => {
selectorsFromNetwork = selectors; selectorsFromNetwork = selectors;
intervalId = setInterval(runTasks, 500); intervalId = setInterval(runTasks, 500);
}); });
} else {
document.addEventListener("DOMContentLoaded", () => {
document.body.style.setProperty("opacity", "1", "important");
});
} }
} }
); );

View File

@ -1,5 +1,5 @@
body { body {
opacity: 0; display: none !important;
} }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {