mirror of https://github.com/gorhill/uBlock.git
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:
parent
2cd0d69c28
commit
987c9c1a21
|
@ -52,7 +52,12 @@
|
||||||
surveyResults.hiddenElementCount = (( ) => {
|
surveyResults.hiddenElementCount = (( ) => {
|
||||||
if ( vAPI.domFilterer instanceof Object === false ) { return 0; }
|
if ( vAPI.domFilterer instanceof Object === false ) { return 0; }
|
||||||
const details = vAPI.domFilterer.getAllSelectors_(true);
|
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 selectors = details.declarative.map(entry => entry[0]);
|
||||||
const simple = [], complex = [];
|
const simple = [], complex = [];
|
||||||
for ( const selectorStr of selectors ) {
|
for ( const selectorStr of selectors ) {
|
||||||
|
@ -70,19 +75,29 @@
|
||||||
document.body,
|
document.body,
|
||||||
NodeFilter.SHOW_ELEMENT
|
NodeFilter.SHOW_ELEMENT
|
||||||
);
|
);
|
||||||
const matched = new Set();
|
const candidates = new Set();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const node = nodeIter.nextNode();
|
const node = nodeIter.nextNode();
|
||||||
if ( node === null ) { break; }
|
if ( node === null ) { break; }
|
||||||
if ( node.offsetParent !== null ) { continue; }
|
if ( node.offsetParent === null ) {
|
||||||
if (
|
candidates.add(node);
|
||||||
node.matches(simpleStr) === false &&
|
}
|
||||||
node.closest(complexStr) !== node
|
}
|
||||||
) {
|
const matched = new Set();
|
||||||
continue;
|
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;
|
return matched.size;
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue