mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-03 01:29:39 +02:00
Ability to negate delay in new setTimeout-if scriptlet
This also apply to setInterval-if. Thus to defuse calls to setTimeout(fn, 1000), the filter could be: ##+js(stif, , !1000) Meaning "allow setTimeout if the delay is not 1000".
This commit is contained in:
parent
e0b8cf24d1
commit
e0f0aedad6
@ -530,9 +530,12 @@
|
|||||||
/// alias siif.js
|
/// alias siif.js
|
||||||
(function() {
|
(function() {
|
||||||
let needle = '{{1}}';
|
let needle = '{{1}}';
|
||||||
const not = needle.charAt(0) === '!';
|
const needleNot = needle.charAt(0) === '!';
|
||||||
if ( not ) { needle = needle.slice(1); }
|
if ( needleNot ) { needle = needle.slice(1); }
|
||||||
const delay = parseInt('{{2}}', 10);
|
let delay = '{{2}}';
|
||||||
|
const delayNot = delay.charAt(0) === '!';
|
||||||
|
if ( delayNot ) { delay = delay.slice(1); }
|
||||||
|
delay = parseInt(delay, 10);
|
||||||
if ( needle === '' || needle === '{{1}}' ) {
|
if ( needle === '' || needle === '{{1}}' ) {
|
||||||
needle = '.?';
|
needle = '.?';
|
||||||
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
||||||
@ -540,7 +543,8 @@
|
|||||||
} else {
|
} else {
|
||||||
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
}
|
}
|
||||||
const log = not === false && needle === '.?' && isNaN(delay)
|
const log = needleNot === false && needle === '.?' &&
|
||||||
|
delayNot === false && isNaN(delay)
|
||||||
? console.log
|
? console.log
|
||||||
: undefined;
|
: undefined;
|
||||||
needle = new RegExp(needle);
|
needle = new RegExp(needle);
|
||||||
@ -551,8 +555,11 @@
|
|||||||
if ( log !== undefined ) {
|
if ( log !== undefined ) {
|
||||||
log('uBO: setInterval("%s", %s)', a, b);
|
log('uBO: setInterval("%s", %s)', a, b);
|
||||||
} else if (
|
} else if (
|
||||||
(isNaN(delay) || b === delay) &&
|
(
|
||||||
needle.test(a) === not
|
isNaN(delay) && (delayNot || needleNot) ||
|
||||||
|
isNaN(delay) === false && (b === delay) === delayNot
|
||||||
|
) &&
|
||||||
|
(needle.test(a) === needleNot)
|
||||||
) {
|
) {
|
||||||
args[0] = function(){};
|
args[0] = function(){};
|
||||||
}
|
}
|
||||||
@ -592,9 +599,12 @@
|
|||||||
/// alias stif.js
|
/// alias stif.js
|
||||||
(function() {
|
(function() {
|
||||||
let needle = '{{1}}';
|
let needle = '{{1}}';
|
||||||
const not = needle.charAt(0) === '!';
|
const needleNot = needle.charAt(0) === '!';
|
||||||
if ( not ) { needle = needle.slice(1); }
|
if ( needleNot ) { needle = needle.slice(1); }
|
||||||
const delay = parseInt('{{2}}', 10);
|
let delay = '{{2}}';
|
||||||
|
const delayNot = delay.charAt(0) === '!';
|
||||||
|
if ( delayNot ) { delay = delay.slice(1); }
|
||||||
|
delay = parseInt(delay, 10);
|
||||||
if ( needle === '' || needle === '{{1}}' ) {
|
if ( needle === '' || needle === '{{1}}' ) {
|
||||||
needle = '.?';
|
needle = '.?';
|
||||||
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
||||||
@ -602,7 +612,8 @@
|
|||||||
} else {
|
} else {
|
||||||
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
}
|
}
|
||||||
const log = not === false && needle === '.?' && isNaN(delay)
|
const log = needleNot === false && needle === '.?' &&
|
||||||
|
delayNot === false && isNaN(delay)
|
||||||
? console.log
|
? console.log
|
||||||
: undefined;
|
: undefined;
|
||||||
needle = new RegExp(needle);
|
needle = new RegExp(needle);
|
||||||
@ -613,8 +624,11 @@
|
|||||||
if ( log !== undefined ) {
|
if ( log !== undefined ) {
|
||||||
log('uBO: setTimeout("%s", %s)', a, b);
|
log('uBO: setTimeout("%s", %s)', a, b);
|
||||||
} else if (
|
} else if (
|
||||||
(isNaN(delay) || b === delay) &&
|
(
|
||||||
needle.test(a) === not
|
isNaN(delay) && (delayNot || needleNot) ||
|
||||||
|
isNaN(delay) === false && (b === delay) === delayNot
|
||||||
|
) &&
|
||||||
|
(needle.test(a) === needleNot)
|
||||||
) {
|
) {
|
||||||
args[0] = function(){};
|
args[0] = function(){};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user