Resources Library·续3

New in 1.27.0.

Defuses calls to requestAnimationFrame() function when parameter: - is not prefixed with ! and matches the stringified callback argument to requestAnimationFrame(); OR - is prefixed with ! and does not match the stringified callback argument to requestAnimationFrame().

Parameters: - optional, string/regular expression, matching in the stringified callback argument passed to requestAnimationFrame.

Use with /^/ parameter to defuse all calls unconditionally.

When used without parameters, will log calls to requestAnimationFrame() to the logger.

Examples: - bloomberg.com##+js(norafif, paywall-inline-tout)

Also see: - AdGuard prevent-requestAnimationFrame


prevent-setInterval.js ↪

no-setInterval-if.js /

nosiif.js /

setInterval-defuser.js

New in 1.23.0

Defuses calls to setInterval() function when parameters: - are not prefixed with ! and match the setInterval() argument; OR - are prefixed with ! and do not match the setInterval() argument.

Parameters: - optional, string/regular expression, matching in stringified callback function - optional, a value to match against the delay. Can be a single value for exact match, or a range: - min-max: matches if delay >= min and delay <= max - min-: matches if delay >= min - -max: matches if delay <= max

Use with /^/ parameter to defuse all calls unconditionally.

When used without parameters, will log calls to setInterval() to the logger.

Examples: - jpidols.tv##+js(nosiif) - finanzen.*##+js(nosiif, nrWrapper) - yachtrevue.at##+js(nosiif, text/css, 10)

Also see: - AdGuard prevent-setInterval


prevent-setTimeout.js ↪

no-setTimeout-if.js /

nostif.js /

setTimeout-defuser.js

New in 1.23.0

Defuses calls to setTimeout() function when parameters: - are not prefixed with ! and match the setTimeout() argument; OR - are prefixed with ! and do not match the setTimeout() argument.

Parameters: - optional, string/regular expression, matching in stringified callback function - optional, a value to match against the delay. Can be a single value for exact match, or a range: - min-max: matches if delay >= min and delay <= max - min-: matches if delay >= min - -max: matches if delay <= max

Use with /^/ parameter to defuse all calls unconditionally.

When used without parameters, will log calls to setTimeout() to the logger.

<sub>Test page: https://gorhill.github.io/uBlock/tests/scriptlet-injection-filters-1.html</sub>

Examples: - computerbild.de##+js(nostif, ())return) - lablue.*##+js(nostif, push, 500)

In 1.31.3b11 aliased as setTimeout-defuser.js for backward compatibility.

Also see: - AdGuard prevent-setTimeout


nowebrtc.js ↪

Disables WebRTC by preventing web pages from using RTCPeerConnection(). Report attempts in console.

Examples: - x1337x.*##+js(nowebrtc)

Also see: - AdGuard nowebrtc


prevent-innerHTML.js ↪

New in 1.63.1b0.

Conditionally prevent assignment to innerHTML property.

Parameters:

  • Optional, selector: The element must matches selector for the prevention to take place.
  • Optional, pattern: A pattern to match against the assigned value. The pattern can be a plain string, or a regex. Prepend with ! to reverse the match condition.

When verbose mode is enabled, the scriptlet will log the assigned value of the element.

Example:

example.com##+js(prevent-innerHTML, body, adblock)

trusted-create-HTML.js ↪

Trusted scriptlet

New in 1.63.3b15

Element(s) from a parsed HTML string are added as child element(s) to a specific parent element in the DOM.

Parameters:

  • required, parent: A CSS selector identifying the element to which created element(s) will be added.
  • required, html: An HTML string to be parsed using DOMParser, and which resulting elements are to be added as child element(s).
  • optional, duration: If specified, the time in ms after which the added elements will be removed. No removal will occur if not specified.

Example:

example.org##+js(trusted-create-html, html, <iframe src=""></iframe>)

prevent-xhr.js ↪

no-xhr-if.js

New in 1.38.0.

Defuses XMLHttpRequest network requests by returning empty response. Based on no-fetch-if.js.

Parameters: - optional, space-separated list of conditions which must be ALL fulfilled in order for the defusing to take place: - string/regular expression, prefixed by ! for negation, matching in URL passed to XMLHttpRequest open() call - colon-separated name:value pairs of XMLHttpRequest method open() parameter names (only method and url currently supported) and string/regular expression matching in value of passed argument. - optional, directive; arguments to define the response body: - true to randomize the response, random 10-character string <sup>1.51.1b15</sup> - emptyObj to return the response value as empty object <sup>1.54.1rc2</sup> - emptyArr to return the response value as empty array <sup>1.54.1rc2</sup> - emptyStr to return the response value as empty string <sup>1.54.1rc2</sup> - length:min[-max] to fulfill the response with randomized text with length specified, limited to 500000 characters <sup>1.54.1b1</sup> - war:[name of resource] to fulfill the response with the content of a web_accessible_resources resource <sup>1.51.1b16</sup>

When used without parameters, the parameters passed to no-xhr-if will be logged to the logger.

Examples:

example.com##+js(no-xhr-if, method:HEAD)
example.com##+js(no-xhr-if, adsbygoogle.js)
example.com##+js(no-xhr-if, adsbygoogle.js method:HEAD)
example.com##+js(no-xhr-if, /adsbygoogle.js$/ method:/HEAD|POST/)
example.com##+js(no-xhr-if, adsbygoogle.js, length:11000)
example.com##+js(no-xhr-if, doubleclick.net/instream/ad_status.js, war:doubleclick_instream_ad_status.js)

Also see: - AdGuard prevent-xhr


trusted-prevent-xhr.js ↪

Trusted scriptlet

New in 1.60.1b3

Essentially the same as no-xhr-if except that if the directive argument is not a known token, it will be used as is as the response text of the xhr request, whereas prevent-xhr returns an empty string when the directive is unknown.

Examples:

anitube.vip##+js(trusted-prevent-xhr, outbrain.com, outbrain)
koramaup.com##+js(trusted-prevent-xhr, googlesyndication, 'a.getAttribute("data-ad-client")||""')

set-attr.js ↪

New in 1.50.1b16.

Sets the specified attribute on the specified elements. This scriptlet runs once when the page loads then afterward on DOM mutations.

Parameters: - required, CSS selector of DOM elements for which the attribute attr must be modified. - required, the name of the attribute to modify - required, the value to assign to the target attribute. Possible values: - '': empty string (default) - true - false - positive decimal integer: 0 <= value < 32768 - [other]: copy the value from attribute other on the same element. This allows to copy the value of one attribute to another attribute on the same element.

Examples:

example.com##+js(set-attr, div.class > a.class, test-attribute, 0)
example.com##+js(set-attr, a > img, src, [data-src])

Solves uBlockOrigin/uBlock-issues#2347.

Also see: - AdGuard set-attr


trusted-set-attr.js ↪

Trusted scriptlet

New in 1.60.1b17

Sets the specified attribute on the specified elements. This scriptlet runs once when the page loads then afterward on DOM mutations.

Parameters: - required, selector: A CSS selector for the elements to target. - required, attr: The name of the attribute to be added. - optional, value: The new value of the attribute. Since the scriptlet requires a trusted source, the value can be anything.

Examples: 1. Adds a class attribute to the body element with the value some-class.

adblock example.com##+js(trusted-set-attr, body, class, some-class)

  1. Adds a test-attribute attribute to the body element with the value [true, true].

adblock example.com##+js(trusted-set-attr, body, test-attribute, '[true, true]')

Also see: - AdGuard trusted-set-attr


~remove-attr.js ↪~

~ra.js~

Deprecated by :remove-attr()

Filter authors must use the new operator instead of the +js() counterpart.

Removes attribute(s) from DOM tree node(s). By default will run only once when the initial HTML document has been completely loaded and parsed but sub-resources such as scripts, images, stylesheets and frames are still loading.

Parameters: - required, attribute or list of attributes joined by | - optional, CSS selector, specifies nodes from which attributes will be removed - optional, new in 1.33, one or more space-separated tokens dictating the behavior of the scriptlet - asap: added in 1.36.1b2, execute as soon as possible, do not wait for DOM to become available. - stay: This tells the scriplet to stay active and act on document changes. - complete: This tells the scriplet to start acting only when the document is complete, i.e. once all secondary resources have been loaded.

Examples: - userscloud.com##+js(ra, onclick, .btn-icon-stacked) - magesy.*,majesy.*##+js(ra, oncontextmenu) - zerodot1.gitlab.io##+js(ra, oncontextmenu|onselectstart|ondragstart) - example.com##+js(remove-attr, class, .j-mini-player, stay)

Also see: - AdGuard remove-attr


~remove-class.js~ ↪

~rc.js~

Deprecated by :remove-class()

Filter authors must use the new operator instead of the +js() counterpart.

New in 1.26.0.

Removes classes from DOM tree node(s). By default will run only once after page load. Syntax based on remove-attr.js

Parameters: - required, class name or list of class names joined by | - optional, CSS selector, specifies nodes from which classes should be removed - optional, new in 1.36, one or more space-separated tokens dictating the behavior of the scriptlet - stay: This tells the scriptlet to stay and act on DOM changes, while the default behavior is to act only once when the document becomes interactive. - complete: This tells the scriplet to start acting only when the document is complete, i.e. once all secondary resources have been loaded, while the default is to start acting when the document is interactive - which is earlier than when the document is complete.

Examples: - danskebank.fi##+js(rc, cookie-consent-banner-open, html) Picture of the element

Also see: - AdGuard remove-class


trusted-replace-node-text.js ↪

trusted-rpnt.js /

replace-node-text.js /

rpnt.js

<span name="rpntjs-"></span> <span name="replace-node-textjs-"></span>

Trusted scriptlet

New in 1.49.3b16

Replace text instance(s) with another text instance inside specific DOM nodes.

By default, the scriptlet will bail out when the document itself has been fully loaded, i.e. when DOMContentLoaded event is fired.

The mutation observer of this scriptlet can be a significant overhead for pages with dynamically updated DOM, and in most cases the scriptlet is useful only for DOM changes occurring before the DOMContentLoaded event, so the default is to quit out when that event is received ("quit out" means discarding the mutation observer and having the scriptlet garbage-collected by the JS engine).

Parameters: - required, the name of the node for which the text content must be substituted. Valid node names can be found at: https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName - required, a string or regex to find in the text content of the node as the target of substitution - optional, the replacement text. Can be omitted if the goal is to delete the text which matches the pattern. Cannot be omitted if extra pairs of parameters have to be used (see below)

Tokens: - includes, pattern: A string or regex which must be found in the text content of the node in order for the substitution to occur - excludes, pattern: A string or regex which must not be found in the text content of the node in order for the substitution to occur - sedCount, n: This will cause the scriptlet to stop after n instances of substitution. Since a mutation oberver is used by the scriptlet, it's advised to stop it whenever it becomes pointless. Default to zero, which means the scriptlet never stops - stay, 1: Force the scriptlet to stay at work forever - quitAfter, ms: This tells the scriptlet to quit ms milliseconds after the page has been loaded, i.e. after the DOMContentLoaded event has been fired - ~~log, 1~~: This will cause the scriptlet to output information at the console, useful as a debugging tool for filter authors
(deprecated, read about the new method of logging scriptlets)