|
583 | 583 | })();
|
584 | 584 |
|
585 | 585 |
|
| 586 | +/// no-fetch-if.js |
| 587 | +(function() { |
| 588 | + let arg1 = '{{1}}'; |
| 589 | + if ( arg1 === '{{1}}' ) { arg1 = ''; } |
| 590 | + const needles = []; |
| 591 | + for ( const condition of arg1.split(/\s+/) ) { |
| 592 | + const pos = condition.indexOf(':'); |
| 593 | + let key, value; |
| 594 | + if ( pos !== -1 ) { |
| 595 | + key = condition.slice(0, pos); |
| 596 | + value = condition.slice(pos + 1); |
| 597 | + } else { |
| 598 | + key = 'url'; |
| 599 | + value = condition; |
| 600 | + } |
| 601 | + if ( value === '' ) { |
| 602 | + value = '^'; |
| 603 | + } else if ( value.startsWith('/') && value.endsWith('/') ) { |
| 604 | + value = value.slice(1, -1); |
| 605 | + } else { |
| 606 | + value = value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 607 | + } |
| 608 | + needles.push({ key, re: new RegExp(value) }); |
| 609 | + } |
| 610 | + self.fetch = new Proxy(self.fetch, { |
| 611 | + apply: function(target, thisArg, args) { |
| 612 | + let proceed = true; |
| 613 | + try { |
| 614 | + const url = args[0] instanceof self.Request |
| 615 | + ? args[0].url |
| 616 | + : args[0]; |
| 617 | + const props = new Map([ [ 'url', url ] ]); |
| 618 | + const init = args[1]; |
| 619 | + if ( init instanceof Object ) { |
| 620 | + for ( const prop in init ) { |
| 621 | + if ( init.hasOwnProperty(prop) === false ) { continue; } |
| 622 | + props.set( prop, init[prop]); |
| 623 | + } |
| 624 | + } |
| 625 | + proceed = false; |
| 626 | + for ( const { key, re } of needles ) { |
| 627 | + if ( |
| 628 | + props.has(key) === false || |
| 629 | + re.test(props.get(key)) === false |
| 630 | + ) { |
| 631 | + proceed = true; |
| 632 | + break; |
| 633 | + } |
| 634 | + } |
| 635 | + } catch(ex) { |
| 636 | + } |
| 637 | + return proceed |
| 638 | + ? Reflect.apply(target, thisArg, args) |
| 639 | + : Promise.resolve(new Response()); |
| 640 | + } |
| 641 | + }); |
| 642 | +})(); |
| 643 | + |
| 644 | + |
586 | 645 | /// remove-attr.js
|
587 | 646 | /// alias ra.js
|
588 | 647 | (function() {
|
|
646 | 705 | })();
|
647 | 706 |
|
648 | 707 |
|
649 |
| -/// requestAnimationFrame-if.js |
650 |
| -/// alias raf-if.js |
651 |
| -// Deprecated, use "no-requestAnimationFrame-if.js" |
652 |
| -(function() { |
653 |
| - let needle = '{{1}}'; |
654 |
| - const not = needle.charAt(0) === '!'; |
655 |
| - if ( not ) { needle = needle.slice(1); } |
656 |
| - if ( needle === '' || needle === '{{1}}' ) { |
657 |
| - needle = '.?'; |
658 |
| - } else if ( needle.startsWith('/') && needle.endsWith('/') ) { |
659 |
| - needle = needle.slice(1,-1); |
660 |
| - } else { |
661 |
| - needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
662 |
| - } |
663 |
| - const log = needle === '.?' && not === false ? console.log : undefined; |
664 |
| - needle = new RegExp(needle); |
665 |
| - window.requestAnimationFrame = new Proxy(window.requestAnimationFrame, { |
666 |
| - apply: function(target, thisArg, args) { |
667 |
| - const a = String(args[0]); |
668 |
| - if ( log !== undefined ) { |
669 |
| - log('uBO: requestAnimationFrame("%s")', a); |
670 |
| - } else if ( needle.test(a) === not ) { |
671 |
| - args[0] = function(){}; |
672 |
| - } |
673 |
| - return target.apply(thisArg, args); |
674 |
| - } |
675 |
| - }); |
676 |
| -})(); |
677 |
| - |
678 |
| - |
679 | 708 | /// no-requestAnimationFrame-if.js
|
680 | 709 | /// alias norafif.js
|
681 | 710 | (function() {
|
|
827 | 856 | })();
|
828 | 857 |
|
829 | 858 |
|
830 |
| -/// setInterval-defuser.js |
831 |
| -/// alias sid.js |
832 |
| -(function() { |
833 |
| - let needle = '{{1}}'; |
834 |
| - const delay = parseInt('{{2}}', 10); |
835 |
| - if ( needle === '' || needle === '{{1}}' ) { |
836 |
| - needle = '.?'; |
837 |
| - } else if ( needle.startsWith('/') && needle.endsWith('/') ) { |
838 |
| - needle = needle.slice(1,-1); |
839 |
| - } else { |
840 |
| - needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
841 |
| - } |
842 |
| - needle = new RegExp(needle); |
843 |
| - window.setInterval = new Proxy(window.setInterval, { |
844 |
| - apply: function(target, thisArg, args) { |
845 |
| - const a = args[0]; |
846 |
| - const b = args[1]; |
847 |
| - if ( (isNaN(delay) || b === delay) && needle.test(a.toString()) ) { |
848 |
| - args[0] = function(){}; |
849 |
| - } |
850 |
| - return target.apply(thisArg, args); |
851 |
| - } |
852 |
| - }); |
853 |
| -})(); |
854 |
| - |
855 |
| - |
856 | 859 | /// no-setInterval-if.js
|
857 | 860 | /// alias nosiif.js
|
858 | 861 | (function() {
|
|
902 | 905 | })();
|
903 | 906 |
|
904 | 907 |
|
905 |
| -/// setTimeout-defuser.js |
906 |
| -/// alias std.js |
907 |
| -(function() { |
908 |
| - let needle = '{{1}}'; |
909 |
| - const delay = parseInt('{{2}}', 10); |
910 |
| - if ( needle === '' || needle === '{{1}}' ) { |
911 |
| - needle = '.?'; |
912 |
| - } else if ( needle.startsWith('/') && needle.endsWith('/') ) { |
913 |
| - needle = needle.slice(1,-1); |
914 |
| - } else { |
915 |
| - needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
916 |
| - } |
917 |
| - needle = new RegExp(needle); |
918 |
| - window.setTimeout = new Proxy(window.setTimeout, { |
919 |
| - apply: function(target, thisArg, args) { |
920 |
| - const a = args[0]; |
921 |
| - const b = args[1]; |
922 |
| - if ( (isNaN(delay) || b === delay) && needle.test(a.toString()) ) { |
923 |
| - args[0] = function(){}; |
924 |
| - } |
925 |
| - return target.apply(thisArg, args); |
926 |
| - } |
927 |
| - }); |
928 |
| -})(); |
929 |
| - |
930 |
| - |
931 | 908 | /// no-setTimeout-if.js
|
932 | 909 | /// alias nostif.js
|
| 910 | +/// alias setTimeout-defuser.js |
933 | 911 | (function() {
|
934 | 912 | let needle = '{{1}}';
|
935 | 913 | const needleNot = needle.charAt(0) === '!';
|
|
0 commit comments