Skip to content

Commit

Permalink
Fine tune cosmetic filtering badge-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 3, 2019
1 parent eff0524 commit 085a8cd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 120 deletions.
1 change: 0 additions & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const µBlock = (( ) => { // jshint ignore:line
filterAuthorMode: false,
loggerPopupType: 'popup',
manualUpdateAssetFetchPeriod: 500,
popupCosmeticFilterBadgeSlow: false,
popupFontSize: 'unset',
requestJournalProcessPeriod: 1000,
selfieAfter: 3,
Expand Down
5 changes: 1 addition & 4 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,7 @@ const onMessage = function(request, sender, callback) {
// Async
switch ( request.what ) {
case 'getHiddenElementCount':
const scriptlet = µb.hiddenSettings.popupCosmeticFilterBadgeSlow
? 'elements-all'
: 'elements';
getElementCount(request.tabId, scriptlet).then(count => {
getElementCount(request.tabId, 'elements').then(count => {
callback(count);
});
return;
Expand Down
72 changes: 0 additions & 72 deletions src/js/scriptlets/dom-survey-elements-all.js

This file was deleted.

46 changes: 3 additions & 43 deletions src/js/scriptlets/dom-survey-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
if ( typeof vAPI !== 'object' ) { return; }

const t0 = Date.now();
const tMax = t0 + 100;

if ( vAPI.domSurveyElements instanceof Object === false ) {
vAPI.domSurveyElements = {
Expand Down Expand Up @@ -59,48 +58,9 @@
) {
return 0;
}
const selectors = details.declarative.map(entry => entry[0]);
const simple = [], complex = [];
for ( const selectorStr of selectors ) {
for ( const selector of selectorStr.split(',\n') ) {
if ( /[ +>~]/.test(selector) ) {
complex.push(selector);
} else {
simple.push(selector);
}
}
}
const simpleStr = simple.join(',\n');
const complexStr = complex.join(',\n');
const nodeIter = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT
);
const matched = new Set();
let node = nodeIter.nextNode();
for (;;) {
if ( node === null ) { break; }
if ( Date.now() > tMax ) { return -1; }
if (
(node.offsetParent !== null) ||
(simpleStr === '' || node.matches(simpleStr) === false) &&
(complexStr === '' || node.closest(complexStr) !== node)
) {
node = nodeIter.nextNode();
continue;
}
matched.add(node);
if ( matched.size === 99 ) { break; }
// https://github.com/uBlockOrigin/uBlock-issues/issues/756#issuecomment-549079064
// Skip descendants when a match is detected.
for (;;) {
node = nodeIter.nextSibling();
if ( node !== null ) { break; }
node = nodeIter.parentNode();
if ( node === null ) { break; }
}
}
return matched.size;
return document.querySelectorAll(
details.declarative.map(entry => entry[0]).join(',')
).length;
})();
}

Expand Down

0 comments on commit 085a8cd

Please sign in to comment.