mirror of https://github.com/gorhill/uBlock.git
Add any-delay to timeout/interval boosters
Using `*` as delay argument will match any delay. As per internal feedback from filter list maintainers.
This commit is contained in:
parent
5657bc466c
commit
001f5a6500
|
@ -468,40 +468,40 @@
|
||||||
// to match all.
|
// to match all.
|
||||||
// delayMatcher
|
// delayMatcher
|
||||||
// The delay matcher, an integer, defaults to 1000.
|
// The delay matcher, an integer, defaults to 1000.
|
||||||
|
// Use `*` to match any delay.
|
||||||
// boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
|
// boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
|
||||||
// 2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
|
// 2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
|
||||||
// 20 times. Speed up and down both cap at 50 times.
|
// 20 times. Speed up and down both cap at 50 times.
|
||||||
/// nano-setInterval-booster.js
|
/// nano-setInterval-booster.js
|
||||||
/// alias nano-sib.js
|
/// alias nano-sib.js
|
||||||
(function() {
|
(function() {
|
||||||
let needle = '{{1}}';
|
let needleArg = '{{1}}';
|
||||||
let delay = parseInt('{{2}}', 10);
|
if ( needleArg === '{{1}}' ) { needleArg = ''; }
|
||||||
let boost = parseFloat('{{3}}');
|
let delayArg = '{{2}}';
|
||||||
if ( needle === '' || needle === '{{1}}' ) {
|
if ( delayArg === '{{2}}' ) { delayArg = ''; }
|
||||||
needle = '.?';
|
let boostArg = '{{3}}';
|
||||||
} else if ( needle.charAt(0) === '/' && needle.slice(-1) === '/' ) {
|
if ( boostArg === '{{3}}' ) { boostArg = ''; }
|
||||||
needle = needle.slice(1, -1);
|
if ( needleArg === '' ) {
|
||||||
|
needleArg = '.?';
|
||||||
|
} else if ( needleArg.charAt(0) === '/' && needleArg.slice(-1) === '/' ) {
|
||||||
|
needleArg = needleArg.slice(1, -1);
|
||||||
} else {
|
} else {
|
||||||
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
needleArg = needleArg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
}
|
}
|
||||||
needle = new RegExp(needle);
|
const reNeedle = new RegExp(needleArg);
|
||||||
if ( isNaN(delay) || !isFinite(delay) ) {
|
let delay = delayArg !== '*' ? parseInt(delayArg, 10) : -1;
|
||||||
delay = 1000;
|
if ( isNaN(delay) || isFinite(delay) === false ) { delay = 1000; }
|
||||||
}
|
let boost = parseFloat(boostArg);
|
||||||
if ( isNaN(boost) || !isFinite(boost) ) {
|
boost = isNaN(boost) === false && isFinite(boost)
|
||||||
boost = 0.05;
|
? Math.min(Math.max(boost, 0.02), 50)
|
||||||
}
|
: 0.05;
|
||||||
if ( boost < 0.02 ) {
|
self.setInterval = new Proxy(self.setInterval, {
|
||||||
boost = 0.02;
|
|
||||||
}
|
|
||||||
if ( boost > 50 ) {
|
|
||||||
boost = 50;
|
|
||||||
}
|
|
||||||
window.setInterval = new Proxy(window.setInterval, {
|
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
const a = args[0];
|
const [ a, b ] = args;
|
||||||
const b = args[1];
|
if (
|
||||||
if ( b === delay && needle.test(a.toString()) ) {
|
(delay === -1 || b === delay) &&
|
||||||
|
reNeedle.test(a.toString())
|
||||||
|
) {
|
||||||
args[1] = b * boost;
|
args[1] = b * boost;
|
||||||
}
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
|
@ -519,40 +519,40 @@
|
||||||
// to match all.
|
// to match all.
|
||||||
// delayMatcher
|
// delayMatcher
|
||||||
// The delay matcher, an integer, defaults to 1000.
|
// The delay matcher, an integer, defaults to 1000.
|
||||||
|
// Use `*` to match any delay.
|
||||||
// boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
|
// boostRatio - The delay multiplier when there is a match, 0.5 speeds up by
|
||||||
// 2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
|
// 2 times and 2 slows down by 2 times, defaults to 0.05 or speed up
|
||||||
// 20 times. Speed up and down both cap at 50 times.
|
// 20 times. Speed up and down both cap at 50 times.
|
||||||
/// nano-setTimeout-booster.js
|
/// nano-setTimeout-booster.js
|
||||||
/// alias nano-stb.js
|
/// alias nano-stb.js
|
||||||
(function() {
|
(function() {
|
||||||
let needle = '{{1}}';
|
let needleArg = '{{1}}';
|
||||||
let delay = parseInt('{{2}}', 10);
|
if ( needleArg === '{{1}}' ) { needleArg = ''; }
|
||||||
let boost = parseFloat('{{3}}');
|
let delayArg = '{{2}}';
|
||||||
if ( needle === '' || needle === '{{1}}' ) {
|
if ( delayArg === '{{2}}' ) { delayArg = ''; }
|
||||||
needle = '.?';
|
let boostArg = '{{3}}';
|
||||||
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
if ( boostArg === '{{3}}' ) { boostArg = ''; }
|
||||||
needle = needle.slice(1, -1);
|
if ( needleArg === '' ) {
|
||||||
|
needleArg = '.?';
|
||||||
|
} else if ( needleArg.charAt(0) === '/' && needleArg.slice(-1) === '/' ) {
|
||||||
|
needleArg = needleArg.slice(1, -1);
|
||||||
} else {
|
} else {
|
||||||
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
needleArg = needleArg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
}
|
}
|
||||||
needle = new RegExp(needle);
|
const reNeedle = new RegExp(needleArg);
|
||||||
if ( isNaN(delay) || !isFinite(delay) ) {
|
let delay = delayArg !== '*' ? parseInt(delayArg, 10) : -1;
|
||||||
delay = 1000;
|
if ( isNaN(delay) || isFinite(delay) === false ) { delay = 1000; }
|
||||||
}
|
let boost = parseFloat(boostArg);
|
||||||
if ( isNaN(boost) || !isFinite(boost) ) {
|
boost = isNaN(boost) === false && isFinite(boost)
|
||||||
boost = 0.05;
|
? Math.min(Math.max(boost, 0.02), 50)
|
||||||
}
|
: 0.05;
|
||||||
if ( boost < 0.02 ) {
|
self.setTimeout = new Proxy(self.setTimeout, {
|
||||||
boost = 0.02;
|
|
||||||
}
|
|
||||||
if ( boost > 50 ) {
|
|
||||||
boost = 50;
|
|
||||||
}
|
|
||||||
window.setTimeout = new Proxy(window.setTimeout, {
|
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
const a = args[0];
|
const [ a, b ] = args;
|
||||||
const b = args[1];
|
if (
|
||||||
if ( b === delay && needle.test(a.toString()) ) {
|
(delay === -1 || b === delay) &&
|
||||||
|
reNeedle.test(a.toString())
|
||||||
|
) {
|
||||||
args[1] = b * boost;
|
args[1] = b * boost;
|
||||||
}
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
|
|
Loading…
Reference in New Issue