From 955fe944caf8f55d12cf89290a2e7b18e8b9ac49 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 4 Nov 2021 12:42:48 -0400 Subject: [PATCH] Suggest network filter as best candidate by default Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/qmjk36/ Regression from: - https://github.com/gorhill/uBlock/commit/d930504e3efade1156664890041c67392e47338a Also, fix immediately selecting the resource when using contextual menu with cosmetic filtering off. --- src/js/scriptlets/epicker.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/js/scriptlets/epicker.js b/src/js/scriptlets/epicker.js index bf0303308..879b83eae 100644 --- a/src/js/scriptlets/epicker.js +++ b/src/js/scriptlets/epicker.js @@ -524,6 +524,22 @@ const filtersFrom = function(x, y) { x = undefined; } + // https://github.com/gorhill/uBlock/issues/1545 + // Network filter candidates from all other elements found at [x,y]. + // https://www.reddit.com/r/uBlockOrigin/comments/qmjk36/ + // Extract network candidates first. + if ( typeof x === 'number' ) { + const magicAttr = `${vAPI.sessionId}-clickblind`; + pickerRoot.setAttribute(magicAttr, ''); + const elems = document.elementsFromPoint(x, y); + pickerRoot.removeAttribute(magicAttr); + for ( const elem of elems ) { + netFilterFromElement(elem); + } + } else 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 @@ -543,18 +559,6 @@ const filtersFrom = function(x, y) { } } - // https://github.com/gorhill/uBlock/issues/1545 - // Network filter candidates from all other elements found at [x,y]. - if ( typeof x === 'number' ) { - const magicAttr = `${vAPI.sessionId}-clickblind`; - pickerRoot.setAttribute(magicAttr, ''); - const elems = document.elementsFromPoint(x, y); - pickerRoot.removeAttribute(magicAttr); - for ( const elem of elems ) { - netFilterFromElement(elem); - } - } - return netFilterCandidates.length + cosmeticFilterCandidates.length; };