This commit is contained in:
gorhill 2015-12-05 18:02:04 -05:00
parent 682131b310
commit 89f0e8f1a9
5 changed files with 20 additions and 10 deletions

View File

@ -423,16 +423,18 @@ var uBlockCollapser = (function() {
// - Injecting a style tag
var addStyleTag = function(selectors) {
var selectorStr = selectors.join(',\n');
// https://github.com/gorhill/uBlock/issues/1015
// Boost specificity of our CSS rules.
var styleText = ':root ' + selectors.join(',\n:root ');
var style = document.createElement('style');
// The linefeed before the style block is very important: do no remove!
style.appendChild(document.createTextNode(selectorStr + '\n{display:none !important;}'));
style.appendChild(document.createTextNode(styleText + '\n{display:none !important;}'));
var parent = document.head || document.documentElement;
if ( parent ) {
parent.appendChild(style);
vAPI.styles.push(style);
}
hideElements(selectorStr);
hideElements(styleText);
messager.send({
what: 'cosmeticFiltersInjected',
type: 'cosmetic',

View File

@ -97,17 +97,19 @@ var cosmeticFilters = function(details) {
}
}
if ( hide.length !== 0 ) {
var text = hide.join(',\n');
// https://github.com/gorhill/uBlock/issues/1015
// Boost specificity of our CSS rules.
var styleText = ':root ' + hide.join(',\n:root ');
var style = document.createElement('style');
// The linefeed before the style block is very important: do not remove!
style.appendChild(document.createTextNode(text + '\n{display:none !important;}'));
style.appendChild(document.createTextNode(styleText + '\n{display:none !important;}'));
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', details.domain, details.hide.length, hideStyleText);
var parent = document.head || document.documentElement;
if ( parent ) {
parent.appendChild(style);
vAPI.styles.push(style);
}
hideElements(text);
hideElements(styleText);
}
vAPI.donthideCosmeticFilters = donthideCosmeticFilters;
vAPI.hideCosmeticFilters = hideCosmeticFilters;

View File

@ -64,6 +64,10 @@ 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;
@ -77,7 +81,7 @@ while ( i-- ) {
continue;
}
loggedSelectors[selector] = true;
matchedSelectors.push(selector);
matchedSelectors.push(selector.replace(reSpecificityBooster, ''));
}
vAPI.loggedSelectors = loggedSelectors;

View File

@ -74,8 +74,7 @@ var localMessager = vAPI.messaging.channel('scriptlets');
localMessager.send({
what: 'liveCosmeticFilteringData',
pageURL: window.location.href,
filteredElementCount: filteredElementCount,
injectedSelectors: injectedSelectors
filteredElementCount: filteredElementCount
}, function() {
localMessager.close();
});

View File

@ -693,6 +693,9 @@ 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' ) {
@ -714,7 +717,7 @@ var cosmeticFilterMapper = (function() {
var i = selectors.length;
var selector, nodes, j, node;
while ( i-- ) {
selector = selectors[i];
selector = selectors[i].replace(reSpecificityBooster, '');
if ( filterMap.has(rootNode) === false && rootNode[matchesFnName](selector) ) {
filterMap.set(rootNode, selector);
hideNode(node);