mirror of https://github.com/gorhill/uBlock.git
this fixes #1015
This commit is contained in:
parent
682131b310
commit
89f0e8f1a9
|
@ -423,16 +423,18 @@ var uBlockCollapser = (function() {
|
||||||
// - Injecting a style tag
|
// - Injecting a style tag
|
||||||
|
|
||||||
var addStyleTag = function(selectors) {
|
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');
|
var style = document.createElement('style');
|
||||||
// The linefeed before the style block is very important: do no remove!
|
// 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;
|
var parent = document.head || document.documentElement;
|
||||||
if ( parent ) {
|
if ( parent ) {
|
||||||
parent.appendChild(style);
|
parent.appendChild(style);
|
||||||
vAPI.styles.push(style);
|
vAPI.styles.push(style);
|
||||||
}
|
}
|
||||||
hideElements(selectorStr);
|
hideElements(styleText);
|
||||||
messager.send({
|
messager.send({
|
||||||
what: 'cosmeticFiltersInjected',
|
what: 'cosmeticFiltersInjected',
|
||||||
type: 'cosmetic',
|
type: 'cosmetic',
|
||||||
|
|
|
@ -97,17 +97,19 @@ var cosmeticFilters = function(details) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( hide.length !== 0 ) {
|
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');
|
var style = document.createElement('style');
|
||||||
// The linefeed before the style block is very important: do not remove!
|
// 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);
|
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', details.domain, details.hide.length, hideStyleText);
|
||||||
var parent = document.head || document.documentElement;
|
var parent = document.head || document.documentElement;
|
||||||
if ( parent ) {
|
if ( parent ) {
|
||||||
parent.appendChild(style);
|
parent.appendChild(style);
|
||||||
vAPI.styles.push(style);
|
vAPI.styles.push(style);
|
||||||
}
|
}
|
||||||
hideElements(text);
|
hideElements(styleText);
|
||||||
}
|
}
|
||||||
vAPI.donthideCosmeticFilters = donthideCosmeticFilters;
|
vAPI.donthideCosmeticFilters = donthideCosmeticFilters;
|
||||||
vAPI.hideCosmeticFilters = hideCosmeticFilters;
|
vAPI.hideCosmeticFilters = hideCosmeticFilters;
|
||||||
|
|
|
@ -64,6 +64,10 @@ if ( injectedSelectors.length === 0 ) {
|
||||||
return;
|
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 matchedSelectors = [];
|
||||||
var selector;
|
var selector;
|
||||||
|
|
||||||
|
@ -77,7 +81,7 @@ while ( i-- ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
loggedSelectors[selector] = true;
|
loggedSelectors[selector] = true;
|
||||||
matchedSelectors.push(selector);
|
matchedSelectors.push(selector.replace(reSpecificityBooster, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
vAPI.loggedSelectors = loggedSelectors;
|
vAPI.loggedSelectors = loggedSelectors;
|
||||||
|
|
|
@ -74,8 +74,7 @@ var localMessager = vAPI.messaging.channel('scriptlets');
|
||||||
localMessager.send({
|
localMessager.send({
|
||||||
what: 'liveCosmeticFilteringData',
|
what: 'liveCosmeticFilteringData',
|
||||||
pageURL: window.location.href,
|
pageURL: window.location.href,
|
||||||
filteredElementCount: filteredElementCount,
|
filteredElementCount: filteredElementCount
|
||||||
injectedSelectors: injectedSelectors
|
|
||||||
}, function() {
|
}, function() {
|
||||||
localMessager.close();
|
localMessager.close();
|
||||||
});
|
});
|
||||||
|
|
|
@ -693,6 +693,9 @@ var cosmeticFilterFromTarget = function(nid, coarseSelector) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var cosmeticFilterMapper = (function() {
|
var cosmeticFilterMapper = (function() {
|
||||||
|
// https://github.com/gorhill/uBlock/issues/1015
|
||||||
|
var reSpecificityBooster = /^:root\s+/;
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/546
|
// https://github.com/gorhill/uBlock/issues/546
|
||||||
var matchesFnName;
|
var matchesFnName;
|
||||||
if ( typeof document.body.matches === 'function' ) {
|
if ( typeof document.body.matches === 'function' ) {
|
||||||
|
@ -714,7 +717,7 @@ var cosmeticFilterMapper = (function() {
|
||||||
var i = selectors.length;
|
var i = selectors.length;
|
||||||
var selector, nodes, j, node;
|
var selector, nodes, j, node;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
selector = selectors[i];
|
selector = selectors[i].replace(reSpecificityBooster, '');
|
||||||
if ( filterMap.has(rootNode) === false && rootNode[matchesFnName](selector) ) {
|
if ( filterMap.has(rootNode) === false && rootNode[matchesFnName](selector) ) {
|
||||||
filterMap.set(rootNode, selector);
|
filterMap.set(rootNode, selector);
|
||||||
hideNode(node);
|
hideNode(node);
|
||||||
|
|
Loading…
Reference in New Issue