1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

Add new scriptlet to defuse calls to requestAnimationFrame

Scriptlet name: `raf-if.js`

Usage: `example.com##+js(raf-if, !/(\d+){4}/)`

Argument: one single argument, which is the "needle" to
find in the stringified argument passed to
requestAnimationFrame.

requestAnimationFrame will be defused when:

- The needle is not prefixed with `!` and the needle
  does not match the stringified argument; OR
- The needle is prefixed with `!` and the needle
  matches the stringified argument.

The `raf-if.js` scriptlet will log calls to
requestAnimationFrame to the console when no parameter
is provided, i.e.:

    example.com##+js(raf-if)

Otherwise no logging occurs.
This commit is contained in:
Raymond Hill 2019-08-21 10:13:23 -04:00
parent 95b77c33eb
commit 6831967f5f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -391,6 +391,36 @@
})();
/// raf-if.js
(function() {
let needle = '{{1}}';
const not = needle.charAt(0) === '!';
if ( not ) { needle = needle.slice(1); }
if ( needle === '' || needle === '{{1}}' ) {
needle = '.?';
} else if ( needle.startsWith('/') && needle.endsWith('/') ) {
needle = needle.slice(1,-1);
} else {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = needle === '.?' && not === false ? console.log : undefined;
needle = new RegExp(needle);
window.requestAnimationFrame = new Proxy(window.setTimeout, {
apply: function(target, thisArg, args) {
const a = args[0];
const s = a.toString();
if ( log !== undefined ) {
log('uBO: requestAnimationFrame("%s")', s);
}
if ( needle.test(s) === not ) {
args[0] = function(){};
}
return target.apply(thisArg, args);
}
});
})();
/// set-constant.js
/// alias set.js
(function() {