Skip to content

Commit

Permalink
Add support to compare delay against literal Number.NaN in nossif/nostif
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 2, 2020
1 parent dd6f41a commit 8f3d8cd
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,37 +705,41 @@
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 ( delay === '{{2}}' ) { delay = undefined; }
let delayNot = false;
if ( delay !== undefined ) {
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('/') ) {
needle = needle.slice(1,-1);
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = needleNot === false && needle === '' &&
delayNot === false && isNaN(delay)
const log = needleNot === false && needle === '' && delay === undefined
? console.log
: undefined;
const reNeedle = new RegExp(needle);
window.setInterval = new Proxy(window.setInterval, {
apply: function(target, thisArg, args) {
const a = String(args[0]);
const b = args[1];
let defuse = false;
if ( log !== undefined ) {
log('uBO: setInterval("%s", %s)', a, b);
} else if ( isNaN(delay) ) {
defuse = reNeedle.test(a) !== needleNot;
} else if ( needle === '' ) {
defuse = (b === delay) !== delayNot;
} else {
defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
}
if ( defuse ) {
args[0] = function(){};
let defuse;
if ( needle !== '' ) {
defuse = reNeedle.test(a) !== needleNot;
}
if ( defuse !== false && delay !== undefined ) {
defuse = (b === delay || isNaN(b) && isNaN(delay) ) !== delayNot;
}
if ( defuse ) {
args[0] = function(){};
}
}
return target.apply(thisArg, args);
}
Expand Down Expand Up @@ -776,37 +780,41 @@
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 ( delay === '{{2}}' ) { delay = undefined; }
let delayNot = false;
if ( delay !== undefined ) {
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('/') ) {
needle = needle.slice(1,-1);
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = needleNot === false && needle === '' &&
delayNot === false && isNaN(delay)
const log = needleNot === false && needle === '' && delay === undefined
? console.log
: undefined;
const reNeedle = new RegExp(needle);
window.setTimeout = new Proxy(window.setTimeout, {
apply: function(target, thisArg, args) {
const a = String(args[0]);
const b = args[1];
let defuse = false;
if ( log !== undefined ) {
log('uBO: setTimeout("%s", %s)', a, b);
} else if ( isNaN(delay) ) {
defuse = reNeedle.test(a) !== needleNot;
} else if ( needle === '' ) {
defuse = (b === delay) !== delayNot;
} else {
defuse = reNeedle.test(a) !== needleNot && (b === delay) !== delayNot;
}
if ( defuse ) {
args[0] = function(){};
let defuse;
if ( needle !== '' ) {
defuse = reNeedle.test(a) !== needleNot;
}
if ( defuse !== false && delay !== undefined ) {
defuse = (b === delay || isNaN(b) && isNaN(delay) ) !== delayNot;
}
if ( defuse ) {
args[0] = function(){};
}
}
return target.apply(thisArg, args);
}
Expand Down

0 comments on commit 8f3d8cd

Please sign in to comment.