A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/gorhill/uBlock/commit/41685f4cce084f3f89e9cdd8fc1cde5b57862958 below:

Replace `exec` with `transpose` in procedural filters · gorhill/uBlock@41685f4 · GitHub

@@ -469,39 +469,28 @@ vAPI.DOMFilterer = (function() {

469 469

}

470 470

this.needle = new RegExp(arg0, arg1);

471 471

}

472 -

exec(input) {

473 -

const output = [];

474 -

for ( const node of input ) {

475 -

if ( this.needle.test(node.textContent) ) {

476 -

output.push(node);

477 -

}

472 +

transpose(node, output) {

473 +

if ( this.needle.test(node.textContent) ) {

474 +

output.push(node);

478 475

}

479 -

return output;

480 476

}

481 477

};

482 478 483 479

const PSelectorIfTask = class {

484 480

constructor(task) {

485 481

this.pselector = new PSelector(task[1]);

486 482

}

487 -

exec(input) {

488 -

const output = [];

489 -

for ( const node of input ) {

490 -

if ( this.pselector.test(node) === this.target ) {

491 -

output.push(node);

492 -

}

483 +

transpose(node, output) {

484 +

if ( this.pselector.test(node) === this.target ) {

485 +

output.push(node);

493 486

}

494 -

return output;

495 487

}

496 488

};

497 489

PSelectorIfTask.prototype.target = true;

498 490 499 491

const PSelectorIfNotTask = class extends PSelectorIfTask {

500 -

constructor(task) {

501 -

super(task);

502 -

this.target = false;

503 -

}

504 492

};

493 +

PSelectorIfNotTask.prototype.target = false;

505 494 506 495

const PSelectorMatchesCSSTask = class {

507 496

constructor(task) {

@@ -512,93 +501,69 @@ vAPI.DOMFilterer = (function() {

512 501

}

513 502

this.value = new RegExp(arg0, arg1);

514 503

}

515 -

exec(input) {

516 -

const output = [];

517 -

for ( const node of input ) {

518 -

const style = window.getComputedStyle(node, this.pseudo);

519 -

if ( style === null ) { return null; } /* FF */

520 -

if ( this.value.test(style[this.name]) ) {

521 -

output.push(node);

522 -

}

504 +

transpose(node, output) {

505 +

const style = window.getComputedStyle(node, this.pseudo);

506 +

if ( style !== null && this.value.test(style[this.name]) ) {

507 +

output.push(node);

523 508

}

524 -

return output;

525 509

}

526 510

};

527 511

PSelectorMatchesCSSTask.prototype.pseudo = null;

528 512 529 513

const PSelectorMatchesCSSAfterTask = class extends PSelectorMatchesCSSTask {

530 -

constructor(task) {

531 -

super(task);

532 -

this.pseudo = ':after';

533 -

}

534 514

};

515 +

PSelectorMatchesCSSAfterTask.prototype.pseudo = ':after';

535 516 536 517

const PSelectorMatchesCSSBeforeTask = class extends PSelectorMatchesCSSTask {

537 -

constructor(task) {

538 -

super(task);

539 -

this.pseudo = ':before';

540 -

}

541 518

};

519 +

PSelectorMatchesCSSBeforeTask.prototype.pseudo = ':before';

542 520 543 521

const PSelectorMinTextLengthTask = class {

544 522

constructor(task) {

545 523

this.min = task[1];

546 524

}

547 -

exec(input) {

548 -

const output = [];

549 -

for ( const node of input ) {

550 -

if ( node.textContent.length >= this.min ) {

551 -

output.push(node);

552 -

}

525 +

transpose(node, output) {

526 +

if ( node.textContent.length >= this.min ) {

527 +

output.push(node);

553 528

}

554 -

return output;

555 529

}

556 530

};

557 531 558 532

const PSelectorNthAncestorTask = class {

559 533

constructor(task) {

560 534

this.nth = task[1];

561 535

}

562 -

exec(input) {

563 -

const output = [];

564 -

for ( let node of input ) {

565 -

let nth = this.nth;

566 -

for (;;) {

567 -

node = node.parentElement;

568 -

if ( node === null ) { break; }

569 -

nth -= 1;

570 -

if ( nth !== 0 ) { continue; }

571 -

output.push(node);

572 -

break;

573 -

}

536 +

transpose(node, output) {

537 +

let nth = this.nth;

538 +

for (;;) {

539 +

node = node.parentElement;

540 +

if ( node === null ) { return; }

541 +

nth -= 1;

542 +

if ( nth === 0 ) { break; }

574 543

}

575 -

return output;

544 +

output.push(node);

576 545

}

577 546

};

578 547 579 548

const PSelectorSpathTask = class {

580 549

constructor(task) {

581 550

this.spath = task[1];

582 551

}

583 -

exec(input) {

584 -

const output = [];

585 -

for ( let node of input ) {

586 -

const parent = node.parentElement;

587 -

if ( parent === null ) { continue; }

588 -

let pos = 1;

589 -

for (;;) {

590 -

node = node.previousElementSibling;

591 -

if ( node === null ) { break; }

592 -

pos += 1;

593 -

}

594 -

const nodes = parent.querySelectorAll(

595 -

':scope > :nth-child(' + pos + ')' + this.spath

596 -

);

597 -

for ( const node of nodes ) {

598 -

output.push(node);

599 -

}

552 +

transpose(node, output) {

553 +

const parent = node.parentElement;

554 +

if ( parent === null ) { return; }

555 +

let pos = 1;

556 +

for (;;) {

557 +

node = node.previousElementSibling;

558 +

if ( node === null ) { break; }

559 +

pos += 1;

560 +

}

561 +

const nodes = parent.querySelectorAll(

562 +

`:scope > :nth-child(${pos})${this.spath}`

563 +

);

564 +

for ( const node of nodes ) {

565 +

output.push(node);

600 566

}

601 -

return output;

602 567

}

603 568

};

604 569

@@ -623,17 +588,14 @@ vAPI.DOMFilterer = (function() {

623 588

filterer.onDOMChanged([ null ]);

624 589

}

625 590

}

626 -

exec(input) {

627 -

if ( input.length === 0 ) { return input; }

591 +

transpose(node, output) {

592 +

output.push(node);

593 +

if ( this.observed.has(node) ) { return; }

628 594

if ( this.observer === null ) {

629 595

this.observer = new MutationObserver(this.handler);

630 596

}

631 -

for ( const node of input ) {

632 -

if ( this.observed.has(node) ) { continue; }

633 -

this.observer.observe(node, this.observerOptions);

634 -

this.observed.add(node);

635 -

}

636 -

return input;

597 +

this.observer.observe(node, this.observerOptions);

598 +

this.observed.add(node);

637 599

}

638 600

};

639 601

@@ -642,23 +604,19 @@ vAPI.DOMFilterer = (function() {

642 604

this.xpe = document.createExpression(task[1], null);

643 605

this.xpr = null;

644 606

}

645 -

exec(input) {

646 -

const output = [];

647 -

for ( const node of input ) {

648 -

this.xpr = this.xpe.evaluate(

649 -

node,

650 -

XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,

651 -

this.xpr

652 -

);

653 -

let j = this.xpr.snapshotLength;

654 -

while ( j-- ) {

655 -

const node = this.xpr.snapshotItem(j);

656 -

if ( node.nodeType === 1 ) {

657 -

output.push(node);

658 -

}

607 +

transpose(node, output) {

608 +

this.xpr = this.xpe.evaluate(

609 +

node,

610 +

XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,

611 +

this.xpr

612 +

);

613 +

let j = this.xpr.snapshotLength;

614 +

while ( j-- ) {

615 +

const node = this.xpr.snapshotItem(j);

616 +

if ( node.nodeType === 1 ) {

617 +

output.push(node);

659 618

}

660 619

}

661 -

return output;

662 620

}

663 621

};

664 622

@@ -677,7 +635,7 @@ vAPI.DOMFilterer = (function() {

677 635

[ ':not', PSelectorIfNotTask ],

678 636

[ ':nth-ancestor', PSelectorNthAncestorTask ],

679 637

[ ':spath', PSelectorSpathTask ],

680 -

[ ':watch-attrs', PSelectorWatchAttrs ],

638 +

[ ':watch-attr', PSelectorWatchAttrs ],

681 639

[ ':xpath', PSelectorXpathTask ],

682 640

]);

683 641

}

@@ -704,21 +662,27 @@ vAPI.DOMFilterer = (function() {

704 662

let nodes = this.prime(input);

705 663

for ( const task of this.tasks ) {

706 664

if ( nodes.length === 0 ) { break; }

707 -

nodes = task.exec(nodes);

665 +

const transposed = [];

666 +

for ( const node of nodes ) {

667 +

task.transpose(node, transposed);

668 +

}

669 +

nodes = transposed;

708 670

}

709 671

return nodes;

710 672

}

711 673

test(input) {

712 674

const nodes = this.prime(input);

713 -

const AA = [ null ];

714 675

for ( const node of nodes ) {

715 -

AA[0] = node;

716 -

let aa = AA;

676 +

let output = [ node ];

717 677

for ( const task of this.tasks ) {

718 -

aa = task.exec(aa);

719 -

if ( aa.length === 0 ) { break; }

678 +

const transposed = [];

679 +

for ( const node of output ) {

680 +

task.transpose(node, transposed);

681 +

}

682 +

output = transposed;

683 +

if ( output.length === 0 ) { break; }

720 684

}

721 -

if ( aa.length !== 0 ) { return true; }

685 +

if ( output.length !== 0 ) { return true; }

722 686

}

723 687

return false;

724 688

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4