Skip to content

Commit

Permalink
Prevent :others() from hiding html tag
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 4, 2024
1 parent c65dbdb commit 9a104bc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/js/contentscript-extra.js
Expand Up @@ -30,6 +30,9 @@ if (
/******************************************************************************/

const nonVisualElements = {
head: true,
link: true,
meta: true,
script: true,
style: true,
};
Expand Down Expand Up @@ -196,28 +199,27 @@ class PSelectorOthersTask extends PSelectorTask {
const toKeep = new Set(this.targets);
const toDiscard = new Set();
const body = document.body;
const head = document.head;
let discard = null;
for ( let keep of this.targets ) {
while ( keep !== null && keep !== body ) {
while ( keep !== null && keep !== body && keep !== head ) {
toKeep.add(keep);
toDiscard.delete(keep);
discard = keep.previousElementSibling;
while ( discard !== null ) {
if (
nonVisualElements[discard.localName] !== true &&
toKeep.has(discard) === false
) {
toDiscard.add(discard);
if ( nonVisualElements[discard.localName] !== true ) {
if ( toKeep.has(discard) === false ) {
toDiscard.add(discard);
}
}
discard = discard.previousElementSibling;
}
discard = keep.nextElementSibling;
while ( discard !== null ) {
if (
nonVisualElements[discard.localName] !== true &&
toKeep.has(discard) === false
) {
toDiscard.add(discard);
if ( nonVisualElements[discard.localName] !== true ) {
if ( toKeep.has(discard) === false ) {
toDiscard.add(discard);
}
}
discard = discard.nextElementSibling;
}
Expand Down

0 comments on commit 9a104bc

Please sign in to comment.