1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-24 19:33:01 +01:00
Raymond Hill 2018-07-23 09:54:25 -04:00
parent 597f856417
commit 12118e83aa
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -45,7 +45,8 @@ let reHasCSSCombinators = /[ >+~]/,
proceduralDict = new Map(), proceduralDict = new Map(),
nodesToProcess = new Set(), nodesToProcess = new Set(),
shouldProcessDeclarativeComplex = false, shouldProcessDeclarativeComplex = false,
shouldProcessProcedural = false; shouldProcessProcedural = false,
loggedSelectors = new Set();
/******************************************************************************/ /******************************************************************************/
@ -70,14 +71,16 @@ let processDeclarativeSimple = function(node, out) {
} }
for ( let selector of simpleDeclarativeSet ) { for ( let selector of simpleDeclarativeSet ) {
if ( if (
node !== document && node.matches(selector) || (node === document || node.matches(selector) === false) &&
node.querySelector(selector) !== null (node.querySelector(selector) === null)
) { ) {
out.push(sanitizedSelectors.get(selector) || selector); continue;
simpleDeclarativeSet.delete(selector);
simpleDeclarativeStr = undefined;
if ( simpleDeclarativeSet.size === 0 ) { return; }
} }
out.push(sanitizedSelectors.get(selector) || selector);
simpleDeclarativeSet.delete(selector);
simpleDeclarativeStr = undefined;
loggedSelectors.add(selector);
if ( simpleDeclarativeSet.size === 0 ) { return; }
} }
}; };
@ -94,6 +97,7 @@ let processDeclarativeComplex = function(out) {
out.push(sanitizedSelectors.get(selector) || selector); out.push(sanitizedSelectors.get(selector) || selector);
complexDeclarativeSet.delete(selector); complexDeclarativeSet.delete(selector);
complexDeclarativeStr = undefined; complexDeclarativeStr = undefined;
loggedSelectors.add(selector);
if ( complexDeclarativeSet.size === 0 ) { return; } if ( complexDeclarativeSet.size === 0 ) { return; }
} }
}; };
@ -117,8 +121,9 @@ let processTimer = new vAPI.SafeAnimationFrame(() => {
processTimer.clear(); processTimer.clear();
let toLog = []; let toLog = [];
if ( nodesToProcess.size !== 0 && simpleDeclarativeSet.size !== 0 ) { if ( nodesToProcess.size !== 0 && simpleDeclarativeSet.size !== 0 ) {
if ( nodesToProcess.has(document) ) { if ( nodesToProcess.size !== 1 && nodesToProcess.has(document) ) {
nodesToProcess = new Set([ document ]); nodesToProcess.clear();
nodesToProcess.add(document);
} }
for ( let node of nodesToProcess ) { for ( let node of nodesToProcess ) {
processDeclarativeSimple(node, toLog); processDeclarativeSimple(node, toLog);
@ -177,21 +182,22 @@ let handlers = {
logNow = []; logNow = [];
for ( let entry of (changes.declarative || []) ) { for ( let entry of (changes.declarative || []) ) {
for ( let selector of entry[0].split(',\n') ) { for ( let selector of entry[0].split(',\n') ) {
if ( entry[1] === 'display:none!important;' ) { if ( entry[1] !== 'display:none!important;' ) {
if ( reHasPseudoClass.test(selector) ) {
let sanitized = selector.replace(reHasPseudoClass, '');
sanitizedSelectors.set(sanitized, selector);
selector = sanitized;
}
if ( reHasCSSCombinators.test(selector) ) {
complexDeclarativeSet.add(selector);
complexDeclarativeStr = undefined;
} else {
simpleDeclarativeSet.add(selector);
simpleDeclarativeStr = undefined;
}
} else {
logNow.push(selector + ':style(' + entry[1] + ')'); logNow.push(selector + ':style(' + entry[1] + ')');
continue;
}
if ( reHasPseudoClass.test(selector) ) {
let sanitized = selector.replace(reHasPseudoClass, '');
sanitizedSelectors.set(sanitized, selector);
selector = sanitized;
}
if ( loggedSelectors.has(selector) ) { continue; }
if ( reHasCSSCombinators.test(selector) ) {
complexDeclarativeSet.add(selector);
complexDeclarativeStr = undefined;
} else {
simpleDeclarativeSet.add(selector);
simpleDeclarativeStr = undefined;
} }
} }
} }