1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Fix on-demand no-cosmetic-filtering badge when generichide in use

Related feedback:
- c090d2fde4 (commitcomment-35767596)

Mind that there might not be selectors to match as a
result of `generichide` or `no-cosmetic-filtering`.
This commit is contained in:
Raymond Hill 2019-11-01 14:01:30 -04:00
parent 2cd0d69c28
commit 987c9c1a21
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -52,7 +52,12 @@
surveyResults.hiddenElementCount = (( ) => {
if ( vAPI.domFilterer instanceof Object === false ) { return 0; }
const details = vAPI.domFilterer.getAllSelectors_(true);
if ( Array.isArray(details.declarative) === false ) { return 0; }
if (
Array.isArray(details.declarative) === false ||
details.declarative.length === 0
) {
return 0;
}
const selectors = details.declarative.map(entry => entry[0]);
const simple = [], complex = [];
for ( const selectorStr of selectors ) {
@ -70,19 +75,29 @@
document.body,
NodeFilter.SHOW_ELEMENT
);
const matched = new Set();
const candidates = new Set();
for (;;) {
const node = nodeIter.nextNode();
if ( node === null ) { break; }
if ( node.offsetParent !== null ) { continue; }
if (
node.matches(simpleStr) === false &&
node.closest(complexStr) !== node
) {
continue;
if ( node.offsetParent === null ) {
candidates.add(node);
}
}
const matched = new Set();
if ( simpleStr !== '') {
for ( const node of candidates ) {
if ( node.matches(simpleStr) === false ) { continue; }
candidates.delete(node);
matched.add(node);
if ( matched.size === 99 ) { break; }
}
}
if ( matched.size < 99 && complexStr !== '') {
for ( const node of candidates ) {
if ( node.closest(complexStr) !== node ) { continue; }
matched.add(node);
if ( matched.size === 99 ) { break; }
}
matched.add(node);
if ( matched.size === 99 ) { break; }
}
return matched.size;
})();