diff --git a/js/contentscript-end.js b/js/contentscript-end.js index fb6d0be8c..ef2f2b81d 100644 --- a/js/contentscript-end.js +++ b/js/contentscript-end.js @@ -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'); } }; diff --git a/js/contentscript-start.js b/js/contentscript-start.js index 0c2bcb4ee..2554bd19f 100644 --- a/js/contentscript-start.js +++ b/js/contentscript-start.js @@ -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'); } };