Skip to content

Commit

Permalink
Allow :upward() operator to select html element
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill authored and hawkeye116477 committed Aug 11, 2020
1 parent 1a53571 commit c79db5c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,12 @@ vAPI.DOMFilterer = (function() {
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;
Expand All @@ -440,9 +444,13 @@ vAPI.DOMFilterer = (function() {
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 ( let node of nodes ) {
output.push(node);
}
Expand Down

0 comments on commit c79db5c

Please sign in to comment.