From 23b9acd118b00bebfd2c3177bc598456c102f404 Mon Sep 17 00:00:00 2001 From: wanhose Date: Wed, 10 Aug 2022 13:29:59 +0200 Subject: [PATCH] feat(packages): implement new tags file --- data/tags.txt | 16 ++++++++++++++++ packages/api/src/routes/v2/data.ts | 3 +++ .../browser-extension/src/scripts/content.js | 10 ++-------- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 data/tags.txt diff --git a/data/tags.txt b/data/tags.txt new file mode 100644 index 0000000..92f839b --- /dev/null +++ b/data/tags.txt @@ -0,0 +1,16 @@ +BASE +BODY +HEAD +HTML +IMG +LI +LINK +META +NAV +OL +SCRIPT +STYLE +SVG +TITLE +UL +VIDEO \ No newline at end of file diff --git a/packages/api/src/routes/v2/data.ts b/packages/api/src/routes/v2/data.ts index c60b100..e02087b 100644 --- a/packages/api/src/routes/v2/data.ts +++ b/packages/api/src/routes/v2/data.ts @@ -9,12 +9,14 @@ export default (server: FastifyInstance, options: RouteShorthandOptions, done: ( const elementsUrl = `${dataUrl}/elements.txt`; const fixesUrl = `${dataUrl}/fixes.txt`; const skipsUrl = `${dataUrl}/skips.txt`; + const tagsUrl = `${dataUrl}/tags.txt`; const results = await Promise.all([ fetch(classesUrl), fetch(elementsUrl), fetch(fixesUrl), fetch(skipsUrl), + fetch(tagsUrl), ]); reply.send({ @@ -23,6 +25,7 @@ export default (server: FastifyInstance, options: RouteShorthandOptions, done: ( elements: (await results[1].text()).split('\n'), fixes: (await results[2].text()).split('\n'), skips: (await results[3].text()).split('\n'), + tags: (await results[4].text()).split('\n'), }, success: true, }); diff --git a/packages/browser-extension/src/scripts/content.js b/packages/browser-extension/src/scripts/content.js index 9937216..2ff2097 100644 --- a/packages/browser-extension/src/scripts/content.js +++ b/packages/browser-extension/src/scripts/content.js @@ -1,6 +1,6 @@ /** * @description Data properties - * @type {{ classes: string[], fixes: string[], elements: string[], skips: string[] }?} + * @type {{ classes: string[], fixes: string[], elements: string[], skips: string[], tags: string[] }?} */ let data = null; @@ -11,12 +11,6 @@ let data = null; const dispatch = chrome.runtime.sendMessage; -/** - * @description Forbidden tags to ignore in the DOM - */ - -const forbiddenTags = ['BASE', 'BODY', 'HEAD', 'HTML', 'LINK', 'META', 'SCRIPT', 'STYLE', 'TITLE']; - /** * @description Current hostname * @type {string} @@ -51,7 +45,7 @@ const match = (node) => { const isVisible = rect.top <= (window.innerHeight || document.documentElement.clientHeight); return ( - !forbiddenTags.includes(node.tagName?.toUpperCase?.()) && + !data?.tags.includes(node.tagName?.toUpperCase?.()) && (isFullscreen || isVisible) && (node.offsetParent || window.getComputedStyle(node).position === 'fixed') && node.parentElement &&