mirror of https://github.com/gorhill/uBlock.git
Ignore pseudo-elements when querying selectors in element picker
Related issue: - https://github.com/gorhill/uBlock/issues/2515
This commit is contained in:
parent
aaee898d95
commit
8d136ec2d5
|
@ -698,6 +698,7 @@ const filtersFrom = function(x, y) {
|
||||||
const filterToDOMInterface = (( ) => {
|
const filterToDOMInterface = (( ) => {
|
||||||
const reHnAnchorPrefix = '^[\\w-]+://(?:[^/?#]+\\.)?';
|
const reHnAnchorPrefix = '^[\\w-]+://(?:[^/?#]+\\.)?';
|
||||||
const reCaret = '(?:[^%.0-9a-z_-]|$)';
|
const reCaret = '(?:[^%.0-9a-z_-]|$)';
|
||||||
|
const rePseudoElements = /::?(?:after|before)$/;
|
||||||
|
|
||||||
// Net filters: we need to lookup manually -- translating into a foolproof
|
// Net filters: we need to lookup manually -- translating into a foolproof
|
||||||
// CSS selector is just not possible.
|
// CSS selector is just not possible.
|
||||||
|
@ -795,11 +796,16 @@ const filterToDOMInterface = (( ) => {
|
||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/389
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/389
|
||||||
// Test filter using comma-separated list to better detect invalid CSS
|
// Test filter using comma-separated list to better detect invalid CSS
|
||||||
// selectors.
|
// selectors.
|
||||||
|
//
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2515
|
||||||
|
// Remove trailing pseudo-element when querying.
|
||||||
const fromPlainCosmeticFilter = function(raw) {
|
const fromPlainCosmeticFilter = function(raw) {
|
||||||
let elems;
|
let elems;
|
||||||
try {
|
try {
|
||||||
document.documentElement.matches(`${raw},\na`);
|
document.documentElement.matches(`${raw},\na`);
|
||||||
elems = document.querySelectorAll(raw);
|
elems = document.querySelectorAll(
|
||||||
|
raw.replace(rePseudoElements, '')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return;
|
return;
|
||||||
|
@ -814,21 +820,25 @@ const filterToDOMInterface = (( ) => {
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/1772
|
// https://github.com/gorhill/uBlock/issues/1772
|
||||||
// Handle procedural cosmetic filters.
|
// Handle procedural cosmetic filters.
|
||||||
|
//
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2515
|
||||||
|
// Remove trailing pseudo-element when querying.
|
||||||
const fromCompiledCosmeticFilter = function(raw) {
|
const fromCompiledCosmeticFilter = function(raw) {
|
||||||
if ( typeof raw !== 'string' ) { return; }
|
if ( typeof raw !== 'string' ) { return; }
|
||||||
let o;
|
|
||||||
try {
|
|
||||||
o = JSON.parse(raw);
|
|
||||||
} catch(ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let elems;
|
let elems;
|
||||||
|
try {
|
||||||
|
const o = JSON.parse(raw);
|
||||||
if ( o.style ) {
|
if ( o.style ) {
|
||||||
elems = document.querySelectorAll(o.style[0]);
|
elems = document.querySelectorAll(
|
||||||
|
o.style[0].replace(rePseudoElements, '')
|
||||||
|
);
|
||||||
lastAction = o.style[0] + ' {' + o.style[1] + '}';
|
lastAction = o.style[0] + ' {' + o.style[1] + '}';
|
||||||
} else if ( o.tasks ) {
|
} else if ( o.tasks ) {
|
||||||
elems = vAPI.domFilterer.createProceduralFilter(o).exec();
|
elems = vAPI.domFilterer.createProceduralFilter(o).exec();
|
||||||
}
|
}
|
||||||
|
} catch(ex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ( !elems ) { return; }
|
if ( !elems ) { return; }
|
||||||
const out = [];
|
const out = [];
|
||||||
for ( const elem of elems ) {
|
for ( const elem of elems ) {
|
||||||
|
|
Loading…
Reference in New Issue