- Resources Library·续5
Resources Library·续5
Examples:
- kompetent.de##+js(set, Object.keys, trueFunc)
- t-online.de##+js(set, abp, false)
- identi.li##+js(set, t_spoiler, 0)
- ~~joysound.com##+js(set, document.body.oncopy, null, 3)~~ (deprecated)
- joysound.com##+js(set, document.body.oncopy, null, runAt, 3)
Also see:
- trusted-set-constant
- AdGuard set-constant
trusted-set-constant.js ↪
trusted-set.js
Trusted scriptlet
Behaves exactly like set-constant, except that any arbitrary JSON-compatible value can be set.
By default the value is treated as a string, which can be anything.
If the value starts with { and ends with }, the value will be JSON-parsed, and the value property of the resulting object will be used. Since 1.59.1b9, { "value": ... } can be replaced with json:.
Solves: https://github.com/uBlockOrigin/uAssets/discussions/18185#discussioncomment-5977456
Examples:
- example.com##+js(trusted-set, prop, { "value": 100000 })
- example.com##+js(trusted-set, prop, '{ "value": [ "one", "two", 3 ]}')
- example.com##+js(trusted-set, prop, { "value": { "url": "about:blank" }})
Also see:
- set-constant
- AdGuard trusted-set-constant
trusted-suppress-native-method.js ↪
Trusted scriptlet
New in 1.58.1rc0
This is a first draft version with current limitations: - Does not support matching arguments which are object or array
Syntax:
- example.org##+js(trusted-suppress-native-method, methodPath, signatureStr[, how[, stack]])
Parameters:
- methodPath – required, string path to a native method (joined with . if needed). The property must be attached to window.
- signatureStr – required, string of |-separated argument matchers. Supported value types with corresponding matchers:
- string – exact string, part of the string or regexp pattern. Empty string "" to match an empty string. Regexp patterns inside object matchers are not supported.
- number, boolean, null, undefined – exact value,
- object – partial of the object with the values as mentioned above, i.e by another object, that includes property names and values to be matched,
- array – partial of the array with the values to be included in the incoming array, without considering the order of values.
To ignore specific argument, explicitly use whitespace as a matcher, e.g ' | |{"prop":"val"}' to skip matching first and second arguments.
If signatureStr parameter is not declared, the scriptlet will log all calls to methodPath along with the arguments passed and will not prevent the trapped method.
Tokens:
- "how": optional, string, one of the following:
- abort – default, aborts the call by throwing an error,
- prevent – replaces the method call with the call of an empty function.
- debug – triggers a debugger statement and the target
method is not suppressed. Useful to find out how the method is
being called by the page's code.
- "stack": optional, string or regular expression that must match the current function call stack trace. Prepend pattern with ! to test for unmatched patterns in stack trace.
The scriptlet will log stack trace in uBO's logger when verbose mode is enabled.
Examples:
example.org##+js(trusted-suppress-native-method, localStorage.setItem, '/key/|"value"', prevent)
example.org##+js(trusted-suppress-native-method, Object.prototype.hasOwnProperty, '"test"')
example.org##+js(trusted-suppress-native-method, Node.prototype.appendChild, '{"id":"str"}', prevent)
example.org##+js(trusted-suppress-native-method, Document.prototype.querySelectorAll, '"div"')
example.org##+js(trusted-suppress-native-method, Array.prototype.concat, '[1, "str", true]')
example.org##+js(trusted-suppress-native-method, sessionStorage.setItem, ' |"item-value"', abort, someFuncName)
- Prevent
localStorage.setItem('test-key', 'test-value')call matching first argument by regexp pattern and the second one by substring. - Abort
obj.hasOwnProperty('test')call matching the first argument. - Prevent
Node.prototype.appendChildcall on element with the idtest-idby object matcher. - Abort all
document.querySelectorAllcalls withdivas the first argument. - Abort
Array.prototype.concat([1, 'str', true, null])calls by matching array argument contents. - Use stack argument to match by the call, while also matching the second argument.
Also see:
- AdGuard trusted-suppress-native-method
trusted-override-element-method.js ↪
Trusted scriptlet
New in 1.60.1b5
Override the behavior of a method on matching elements.
Parameters:
- required, methodPath: The method which calls must be intercepted.
- optional, selector: A CSS selector which the target element must match. If not specified, the override will occur for all elements.
- optional, disposition: How the override should be handled. If not specified, the overridden call will be equivalent to an empty function.
throw: an exception will be thrown (throwsReferenceError).debug: triggers adebuggerstatement if uBO's logger is opened. Useful for debugging purposes.- Any other value will be validated and returned as a supported safe constant.
Example:
streamsilk.com##+js(trusted-override-element-method, HTMLAnchorElement.prototype.click, a[target="_blank"][style])
trusted-prevent-dom-bypass.js ↪
Trusted scriptlet
New in 1.60.1b4
Prevent the bypassing of uBO scriptlets through anonymous embedded context.
Ensure that a target method in the embedded context is using the corresponding parent context's method (which is assumed to be properly patched), or to replace the embedded context with that of the parent context.
Root issue: https://issues.chromium.org/issues/40202434
Parameters:
- required, methodPath: The method which calls must be intercepted. The arguments of the intercepted calls are assumed to be HTMLElement, anything else will be ignored.
- optional, targetProp: The method in the embedded context which should be delegated to the parent context. If no method is specified, the embedded context becomes the parent one, i.e. all properties of the embedded context will be that of the parent context.
Examples:
##+js(trusted-prevent-dom-bypass, Element.prototype.append, open)##+js(trusted-prevent-dom-bypass, Element.prototype.appendChild, XMLHttpRequest)
set-cookie.js ↪
New in 1.50.1b0.
Sets a cookie with the specified name, value, and path. Double quotes surrounding the cookie value are allowed.
Parameters:
- required, cookie name to be set
- required, cookie value; possible values:
- decimal integer: >= -32767 && <= 32767 (<= 15 up to 1.56.1b18, >= 0 up to 1.61.1b0)
- one of the predefined constants (in any case variation):
- accept / reject,
- accepted<sup>2</sup> / rejected<sup>2</sup> / notaccepted<sup>2</sup>,
- allow / disallow<sup>2</sup> / deny,
- allowed<sup>2</sup> / denied,
- approved<sup>5</sup> / disapproved<sup>5</sup>,
- checked<sup>8</sup> / unchecked<sup>8</sup>,
- dismiss / dismissed,
- enable<sup>2</sup> / disable<sup>2</sup>,
- enabled<sup>2</sup> / disabled<sup>2</sup>,
- essential<sup>7</sup> / nonessential<sup>7</sup>,
- forbidden<sup>9</sup> / forever<sup>9</sup>,
- hide<sup>6</sup> / hidden<sup>6</sup>,
- necessary<sup>4</sup> / required<sup>4</sup>,
- ok,
- on<sup>1</sup> / off<sup>1</sup>,
- true / t<sup>3</sup> / false / f<sup>3</sup>,
- yes / y / no / n,
- all<sup>10</sup> / none<sup>10</sup> / functional<sup>10</sup>,
- granted<sup>11</sup> / done<sup>11</sup>,
- decline<sup>12</sup> / declined<sup>12</sup>,
- closed<sup>13</sup> / next<sup>13</sup> / mandatory<sup>13</sup>,
- disagree<sup>13</sup> / agree<sup>13</sup>
- optional, cookie path, defaults to /; possible values:
- /: root path
- none: to set no path at all
<sup>1. 1.52.3b17</sup>
<sup>2. 1.52.3rc12</sup>
<sup>3. 1.53.1b8</sup>
<sup>4. 1.53.5rc5</sup>
<sup>5. 1.57.3rc1</sup>
<sup>6. 1.58.1b7</sup>
<sup>7. 1.58.1rc0</sup>
<sup>8. 1.59.1b5</sup>
<sup>9. 1.60.1b12</sup>
<sup>10. 1.61.3b10</sup>
<sup>11. 1.62</sup>
<sup>12. 1.62.1b1</sup>
<sup>13. 1.62.1b2</sup>
The scriptlet encodes cookie names and values, e.g value "{ test: 'value'}" becomes %7B%20test%3A%20'value'%7D.
Tokens:
- reload, 1: the scriplet will force a reload of the webpage if the cookie being set was not already set.
- dontOverwrite, 1: the scriptlet will not modify the cookie if it already exists.
; Secure will be automatically used when cookie names starts with __Secure- or __Host- (since 1.58.1b8).
Examples:
- example.com##+js(set-cookie, CookieConsent, 1)
- example.com##+js(set-cookie, gdpr-settings-cookie, true)
- example.com##+js(set-cookie, cookie_consent, ok, none)
- example.com##+js(set-cookie, CookieConsent, 1, , reload, 1)
Also see:
- trusted-set-cookie
- AdGuard set-cookie
- AdGuard set-cookie-reload
set-cookie-reload.js ↪
New in 1.52.3b16.
Sets a cookie with the specified name, value. Forces a reload of the page if the cookie being set was not already set. Double quotes surrounding the cookie value are allowed.
Equivalent to set-cookie with reload, 1 token.
trusted-set-cookie.js ↪
Trusted scriptlet
Sets a cookie with arbitrary name and value, and with optional ability to offset cookie attribute 'expires' and set path.
New in 1.50.1b1.
Parameters:
- required, cookie name to be set
- required, cookie value. Possible values:
- arbitrary value
- empty string for no value
- $now$ keyword for setting current time in ms, e.g 1667915146503. Can be used inside a string since 1.58.1b0
- $currentDate$ keyword for setting current time as string, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'
- $currentISODate$ keyword for setting current time in ISO format as string, e.g '2024-07-07T12:10:00.641Z' (since 1.58.1rc0)
- optional, offset from current time in seconds, after which cookie should expire; defaults to no offset. Possible values:
- positive integer in seconds
- 1year keyword for setting expiration date to one year
- 1day keyword for setting expiration date to one day
- optional, argument for setting cookie path, defaults to /; possible values:
- /: root path
- none: to set no path at all
Variadic parameters (must appears after required and optional parameters):
- reload, 1: the scriptlet will force a reload of the webpage if the cookie being set was not already set.
- domain, [value]: the scriptlet will set the domain of the cookie to value. Regex is supported (1.64.1b5), if used it will be matched against document.location.hostname.
- dontOverwrite, 1: the scriptlet will not modify the cookie if it already exists.
; Secure will be automatically used when cookie names starts with __Secure- or __Host-.
Examples:
- example.com##+js(trusted-set-cookie, cmpconsent, 1-accept_1)
- example.com##+js(trusted-set-cookie, cmpconsent, $now$)
- example.com##+js(trusted-set-cookie, cmpconsent, '{"accepted":true,"expire":$now$}')
- example.com##+js(trusted-set-cookie, cmpconsent, accept, 259200)
- example.com##+js(trusted-set-cookie, cmpconsent, accept, 1year)
- example.com##+js(trusted-set-cookie, cmpconsent, decline, , none)
- www.google.*##+js(trusted-set-cookie, SOCS, CAESHAgBEhJnd3NfMjAyNTA2MDQtMF9SQzEaAnJvIAEaBgiAgo7CBg, 1year, , domain, /\bgoogle\..+$/, dontOverwrite, 1)
The second and third filters will set a cookie with new Date().getTime() value.
The forth and fifth filters will set a cookie which will expire in 3 days or 1 year.
The sixth filter sets a cookie with no path.
The seventh filter sets a cookie where the domain value is the result of the regex matched against document.location.hostname.
Also see:
- set-cookie
- AdGuard trusted-set-cookie
- AdGuard trusted-set-cookie-reload
trusted-set-cookie-reload.js ↪
New in 1.52.3b16.
Sets a cookie with arbitrary name and value, and with optional ability to offset cookie attribute 'expires' and set path. Forces a reload of the page if the cookie being set was not already set.
Equivalent to trusted-set-cookie with reload, 1 token.
