- trusted-click-element
- trusted-create-element
- trusted-dispatch-event
- trusted-prune-inbound-object
- trusted-replace-argument
- trusted-replace-fetch-response
- trusted-replace-node-text
- trusted-replace-outbound-text
- trusted-replace-xhr-response
- trusted-set-attr
- trusted-set-constant
- trusted-set-cookie-reload
- trusted-set-cookie
- trusted-set-local-storage-item
- trusted-set-session-storage-item
- trusted-suppress-native-method
Added in v1.7.3.
Clicks selected elements in a strict sequence, ordered by selectors passed,
and waiting for them to render in the DOM first.
First matched element is clicked unless containsText is specified.
If containsText is specified, then it searches for all given selectors and clicks
the first element containing the specified text.
Deactivates after all elements have been clicked or by timeout (configurable).
example.com#%#//scriptlet('trusted-click-element', selectors[, extraMatch[, delay[, reload[, observerTimeout]]]])
selectors— required, string with query selectors delimited by comma. The scriptlet supports>>>combinator to select elements inside open shadow DOM. For usage, see example below.extraMatch— optional, extra condition to check on a page; allows to matchcookie,localStorageand specified text; can be set asname:key[=value]wherevalueis optional. Ifcookie/localStoragestarts with!then the element will only be clicked if specifiedcookie/localStorageitem does not exist. Multiple conditions are allowed inside oneextraMatchbut they should be delimited by comma and each of them should match the syntax. Possiblenames:cookie— test string or regex against cookies on a pagelocalStorage— check if localStorage item is presentcontainsText— check if clicked element contains specified text
delay— optional, time in ms to delay scriptlet execution, defaults to instant execution. Must be a number less thanobserverTimeout(default 10 seconds) which can be configured.reload— optional, string with reloadAfterClick marker and optional value. Possible values:reloadAfterClick- reloads the page after all elements have been clicked, with default delay — 500ms- colon-separated pair
reloadAfterClick:valuewherevalue— time delay in milliseconds before reloading the page, after all elements have been clicked. Must be a number less thanobserverTimeout.
observerTimeout— optional, time in seconds to use instead default 10 seconds observer timeout. Must be an integer number and more than 0.
-
Click single element by selector
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]')
-
Delay click execution by 500ms
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '', '500')
-
Click multiple elements by selector with a delay
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], button[name="check"], input[type="submit"][value="akkoord"]', '', '500')
-
Match cookies by keys using regex and string
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity, cookie:/cmpconsent|cmp/')
-
Match by cookie key=value pairs using regex and string
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'cookie:userConsentCommunity=true, cookie:/cmpconsent|cmp/=/[a-z]{1,5}/')
-
Match by localStorage item 'promo' key
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', 'localStorage:promo')
-
Click multiple elements with delay and matching by both cookie string and localStorage item
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], input[type="submit"][value="akkoord"]', 'cookie:cmpconsent, localStorage:promo', '250')
-
Click element only if clicked element contains text
Accept cookieexample.com#%#//scriptlet('trusted-click-element', 'button', 'containsText:Accept cookie')
-
Click element only if cookie with name
cmpconsentdoes not existexample.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:cmpconsent')
-
Click element only if specified cookie string and localStorage item does not exist
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '!cookie:consent, !localStorage:promo')
-
Click element inside open shadow DOM, which could be selected by
div > button, but is inside shadow host element with host element selected byarticle .containerexample.com#%#//scriptlet('trusted-click-element', 'article .container > div#host >>> div > button')
-
Click elements after 1000ms delay and reload page after all elements have been clicked with 200ms delay
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"], button[name="check"], input[type="submit"][value="akkoord"]', '', '1000', 'reloadAfterClick:200')
-
Extend observer timeout to 40 seconds to allow clicking elements that appear after user interaction
example.com#%#//scriptlet('trusted-click-element', 'button[name="agree"]', '', '', '', '40')
Added in v1.10.1.
Creates an element with specified attributes and text content, and appends it to the specified parent element.
example.com#%#//scriptlet('trusted-create-element', parentSelector, tagName[, attributePairs[, textContent[, cleanupDelayMs]]])
parentSelector— required, CSS selector of the parent element to append the created element to.tagName— required, tag name of the created element.attributePairs— optional, space-separated list of attribute name and value pairs separated by=. Value can be omitted. If value is set, it should be wrapped in quotes. If quotes are needed inside value, they should be escaped with backslash. Defaults to no attributes.textContent— optional, text content of the created element. Defaults to empty string.cleanupDelayMs— optional, delay in milliseconds before the created element is removed from the DOM. Defaults to no cleanup.
-
Create a div element with a single attribute
example.com#%#//scriptlet('trusted-create-element', 'body', 'div', 'data-cur="1"')
-
Create a div element with text content
example.com#%#//scriptlet('trusted-create-element', 'body', 'div', '', 'Hello world!')
-
Create a button element with multiple attributes, including attribute without value, and text content
example.com#%#//scriptlet('trusted-create-element', 'body', 'button', 'disabled aria-hidden="true" style="width: 0px"', 'Press here')
-
Create a button element with an attribute whose value contains quotes
example.com#%#//scriptlet('trusted-create-element', 'body', 'button', 'data="a\\"quote"')
-
Create a paragraph element with text content and remove it after 5 seconds
example.com#%#//scriptlet('trusted-create-element', '.container > article', 'p', '', 'Hello world!', '5000')
Added in v1.11.1.
Dispatches a custom event on a specified target.
example.org#%#//scriptlet('trusted-dispatch-event', event[, target])
event— required, name of the event to dispatchtarget— optional, target on which event will be invoked. Possible values:- CSS selector — dispatch event on the element with the specified selector
window— dispatch event on the window object- if not set, then "document" is used — it's default value
-
Dispatches a custom event "click" on the document.
example.org#%#//scriptlet('trusted-dispatch-event', 'click')
-
Dispatches a custom event "submit" on the element with the class "test".
example.org#%#//scriptlet('trusted-dispatch-event', 'submit', '.test')
-
Dispatches a custom event "load" on the window object.
example.org#%#//scriptlet('trusted-dispatch-event', 'load', 'window')
Added in v1.9.91.
Removes listed properties from the result of calling specific function (if payload contains Object)
and returns to the caller.
Related UBO scriptlet: https://github.com/gorhill/uBlock/commit/1c9da227d7
example.org#%#//scriptlet('trusted-prune-inbound-object', functionName[, propsToRemove [, obligatoryProps [, stack]]])
functionName— required, the name of the function to trap, it must have an object as an argumentpropsToRemove— optional, string of space-separated properties to removeobligatoryProps— optional, string of space-separated properties which must be all present for the pruning to occurstack— optional, string or regular expression that must match the current function call stack trace; if regular expression is invalid it will be skipped
Note please that you can use wildcard
*for chain property name, e.g.ad.*.srcinstead ofad.0.src ad.1.src ad.2.src.
-
Removes property
examplefrom the payload of the Object.getOwnPropertyNames callexample.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.getOwnPropertyNames', 'example')
Function call:
Object.getOwnPropertyNames({ one: 1, example: true })
Input:
{ "one": 1, "example": true }Output:
["one"] -
Removes property
adsfrom the payload of the Object.keys callexample.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.keys', 'ads')
Function call:
Object.keys({ one: 1, two: 2, ads: true })
Input:
{ "one": 1, "two": 2, "ads": true }Output:
["one", "two"]
-
Removes property
foo.barfrom the payload of the JSON.stringify callexample.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', 'foo.bar')
Function call:
JSON.stringify({ foo: { bar: 1, a: 2 }, b: 3 })
Input:
{ "foo": { "bar": 1, "a": 2 }, "b": 3 }Output:
{"foo":{"a":2},"b":3} -
Removes property
foo.barfrom the payload of the JSON.stringify call if its error stack trace containstest.jsexample.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', 'foo.bar', '', 'test.js')
Function call:
JSON.stringify({ foo: { bar: 1, a: 2 }, b: 3 })
Input:
{ "foo": { "bar": 1, "a": 2 }, "b": 3 }Output (if
test.jsin stack):{"foo":{"a":2},"b":3} -
Removes all
slotsproperties at any depth during Object.entries callexample.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.entries', '*.slots')
Function call:
Object.entries({ ad: { slots: [1, 2], type: "banner" }, main: { title: "News" } })
Input:
{ "ad": { "slots": [1, 2], "type": "banner" }, "main": { "slots": [3, 4], "title": "News" } }Output:
[ ["ad", { "type": "banner" }], ["main", { "title": "News" }] ]
-
Call with only first and third argument will log the current hostname and matched payload at the console
example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', '', 'bar', '')
Added in v2.2.9.
Replaces a specific argument of a native method with a constant value, JSON parsed value or a value derived from a regular expression replacement.
Related UBO scriptlet: https://github.com/gorhill/ublock/wiki/Resources-Library#trusted-replace-argumentjs-
example.org#%#//scriptlet('trusted-replace-argument', methodPath, [argumentIndex, [argumentValue[, pattern[, stack[, verbose]]]]])
methodPath– required, string path to a native method (joined with.if needed). The property must be attached towindow.argumentIndex– required, string index of the argument to replace (0-based).argumentValue– required, string value to set for the argument. If it starts withreplace:, it is treated as a replacement pattern in the formatreplace:/regex/replacement/. To replace all occurrences of a pattern, the replacement string must include the global flagg, like this:replace:/foo/bar/g, otherwise only the first occurrence will be replaced. If it starts withjson:, it is treated as a JSON string to parse and set for the argument. For example,json:{"key": "value"}will set the argument to an object{ key: 'value' }. If it does not start withreplace:orjson:, it is treated as a constant value to set for the argument, or as one of the following predefined constants:undefinedfalsetruenullemptyObj— empty objectemptyArr— empty arraynoopFunc— function with empty bodynoopCallbackFunc— function returning noopFunctrueFunc— function returning truefalseFunc— function returning falsethrowFunc— function throwing an errornoopPromiseResolve— function returning Promise object that is resolved with an empty responsenoopPromiseReject— function returning Promise.reject()
pattern– optional, string or regular expression pattern to match the argument against. If provided, the argument will only be replaced if it matches this pattern.stack— optional, string or regular expression that must match the current function call stack trace.verbose— optional, string, if set to'true', logs the method arguments. Defaults to'false'. It may be useful for debugging but it is not allowed for prod versions of filter lists.
-
Set the first argument of
evalwith a constant value"Replacement"if the pattern matches:example.org#%#//scriptlet('trusted-replace-argument', 'eval', '0', '"Replacement"', 'Foo bar')
For instance, the following call will return
"Replacement":eval('"Foo bar"'); -
Replace the part
fooof the first argument ofevalwith abarvalue if the pattern matches:example.org#%#//scriptlet('trusted-replace-argument', 'eval', '0', 'replace:/foo/bar/', 'Text content foo')
For instance, the following call will return
"Text content bar":eval('"Text content foo"'); -
Replace all occurrences of the first argument of
JSON.parsewith a constant value"no_ads"if the pattern matches:example.org#%#//scriptlet('trusted-replace-argument', 'JSON.parse', '0', 'replace:/ads/no_ads/g', 'ads')
For instance, the following call:
const jsonString = '{ "ads1": 1, "ads2": 2, "content": "fooBar", "ads3": 3 }'; const result = JSON.parse(jsonString);will return the object:
{ no_ads1: 1, no_ads2: 2, content: 'fooBar', no_ads3: 3 } -
Replace the third argument of
Object.definePropertywith a JSON object{"value": "disabled"}if the pattern matches:example.org#%#//scriptlet('trusted-replace-argument', 'Object.defineProperty', '2', 'json:{"value": "disabled"}', 'enabled')
For instance,
window.adblockproperty for the following call will return"disabled":Object.defineProperty(window, 'adblock', { value: 'enabled' }); -
Replace first argument of
MutationObserverwithnoopFuncif the pattern matches:example.org#%#//scriptlet('trusted-replace-argument', 'MutationObserver', '0', 'noopFunc', 'Adblock')
For instance,
callbackfunction for the following call will be replaced withnoopFunc:const callback = () => { if(adblock) { document.body.innerHTML = 'Adblock detected'; } }; const observerToPrevent = new MutationObserver(callback);
Added in v1.7.3.
Replaces response text content of fetch requests if all given parameters match.
example.org#%#//scriptlet('trusted-replace-fetch-response'[, pattern, replacement[, propsToMatch]])
pattern— optional, argument for matching contents of responseText that should be replaced. If set,replacementis required. Possible values:*to match all text content- non-empty string
- regular expression
By default only first occurrence is replaced. To replace all occurrences use
gflag in RegExp -/pattern/g.
replacement— optional, should be set ifpatternis set. String to replace the response text content matched bypattern. Empty string to remove content. Defaults to empty string.propsToMatch— optional, string of space-separated properties to match; possible props:- string or regular expression for matching the URL passed to fetch call;
empty string, wildcard
*or invalid regular expression will match all fetch calls - colon-separated pairs
name:valuewherenameisinitoption namevalueis string or regular expression for matching the value of the option passed to fetch call; invalid regular expression will cause any value matching
- string or regular expression for matching the URL passed to fetch call;
empty string, wildcard
verbose— optional, boolean, if set to 'true' will log original and modified text content of fetch responses.
verbosemay be useful for debugging but it is not allowed for prod versions of filter lists.
Usage with no arguments will log fetch calls to browser console; it may be useful for debugging but it is not allowed for prod versions of filter lists.
Scriptlet does nothing if response body can't be converted to text.
-
Log all fetch calls
example.org#%#//scriptlet('trusted-replace-fetch-response')
-
Replace response text content of fetch requests with specific url
example.org#%#//scriptlet('trusted-replace-fetch-response', 'adb_detect:true', 'adb_detect:false', 'example.org') example.org#%#//scriptlet('trusted-replace-fetch-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', 'example.org')
-
Remove all text content of fetch responses with specific request method
example.org#%#//scriptlet('trusted-replace-fetch-response', '*', '', 'method:GET')
-
Replace response text content of fetch requests matching by URL regex and request methods
example.org#%#//scriptlet('trusted-replace-fetch-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/')
-
Remove text content of all fetch responses for example.com
example.org#%#//scriptlet('trusted-replace-fetch-response', '*', '', 'example.com')
-
Replace "foo" text content with "bar" of all fetch responses for example.com and log original and modified text content
example.org#%#//scriptlet('trusted-replace-fetch-response', 'foo', 'bar', 'example.com', 'true')
-
Replace all "noAds=false" text content with "noAds=true" of all fetch responses for example.com and log original and modified text content
example.org#%#//scriptlet('trusted-replace-fetch-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
Added in v1.9.37.
Replaces text in text content of matched DOM nodes.
example.org#%#//scriptlet('trusted-replace-node-text', nodeName, textMatch, pattern, replacement)
nodeName— required, string or RegExp, specifies DOM node name from which the text will be removed. Must target lowercased node names, e.gdivinstead ofDIV.textMatch— required, string or RegExp to match against node's text content. If matched, thepatternwill be replaced by thereplacement. Case sensitive.pattern— required, string or regexp for matching contents ofnode.textContentthat should be replaced. By default only first occurrence is replaced. To replace all occurrences usegflag in RegExp -/pattern/g.replacement— required, string to replace text content matched bypattern....extraArgs— optional, string, if includes 'verbose' will log original and modified text content.
verbosemay be useful for debugging but it is not allowed for prod versions of filter lists.
-
Replace node's text content:
example.org#%#//scriptlet('trusted-replace-node-text', 'div', 'some', 'text', 'other text')
<!-- before --> <div>some text</div> <div>text</div> <span>some text</span> <!-- after --> <div>some other text</div> <div>text</div> <span>some text</span>
-
Replace node's text content, matching both node name, text and pattern by RegExp:
example.org#%#//scriptlet('trusted-replace-node-text', '/[a-z]*[0-9]/', '/s\dme/', '/t\dxt/', 'other text')
<!-- before --> <qrce3>s0me t3xt</qrce3> // this node is going to be matched by both node name and text <qrce3>text</qrce3> // this node won't be matched by text content nor text content <span>some text</span> <!-- after --> <qrce3>s0me other text</qrce3> // text content has changed <qrce3>text</qrce3> <span>some text</span>
-
Replace all occurrences in node's text content, matching both node name and text:
example.org#%#//scriptlet('trusted-replace-node-text', 'p', 'bar', '/a/g', 'x')
<!-- before --> <p>foa bar baz</p> // this node is going to be matched by both node name and text <!-- after --> <p>fox bxr bxz</p> // text content has changed
-
Replace node's text content and log original and modified text content:
example.org#%#//scriptlet('trusted-replace-node-text', 'div', 'some', 'text', 'other text', 'verbose')
Added in v1.11.1.
Replace the text in the outbound function call.
Related UBO scriptlet: https://github.com/gorhill/uBlock/commit/21e1ee30ee36c1b9a7a3c9f43ac97e52d8e79661
example.org#%#//scriptlet('trusted-replace-outbound-text', methodPath[, textToReplace[, replacement[, decodeMethod[, stack[, logContent]]]]])
methodPath— required, the name of the function to trap, it must have an object as an argument. Call with onlymethodPathas an argument will log all text content of the specified function to console, but only if function call returns a string, otherwise it will log information that content is not a string.textToReplace— optional, string or regular expression which should be replaced. By default it's set to''. If it's not set to other value andlogContentis set, it will log the original content.replacement— optional, string which replace the matched text. By default it's set to '', so matched content will removed.decodeMethod— optional, string which specifies the method used to decode the content. For now supported value is 'base64'. By default it's set to''and no decoding is performed. If it's set andlogContentis also set andtextToReplaceandreplacementare not set, then it will log the decoded content.stack— optional, string or regular expression that must match the current function call stack trace. If regular expression is invalid it will be skipped.logContent— optional, if set to any value, the original and modified content will be logged. By default it's set to '' and no content will be logged.
Logging content may be useful for debugging but it is not allowed for prod versions of filter lists.
-
Replace
foowith 'bar' from the payload of the atob call:example.org#%#//scriptlet('trusted-replace-outbound-text', 'atob', 'foo', 'bar')
For instance, the following call will return
barconst text = btoa('foo'); atob(text); -
Replace
disable_ads:falsewith 'disable_ads:true' from the payload of theArray.prototype.joinif content is encoded in base64:example.org#%#//scriptlet('trusted-replace-outbound-text', 'Array.prototype.join', 'disable_ads:false', 'disable_ads:true', 'base64')
For instance, the following call will return
ZGlzYWJsZV9hZHM6dHJ1ZQ==which is'disable_ads:true'after decodingconst arrayBase64 = ['ZGlzYWJsZV9h','ZHM6ZmFsc2U=']; // `ZGlzYWJsZV9hZHM6ZmFsc2U=` after decoding is `disable_ads:false` arrayBase64.join(''); -
Replace
"loadAds":truewith"loadAds":falsefrom the payload of the JSON.stringify if the stack trace containstestStackFunction:example.org#%#//scriptlet('trusted-replace-outbound-text', 'JSON.stringify', '"loadAds":true', '"loadAds":false', '', 'testStackFunction')
For instance, the following call will return
'{"loadAds":false,"content":"bar"}'const testStackFunction = () => JSON.stringify({ loadAds: true, content: 'bar' }); testStackFunction(); -
Call with
decodeMethodandlogContentarguments will log original and decoded text content of the specified function:example.org#%#//scriptlet('trusted-replace-outbound-text', 'Array.prototype.join', '', '', 'base64', '', 'true')
-
Call with only first argument will log text content of the specified function:
example.org#%#//scriptlet('trusted-replace-outbound-text', 'atob')
-
Call with
logContentargument will log original and modified text content of the specified function:example.org#%#//scriptlet('trusted-replace-outbound-text', 'atob', 'foo', 'bar', '', '', 'true')
Added in v1.7.3.
Replaces response content of xhr requests if all given parameters match.
example.org#%#//scriptlet('trusted-replace-xhr-response'[, pattern, replacement[, propsToMatch]])
pattern— optional, argument for matching contents of responseText that should be replaced. If set,replacementis required. Possible values:*to match all text content- non-empty string
- regular expression
By default only first occurrence is replaced. To replace all occurrences use
gflag in RegExp -/pattern/g.
replacement— optional, should be set ifpatternis set. String to replace matched content with. Empty string to remove content.propsToMatch— optional, string of space-separated properties to match for extra condition; possible props:- string or regular expression for matching the URL passed to
XMLHttpRequest.open()call; - colon-separated pairs
name:valuewherename— string or regular expression for matching XMLHttpRequest property namevalue— string or regular expression for matching the value of the option passed toXMLHttpRequest.open()call
- string or regular expression for matching the URL passed to
verbose— optional, boolean, if set to 'true' will log original and modified text content of XMLHttpRequests.
verbosemay be useful for debugging but it is not allowed for prod versions of filter lists.
Usage with no arguments will log XMLHttpRequest objects to browser console; it may be useful for debugging but it is not allowed for prod versions of filter lists.
-
Log all XMLHttpRequests
example.org#%#//scriptlet('trusted-replace-xhr-response')
-
Replace text content of XMLHttpRequests with specific url
example.org#%#//scriptlet('trusted-replace-xhr-response', 'adb_detect:true', 'adb_detect:false', 'example.org') example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', 'example.org')
-
Remove all text content of XMLHttpRequests with specific request method
example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'method:GET')
-
Replace text content of XMLHttpRequests matching by URL regex and request methods
example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/')
-
Remove all text content of all XMLHttpRequests for example.com
example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'example.com')
-
Replace "foo" text content with "bar" of all XMLHttpRequests for example.com and log original and modified text content
example.org#%#//scriptlet('trusted-replace-xhr-response', 'foo', 'bar', 'example.com', 'true')
-
Replace all "noAds=false" text content with "noAds=true" of all XMLHttpRequests for example.com and log original and modified text content
example.org#%#//scriptlet('trusted-replace-xhr-response', '/noAds=false/g', 'noAds=true', 'example.com', 'true')
Added in v1.10.1.
Sets attribute with arbitrary value on the specified elements. This scriptlet runs once when the page loads and after that on DOM tree changes.
example.org#%#//scriptlet('trusted-set-attr', selector, attr[, value])
selector— required, CSS selector, specifies DOM nodes to set attributes onattr— required, attribute to be setvalue— optional, the value to assign to the attribute, defaults to ''.
-
Set attribute by selector
example.org#%#//scriptlet('trusted-set-attr', 'div > a.class', 'test-attribute', '[true, true]')
<!-- before --> <div> <a>Another text</a> <a class="class">Some text</a> </div> <!-- after --> <div> <a>Another text</a> <a class="class" test-attribute="[true, true]">Some text</a> </div>
-
Set attribute without value
example.org#%#//scriptlet('trusted-set-attr', 'a.class', 'test-attribute')
<!-- before --> <a class="class">Some text</div> <!-- after --> <a class="class" test-attribute>Some text</div>
-
Set attribute value to
MTIzNTY=example.org#%#//scriptlet('trusted-set-attr', 'a.class', 'test-attribute', 'MTIzNTY=')
<!-- before --> <a class="class">Some text</div> <!-- after --> <a class="class" test-attribute="MTIzNTY=">Some text</div>
-
Set attribute value to
{ playback: false }example.org#%#//scriptlet('trusted-set-attr', 'a.class', 'test-attribute', '{ playback: false }')
<!-- before --> <a class="class">Some text</div> <!-- after --> <a class="class" test-attribute="{ playback: false }">Some text</div>
Added in v1.8.2.
Creates a constant property and assigns it a specified value.
Actually, it's not a constant. Please note, that it can be rewritten with a value of a different type.
If empty object is present in chain it will be trapped until chain leftovers appear.
Use set-constant to set predefined values and functions.
example.org#%#//scriptlet('trusted-set-constant', property, value[, stack])
property— required, path to a property (joined with.if needed). The property must be attached towindow.value— required, an arbitrary value to be set; value type is being inferred from the argument, e.g '500' will be set as number; simple strings that do not match other types are automatically set as strings, e.g 'yes', 'no', 'allow'; to set string type value that looks like other types, wrap argument into another pair of quotes, e.g.'"500"'for a string;stack— optional, string or regular expression that must match the current function call stack trace; if regular expression is invalid it will be skipped
-
Set property values of different types
! Set string value wrapping argument into another pair of quotes example.org#%#//scriptlet('trusted-set-constant', 'click_r', '"null"') ✔ window.click_r === 'null' ✔ typeof window.click_r === 'string' ! Set inferred null value example.org#%#//scriptlet('trusted-set-constant', 'click_r', 'null') ✔ window.click_r === null ✔ typeof window.click_r === 'object' ! Set number type value example.org#%#//scriptlet('trusted-set-constant', 'click_r', '48') ✔ window.click_r === 48 ✔ typeof window.click_r === 'number' ! Set array or object as property value, argument should be a JSON string example.org#%#//scriptlet('trusted-set-constant', 'click_r', '[1,"string"]') example.org#%#//scriptlet('trusted-set-constant', 'click_r', '{"aaa":123,"bbb":{"ccc":"string"}}') ! Set simple string value without quotes example.org#%#//scriptlet('trusted-set-constant', 'test', 'no') ✔ window.test === 'no' ✔ typeof window.test === 'string'
-
Use script stack matching to set value
! `document.first` will return `1` if the method is related to `checking.js` example.org#%#//scriptlet('trusted-set-constant', 'document.first', '1', 'checking.js') ✔ document.first === 1 // if the condition described above is met
Added in v1.7.10.
Sets a cookie with arbitrary name and value,
and with optional ability to offset cookie attribute 'expires', set path
and set domain.
Also reloads the current page after the cookie setting.
If reloading option is not needed, use the trusted-set-cookie scriptlet.
example.org#%#//scriptlet('trusted-set-cookie-reload', name, value[, offsetExpiresSec[, path[, domain]]])
name— required, cookie name to be setvalue— required, cookie value. Possible values:- arbitrary value
- empty string for no value
$now$keyword for setting current time in ms, e.g 1667915146503$currentDate$keyword for setting current time as string, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'$currentISODate$keyword for setting current date in the date time string format, e.g '2022-11-08T13:53:19.650Z'
offsetExpiresSec— optional, offset from current time in seconds, after which cookie should expire; defaults to no offset. Possible values:- positive integer in seconds
1yearkeyword for setting expiration date to one year1daykeyword for setting expiration date to one day
path— optional, argument for setting cookie path, defaults to/; possible values:/— root pathnone— to set no path at all
domain— optional, cookie domain, if not set origin will be set as domain, if the domain does not match the origin, the cookie will not be set
Note that the scriptlet does not encode cookie names and values. As a result, if a cookie's name or value includes
;, the scriptlet will not set the cookie since this may cause the cookie to break.
-
Set cookie and reload the page after it
example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'accept')
-
Set cookie with
new Date().getTime()value and reload the page after itexample.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', '$now$')
-
Set cookie which will expire in 3 days and reload the page after it
example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'accept', '259200')
-
Set cookie which will expire in one year and reload the page after it
example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'accept', '1year')
-
Set cookie with no 'expire' and no path, reload the page after it
example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'decline', '', 'none')
-
Set cookie with domain
example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'decline', '', 'none', 'example.org')
Added in v1.7.3.
Sets a cookie with arbitrary name and value, and with optional ability to offset cookie attribute 'expires', set path and set domain.
example.org#%#//scriptlet('trusted-set-cookie', name, value[, offsetExpiresSec[, path[, domain]]])
name— required, cookie name to be setvalue— required, cookie value. Possible values:- arbitrary value
- empty string for no value
$now$keyword for setting current time in ms, e.g 1667915146503$currentDate$keyword for setting current time as string, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'$currentISODate$keyword for setting current date in the date time string format, e.g '2022-11-08T13:53:19.650Z'
offsetExpiresSec— optional, offset from current time in seconds, after which cookie should expire; defaults to no offset. Possible values:- positive integer in seconds
1yearkeyword for setting expiration date to one year1daykeyword for setting expiration date to one day
path— optional, argument for setting cookie path, defaults to/; possible values:/— root pathnone— to set no path at all
domain— optional, cookie domain, if not set origin will be set as domain, if the domain does not match the origin, the cookie will not be set
Note that the scriptlet does not encode cookie names and values. As a result, if a cookie's name or value includes
;, the scriptlet will not set the cookie since this may cause the cookie to break.
-
Set cookie
example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', 'accept') example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', '1-accept_1')
-
Set cookie with
new Date().getTime()valueexample.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', '$now$')
-
Set cookie which will expire in 3 days
example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', 'accept', '259200')
-
Set cookie which will expire in one year
example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', 'accept', '1year')
-
Set cookie with no path
example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', 'decline', '', 'none')
-
Set cookie with domain
example.org#%#//scriptlet('trusted-set-cookie', 'cmpconsent', 'decline', '', 'none', 'example.org')
Added in v1.7.3.
Adds item with arbitrary key and value to localStorage object, or updates the value of the key if it already exists. Scriptlet won't set item if storage is full.
example.com#%#//scriptlet('trusted-set-local-storage-item', 'key', 'value')key— required, key name to be set.value— required, key value; possible values:- arbitrary value
$now$keyword for setting current time in ms, corresponds toDate.now()and(new Date).getTime()calls$currentDate$keyword for setting string representation of the current date and time, corresponds toDate()and(new Date).toString()calls$currentISODate$keyword for setting current date in the date time string format, corresponds to(new Date).toISOString()call, e.g '2022-11-08T13:53:19.650Z'
-
Set local storage item
example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.mute', 'false') example.org#%#//scriptlet('trusted-set-local-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"flag":false}') example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '[16364,88364]') example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '{"providers":[123,456],"consent":"all"}')
-
Set item with current time since unix epoch in ms
example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.play', '$now$')
-
Set item with current date, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'
example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.play', '$currentDate$')
-
Set item without value
example.org#%#//scriptlet('trusted-set-local-storage-item', 'ppu_main_none', '')
Added in v1.11.16.
Adds item with arbitrary key and value to sessionStorage object, or updates the value of the key if it already exists. Scriptlet won't set item if storage is full.
example.com#%#//scriptlet('trusted-set-session-storage-item', 'key', 'value')key— required, key name to be set.value— required, key value; possible values:- arbitrary value
$now$keyword for setting current time in ms, corresponds toDate.now()and(new Date).getTime()calls$currentDate$keyword for setting string representation of the current date and time, corresponds toDate()and(new Date).toString()calls$currentISODate$keyword for setting current date in the date time string format, corresponds to(new Date).toISOString()call, e.g '2022-11-08T13:53:19.650Z'
-
Set session storage item
example.org#%#//scriptlet('trusted-set-session-storage-item', 'player.live.current.mute', 'false') example.org#%#//scriptlet('trusted-set-session-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"flag":false}') example.org#%#//scriptlet('trusted-set-session-storage-item', 'providers', '[16364,88364]') example.org#%#//scriptlet('trusted-set-session-storage-item', 'providers', '{"providers":[123,456],"consent":"all"}')
-
Set item with current time since unix epoch in ms
example.org#%#//scriptlet('trusted-set-session-storage-item', 'player.live.current.play', '$now$')
-
Set item with current date, e.g 'Tue Nov 08 2022 13:53:19 GMT+0300'
example.org#%#//scriptlet('trusted-set-session-storage-item', 'player.live.current.play', '$currentDate$')
-
Set item without value
example.org#%#//scriptlet('trusted-set-session-storage-item', 'ppu_main_none', '')
Added in v1.10.25.
Prevents a call of a given native method, matching the call by incoming arguments.
example.org#%#//scriptlet('trusted-suppress-native-method', methodPath, signatureStr[, how[, stack]])
-
methodPath– required, string path to a native method (joined with.if needed). The property must be attached towindow. -
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.
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.
stack— optional, string or regular expression that must match the current function call stack trace.
-
Prevent
localStorage.setItem('test-key', 'test-value')call matching first argument by regexp pattern and the second one by substring:example.org#%#//scriptlet('trusted-suppress-native-method', 'localStorage.setItem', '/key/|"value"', 'prevent')
-
Abort
obj.hasOwnProperty('test')call matching the first argument:example.org#%#//scriptlet('trusted-suppress-native-method', 'Object.prototype.hasOwnProperty', '"test"')
-
Prevent
Node.prototype.appendChildcall on element with the idtest-idby object matcher:example.org#%#//scriptlet('trusted-suppress-native-method', 'Node.prototype.appendChild', '{"id":"str"}', 'prevent')
-
Abort all
document.querySelectorAllcalls withdivas the first argument:example.org#%#//scriptlet('trusted-suppress-native-method', 'Document.prototype.querySelectorAll', '"div"')
-
Abort
Array.prototype.concat([1, 'str', true, null])calls by matching array argument contents:example.org#%#//scriptlet('trusted-suppress-native-method', 'Array.prototype.concat', '[1, "str", true]')
-
Use
stackargument to match by the call, while also matching the second argument:example.org#%#//scriptlet('trusted-suppress-native-method', 'sessionStorage.setItem', ' |"item-value"', 'abort', 'someFuncName')