From d930504e3efade1156664890041c67392e47338a Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 13 Sep 2021 10:39:17 -0400 Subject: [PATCH] Better lookup all elements under mouse cursor in element picker Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/pefaov/elementpickerzapper_often_misses_images/hcnycbx/?context=3 --- src/js/scriptlets/epicker.js | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/js/scriptlets/epicker.js b/src/js/scriptlets/epicker.js index e455bb546..bf0303308 100644 --- a/src/js/scriptlets/epicker.js +++ b/src/js/scriptlets/epicker.js @@ -524,11 +524,6 @@ const filtersFrom = function(x, y) { x = undefined; } - // Network filter from element which was clicked. - if ( first !== null ) { - netFilterFromElement(first); - } - // Cosmetic filter candidates from ancestors. // https://github.com/gorhill/uBlock/issues/2519 // https://github.com/uBlockOrigin/uBlock-issues/issues/17 @@ -549,23 +544,15 @@ const filtersFrom = function(x, y) { } // https://github.com/gorhill/uBlock/issues/1545 - // Network filter candidates from all other elements found at - // point (x, y). + // Network filter candidates from all other elements found at [x,y]. if ( typeof x === 'number' ) { - const attrName = vAPI.sessionId + '-clickblind'; - elem = first; - while ( elem !== null ) { - const previous = elem; - elem.setAttribute(attrName, ''); - elem = elementFromPoint(x, y); - if ( elem === null || elem === previous ) { break; } + const magicAttr = `${vAPI.sessionId}-clickblind`; + pickerRoot.setAttribute(magicAttr, ''); + const elems = document.elementsFromPoint(x, y); + pickerRoot.removeAttribute(magicAttr); + for ( const elem of elems ) { netFilterFromElement(elem); } - for ( const elem of document.querySelectorAll(`[${attrName}]`) ) { - elem.removeAttribute(attrName); - } - - netFilterFromElement(document.body); } return netFilterCandidates.length + cosmeticFilterCandidates.length;