Convert new setTimeout-if scriptlet to blacklist approach

As per feedback from filter list maintainers, the
whitelist approach has been deemed to confusing.

The scriptlet has been renamed `no-setTimeout-if`
alias `nostif` to reflect the blacklist approach.

`setInterval-if` has been Similarly changed to
`no-setInterval-if` alias `nosiif`.
This commit is contained in:
Raymond Hill 2019-09-15 11:01:50 -04:00
parent df49616ae8
commit 9367a6015b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 23 additions and 27 deletions

View File

@ -582,8 +582,8 @@
})(); })();
/// setInterval-if.js /// no-setInterval-if.js
/// alias siif.js /// alias nosiif.js
(function() { (function() {
let needle = '{{1}}'; let needle = '{{1}}';
const needleNot = needle.charAt(0) === '!'; const needleNot = needle.charAt(0) === '!';
@ -611,14 +611,12 @@
let defuse = false; let defuse = false;
if ( log !== undefined ) { if ( log !== undefined ) {
log('uBO: setInterval("%s", %s)', a, b); log('uBO: setInterval("%s", %s)', a, b);
} else if ( needle === '' && needleNot || isNaN(delay) && delayNot ) {
defuse = true;
} else if ( isNaN(delay) ) { } else if ( isNaN(delay) ) {
defuse = reNeedle.test(a) === needleNot; defuse = reNeedle.test(a) !== needleNot;
} else if ( needle === '' ) { } else if ( needle === '' ) {
defuse = (b === delay) === delayNot; defuse = (b === delay) !== delayNot;
} else if ( reNeedle.test(a) === needleNot || (b === delay) === delayNot ) { } else {
defuse = true; defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
} }
if ( defuse ) { if ( defuse ) {
args[0] = function(){}; args[0] = function(){};
@ -655,8 +653,8 @@
})(); })();
/// setTimeout-if.js /// no-setTimeout-if.js
/// alias stif.js /// alias nostif.js
(function() { (function() {
let needle = '{{1}}'; let needle = '{{1}}';
const needleNot = needle.charAt(0) === '!'; const needleNot = needle.charAt(0) === '!';
@ -684,14 +682,12 @@
let defuse = false; let defuse = false;
if ( log !== undefined ) { if ( log !== undefined ) {
log('uBO: setTimeout("%s", %s)', a, b); log('uBO: setTimeout("%s", %s)', a, b);
} else if ( needle === '' && needleNot || isNaN(delay) && delayNot ) {
defuse = true;
} else if ( isNaN(delay) ) { } else if ( isNaN(delay) ) {
defuse = reNeedle.test(a) === needleNot; defuse = reNeedle.test(a) !== needleNot;
} else if ( needle === '' ) { } else if ( needle === '' ) {
defuse = (b === delay) === delayNot; defuse = (b === delay) !== delayNot;
} else if ( reNeedle.test(a) === needleNot || (b === delay) === delayNot ) { } else {
defuse = true; defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
} }
if ( defuse ) { if ( defuse ) {
args[0] = function(){}; args[0] = function(){};

View File

@ -162,21 +162,21 @@ time. When you try a filter, ensure the result is what is expected.</p>
const hostname = self.location.hostname; const hostname = self.location.hostname;
const fragment = document.createDocumentFragment(); const fragment = document.createDocumentFragment();
const filters = [ const filters = [
[ [ '!bad' ], 'GGGG' ], [ [ 'bad' ], 'GGGG' ],
[ [ 'good' ], 'GGGG' ], [ [ '!good' ], 'GGGG' ],
[ [ '', '!33' ], 'GRRG' ], [ [ '', '33' ], 'GRRG' ],
[ [ '', '66' ], 'GRRG' ], [ [ '', '!66' ], 'GRRG' ],
[ [ '!bad', '!33' ], 'GGRG' ], [ [ 'bad', '33' ], 'GRGG' ],
[ [ 'good', '66' ], 'GGRG' ], [ [ '!good', '!66' ], 'GRGG' ],
[ [ '!bad', '33' ], 'GGGR' ], [ [ 'bad', '!33' ], 'RGGG' ],
[ [ 'good', '!66' ], 'GGGR' ], [ [ '!good', '66' ], 'RGGG' ],
[ [ 'bad', '!33' ], 'GRRR' ], [ [ '!bad', '33' ], 'RRRG' ],
[ [ '!good', '66' ], 'GRRR' ], [ [ 'good', '!66' ], 'RRRG' ],
]; ];
for ( const [ args, result ] of filters ) { for ( const [ args, result ] of filters ) {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
let td = document.createElement('td'); let td = document.createElement('td');
td.textContent = `${hostname}##+js(stif, ${args.join(', ')})`; td.textContent = `${hostname}##+js(nostif, ${args.join(', ')})`;
tr.appendChild(td); tr.appendChild(td);
td = document.createElement('td'); td = document.createElement('td');
for ( let i = 0; i < result.length; i++ ) { for ( let i = 0; i < result.length; i++ ) {