feat(packages): implement new tags file

This commit is contained in:
wanhose 2022-08-10 13:29:59 +02:00
parent 317b271dad
commit 23b9acd118
3 changed files with 21 additions and 8 deletions

16
data/tags.txt Normal file
View File

@ -0,0 +1,16 @@
BASE
BODY
HEAD
HTML
IMG
LI
LINK
META
NAV
OL
SCRIPT
STYLE
SVG
TITLE
UL
VIDEO

View File

@ -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,
});

View File

@ -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 &&