Skip to content

Commit

Permalink
feat(browser-extension): add attributes to mutation observer
Browse files Browse the repository at this point in the history
  • Loading branch information
wanhose committed May 17, 2022
1 parent fbfc76e commit e5285cb
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/browser-extension/src/scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const preview = hostname.startsWith('consent.') || hostname.startsWith('myprivac

/**
* @description Options provided to observer
* @type {MutationObserverInit}
*/

const options = { childList: true, subtree: true };
const options = { attributes: true, childList: true, subtree: true };

/**
* @description Selectors list
Expand Down Expand Up @@ -76,13 +77,7 @@ const check = (node) =>
* @returns {void}
*/

const clean = (nodes) => {
if (selectors.length) {
nodes.filter(check).forEach((node) => {
if (node.parentElement) node.outerHTML = '';
});
}
};
const clean = (nodes) => nodes.filter(check).forEach((node) => (node.outerHTML = ''));

/**
* @description Fixes scroll issues
Expand Down Expand Up @@ -139,7 +134,7 @@ const observer = new MutationObserver((mutations, instance) => {

instance.disconnect();
fix();
if (!preview) clean(nodes);
if (!preview && selectors.length) clean(nodes);
instance.observe(target, options);
});

Expand All @@ -163,8 +158,8 @@ const promiseAll = () =>

document.addEventListener('readystatechange', () => {
dispatch({ hostname, type: 'GET_CACHE' }, null, async ({ enabled }) => {
if (document.readyState === 'complete' && enabled && !preview && selectors.length) {
const nodes = Array.from(document.querySelectorAll(selectors));
if (document.readyState === 'complete' && enabled && !preview) {
const nodes = selectors.length ? Array.from(document.querySelectorAll(selectors)) : [];

fix();
clean(nodes);
Expand Down

0 comments on commit e5285cb

Please sign in to comment.