From 9a104bcbd2a6c7e972f3b1e6963725b8a6b53201 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 4 Jan 2024 10:57:27 -0500 Subject: [PATCH] Prevent `:others()` from hiding `html` tag Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3060 --- src/js/contentscript-extra.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/js/contentscript-extra.js b/src/js/contentscript-extra.js index 45c526213..9dee352d3 100644 --- a/src/js/contentscript-extra.js +++ b/src/js/contentscript-extra.js @@ -30,6 +30,9 @@ if ( /******************************************************************************/ const nonVisualElements = { + head: true, + link: true, + meta: true, script: true, style: true, }; @@ -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; }