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:
Raymond Hill 2019-08-24 13:54:31 -04:00
parent e0b8cf24d1
commit e0f0aedad6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 26 additions and 12 deletions

View File

@ -530,9 +530,12 @@
/// alias siif.js
(function() {
let needle = '{{1}}';
const not = needle.charAt(0) === '!';
if ( not ) { needle = needle.slice(1); }
const delay = parseInt('{{2}}', 10);
const needleNot = needle.charAt(0) === '!';
if ( needleNot ) { needle = needle.slice(1); }
let delay = '{{2}}';
const delayNot = delay.charAt(0) === '!';
if ( delayNot ) { delay = delay.slice(1); }
delay = parseInt(delay, 10);
if ( needle === '' || needle === '{{1}}' ) {
needle = '.?';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
@ -540,7 +543,8 @@
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = not === false && needle === '.?' && isNaN(delay)
const log = needleNot === false && needle === '.?' &&
delayNot === false && isNaN(delay)
? console.log
: undefined;
needle = new RegExp(needle);
@ -551,8 +555,11 @@
if ( log !== undefined ) {
log('uBO: setInterval("%s", %s)', a, b);
} 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(){};
}
@ -592,9 +599,12 @@
/// alias stif.js
(function() {
let needle = '{{1}}';
const not = needle.charAt(0) === '!';
if ( not ) { needle = needle.slice(1); }
const delay = parseInt('{{2}}', 10);
const needleNot = needle.charAt(0) === '!';
if ( needleNot ) { needle = needle.slice(1); }
let delay = '{{2}}';
const delayNot = delay.charAt(0) === '!';
if ( delayNot ) { delay = delay.slice(1); }
delay = parseInt(delay, 10);
if ( needle === '' || needle === '{{1}}' ) {
needle = '.?';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
@ -602,7 +612,8 @@
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = not === false && needle === '.?' && isNaN(delay)
const log = needleNot === false && needle === '.?' &&
delayNot === false && isNaN(delay)
? console.log
: undefined;
needle = new RegExp(needle);
@ -613,8 +624,11 @@
if ( log !== undefined ) {
log('uBO: setTimeout("%s", %s)', a, b);
} 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(){};
}