From 3b61f7d11d7cf1302cd3334de8f1438b62e02ac0 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 7 Dec 2015 11:06:06 -0500 Subject: [PATCH] minor code review --- src/js/scriptlets/cosmetic-logger.js | 8 +++----- src/js/scriptlets/dom-inspector.js | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/js/scriptlets/cosmetic-logger.js b/src/js/scriptlets/cosmetic-logger.js index 4503d732a..a36a48e2f 100644 --- a/src/js/scriptlets/cosmetic-logger.js +++ b/src/js/scriptlets/cosmetic-logger.js @@ -64,10 +64,6 @@ if ( injectedSelectors.length === 0 ) { return; } -// https://github.com/gorhill/uBlock/issues/1015 -// Remove runtime prefix used to augment the specificity of our CSS rules. -var reSpecificityBooster = /^:root\s+/; - var matchedSelectors = []; var selector; @@ -81,7 +77,9 @@ while ( i-- ) { continue; } loggedSelectors[selector] = true; - matchedSelectors.push(selector.replace(reSpecificityBooster, '')); + // https://github.com/gorhill/uBlock/issues/1015 + // Discard `:root ` prefix. + matchedSelectors.push(selector.slice(6)); } vAPI.loggedSelectors = loggedSelectors; diff --git a/src/js/scriptlets/dom-inspector.js b/src/js/scriptlets/dom-inspector.js index 0c144c4b6..2ae60a15a 100644 --- a/src/js/scriptlets/dom-inspector.js +++ b/src/js/scriptlets/dom-inspector.js @@ -693,9 +693,6 @@ var cosmeticFilterFromTarget = function(nid, coarseSelector) { /******************************************************************************/ var cosmeticFilterMapper = (function() { - // https://github.com/gorhill/uBlock/issues/1015 - var reSpecificityBooster = /^:root\s+/; - // https://github.com/gorhill/uBlock/issues/546 var matchesFnName; if ( typeof document.body.matches === 'function' ) { @@ -717,7 +714,9 @@ var cosmeticFilterMapper = (function() { var i = selectors.length; var selector, nodes, j, node; while ( i-- ) { - selector = selectors[i].replace(reSpecificityBooster, ''); + // https://github.com/gorhill/uBlock/issues/1015 + // Discard `:root ` prefix. + selector = selectors[i].slice(6); if ( filterMap.has(rootNode) === false && rootNode[matchesFnName](selector) ) { filterMap.set(rootNode, selector); hideNode(node);