### Prevent window.open for URLs NOT containing 'example' Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Negates the match with '!example' to block all URLs except those containing 'example'. ```adblock example.org#%#//scriptlet('prevent-window-open', '!example') ``` -------------------------------- ### Install dependencies with pnpm Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Installs project dependencies. Note that package.json pins the transitive basic-ftp dependency to 5.2.1 via pnpm.overrides; it comes through Puppeteer's proxy chain and can be removed once upstream resolves basic-ftp@>=5.2.1. ```bash pnpm install ``` -------------------------------- ### Input JSON for merge example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JSON for the merge example. ```json { "foo": { "a": { "old": 0 }, "c": 3 } } ``` -------------------------------- ### debug-on-property-read example for open Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Use to start the debugger when a script tries to access window.open. Not allowed in prod versions of filter lists. ```adblock example.org#%#//scriptlet('debug-on-property-read', 'open') ``` -------------------------------- ### Output JSON for example 1 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Output JSON after pruning property 'example'. ```json { "one": 1 } ``` -------------------------------- ### log-on-stack-trace example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage of log-on-stack-trace to log stack traces when accessing window.open. ```adblock example.org#%#//scriptlet('log-on-stack-trace', 'open') ``` -------------------------------- ### Input JSON for replace example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JSON for the replace example. ```json { "content": "The advertisement block" } ``` -------------------------------- ### Install and link extension packages Source: https://github.com/adguardteam/scriptlets/blob/master/README.md In the extension directory, install dependencies, link packages and build. ```bash pnpm install pnpm link --global "@adguard/scriptlets" # run build script ``` -------------------------------- ### abort-on-property-read examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Examples aborting script when accessing window.alert or navigator.language. ```adblock ! Aborts script when it tries to access `window.alert` example.org#%#//scriptlet('abort-on-property-read', 'alert') ! Aborts script when it tries to access `navigator.language` example.org#%#//scriptlet('abort-on-property-read', 'navigator.language') ``` -------------------------------- ### JSON.parse call for example 1 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md JSON.parse call used in the first example to demonstrate pruning of property 'example'. ```html JSON.parse('{"one":1,"example":true}') ``` -------------------------------- ### Prevent window.open for URLs containing 'example' Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Matches URLs containing the string 'example'. ```adblock example.org#%#//scriptlet('prevent-window-open', 'example') ``` -------------------------------- ### Input JSON for removal example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JSON for the removal example. ```json { "ads": { "enabled": true, "type": "banner" }, "content": "article" } ``` -------------------------------- ### abort-on-property-write example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example aborting script when setting window.adblock value. ```adblock ! Aborts script when it tries to set `window.adblock` value example.org#%#//scriptlet('abort-on-property-write', 'adblock') ``` -------------------------------- ### Input JSON for example 1 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Input JSON object for the first example. ```json { "one": 1, "example": true } ``` -------------------------------- ### Input JSON for example 5 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Input JSON object for the fifth example. ```json { "content": { "block1": { "media": { "src": "1.jpg", "ad": true } }, "block2": { "media": { "src": "2.jpg" } } } } ``` -------------------------------- ### Old syntax examples for prevent-window-open Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Examples of the deprecated parameter format. Old syntax is not recommended for better uBO compatibility. ```adblock example.org#%#//scriptlet('prevent-window-open', '1', '/example\./') ``` ```adblock example.org#%#//scriptlet('prevent-window-open', '0', 'example') ``` ```adblock example.org#%#//scriptlet('prevent-window-open', '', '', 'trueFunc') ``` ```adblock example.org#%#//scriptlet('prevent-window-open', '1', '', '{propName=noopFunc}') ``` -------------------------------- ### Example 1: Remove property 'example' (legacy syntax) Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes the property 'example' from the JSON response of any XMLHttpRequest call using legacy syntax. ```adblock example.org#%#//scriptlet('json-prune-xhr-response', 'example') ``` -------------------------------- ### Input JSON for example 2 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Input JSON object for the second example. ```json { "one": 1, "two": 2 } ``` -------------------------------- ### Build the library Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Builds the library and outputs to dist/. ```bash pnpm build ``` -------------------------------- ### set-cookie scriptlet usage examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Examples of using the set-cookie scriptlet with various parameters, including a set-cookie-reload variant. The last example uses the 'none' path and a domain. ```adblock example.org#%#//scriptlet('set-cookie', 'CookieConsent', '1') example.org#%#//scriptlet('set-cookie', 'gdpr-settings-cookie', 'true') example.org#%#//scriptlet('set-cookie', 'cookie_consent', 'ok', 'none') example.org#%#//scriptlet('set-cookie-reload', 'test', '1', 'none', 'example.org') ``` -------------------------------- ### debug-on-property-write example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Use to start the debugger when a script tries to write to property window.test. Not allowed in prod versions of filter lists. ```adblock example.org#%#//scriptlet('debug-on-property-write', 'test') ``` -------------------------------- ### Example 1: Output JSON response after pruning Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md The JSON response after the scriptlet removes the 'example' property. ```js {one: 1} ``` -------------------------------- ### debug-on-property-read example for alert Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Use to start the debugger when a script tries to access window.alert. Not allowed in prod versions of filter lists. ```adblock example.org#%#//scriptlet('debug-on-property-read', 'alert') ``` -------------------------------- ### Input JavaScript for adManager stack trace example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JavaScript function for the adManager stack trace example. ```js function adManager() { return JSON.parse('{"ads":{"enabled":true},"content":"article"}'); } ``` -------------------------------- ### Input JSON for example 3 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Input JSON object for the third example. ```json { "a": { "b": 123 }, "ads": { "url": { "first": "abc" } } } ``` -------------------------------- ### set-local-storage-item usage examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Examples of setting localStorage items and removing them. Use $remove$ as value to delete a specific item or a regular expression key to remove matching items. ```adblock example.org#%#//scriptlet('set-local-storage-item', 'player.live.current.mute', 'false') example.org#%#//scriptlet('set-local-storage-item', 'exit-intent-marketing', '1') ! Removes the item with key 'foo' from local storage example.org#%#//scriptlet('set-local-storage-item', 'foo', '$remove$') ! Removes from local storage all items whose key matches the regular expression `/mp_.*_mixpanel/` example.org#%#//scriptlet('set-local-storage-item', '/mp_.*_mixpanel/', '$remove$') ``` -------------------------------- ### debug-current-inline-script example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Use to start the debugger when an inline script tries to access window.alert. Not allowed in prod versions of filter lists. ```adblock example.org#%#//scriptlet('debug-current-inline-script', 'alert') ``` -------------------------------- ### Input JSON for example 4 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Input JSON object for the fourth example. ```json { "content": { "ad": { "src": "a.js" } } } ``` -------------------------------- ### Example 1: Remove property 'example' (JSONPath syntax) Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes the property 'example' from the JSON response of any XMLHttpRequest call using JSONPath syntax. ```adblock example.org#%#//scriptlet('json-prune-xhr-response', '$.example') ``` -------------------------------- ### remove-cookie example: remove cookies matching 'example' Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage that removes cookies whose name contains the string 'example'. The following JavaScript shows a cookie that would be removed. ```adblock example.org#%#//scriptlet('remove-cookie', 'example') ``` ```javascript document.cookie = '__example=randomValue'; ``` -------------------------------- ### Run linters with pnpm Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Runs all linters or individual ones: ESLint, TypeScript type checking, and markdownlint. ```bash # All linters pnpm lint # Individual linters pnpm lint:code # ESLint pnpm lint:types # TypeScript type checking pnpm lint:md # markdownlint ``` -------------------------------- ### Remove 'example' property from Object.getOwnPropertyNames payload Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Example 1: Removes property 'example' from the payload of the Object.getOwnPropertyNames call. Shows the scriptlet usage, the function call, input object, and resulting output. ```adblock example.org#%#//scriptlet('trusted-prune-inbound-object', 'Object.getOwnPropertyNames', 'example') ``` ```js Object.getOwnPropertyNames({ one: 1, example: true }) ``` ```json { "one": 1, "example": true } ``` ```json ["one"] ``` -------------------------------- ### Adjust setTimeout x20 matching callback 'example' at 400ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Adjusts setTimeout callbacks matching 'example' with delay 400ms, by a factor of 20. ```adblock example.org#%#//scriptlet('adjust-setTimeout', 'example', '400') ``` -------------------------------- ### CoreLibs scriptlets JSON file example Source: https://github.com/adguardteam/scriptlets/blob/master/README.md Example of the dist/scriptlets.corelibs.json file structure for CoreLibs usage. Contains a version and an array of scriptlet objects with names and scriptlet code. ```json { "version": "1.0.0", "scriptlets": [ { "names": [ "abort-on-property-read", "ubo-abort-on-property-read.js", "abp-abort-on-property-read" ], "scriptlet": "function() { ...code... }" } ] } ``` -------------------------------- ### Example call to Response.prototype.json Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Example call to Response.prototype.json that would be affected by the scriptlet. ```js const data = await new Response('{"ads":{"enabled":true},"content":"article"}').json(); ``` -------------------------------- ### Remove property 'example' with legacy syntax Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes property 'example' from the result of JSON.parse call using legacy path syntax. ```adblock example.org#%#//scriptlet('json-prune', 'example') ``` -------------------------------- ### Input JSON for trusted-json-set example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JSON used in the first example of the trusted-json-set scriptlet. ```json { "items": { "a": { "enabled": true }, "b": { "enabled": 1 } } } ``` -------------------------------- ### Input JSON for conditional modification example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Input JSON for the conditional modification example. ```json { "tracking": { "enabled": true }, "meta": { "v": 1 } } ``` -------------------------------- ### Example 1: Input JSON response Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example JSON response of an XMLHttpRequest call before pruning. ```js {one: 1, example: true} ``` -------------------------------- ### JSON.parse call for example 5 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md JSON.parse call used in the fifth example. ```html JSON.parse('{"content":{"block1":{"media":{"src":"1.jpg","ad":true}},"block2":{"media":{"src":"2.jpg"}}}}') ``` -------------------------------- ### JSON.parse call for example 2 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md JSON.parse call used in the second example. ```html JSON.parse('{"one":1,"two":2}') ``` -------------------------------- ### evaldata-prune example 6: no arguments Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Logs current hostname and object payload to console. ```adblock example.org#%#//scriptlet('evaldata-prune') ``` -------------------------------- ### Adjust setTimeout x20 matching callback 'example' at 1000ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Adjusts setTimeout callbacks whose stringified callback matches 'example' and delay is 1000ms, by a factor of 20. ```adblock example.org#%#//scriptlet('adjust-setTimeout', 'example') ``` -------------------------------- ### google-ima3-dai redirect example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-redirects.md Adblock filter rule to redirect imasdk.googleapis.com/js/sdkloader/ima3_dai.js to the google-ima3-dai mock. Added in v2.4.2. ```adblock ||imasdk.googleapis.com/js/sdkloader/ima3_dai.js$script,redirect=google-ima3-dai ``` -------------------------------- ### Set local storage item examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Four examples of setting localStorage items with arbitrary values: boolean, JSON object, array, and JSON object with consent. Each uses the trusted-set-local-storage-item scriptlet. ```adblock 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"}') ``` -------------------------------- ### JSON.parse call for example 3 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md JSON.parse call used in the third example. ```html JSON.parse('{"a":{"b":123},"ads":{"url":{"first":"abc"}}}') ``` -------------------------------- ### remove-cookie example: remove all cookies Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage that removes all accessible cookies on the page. ```adblock example.org#%#//scriptlet('remove-cookie') ``` -------------------------------- ### google-ima3 redirect example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-redirects.md Adblock filter rule to redirect imasdk.googleapis.com/js/sdkloader/ima3.js to the google-ima3 mock. Added in v1.6.2. ```adblock ||imasdk.googleapis.com/js/sdkloader/ima3.js$script,redirect=google-ima3 ``` -------------------------------- ### prevent-canvas examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Three usage examples: prevent all canvas contexts, prevent only '2d' contexts, and prevent all except '2d' using negation. ```adblock example.org#%#//scriptlet('prevent-canvas') ``` ```adblock example.org#%#//scriptlet('prevent-canvas', '2d') ``` ```adblock example.org#%#//scriptlet('prevent-canvas', '!2d') ``` -------------------------------- ### Link and build tsurlfilter package Source: https://github.com/adguardteam/scriptlets/blob/master/README.md In the tsurlfilter directory, install and link dependencies, link scriptlets, move into package and build, and create tsurlfilter link. ```bash lerna bootstrap pnpm link --global "@adguard/scriptlets" cd ./packages/tsurlfilter pnpm build pnpm link --global ``` -------------------------------- ### Output JavaScript for adManager stack trace example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Output JavaScript after applying the scriptlet. ```js { ads: { enabled: false }, content: 'article' } ``` -------------------------------- ### Slow down setTimeout x2 matching callback 'example' at 1000ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Slows down setTimeout callbacks matching 'example' with delay 1000ms by a factor of 2 (boost '2'). ```adblock example.org#%#//scriptlet('adjust-setTimeout', 'example', '', '2') ``` -------------------------------- ### Create div with text content Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Creates a div element with text content 'Hello world!' appended to body. ```adblock example.com#%#//scriptlet('trusted-create-element', 'body', 'div', '', 'Hello world!') ``` -------------------------------- ### prevent-navigation example: log all navigation attempts Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Logs all navigation attempts without blocking, as no urlPattern is provided. ```adblock example.org#%#//scriptlet('prevent-navigation') ``` -------------------------------- ### Adjust setInterval() x20 with callback 'example' and delay 1000ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Adjusts setInterval() callbacks matching 'example' with delay 1000ms by a factor of 20. ```adblock example.org#%#//scriptlet('adjust-setInterval', 'example') ``` -------------------------------- ### Adjust setInterval() x20 with callback 'example' and delay 400ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Adjusts setInterval() callbacks matching 'example' with delay 400ms by a factor of 20. ```adblock example.org#%#//scriptlet('adjust-setInterval', 'example', '400') ``` -------------------------------- ### Remove property 'example' with JSONPath syntax Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes property 'example' from the result of JSON.parse call using JSONPath syntax. ```adblock example.org#%#//scriptlet('json-prune', '$.example') ``` -------------------------------- ### Example: Remove all text content for specific request method Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Removes all text content of XMLHttpRequests with the request method GET. The pattern '*' matches all text, and the empty replacement removes it. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'method:GET') ``` -------------------------------- ### Run lint and tests before committing Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Run these checks before every commit. Both must pass with no errors. Use the relevant test command based on the type of change. ```bash # Lint all (ESLint + TypeScript + markdownlint) pnpm lint # Run the relevant test suite pnpm test:qunit scriptlets --name # for scriptlet changes pnpm test:vitest # for API/converter/validator/helper changes and scriptlet specs ``` -------------------------------- ### Output JSON for trusted-json-set example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Output JSON after applying the trusted-json-set scriptlet to the input. ```json { "items": { "a": { "enabled": false }, "b": { "enabled": 1 } } } ``` -------------------------------- ### prevent-element-src-loading example: prevent script source loading Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage to prevent loading of script sources matching 'adsbygoogle'. ```adblock example.org#%#//scriptlet('prevent-element-src-loading', 'script', 'adsbygoogle') ``` -------------------------------- ### Commit message format Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Every commit message must start with the ticket number (AG-XXX) followed by a short description in the present tense. Automated CI commits use a Conventional Commits prefix such as 'docs:'. ```text AG-XXX ``` -------------------------------- ### Set cookie with domain and reload Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Sets the cookie with domain 'example.org' and no path, then reloads the page. The domain must match the origin or the cookie will not be set. ```adblock example.org#%#//scriptlet('trusted-set-cookie-reload', 'cmpconsent', 'decline', '', 'none', 'example.org') ``` -------------------------------- ### Remove property 'example' from fetch JSON response Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes the property 'example' from any fetch call's JSON response. The first block uses legacy syntax, the second uses JSONPath syntax. If the response is {one: 1, example: true}, it becomes {one: 1}. ```adblock example.org#%#//scriptlet('json-prune-fetch-response', 'example') ``` ```adblock example.org#%#//scriptlet('json-prune-fetch-response', '$.example') ``` ```js {one: 1, example: true} ``` ```js {one: 1} ``` -------------------------------- ### Example: Log all XMLHttpRequests Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Usage with no arguments logs XMLHttpRequest objects to the browser console. This is useful for debugging but not allowed for prod versions of filter lists. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response') ``` -------------------------------- ### Output JSON for replace example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Output JSON after applying the replace operation. ```json { "content": "The article block" } ``` -------------------------------- ### xml-prune example: log response payload for matched URL Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Call with only urlToMatch argument logs response payload and URL only for the matched URL. ```adblock example.org#%#//scriptlet('xml-prune', '', '', '.mpd') ``` -------------------------------- ### remove-attr Example: Remove by Attribute Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes the specified attributes from DOM nodes. The example removes 'example' and 'test' attributes from all elements. ```adblock example.org#%#//scriptlet('remove-attr', 'example|test') ``` ```html
Some text
Some text
``` -------------------------------- ### Example: Remove all text content for example.com Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Removes all text content of all XMLHttpRequests for example.com by using '*' as pattern and an empty replacement. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', '*', '', 'example.com') ``` -------------------------------- ### Output JSON for merge example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Output JSON after merging the object. ```json { "foo": { "a": { "test": 1 }, "c": 3, "b": { "c": 1 } } } ``` -------------------------------- ### Slow down setInterval() x2 with callback 'example' and delay 1000ms Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Slows down setInterval() callbacks matching 'example' with delay 1000ms by a factor of 2 (boost '2'). ```adblock example.org#%#//scriptlet('adjust-setInterval', 'example', '', '2') ``` -------------------------------- ### xml-prune example: log response payload and URL Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Call with no arguments logs response payload and URL to browser console. Not allowed for prod versions of filter lists. ```adblock example.org#%#//scriptlet('xml-prune') ``` -------------------------------- ### evaldata-prune example 7: only second argument Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Logs current hostname and matched object payload to console. ```adblock example.org#%#//scriptlet('evaldata-prune', '', '"id":"117458"') ``` -------------------------------- ### remove-in-shadow-dom examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Two example usages: one removes a menu bar using a base selector, the other removes a floating element without a base selector. ```adblock ! removes menu bar virustotal.com#%#//scriptlet('remove-in-shadow-dom', 'iron-pages', 'vt-virustotal-app') ! removes floating element virustotal.com#%#//scriptlet('remove-in-shadow-dom', 'vt-ui-contact-fab') ``` -------------------------------- ### evaldata-prune example 3: chain property Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Property can be a chain like 'a.b' and 'ads.url.first'. ```adblock example.org#%#//scriptlet('evaldata-prune', 'a.b', 'ads.url.first') ``` -------------------------------- ### remove-attr Example: Remove with Selector Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes the specified attribute only from DOM nodes matching the given CSS selector. The example removes 'example' from elements with class 'inner'. ```adblock example.org#%#//scriptlet('remove-attr', 'example', 'div[class="inner"]') ``` ```html
Some text
Some text
``` -------------------------------- ### Apply style to all shadow DOM subtrees Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage of inject-css-in-shadow-dom to apply a CSS rule to all shadow DOM subtrees on example.org. ```adblock example.org#%#//scriptlet('inject-css-in-shadow-dom', '#advertisement { display: none !important; }') ``` -------------------------------- ### Run all tests with pnpm Source: https://github.com/adguardteam/scriptlets/blob/master/README.md Run all tests (QUnit and Vitest). ```bash pnpm test ``` -------------------------------- ### Apply abort-on-property-read scriptlet Source: https://github.com/adguardteam/scriptlets/blob/master/README.md Applies the abort-on-property-read scriptlet on all pages of example.org and its subdomains, passing one argument 'alert'. ```adblock example.org#%#//scriptlet('abort-on-property-read', 'alert') ``` -------------------------------- ### Set session storage item examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Four examples of setting sessionStorage items with various values: strings, JSON objects, and arrays. The scriptlet adds or updates the key; it won't set if storage is full. ```adblock 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"}') ``` -------------------------------- ### Output JSON for example 5 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Output JSON after pruning 'content.*.media.src'. ```json { "content": { "block1": { "media": { "ad": true } }, "block2": { "media": {} } } } ``` -------------------------------- ### evaldata-prune example 5: wildcard chain Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Uses wildcard in chain property names. ```adblock example.org#%#//scriptlet('evaldata-prune', 'content.*.media.src', 'content.*.media.ad') ``` -------------------------------- ### Example JSON.stringify call with input and output Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Shows a JSON.stringify call with input JSON and the expected output after applying the trusted-json-set modification. The output has 'config.ads.blocked' set to true. ```js JSON.stringify({ config: {} }) ``` ```json { "config": {} } ``` ```json { "config": { "ads": { "blocked": true } } } ``` -------------------------------- ### Prevent window.open for URLs matching regex /example\./ Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Matches URLs using the regular expression /example\./. ```adblock example.org#%#//scriptlet('prevent-window-open', '/example\./') ``` -------------------------------- ### Output JSON for example 4 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Output JSON after pruning 'content.ad'. ```json { "content": {} } ``` -------------------------------- ### Input JSON for json-prune example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md The input JSON object that is passed to JSON.parse. It contains two video objects, one with isAd set to true. ```json { "videos": { "video1": { "isAd": true, "src": "video1.mp4" }, "video2": { "src": "video1.mp4" } } } ``` -------------------------------- ### remove-attr Example: Using Flags Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Uses the 'asap complete' flags to run the scriptlet once after the whole page has loaded. ```adblock example.org#%#//scriptlet('remove-attr', 'example', 'html', 'asap complete') ``` -------------------------------- ### Run tests with pnpm Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Runs all tests (Vitest + smoke + QUnit) or specific test suites. Use --name to target a single scriptlet and --build to rebuild it. ```bash # All tests (Vitest + smoke + QUnit) pnpm test # Vitest only pnpm test:vitest # QUnit only (scriptlets) pnpm test:qunit scriptlets # QUnit only (redirects) pnpm test:qunit redirects # Single scriptlet with rebuild pnpm test:qunit scriptlets --name # Only rebuild a single scriptlet test, e.g. while it is open with --gui pnpm test:qunit scriptlets --name --build ``` -------------------------------- ### Example 6: Log all JSON responses Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Logs all JSON responses of XMLHttpRequest calls to the browser console. Useful for debugging but not allowed for production filter lists. ```adblock example.org#%#//scriptlet('json-prune-xhr-response') ``` -------------------------------- ### JSON.parse call for example 4 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md JSON.parse call used in the fourth example. ```html JSON.parse('{"content":{"ad":{"src":"a.js"}}}') ``` -------------------------------- ### JSON.parse call for json-prune example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Shows the JSON.parse call that would be intercepted by the scriptlet. The input JSON contains videos with an isAd property. ```html JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"src":"video1.mp4"}}}') ``` -------------------------------- ### m3u-prune syntax Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Shows the syntax for the m3u-prune scriptlet. Arguments: propsToRemove (optional), urlToMatch (optional), verbose (optional). ```text example.org#%#//scriptlet('m3u-prune'[, propsToRemove[, urlToMatch]]) ``` -------------------------------- ### Example: Replace 'foo' with 'bar' and log Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Replaces 'foo' with 'bar' in all XMLHttpRequests for example.com and logs original and modified text content because verbose is set to 'true'. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', 'foo', 'bar', 'example.com', 'true') ``` -------------------------------- ### spoof-css example: spoof display to block Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Spoofs the CSS property 'display' to 'block' for all elements with class 'adsbygoogle'. ```adblock example.org#%#//scriptlet('spoof-css', '.adsbygoogle', 'display', 'block') ``` -------------------------------- ### Set attribute value to MTIzNTY= Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Example of setting an attribute value to a base64-encoded string 'MTIzNTY='. ```adblock example.org#%#//scriptlet('trusted-set-attr', 'a.class', 'test-attribute', 'MTIzNTY=') ``` ```html Some text Some text ``` -------------------------------- ### Apply style using style tag injection method Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage of inject-css-in-shadow-dom with cssInjectionMethod set to 'styleTag' to inject the CSS rule using a style tag. ```adblock example.org#%#//scriptlet('inject-css-in-shadow-dom', '.ads { display: none !important; }', '', 'styleTag') ``` -------------------------------- ### Example JSON.parse call with input and output Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Shows a JSON.parse call with input JSON and the expected output after applying the trusted-json-set modification. The output has 'ads.enabled' set to false. ```js JSON.parse('{"ads":{"enabled":true},"content":"article"}') ``` ```json { "ads": { "enabled": true }, "content": "article" } ``` ```json { "ads": { "enabled": false }, "content": "article" } ``` -------------------------------- ### Example array input and output with enabled set to false Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Shows input JSON with an array of items and the expected output after applying the trusted-json-set modification. All 'enabled' values are set to false. ```json { "items": [ { "id": 1, "enabled": true }, { "id": 2, "enabled": true } ] } ``` ```json { "items": [ { "id": 1, "enabled": false }, { "id": 2, "enabled": false } ] } ``` -------------------------------- ### Clone the repository Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Clones the canonical private repository and changes into its directory. The repository is mirrored to the public AdguardTeam/Scriptlets on every push to master. ```bash git clone git@github.com:AdGuardSoftwareLimited/ext-scriptlets.git cd ext-scriptlets ``` -------------------------------- ### debug-on-property-write Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md This scriptlet is basically the same as abort-on-property-write, but instead of aborting it starts the debugger. It is not allowed for prod versions of filter lists. ```APIDOC ## debug-on-property-write ### Description This scriptlet is basically the same as abort-on-property-write, but instead of aborting it starts the debugger. It is not allowed for prod versions of filter lists. ### Examples 1. Debug script when it tries to write in property `window.test` ```adblock example.org#%#//scriptlet('debug-on-property-write', 'test') ``` ``` -------------------------------- ### Apply adjust-setInterval and set-local-storage-item with multiple exceptions Source: https://github.com/adguardteam/scriptlets/blob/master/README.md Applies adjust-setInterval on any webpage and set-local-storage-item on example.com, but the multiple exception rule disables all scriptlets on example.com and its subdomains. ```adblock #%#//scriptlet('adjust-setInterval', 'count', '*', '0.001') example.com#%#//scriptlet('set-local-storage-item', 'ALLOW_COOKIES', 'false') example.com#@%#//scriptlet() ``` -------------------------------- ### remove-class with flags example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Uses the 'asap complete' flags to control when the scriptlet runs. The applying parameter accepts space-separated flags. ```adblock example.org#%#//scriptlet('remove-class', 'branding', 'div[class^="inner"]', 'asap complete') ``` -------------------------------- ### prevent-setInterval with negative delay - example call Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval call that will be prevented because the delay is -10, which is negative. ```javascript setInterval(function () { window.test = "negative -- prevented"; }, -10); ``` -------------------------------- ### prevent-eval-if example: prevent eval matching 'test' Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example usage to prevent eval if it matches 'test'. ```adblock ! Prevents eval if it matches 'test' example.org#%#//scriptlet('prevent-eval-if', 'test') ``` -------------------------------- ### Example: Replace text content matching URL regex and request methods Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Replaces content matching the regex '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/' with '#EXT-X-ENDLIST' for requests whose URL matches '/\.m3u8/' and whose method matches '/GET|HEAD/'. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', '/\.m3u8/ method:/GET|HEAD/') ``` -------------------------------- ### google-ima3 Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Mocks the IMA SDK of Google. Added in v1.10.25. ```APIDOC ## google-ima3 ### Description Mocks the IMA SDK of Google. ### Usage ```adblock example.org#%#//scriptlet('google-ima3') ``` ### Example ```adblock example.org#%#//scriptlet('google-ima3') ``` ``` -------------------------------- ### Replace first argument of MutationObserver with noopFunc Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Replaces the first argument of MutationObserver with noopFunc when the pattern 'Adblock' matches. The example callback function is replaced with noopFunc. ```adblock example.org#%#//scriptlet('trusted-replace-argument', 'MutationObserver', '0', 'noopFunc', 'Adblock') ``` ```html const callback = () => { if(adblock) { document.body.innerHTML = 'Adblock detected'; } }; const observerToPrevent = new MutationObserver(callback); ``` -------------------------------- ### Run QUnit tests for scriptlets, redirects, and helpers Source: https://github.com/adguardteam/scriptlets/blob/master/README.md QUnit is used for testing scriptlets, redirects, and helpers. The command accepts a test group argument. ```text pnpm test:qunit [scriptlets | redirects | helpers] ``` -------------------------------- ### prevent-setInterval with callback not containing 'value' - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls where only the first is prevented because its callback does not contain 'value'. ```javascript setInterval(function () { window.test = "test -- prevented"; }, 300); setInterval(function () { window.test = "value -- executed"; }, 400); setInterval(function () { window.value = "test -- executed"; }, 500); ``` -------------------------------- ### Example: Replace text content for specific URL Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Replaces response content of XMLHttpRequests when all parameters match. The first line replaces 'adb_detect:true' with 'adb_detect:false' for requests to example.org. The second line replaces content matching the regex '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/' with '#EXT-X-ENDLIST' for example.org. ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', 'adb_detect:true', 'adb_detect:false', 'example.org') ``` ```adblock example.org#%#//scriptlet('trusted-replace-xhr-response', '/#EXT-X-VMAP-AD-BREAK[\s\S]*?/', '#EXT-X-ENDLIST', 'example.org') ``` -------------------------------- ### evaldata-prune example 1: remove property Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes property 'example' from eval payload. The call returns { one: 1}. ```adblock example.org#%#//scriptlet('evaldata-prune', 'example') ``` ```html eval({ one: 1, example: true }) ``` -------------------------------- ### prevent-setInterval with delay at least 30 - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls where only the second is prevented because its delay is 60, which is at least 30. ```javascript setInterval(function () { window.test = "10 -- executed"; }, 10); setInterval(function () { window.test = "60 -- prevented"; }, 60); ``` -------------------------------- ### prevent-setInterval with callback regex /\\.test/ - example call Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval call that will be prevented by the previous rule because the callback matches /\\.test/. ```javascript setInterval(function () { window.test = "value"; }, 100); ``` -------------------------------- ### set-cookie-reload Usage Examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Examples of using set-cookie-reload with various parameters. The scriptlet does not encode cookie names, and names containing ';' will not set the cookie. ```adblock example.org#%#//scriptlet('set-cookie-reload', 'checking', 'ok') example.org#%#//scriptlet('set-cookie-reload', 'gdpr-settings-cookie', '1') example.org#%#//scriptlet('set-cookie-reload', 'cookie-set', 'true', 'none') example.org#%#//scriptlet('set-cookie-reload', 'test', '1', 'none', 'example.org') ``` -------------------------------- ### Call with only first and third argument for logging Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Example 6: Call with only first and third argument will log the current hostname and matched payload at the console. Shows the scriptlet usage with empty stack parameter. ```adblock example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', '', 'bar', '') ``` -------------------------------- ### prevent-setInterval with delay range 20-50 - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls where only the second is prevented because its delay is 30, within the 20-50 range. ```javascript setInterval(function () { window.test = "10 -- executed"; }, 10); setInterval(function () { window.test = "30 -- prevented"; }, 30); ``` -------------------------------- ### set-popads-dummy redirect rule Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-redirects.md Use this Adblock rule to redirect requests matching ||popads.net^$script to the set-popads-dummy redirect, which sets static properties to PopAds and popns objects. The domain=example.org option restricts the rule to example.org. ```adblock ||popads.net^$script,redirect=set-popads-dummy,domain=example.org ``` -------------------------------- ### prebid scriptlet usage Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Mocks the prebid.js header bidding suit. Syntax: example.org#%#//scriptlet('prebid') ```adblock example.org#%#//scriptlet('prebid') ``` -------------------------------- ### Run specific QUnit tests for scriptlets and redirects Source: https://github.com/adguardteam/scriptlets/blob/master/README.md For scriptlets and redirects, test runs can be more specific using the --name flag. Both node and GUI test runs are shown. ```bash // node test run pnpm test:qunit scriptlets --name set-cookie pnpm test:qunit redirects --name ati-smarttag // gui test run pnpm test:qunit scriptlets --name set-cookie --gui pnpm test:qunit redirects --name ati-smarttag --gui ``` -------------------------------- ### prevent-setInterval with callback not containing 'value' and delay not 300 - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls where only the second is prevented because its callback does not contain 'value' and delay is not 300. ```javascript setInterval(function () { window.test = "test -- executed"; }, 300); setInterval(function () { window.test = "test -- prevented"; }, 400); setInterval(function () { window.test = "value -- executed"; }, 400); setInterval(function () { window.value = "test -- executed"; }, 500); ``` -------------------------------- ### prevent-setInterval with callback containing 'value' and delay not 300 - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls where only the first is not prevented because it has delay 300 and callback contains 'value'. ```javascript setInterval(function () { window.test = "value 1 -- executed"; }, 300); setInterval(function () { window.test = "value 2 -- prevented"; }, 400); setInterval(function () { window.test = "value 3 -- prevented"; }, 500); ``` -------------------------------- ### close-window usage examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Closes any example.org tab by default, or a specific tab when a path is provided. Note: window.close() is restricted in Chrome; the tab will only close when using the AdGuard Browser extension. ```adblock ! closes any example.org tab example.org#%#//scriptlet('close-window') ! closes specific example.org tab example.org#%#//scriptlet('close-window', '/example-page.html') ``` -------------------------------- ### prevent-window-open syntax Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Shows the scriptlet syntax with optional match, delay, and replacement parameters. ```text example.org#%#//scriptlet('prevent-window-open'[, match[, delay[, replacement]]]) ``` -------------------------------- ### prevent-setInterval with callback containing 'value' and delay 300 - example calls Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Example setInterval calls that will be prevented because the callback contains 'value' and the delay is 300 or a decimal number. ```javascript setInterval(function () { window.test = "value"; }, 300); setInterval(function () { window.test = "value"; }, 300 + Math.random()); ``` -------------------------------- ### Regenerate wiki documentation Source: https://github.com/adguardteam/scriptlets/blob/master/DEVELOPMENT.md Regenerate the whole wiki or only one part. If 'pnpm wiki' reports that sources have changed, review 'scripts/compatibility-table.json', run 'pnpm wiki' again, and only then commit the result. Files in 'wiki/' are auto-generated and should not be edited manually. ```bash # Regenerate the whole wiki: compatibility table, then the docs pnpm wiki # Regenerate only one part pnpm wiki:build-table pnpm wiki:build-docs ``` -------------------------------- ### m3u-prune remove tag from all requests Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Removes a tag containing 'example.com/video/' from all requests. ```adblock example.org#%#//scriptlet('m3u-prune', 'example.com/video/') ``` -------------------------------- ### google-ima3-dai Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Mocks the IMA DAI SDK of Google. Added in v2.4.2. ```APIDOC ## google-ima3-dai ### Description Mocks the IMA DAI SDK of Google. ### Usage ```adblock example.org#%#//scriptlet('google-ima3-dai') ``` ### Example ```adblock example.org#%#//scriptlet('google-ima3-dai') ``` ``` -------------------------------- ### hide-in-shadow-dom scriptlet examples Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-scriptlets.md Two usage examples for hiding elements inside open shadow DOM. The first hides a menu bar with a baseSelector; the second hides a floating element without one. ```adblock ! hides menu bar example.com#%#//scriptlet('hide-in-shadow-dom', '.storyAd', '#app') ! hides floating element example.com#%#//scriptlet('hide-in-shadow-dom', '.contact-fab') ``` -------------------------------- ### Output JSON for removal example Source: https://github.com/adguardteam/scriptlets/blob/master/wiki/about-trusted-scriptlets.md Output JSON after removing the ads.enabled property. ```json { "content": "article" } ```