@@ -698,6 +698,7 @@ const filtersFrom = function(x, y) {
698
698
const filterToDOMInterface = ( ( ) => {
699
699
const reHnAnchorPrefix = '^[\\w-]+://(?:[^/?#]+\\.)?' ;
700
700
const reCaret = '(?:[^%.0-9a-z_-]|$)' ;
701
+ const rePseudoElements = / : : ? (?: a f t e r | b e f o r e ) $ / ;
701
702
702
703
// Net filters: we need to lookup manually -- translating into a foolproof
703
704
// CSS selector is just not possible.
@@ -795,11 +796,16 @@ const filterToDOMInterface = (( ) => {
795
796
// https://github.com/uBlockOrigin/uBlock-issues/issues/389
796
797
// Test filter using comma-separated list to better detect invalid CSS
797
798
// selectors.
799
+ //
800
+ // https://github.com/gorhill/uBlock/issues/2515
801
+ // Remove trailing pseudo-element when querying.
798
802
const fromPlainCosmeticFilter = function ( raw ) {
799
803
let elems ;
800
804
try {
801
805
document . documentElement . matches ( `${ raw } ,\na` ) ;
802
- elems = document . querySelectorAll ( raw ) ;
806
+ elems = document . querySelectorAll (
807
+ raw . replace ( rePseudoElements , '' )
808
+ ) ;
803
809
}
804
810
catch ( e ) {
805
811
return ;
@@ -814,21 +820,25 @@ const filterToDOMInterface = (( ) => {
814
820
815
821
// https://github.com/gorhill/uBlock/issues/1772
816
822
// Handle procedural cosmetic filters.
823
+ //
824
+ // https://github.com/gorhill/uBlock/issues/2515
825
+ // Remove trailing pseudo-element when querying.
817
826
const fromCompiledCosmeticFilter = function ( raw ) {
818
827
if ( typeof raw !== 'string' ) { return ; }
819
- let o ;
828
+ let elems ;
820
829
try {
821
- o = JSON . parse ( raw ) ;
830
+ const o = JSON . parse ( raw ) ;
831
+ if ( o . style ) {
832
+ elems = document . querySelectorAll (
833
+ o . style [ 0 ] . replace ( rePseudoElements , '' )
834
+ ) ;
835
+ lastAction = o . style [ 0 ] + ' {' + o . style [ 1 ] + '}' ;
836
+ } else if ( o . tasks ) {
837
+ elems = vAPI . domFilterer . createProceduralFilter ( o ) . exec ( ) ;
838
+ }
822
839
} catch ( ex ) {
823
840
return ;
824
841
}
825
- let elems ;
826
- if ( o . style ) {
827
- elems = document . querySelectorAll ( o . style [ 0 ] ) ;
828
- lastAction = o . style [ 0 ] + ' {' + o . style [ 1 ] + '}' ;
829
- } else if ( o . tasks ) {
830
- elems = vAPI . domFilterer . createProceduralFilter ( o ) . exec ( ) ;
831
- }
832
842
if ( ! elems ) { return ; }
833
843
const out = [ ] ;
834
844
for ( const elem of elems ) {
0 commit comments