mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-03 01:29:39 +02:00
Add two scriptlets: setTimeout-if and setInterval-if
Usage is similar to that of raf-if introduced in
commit 6831967f5f
.
The two new scriptlets are meant to replace:
- setTimeout-defuser
- setTimeout-logger
- setInterval-defuser
- setInterval-logger
setTimeout-logger and setInterval-logger have been
removed, since they are not to be used in production.
To log setTimeout and setInterval usage, respectively
(using aliases):
- ##+js(stif)
- ##+js(siif)
To defuse setTimeout unconditionally:
- ##+js(stif, !)
Usage of setTimeout-defuser and setInterval-defuser
is deprecated and will be removed in some future when
they are no longer in use.
Keep in mind that the new scriptlets function on a
whitelist basis, whereas the deprecated ones
function on a blacklist basis. Prefixing the needle
with `!` allow to use the new scriptlets on a
blacklist basis.
This commit is contained in:
parent
708e5004e8
commit
c5536577b2
@ -407,12 +407,10 @@
|
|||||||
needle = new RegExp(needle);
|
needle = new RegExp(needle);
|
||||||
window.requestAnimationFrame = new Proxy(window.requestAnimationFrame, {
|
window.requestAnimationFrame = new Proxy(window.requestAnimationFrame, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
const a = args[0];
|
const a = String(args[0]);
|
||||||
const s = a.toString();
|
|
||||||
if ( log !== undefined ) {
|
if ( log !== undefined ) {
|
||||||
log('uBO: requestAnimationFrame("%s")', s);
|
log('uBO: requestAnimationFrame("%s")', a);
|
||||||
}
|
} else if ( needle.test(a) === not ) {
|
||||||
if ( needle.test(s) === not ) {
|
|
||||||
args[0] = function(){};
|
args[0] = function(){};
|
||||||
}
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
@ -528,15 +526,36 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
/// setInterval-logger.js
|
/// setInterval-if.js
|
||||||
/// alias sil.js
|
/// alias siif.js
|
||||||
(function() {
|
(function() {
|
||||||
const log = console.log.bind(console);
|
let needle = '{{1}}';
|
||||||
|
const not = needle.charAt(0) === '!';
|
||||||
|
if ( not ) { needle = needle.slice(1); }
|
||||||
|
const delay = parseInt('{{2}}', 10);
|
||||||
|
if ( needle === '' || needle === '{{1}}' ) {
|
||||||
|
needle = '.?';
|
||||||
|
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
||||||
|
needle = needle.slice(1,-1);
|
||||||
|
} else {
|
||||||
|
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
}
|
||||||
|
const log = not === false && needle === '.?' && isNaN(delay)
|
||||||
|
? console.log
|
||||||
|
: undefined;
|
||||||
|
needle = new RegExp(needle);
|
||||||
window.setInterval = new Proxy(window.setInterval, {
|
window.setInterval = new Proxy(window.setInterval, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
const a = args[0];
|
const a = String(args[0]);
|
||||||
const b = args[1];
|
const b = args[1];
|
||||||
log('uBO: setInterval("%s", %s)', a.toString(), b);
|
if ( log !== undefined ) {
|
||||||
|
log('uBO: setInterval("%s", %s)', a, b);
|
||||||
|
} else if (
|
||||||
|
(isNaN(delay) || b === delay) &&
|
||||||
|
needle.test(a) === not
|
||||||
|
) {
|
||||||
|
args[0] = function(){};
|
||||||
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -569,15 +588,36 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
/// setTimeout-logger.js
|
/// setTimeout-if.js
|
||||||
/// alias stl.js
|
/// alias stif.js
|
||||||
(function() {
|
(function() {
|
||||||
const log = console.log.bind(console);
|
let needle = '{{1}}';
|
||||||
|
const not = needle.charAt(0) === '!';
|
||||||
|
if ( not ) { needle = needle.slice(1); }
|
||||||
|
const delay = parseInt('{{2}}', 10);
|
||||||
|
if ( needle === '' || needle === '{{1}}' ) {
|
||||||
|
needle = '.?';
|
||||||
|
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
|
||||||
|
needle = needle.slice(1,-1);
|
||||||
|
} else {
|
||||||
|
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
}
|
||||||
|
const log = not === false && needle === '.?' && isNaN(delay)
|
||||||
|
? console.log
|
||||||
|
: undefined;
|
||||||
|
needle = new RegExp(needle);
|
||||||
window.setTimeout = new Proxy(window.setTimeout, {
|
window.setTimeout = new Proxy(window.setTimeout, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
const a = args[0];
|
const a = String(args[0]);
|
||||||
const b = args[1];
|
const b = args[1];
|
||||||
log('uBO: setTimeout("%s", %s)', a.toString(), b);
|
if ( log !== undefined ) {
|
||||||
|
log('uBO: setTimeout("%s", %s)', a, b);
|
||||||
|
} else if (
|
||||||
|
(isNaN(delay) || b === delay) &&
|
||||||
|
needle.test(a) === not
|
||||||
|
) {
|
||||||
|
args[0] = function(){};
|
||||||
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user