mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Be more flexible when converting procedural to declarative
Allows for the selector part to come after :media-matches().
This commit is contained in:
parent
07fae6a0d1
commit
9f2bfecd27
@ -105,25 +105,30 @@ if ( selectors.length === 0 ) { return; }
|
|||||||
|
|
||||||
const cssRuleFromProcedural = details => {
|
const cssRuleFromProcedural = details => {
|
||||||
const { tasks, action } = details;
|
const { tasks, action } = details;
|
||||||
let mq;
|
let mq, selector;
|
||||||
if ( tasks !== undefined ) {
|
if ( Array.isArray(tasks) ) {
|
||||||
if ( tasks.length > 1 ) { return; }
|
|
||||||
if ( tasks[0][0] !== 'matches-media' ) { return; }
|
if ( tasks[0][0] !== 'matches-media' ) { return; }
|
||||||
mq = tasks[0][1];
|
mq = tasks[0][1];
|
||||||
|
if ( tasks.length > 2 ) { return; }
|
||||||
|
if ( tasks.length === 2 ) {
|
||||||
|
if ( tasks[1][0] !== 'spath' ) { return; }
|
||||||
|
selector = tasks[1][1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let style;
|
let style;
|
||||||
if ( Array.isArray(action) ) {
|
if ( Array.isArray(action) ) {
|
||||||
if ( action[0] !== 'style' ) { return; }
|
if ( action[0] !== 'style' ) { return; }
|
||||||
|
selector = selector || details.selector;
|
||||||
style = action[1];
|
style = action[1];
|
||||||
}
|
}
|
||||||
if ( mq === undefined && style === undefined ) { return; }
|
if ( mq === undefined && style === undefined && selector === undefined ) { return; }
|
||||||
if ( mq === undefined ) {
|
if ( mq === undefined ) {
|
||||||
return `${details.selector}\n{${style}}`;
|
return `${selector}\n{${style}}`;
|
||||||
}
|
}
|
||||||
if ( style === undefined ) {
|
if ( style === undefined ) {
|
||||||
return `@media ${mq} {\n${details.selector}\n{display:none!important;}\n}`;
|
return `@media ${mq} {\n${selector}\n{display:none!important;}\n}`;
|
||||||
}
|
}
|
||||||
return `@media ${mq} {\n${details.selector}\n{${style}}\n}`;
|
return `@media ${mq} {\n${selector}\n{${style}}\n}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sheetText = [];
|
const sheetText = [];
|
||||||
|
@ -3115,7 +3115,10 @@ class ExtSelectorCompiler {
|
|||||||
if ( Array.isArray(r.tasks) === false ) { return true; }
|
if ( Array.isArray(r.tasks) === false ) { return true; }
|
||||||
if ( r.tasks[0][0] === 'matches-media' ) {
|
if ( r.tasks[0][0] === 'matches-media' ) {
|
||||||
if ( r.tasks.length === 1 ) { return true; }
|
if ( r.tasks.length === 1 ) { return true; }
|
||||||
if ( r.tasks.length === 2 && r.tasks[1][0] === 'spath' ) { return true; }
|
if ( r.tasks.length === 2 ) {
|
||||||
|
if ( r.selector !== '' ) { return false; }
|
||||||
|
if ( r.tasks[1][0] === 'spath' ) { return true; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user