This commit is contained in:
gorhill 2014-08-17 16:07:42 -04:00
parent 7e5c176253
commit 4ce8e63d54
2 changed files with 14 additions and 6 deletions

View File

@ -153,6 +153,9 @@ var uBlockMessaging = (function(name){
while ( i-- ) {
injectedSelectors[selectors[i]] = true;
}
// https://github.com/gorhill/uBlock/issues/158
// Ensure injected styles are enforced
hideElements(selectors.join(','));
}
idsFromNodeList(document.querySelectorAll('[id]'));
classesFromNodeList(document.querySelectorAll('[class]'));
@ -239,7 +242,7 @@ var uBlockMessaging = (function(name){
}
}
if ( hideSelectors.length ) {
applyCSS(hideSelectors, 'display', 'none');
hideElements(hideSelectors);
var style = document.createElement('style');
style.setAttribute('class', 'ublock-postload-1ae7a5f130fc79b4fdb8a4272d9426b5');
// The linefeed before the style block is very important: do no remove!
@ -259,14 +262,16 @@ var uBlockMessaging = (function(name){
contextNodes.length = 0;
};
var applyCSS = function(selectors, prop, value) {
var hideElements = function(selectors) {
if ( document.body === null ) {
return;
}
// https://github.com/gorhill/uBlock/issues/158
// Using CSSStyleDeclaration.setProperty is more reliable
var elems = document.querySelectorAll(selectors);
var i = elems.length;
while ( i-- ) {
elems[i].style[prop] = value;
elems[i].style.setProperty('display', 'none', 'important');
}
};

View File

@ -161,7 +161,7 @@ var cosmeticFilters = function(details) {
}
if ( hide.length !== 0 ) {
var text = hide.join(',\n');
applyCSS(text, 'display', 'none');
hideElements(text);
// The linefeed before the style block is very important: do no remove!
style.appendChild(document.createTextNode(text + '\n{display:none !important;}'));
//console.debug('µBlock> "%s" cosmetic filters: injecting %d CSS rules:', details.domain, details.hide.length, hideStyleText);
@ -185,6 +185,7 @@ var netFilters = function(details) {
'\n{visibility:hidden !important;}';
style.appendChild(document.createTextNode(text + css));
parent.appendChild(style);
//console.debug('document.querySelectorAll("%s") = %o', text, document.querySelectorAll(text));
};
var filteringHandler = function(details) {
@ -199,14 +200,16 @@ var filteringHandler = function(details) {
}
};
var applyCSS = function(selectors, prop, value) {
var hideElements = function(selectors) {
if ( document.body === null ) {
return;
}
// https://github.com/gorhill/uBlock/issues/158
// Using CSSStyleDeclaration.setProperty is more reliable
var elems = document.querySelectorAll(selectors);
var i = elems.length;
while ( i-- ) {
elems[i].style[prop] = value;
elems[i].style.setProperty('display', 'none', 'important');
}
};