Skip to content

Commit

Permalink
Replace requestAnimationFrame-if.js with no-requestAnimationFrame-if.js
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#981

To be consistent with no-setTimeout-if.js.

requestAnimationFrame-if.js is deprecated and must no longer be
used, it will be removed in the near future when it's no longer
in use in default filter lists.

no-requestAnimationFrame-if.js is aliased to norafif.js.
  • Loading branch information
gorhill committed Apr 15, 2020
1 parent 042935b commit 1de0e82
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions assets/resources/scriptlets.js
Expand Up @@ -491,6 +491,7 @@

/// requestAnimationFrame-if.js
/// alias raf-if.js
// Deprecated, use "no-requestAnimationFrame-if.js"
(function() {
let needle = '{{1}}';
const not = needle.charAt(0) === '!';
Expand Down Expand Up @@ -518,6 +519,38 @@
})();


/// no-requestAnimationFrame-if.js
/// alias norafif.js
(function() {
let needle = '{{1}}';
if ( needle === '{{1}}' ) { needle = ''; }
const needleNot = needle.charAt(0) === '!';
if ( needleNot ) { needle = needle.slice(1); }
if ( needle.startsWith('/') && needle.endsWith('/') ) {
needle = needle.slice(1, -1);
} else if ( needle !== '' ) {
needle = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
const log = needleNot === false && needle === '' ? console.log : undefined;
const reNeedle = new RegExp(needle);
window.requestAnimationFrame = new Proxy(window.requestAnimationFrame, {
apply: function(target, thisArg, args) {
const a = String(args[0]);
let defuse = false;
if ( log !== undefined ) {
log('uBO: requestAnimationFrame("%s")', a);
} else {
defuse = reNeedle.test(a) !== needleNot;
}
if ( defuse ) {
args[0] = function(){};
}
return target.apply(thisArg, args);
}
});
})();


/// set-constant.js
/// alias set.js
(function() {
Expand Down

2 comments on commit 1de0e82

@uBlock-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

norafif

Wouldn't that be noraf-if.js, to be consistent with the previous alias ?

@gorhill
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-setTimeout-if.js is aliased to nostif.js.

Please sign in to comment.