diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 1aaac401b..de3b8c720 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -828,7 +828,8 @@ FilterContainer.prototype.cssRuleFromProcedural = function(json) { if ( pfilter.cssable !== true ) { return; } const { tasks, action } = pfilter; let mq; - if ( tasks !== undefined && tasks.length === 1 ) { + if ( tasks !== undefined ) { + if ( tasks.length > 1 ) { return; } if ( tasks[0][0] !== ':matches-media' ) { return; } mq = tasks[0][1]; } diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 919169559..985019292 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1862,9 +1862,6 @@ Parser.prototype.SelectorCompiler = class { } const out = { selector: prefix }; - if ( root && this.sheetSelectable(prefix) ) { - out.cssable = true; - } if ( tasks.length !== 0 ) { out.tasks = tasks; @@ -1875,6 +1872,19 @@ Parser.prototype.SelectorCompiler = class { out.action = action; } + // Flag to quickly find out whether the filter can be converted into + // a declarative CSS rule. + if ( + root && + (action === undefined || action[0] === ':style') && + ( + tasks.length === 0 || + tasks.length === 1 && tasks[0][0] === ':matches-media' + ) + ) { + out.cssable = this.sheetSelectable(prefix); + } + return out; }