1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-18 08:52:26 +02:00

Allow :upward() operator to select html element

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/hvwwj0/element_hiding_by_url_not_by_domain_is_it_possible/fyzykw0/
This commit is contained in:
Raymond Hill 2020-07-30 11:58:49 -04:00
parent 2931b4181f
commit 7dd48a6c8c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -573,8 +573,12 @@ vAPI.injectScriptlet = function(doc, text) {
const PSelectorSpathTask = class {
constructor(task) {
this.spath = task[1];
this.nth = /^(?:\s*[+~]|:)/.test(this.spath);
}
transpose(node, output) {
qsa(node) {
if ( this.nth === false ) {
return node.querySelectorAll(this.spath);
}
const parent = node.parentElement;
if ( parent === null ) { return; }
let pos = 1;
@ -583,9 +587,13 @@ vAPI.injectScriptlet = function(doc, text) {
if ( node === null ) { break; }
pos += 1;
}
const nodes = parent.querySelectorAll(
return parent.querySelectorAll(
`:scope > :nth-child(${pos})${this.spath}`
);
}
transpose(node, output) {
const nodes = this.qsa(node);
if ( nodes === undefined ) { return; }
for ( const node of nodes ) {
output.push(node);
}