Prevent `:others()` from hiding `html` tag

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3060
This commit is contained in:
Raymond Hill 2024-01-04 10:57:27 -05:00
parent c65dbdbffa
commit 9a104bcbd2
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 13 additions and 11 deletions

View File

@ -30,6 +30,9 @@ if (
/******************************************************************************/
const nonVisualElements = {
head: true,
link: true,
meta: true,
script: true,
style: true,
};
@ -196,29 +199,28 @@ 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
) {
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
) {
if ( nonVisualElements[discard.localName] !== true ) {
if ( toKeep.has(discard) === false ) {
toDiscard.add(discard);
}
}
discard = discard.nextElementSibling;
}
keep = keep.parentElement;