Merge pull request #964 from wanhose/v7.3.0

7.3.0
This commit is contained in:
wanhose 2024-09-14 20:33:29 +02:00 committed by GitHub
commit 0a853d8cef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 122 additions and 183 deletions

View File

@ -14,7 +14,7 @@
- All browsers based on Chromium 88+ (Blisk, Brave, Colibri, Epic Browser, Iron Browser, Vivaldi and many more) - All browsers based on Chromium 88+ (Blisk, Brave, Colibri, Epic Browser, Iron Browser, Vivaldi and many more)
- Google Chrome 109+ - Google Chrome 109+
- Microsoft Edge 109+ - Microsoft Edge 109+
- Mozilla Firefox 113+ - Mozilla Firefox 126+
- Mozilla Firefox Mobile 126+ - Mozilla Firefox Mobile 126+
## Installation (for Mozilla Firefox users) ## Installation (for Mozilla Firefox users)

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Cookie Dialog Monster", "name": "Cookie Dialog Monster",
"version": "7.2.4", "version": "7.3.0",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"icons": { "icons": {
@ -22,7 +22,7 @@
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "{77e2c00b-e173-4604-863d-01645d8d2826}", "id": "{77e2c00b-e173-4604-863d-01645d8d2826}",
"strict_min_version": "113.0", "strict_min_version": "126.0",
"update_url": "https://www.cookie-dialog-monster.com/mozilla/updates.json" "update_url": "https://www.cookie-dialog-monster.com/mozilla/updates.json"
} }
}, },

View File

@ -115,7 +115,6 @@ browser.runtime.onMessage.addListener((message, sender, callback) => {
case 'DISABLE_ICON': case 'DISABLE_ICON':
if (isPage && tabId !== undefined) { if (isPage && tabId !== undefined) {
browser.action.setIcon({ path: '/assets/icons/disabled.png', tabId }, suppressLastError); browser.action.setIcon({ path: '/assets/icons/disabled.png', tabId }, suppressLastError);
browser.action.setBadgeText({ tabId, text: '' });
} }
break; break;
case 'ENABLE_ICON': case 'ENABLE_ICON':
@ -130,11 +129,8 @@ browser.runtime.onMessage.addListener((message, sender, callback) => {
break; break;
case 'GET_DATA': case 'GET_DATA':
storage.get('data', ({ data }) => { storage.get('data', ({ data }) => {
if (data) { if (data) callback(data);
callback(data); else refreshData(callback);
} else {
refreshData(callback);
}
}); });
return true; return true;
case 'GET_EXCLUSION_LIST': case 'GET_EXCLUSION_LIST':
@ -163,9 +159,19 @@ browser.runtime.onMessage.addListener((message, sender, callback) => {
script.insertCSS({ files: ['styles/dialog.css'], target: { tabId } }); script.insertCSS({ files: ['styles/dialog.css'], target: { tabId } });
} }
break; break;
case 'INSERT_EXTENSION_CSS':
if (isPage && tabId !== undefined) {
script.insertCSS({ files: ['styles/extension.css'], target: { tabId } });
}
break;
case 'REFRESH_DATA': case 'REFRESH_DATA':
refreshData(callback); refreshData(callback);
return true; return true;
case 'RELOAD_TAB':
if (tabId !== undefined) {
browser.tabs.reload(tabId, { bypassCache: true });
}
break;
case 'REPORT': case 'REPORT':
if (tabId !== undefined) { if (tabId !== undefined) {
report(message, sender.tab, callback); report(message, sender.tab, callback);
@ -173,18 +179,15 @@ browser.runtime.onMessage.addListener((message, sender, callback) => {
} }
break; break;
case 'SET_BADGE': case 'SET_BADGE':
if (tabId !== undefined) { if (isPage && tabId !== undefined) {
browser.action.setBadgeBackgroundColor({ color: '#6b7280' }); browser.action.setBadgeBackgroundColor({ color: '#6b7280' });
browser.action.setBadgeText({ tabId, text: message.value }); browser.action.setBadgeText({ tabId, text: message.value ? `${message.value}` : null });
} }
break; break;
case 'SET_HOSTNAME_STATE': case 'SET_HOSTNAME_STATE':
if (hostname) { if (hostname) {
if (message.state.enabled === false) { if (message.state.enabled === false) storage.set({ [hostname]: message.state });
storage.set({ [hostname]: message.state }); else storage.remove(hostname);
} else {
storage.remove(hostname);
}
} }
break; break;
default: default:
@ -252,22 +255,20 @@ browser.webRequest.onBeforeRequest.addListener(
return; return;
} }
const hostname = url.split('.').slice(-3).join('.').replace('www.', ''); const hostname = new URL(url).hostname.split('.').slice(-3).join('.').replace('www.', '');
const store = await storage.get(hostname); const { data, ...store } = await storage.get(['data', hostname]);
const state = store[hostname] ?? { enabled: true }; const state = store[hostname] ?? { enabled: true };
if (state.enabled) { if (data?.rules?.length) {
const { data } = await storage.get('data'); browser.declarativeNetRequest.updateSessionRules({
addRules: state.enabled
if (data?.rules?.length) { ? data.rules.map((rule) => ({
browser.declarativeNetRequest.updateSessionRules({ ...rule,
addRules: data.rules.map((rule) => ({ condition: { ...rule.condition, tabIds: [tabId] },
...rule, }))
condition: { ...rule.condition, tabIds: [tabId] }, : undefined,
})), removeRuleIds: data.rules.map((rule) => rule.id),
removeRuleIds: data.rules.map((rule) => rule.id), });
});
}
} }
} }
}, },

View File

@ -37,10 +37,10 @@ if (typeof browser === 'undefined') {
} }
/** /**
* @description Matched elements count * @description Actions done by the extension
* @type {number} * @type {Set<string>}
*/ */
let count = 0; let actions = new Set();
/** /**
* @description Data object with all the necessary information * @description Data object with all the necessary information
@ -90,9 +90,9 @@ const options = { childList: true, subtree: true };
/** /**
* @description Elements that were already matched and are removable * @description Elements that were already matched and are removable
* @type {HTMLElement[]} * @type {Set<HTMLElement>}
*/ */
const removables = []; const removables = new Set();
/** /**
* @description Elements that were already seen * @description Elements that were already seen
@ -123,26 +123,12 @@ function clean(elements, skipMatch) {
const element = elements[index]; const element = elements[index];
if (match(element, skipMatch)) { if (match(element, skipMatch)) {
const observer = new MutationObserver(forceElementStyles); if (element instanceof HTMLDialogElement) element.close();
else element.setAttribute(dataAttributeName, 'true');
if (element instanceof HTMLDialogElement) { actions.add(new Date().getTime().toString());
element.close(); dispatch({ type: 'SET_BADGE', value: actions.size });
} else { removables.add(element);
element.setAttribute(dataAttributeName, 'true');
element.style.setProperty('display', 'none', 'important');
}
observer.observe(element, {
attributes: true,
attributeFilter: [dataAttributeName, 'class', 'style'],
});
count += 1;
dispatch({ type: 'SET_BADGE', value: `${count}` });
if (!removables.includes(element)) {
removables.push(element);
}
} }
seen.push(element); seen.push(element);
@ -178,23 +164,6 @@ function forceClean(from) {
} }
} }
/**
* @description Force element to have these styles
* @type {MutationCallback}
*/
function forceElementStyles(mutations, observer) {
for (const mutation of mutations) {
const element = mutation.target;
const value = element.getAttribute(dataAttributeName);
if (value === null) {
observer.disconnect();
} else {
element.style.setProperty('display', 'none', 'important');
}
}
}
/** /**
* Get all elements that match the selector * Get all elements that match the selector
* @param {string | string[]} [selector] * @param {string | string[]} [selector]
@ -341,46 +310,9 @@ function fix() {
const domains = skips.domains.map((x) => (x.split('.').length < 3 ? `*${x}` : x)); const domains = skips.domains.map((x) => (x.split('.').length < 3 ? `*${x}` : x));
for (const backdrop of backdrops) { for (const backdrop of backdrops) {
if (backdrop.children.length === 0 && backdrop.style.display !== 'none') { if (backdrop.children.length === 0 && !backdrop.hasAttribute(dataAttributeName)) {
backdrop.style.setProperty('display', 'none'); actions.add(new Date().getTime().toString());
count += 1; backdrop.setAttribute(dataAttributeName, 'true');
dispatch({ type: 'SET_BADGE', value: `${count}` });
}
}
// 2024-08-02: fix #644 temporarily
document.getElementsByTagName('ion-router-outlet')[0]?.removeAttribute('inert');
for (const fix of fixes) {
const { action, domain, property, selector } = fix;
if (hostname.includes(domain)) {
switch (action) {
case 'click': {
const element = document.querySelector(selector);
element?.click();
break;
}
case 'remove': {
const element = document.querySelector(selector);
element?.style?.removeProperty(property);
break;
}
case 'reload': {
window.location.reload();
break;
}
case 'reset': {
const element = document.querySelector(selector);
element?.style?.setProperty(property, 'initial', 'important');
break;
}
case 'resetAll': {
const elements = getElements(selector);
elements.forEach((e) => e?.style?.setProperty(property, 'initial', 'important'));
break;
}
}
} }
} }
@ -391,37 +323,65 @@ function fix() {
element?.style.setProperty('overflow-y', 'initial', 'important'); element?.style.setProperty('overflow-y', 'initial', 'important');
} }
} }
}
/** for (const fix of fixes) {
* @description Restore DOM to its previous state const { action, domain, property, selector } = fix;
* @returns {void}
*/
function restoreDOM() {
const backdrops = getElements(tokens.backdrops);
for (const backdrop of backdrops) { if (hostname.includes(domain)) {
if (backdrop.children.length === 0 && backdrop.hasAttribute(dataAttributeName)) { switch (action) {
backdrop.style.removeProperty('display'); case 'click': {
const element = document.querySelector(selector);
actions.add('click');
element?.click();
break;
}
case 'remove': {
const element = document.querySelector(selector);
actions.add('remove');
element?.style?.removeProperty(property);
break;
}
case 'reload': {
window.location.reload();
break;
}
case 'reset': {
const element = document.querySelector(selector);
actions.add('reset');
element?.style?.setProperty(property, 'initial', 'important');
break;
}
case 'resetAll': {
const elements = getElements(selector);
actions.add('resetAll');
elements.forEach((e) => e?.style?.setProperty(property, 'initial', 'important'));
break;
}
}
} }
} }
for (const element of removables) { const ionRouterOutlet = document.getElementsByTagName('ion-router-outlet')[0];
element.removeAttribute(dataAttributeName);
element.style.removeProperty('display');
if (element instanceof HTMLDialogElement) { if (ionRouterOutlet) {
element.showModal(); actions.add('ion-router-outlet');
} // 2024-08-02: fix #644 temporarily
ionRouterOutlet.removeAttribute('inert');
} }
for (const element of [document.body, document.documentElement]) { const t4Wrapper = document.getElementsByClassName('t4-wrapper')[0];
element?.style.removeProperty('position');
element?.style.removeProperty('overflow-y'); if (t4Wrapper) {
actions.add('t4-wrapper');
// 2024-09-12: fix #945 temporarily
t4Wrapper.removeAttribute('inert');
} }
count = 0; dispatch({ type: 'SET_BADGE', value: actions.size });
seen.splice(0, seen.length);
} }
/** /**
@ -462,18 +422,14 @@ async function setUp(params = {}) {
skips = data?.skips ?? skips; skips = data?.skips ?? skips;
tokens = data?.tokens ?? tokens; tokens = data?.tokens ?? tokens;
if (count > 0) {
dispatch({ type: 'SET_BADGE', value: `${count}` });
}
dispatch({ type: 'ENABLE_ICON' }); dispatch({ type: 'ENABLE_ICON' });
dispatch({ type: 'INSERT_EXTENSION_CSS' });
dispatch({ type: 'SET_BADGE', value: actions.size });
observer.observe(document.body ?? document.documentElement, options); observer.observe(document.body ?? document.documentElement, options);
if (!params.skipRunFn) run({ containers: tokens.containers });
if (!params.skipRunFn) {
run({ containers: tokens.containers });
}
} else { } else {
dispatch({ type: 'DISABLE_ICON' }); dispatch({ type: 'DISABLE_ICON' });
dispatch({ type: 'SET_BADGE', value: actions.size });
observer.disconnect(); observer.disconnect();
} }
} }
@ -500,13 +456,12 @@ const observer = new MutationObserver((mutations) => {
browser.runtime.onMessage.addListener(async (message) => { browser.runtime.onMessage.addListener(async (message) => {
switch (message.type) { switch (message.type) {
case 'RESTORE': { case 'RESTORE': {
restoreDOM(); await dispatch({ type: 'RELOAD_TAB' });
await setUp({ skipRunFn: true });
break; break;
} }
case 'RUN': { case 'RUN': {
await setUp({ skipRunFn: !!removables.length }); await setUp({ skipRunFn: !!removables.size });
run({ elements: removables, skipMatch: true }); run({ elements: [...removables], skipMatch: true });
break; break;
} }
} }

View File

@ -40,16 +40,12 @@ const reportDialogHtml = `
${browser.i18n.getMessage('reportDialog_urlInputLabel')} ${browser.i18n.getMessage('reportDialog_urlInputLabel')}
<span class="report-dialog-input-label-required">*</span> <span class="report-dialog-input-label-required">*</span>
</div> </div>
<div <input
aria-labelledby="report-dialog-label-url" aria-labelledby="report-dialog-label-url"
aria-multiline="false"
aria-required="true" aria-required="true"
class="report-dialog-input" class="report-dialog-input"
contenteditable="true"
id="report-dialog-input-url" id="report-dialog-input-url"
role="textbox" />
tabindex="0"
></div>
<div class="report-dialog-input-error" id="report-dialog-input-url-error"> <div class="report-dialog-input-error" id="report-dialog-input-url-error">
${browser.i18n.getMessage('reportDialog_urlInputError')} ${browser.i18n.getMessage('reportDialog_urlInputError')}
</div> </div>
@ -59,19 +55,13 @@ const reportDialogHtml = `
${browser.i18n.getMessage('reportDialog_reasonInputLabel')} ${browser.i18n.getMessage('reportDialog_reasonInputLabel')}
<span class="report-dialog-input-label-required">*</span> <span class="report-dialog-input-label-required">*</span>
</div> </div>
<div <textarea
aria-labelledby="report-dialog-label-reason" aria-labelledby="report-dialog-label-reason"
aria-multiline="true"
aria-placeholder="${browser.i18n.getMessage('reportDialog_reasonInputLabel')}"
aria-required="true" aria-required="true"
class="report-dialog-input" class="report-dialog-input"
contenteditable="true"
id="report-dialog-input-reason" id="report-dialog-input-reason"
role="textbox" rows="4"
tabindex="0" >${browser.i18n.getMessage('reportDialog_reasonInputPlaceholder')}</textarea>
>
${browser.i18n.getMessage('reportDialog_reasonInputPlaceholder')}
</div>
<div class="report-dialog-input-error" id="report-dialog-input-reason-error"> <div class="report-dialog-input-error" id="report-dialog-input-reason-error">
${browser.i18n.getMessage('reportDialog_reasonInputError')} ${browser.i18n.getMessage('reportDialog_reasonInputError')}
</div> </div>
@ -146,22 +136,6 @@ function inputKeyDownHandler(event) {
} }
} }
/**
* @description Input paste handler
* @param {ClipboardEvent} event
*/
function inputPasteHandler(event) {
event.preventDefault();
const text = event.clipboardData?.getData('text').replace(/\r?\n|\r/g, ' ');
const selection = window.getSelection();
if (selection.rangeCount) {
selection.deleteFromDocument();
selection.getRangeAt(0).insertNode(document.createTextNode(text));
}
}
/** /**
* @description Show report dialog * @description Show report dialog
*/ */
@ -174,7 +148,7 @@ function showReportDialog() {
existingDialog.showModal(); existingDialog.showModal();
submitButton.setAttribute('aria-disabled', 'false'); submitButton.setAttribute('aria-disabled', 'false');
urlInput.textContent = window.location.origin + window.location.pathname; urlInput.setAttribute('value', window.location.origin + window.location.pathname);
return; return;
} }
@ -188,18 +162,15 @@ function showReportDialog() {
const urlInput = dialog?.querySelector('#report-dialog-input-url'); const urlInput = dialog?.querySelector('#report-dialog-input-url');
closeButton.addEventListener('click', closeButtonClickHandler); closeButton.addEventListener('click', closeButtonClickHandler);
dialog.querySelector('#report-dialog-input-url').textContent = urlInput.setAttribute('value', window.location.origin + window.location.pathname);
window.location.origin + window.location.pathname;
link.setAttribute('href', 'https://fonts.googleapis.com/css?family=Inter'); link.setAttribute('href', 'https://fonts.googleapis.com/css?family=Inter');
link.setAttribute('id', 'report-dialog-font'); link.setAttribute('id', 'report-dialog-font');
link.setAttribute('rel', 'stylesheet'); link.setAttribute('rel', 'stylesheet');
reasonInput.addEventListener('input', inputChangeHandler); reasonInput.addEventListener('input', inputChangeHandler);
reasonInput.addEventListener('keydown', inputKeyDownHandler); reasonInput.addEventListener('keydown', inputKeyDownHandler);
reasonInput.addEventListener('paste', inputPasteHandler);
submitButton.addEventListener('click', submitButtonClickHandler); submitButton.addEventListener('click', submitButtonClickHandler);
urlInput.addEventListener('input', inputChangeHandler); urlInput.addEventListener('input', inputChangeHandler);
urlInput.addEventListener('keydown', inputKeyDownHandler); urlInput.addEventListener('keydown', inputKeyDownHandler);
urlInput.addEventListener('paste', inputPasteHandler);
dispatch({ type: 'INSERT_DIALOG_CSS' }); dispatch({ type: 'INSERT_DIALOG_CSS' });
document.body.appendChild(dialog); document.body.appendChild(dialog);
@ -222,9 +193,9 @@ async function submitButtonClickHandler(event) {
const dialog = document.getElementById(reportDialogId); const dialog = document.getElementById(reportDialogId);
const reasonInput = dialog?.querySelector('#report-dialog-input-reason'); const reasonInput = dialog?.querySelector('#report-dialog-input-reason');
const reasonText = reasonInput?.textContent.trim(); const reasonText = reasonInput?.value.trim();
const urlInput = dialog?.querySelector('#report-dialog-input-url'); const urlInput = dialog?.querySelector('#report-dialog-input-url');
const urlText = urlInput?.textContent.trim(); const urlText = urlInput?.value.trim();
const errors = validateForm({ reason: reasonText, url: urlText }); const errors = validateForm({ reason: reasonText, url: urlText });

View File

@ -126,6 +126,7 @@
} }
#report-dialog .report-dialog-input { #report-dialog .report-dialog-input {
all: unset;
border: 1px solid var(--cookie-dialog-monster-color-tertiary); border: 1px solid var(--cookie-dialog-monster-color-tertiary);
border-radius: 4px; border-radius: 4px;
color: var(--cookie-dialog-monster-color-secondary); color: var(--cookie-dialog-monster-color-secondary);
@ -213,7 +214,7 @@
display: flex; display: flex;
font-family: Inter, Arial, Helvetica, sans-serif; font-family: Inter, Arial, Helvetica, sans-serif;
font-size: 14px; font-size: 14px;
height: 39px; height: 42px;
justify-content: center; justify-content: center;
line-height: 1.2; line-height: 1.2;
outline: none; outline: none;

View File

@ -0,0 +1,3 @@
*[data-cookie-dialog-monster='true'] {
clip-path: circle(0px) !important;
}

View File

@ -13,6 +13,10 @@
{ {
"version": "7.2.4", "version": "7.2.4",
"update_link": "https://www.cookie-dialog-monster.com/releases/7.2.4-mozilla-mobile.xpi" "update_link": "https://www.cookie-dialog-monster.com/releases/7.2.4-mozilla-mobile.xpi"
},
{
"version": "7.3.0",
"update_link": "https://www.cookie-dialog-monster.com/releases/7.3.0-mozilla-mobile.xpi"
} }
] ]
} }

View File

@ -45,6 +45,10 @@
{ {
"version": "7.2.4", "version": "7.2.4",
"update_link": "https://www.cookie-dialog-monster.com/releases/7.2.4.xpi" "update_link": "https://www.cookie-dialog-monster.com/releases/7.2.4.xpi"
},
{
"version": "7.3.0",
"update_link": "https://www.cookie-dialog-monster.com/releases/7.3.0.xpi"
} }
] ]
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.