diff --git a/src/js/contentscript.js b/src/js/contentscript.js index 1b8d32ff2..f7c62bd7d 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -366,6 +366,19 @@ var domFilterer = { } }, + addStyleTag: function(text) { + var styleTag = document.createElement('style'); + styleTag.setAttribute('type', 'text/css'); + styleTag.textContent = text; + if ( document.head ) { + document.head.appendChild(styleTag); + } + this.styleTags.push(styleTag); + if ( userCSS ) { + userCSS.add(text); + } + }, + checkStyleTags_: function() { var doc = document, html = doc.documentElement, @@ -422,16 +435,7 @@ var domFilterer = { } if ( styleText !== '' ) { - var styleTag = document.createElement('style'); - styleTag.setAttribute('type', 'text/css'); - styleTag.textContent = styleText; - if ( document.head ) { - document.head.appendChild(styleTag); - } - this.styleTags.push(styleTag); - if ( userCSS ) { - userCSS.add(styleText); - } + this.addStyleTag(styleText); } // Simple selectors: incremental. @@ -462,8 +466,15 @@ var domFilterer = { this.runJob(this.jobQueue[i], complexHideNode); } + // https://github.com/gorhill/uBlock/issues/1912 + // If one or more nodes have been manually hidden, insert a style tag + // targeting these manually hidden nodes. For browsers supporting + // user styles, this allows uBO to win. var commitHit = this.hiddenNodeCount !== beforeHiddenNodeCount; if ( commitHit ) { + if ( beforeHiddenNodeCount === 0 ) { + this.addStyleTag(':root *[' + this.hiddenId + '][hidden] { display: none !important; }'); + } this.addedNodesHandlerMissCount = 0; } else { this.addedNodesHandlerMissCount += 1;