mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +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:
parent
95b77c33eb
commit
6831967f5f
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user