{"id":13447684,"url":"https://github.com/AdguardTeam/Scriptlets","last_synced_at":"2025-03-22T01:31:12.957Z","repository":{"id":41284346,"uuid":"171706245","full_name":"AdguardTeam/Scriptlets","owner":"AdguardTeam","description":"AdGuard scriptlets library","archived":false,"fork":false,"pushed_at":"2024-10-16T16:11:56.000Z","size":11747,"stargazers_count":148,"open_issues_count":64,"forks_count":29,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-19T05:11:32.095Z","etag":null,"topics":["adguard","open-source"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AdguardTeam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-20T16:14:10.000Z","updated_at":"2024-10-16T16:12:00.000Z","dependencies_parsed_at":"2023-11-13T08:31:21.344Z","dependency_job_id":"5680971f-2af1-434c-a394-03f13f68db77","html_url":"https://github.com/AdguardTeam/Scriptlets","commit_stats":{"total_commits":1203,"total_committers":18,"mean_commits":66.83333333333333,"dds":0.6076475477971737,"last_synced_commit":"402972c3ca6c11e075aa576ee88bec34d9752e24"},"previous_names":[],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdguardTeam%2FScriptlets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdguardTeam%2FScriptlets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdguardTeam%2FScriptlets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdguardTeam%2FScriptlets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdguardTeam","download_url":"https://codeload.github.com/AdguardTeam/Scriptlets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244893430,"owners_count":20527588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adguard","open-source"],"created_at":"2024-07-31T05:01:24.325Z","updated_at":"2025-03-22T01:31:12.951Z","avatar_url":"https://github.com/AdguardTeam.png","language":"JavaScript","readme":"# AdGuard Scriptlets and Redirect Resources\n\nAdGuard's Scriptlets and Redirect resources library which provides extended capabilities for content blocking.\n\n- [Scriptlets](#scriptlets)\n    - [Syntax](#scriptlet-syntax)\n        - [Blocking rules](#scriptlet-syntax--blocking)\n        - [Exception rules](#scriptlet-syntax--exceptions)\n    - [Available scriptlets](./wiki/about-scriptlets.md#scriptlets)\n    - [Scriptlets compatibility table](./wiki/compatibility-table.md#scriptlets)\n    - [Trusted scriptlets](#trusted-scriptlets)\n        - [Restriction](#trusted-scriptlets-restriction)\n        - [Available trusted scriptlets](./wiki/about-trusted-scriptlets.md#trusted-scriptlets)\n- [Redirect resources](#redirect-resources)\n    - [Syntax](#redirect-syntax)\n    - [Available redirect resources](./wiki/about-redirects.md#redirect-resources)\n    - [Redirect resources compatibility table](./wiki/compatibility-table.md#redirects)\n- [Development](#development)\n    - [How to build](#how-to-build)\n    - [How to test](#how-to-test)\n    - [How to link packages](#how-to-link-packages)\n    - [How to update wiki](#how-to-update-wiki)\n- [Usage](#usage)\n    - [CoreLibs](#corelibs)\n    - [NPM module](#npm-module)\n- [API description](#api-description)\n    - [Scriptlets API](#scriptlets-api)\n        - [`invoke()`](#scriptlets-api--invoke)\n        - [`getScriptletFunction()`](#scriptlets-api--getScriptletFunction)\n        - [Properties](#scriptlets-api-properties)\n            - [`SCRIPTLETS_VERSION`](#scriptlets-api--version)\n    - [Redirects API](#redirects-api)\n        - [Redirects class](#redirects-api--redirects-class)\n        - [`getRedirect()`](#redirects-api--getRedirect)\n        - [`isBlocking()`](#redirects-api--isBlocking)\n        - [`getRedirectFilename()`](#redirects-api--getRedirectFilename)\n    - [Validators API](#validators-api)\n        - [`isValidScriptletName()`](#validators-api--isValidScriptletName)\n        - [`isValidScriptletRule()`](#validators-api--isValidScriptletRule)\n        \u003c!-- markdownlint-disable-next-line --\u003e\n        - [`isAdgScriptletRule()`, `isUboScriptletRule()`, `isAbpSnippetRule()`](#scriptlets-api--is-Abg-Ubo-Abp-ScriptletRule)\n        - [`isValidAdgRedirectRule()`](#redirects-api--isValidAdgRedirectRule)\n        - [`isRedirectResourceCompatibleWithAdg()`](#redirects-api--isRedirectResourceCompatibleWithAdg)\n    - [Converters API](#converters-api)\n        - [`convertUboToAdg()`](#converters-api--convertUboToAdg)\n        - [`convertAbpToAdg()`](#converters-api--convertAbpToAdg)\n        - [`convertScriptletToAdg()`](#converters-api--convertScriptletToAdg)\n        - [`convertAdgToUbo()`](#converters-api--convertAdgToUbo)\n        - [`convertAdgRedirectToUbo()`](#converters-api--convertAdgRedirectToUbo)\n- [Browser compatibility](#browser-compatibility)\n- [Projects using Scriptlets](#used-by)\n\n* * *\n\n## Scriptlets\n\nScriptlet is a JavaScript function which can be used in a declarative manner in AdGuard filtering rules.\n\nAdGuard supports a lot of different scriptlets.\nPlease note, that in order to achieve cross-blocker compatibility, we also support syntax of uBO and ABP.\n\n### \u003ca name=\"scriptlet-syntax\"\u003e\u003c/a\u003e Syntax\n\n#### \u003ca name=\"scriptlet-syntax--blocking\"\u003e\u003c/a\u003e Blocking rules\n\n```text\n[domains]#%#//scriptlet(name[, arguments])\n```\n\n- `domains` — optional, a list of domains where the rule should be applied;\n- `name` — required, a name of the scriptlet from AdGuard Scriptlets library;\n- `arguments` — optional, a list of `string` arguments (no other types of arguments are supported).\n\n\u003e **Remarks**\n\u003e\n\u003e - The meaning of the arguments depends on the scriptlet.\n\u003e\n\u003e - Special characters in scriptlet argument must be escaped properly:\n\u003e     - valid:\n\u003e         - `'prop[\"nested\"]'`\n\u003e         - `\"prop['nested']\"`\n\u003e         - `'prop[\\'nested\\']'`\n\u003e         - `\"prop[\\\"nested\\\"]\"`\n\u003e     - not valid:\n\u003e         - `'prop['nested']'`\n\u003e         - `\"prop[\"nested\"]\"`\n\u003e\n\u003e - Scriptlet `name` and each of the `arguments` should be wrapped in quotes.\n\u003e You can use either single or double quotes for the scriptlet name and arguments.\n\u003e Single quote is recommended but not for cases when its usage makes readability worse,\n\u003e e.g. `\".css('display','block');\"` is more preferred then `'.css(\\'display\\',\\'block\\');'`.\n\n#### \u003ca name=\"scriptlet-syntax--exceptions\"\u003e\u003c/a\u003e Exception rules\n\n```text\n[domains]#@%#//scriptlet([name[, arguments]])\n```\n\n- `domains` — optional, a list of domains where the rule should be applied;\n- `name` — optional, a name of the scriptlet to except from the applying;\n  if not set, all scriptlets will not be applied;\n- `arguments` — optional, a list of `string` arguments to match the same blocking rule and disable it.\n\n#### Examples\n\n1. Apply the `abort-on-property-read` scriptlet on all pages of `example.org` and its subdomains,\n   and passes one argument to it (`alert`):\n\n    ```adblock\n    example.org#%#//scriptlet('abort-on-property-read', 'alert')\n    ```\n\n1. Remove the `branding` class from all `div[class^=\"inner\"]` elements\n   on all pages of `example.org` and its subdomains:\n\n    ```adblock\n    example.org#%#//scriptlet('remove-class', 'branding', 'div[class^=\"inner\"]')\n    ```\n\n1. Apply `set-constant` and `set-cookie` on any webpage,\n   but because of specific scriptlet exception rule\n   only `set-constant` scriptlet will be applied on `example.org` and its subdomains:\n\n    ```adblock\n    #%#//scriptlet('set-constant', 'adList', 'emptyArr')\n    #%#//scriptlet('set-cookie', 'accepted', 'true')\n    example.org#@%#//scriptlet('set-cookie')\n    ```\n\n1. Apply `adjust-setInterval` on any webpage,\n   and `set-local-storage-item` on all pages of `example.com` and its subdomains,\n   but there is also multiple scriptlet exception rule,\n   so no scriptlet rules will be applied on `example.com` and its subdomains:\n\n    ```adblock\n    #%#//scriptlet('adjust-setInterval', 'count', '*', '0.001')\n    example.com#%#//scriptlet('set-local-storage-item', 'ALLOW_COOKIES', 'false')\n    example.com#@%#//scriptlet()\n    ```\n\n- **[Scriptlets list](./wiki/about-scriptlets.md#scriptlets)**\n- **[Scriptlets compatibility table](./wiki/compatibility-table.md#scriptlets)**\n\n\n### \u003ca name=\"trusted-scriptlets\"\u003e\u003c/a\u003e Trusted scriptlets\n\nTrusted scriptlets are scriptlets with extended functionality.\nTheir names are prefixed with `trusted-`, e.g `trusted-click-element`,\nto be easily distinguished from common scriptlets.\n\n#### \u003ca name=\"trusted-scriptlets-restriction\"\u003e\u003c/a\u003e Restriction\n\nTrusted scriptlets application must be restricted due to dangerous nature of their capabilities.\nAllowed sources of trusted scriptlets are:\n\n- filters created by AdGuard Team,\n- custom filters which were installed as `trusted`,\n- user rules.\n\n\u003e Trusted scriptlets has no compatibility table as they are not compatible with any other blocker.\n\n**[Trusted scriptlets list](./wiki/about-trusted-scriptlets.md#trusted-scriptlets)**\n\n## Redirect resources\n\nAdGuard is able to redirect web requests to a local \"resource\".\n\n### \u003ca name=\"redirect-syntax\"\u003e\u003c/a\u003e Syntax\n\nAdGuard uses the same filtering rule syntax as [uBlock Origin][ubo-redirect].\nAlso, it is compatible with ABP `$rewrite=abp-resource` modifier.\n\n`$redirect` is a modifier for [the basic filtering rules][kb-basic-rules]\nso rules with this modifier support all other basic modifiers like `$domain`, `$third-party`, `$script`, etc.\n\nThe value of the `$redirect` modifier must be the name of the resource that will be used for redirection.\nSee the list of [available redirect resources](./wiki/about-redirects.md#redirect-resources).\n\n\u003e Priority of `$redirect` rules is described in the [Knowledge Base][kb-redirect-priority].\n\n### Examples\n\n- `||example.org/script.js$script,redirect=noopjs` — redirects all requests to `script.js`\n  to the resource named `noopjs`.\n- `||example.org/test.mp4$media,redirect=noopmp4-1s` — requests to `example.org/test.mp4` will be redirected\n  to the resource named `noopmp4-1s`.\n\n\u003e uBlock Origin specifies additional resource name `none` that can disable other redirect rules.\n\u003e AdGuard does not support it, use `$badfilter` to disable specific rules.\n\n- **[Redirect resources list](./wiki/about-redirects.md#redirect-resources)**\n- **[Redirect resources compatibility table](./wiki/compatibility-table.md#redirects)**\n\n* * *\n\n## \u003ca name=\"development\"\u003e\u003c/a\u003e Development\n\n### \u003ca name=\"how-to-build\"\u003e\u003c/a\u003e How to build\n\nInstall dependencies:\n\n```bash\npnpm install\n```\n\nBuild dist:\n\n```bash\npnpm build\n```\n\nIn tsurlfilter directory install and link dependencies, link scriptlets,\nmove into package and build, and create tsurlfilter link.\n\n```bash\nlerna bootstrap\n\npnpm link --global \"@adguard/scriptlets\"\n\ncd ./packages/tsurlfilter\npnpm build\nyarn link\n```\n\nIn extension directory install dependencies, link packages and build\n\n``` bash\nyarn\n\nyarn link @adguard/scriptlets\nyarn link @adguard/tsurlfilter\n\nyarn dev\n```\n\n### \u003ca name=\"how-to-test\"\u003e\u003c/a\u003e How to test\n\nSome tests are run in QUnit, some in Vitest.\n\nRun all tests:\n\n```bash\npnpm test\n```\n\n1. QUnit is used for testing of scriptlets, redirects, and helpers:\n\n    ```text\n    pnpm test:qunit [scriptlets | redirects | helpers]\n    ```\n\n    For scriptlets and redirects test run can be more specific:\n\n    ```bash\n    // node test run\n    pnpm test:qunit scriptlets --name set-cookie\n    pnpm test:qunit redirects --name ati-smarttag\n\n    // gui test run\n    pnpm test:qunit scriptlets --name set-cookie --gui\n    pnpm test:qunit redirects --name ati-smarttag --gui\n    ```\n\n    For debugging purposes after some test is running in gui mode,\n    you may change your scriptlet/redirect code, and without stopping the server\n    run in new terminal:\n\n    ```bash\n    pnpm test:qunit scriptlets --name set-cookie --build\n    ```\n\n1. Run all jest tests:\n\n    ```bash\n    pnpm test:vitest\n    ```\n\n    or limit the testing — `include` may be specified in `vitest.config.ts`\n    or specify [test name](https://vitest.dev/guide/filtering#cli) in command line, e.g.:\n\n    ```bash\n    pnpm test:vitest -t isValidScriptletRule\n    ```\n\nTo run browserstack tests create `.env` file or copy and rename `.env-example`.\n\nFill in `\u003cusername\u003e` and `\u003ckey\u003e` with data from your Browserstack profile.\nRun next command:\n\n```bash\npnpm browserstack\n```\n\nTests run by `jest` should be named `.spec.js`, so they will be not included in the `QUnit` tests.\n\n#### Debugging\n\nUse `debugger;` statement where you need it, run\n\n```bash\npnpm test\n```\n\nand open needed HTML file from `tests/dist` in your browser with devtools\n\n\n### \u003ca name=\"how-to-link-packages\"\u003e\u003c/a\u003e How to link packages\n\nScriptlets library relies on external packages, such as `@adguard/agtree`.\nDuring development, you might need to link these packages using `pnpm link`.\n\n### \u003ca name=\"how-to-update-wiki\"\u003e\u003c/a\u003e How to update wiki\n\nThere are two scripts to update wiki:\n\n1. `pnpm wiki:build-table` — checks compatibility data updates and updates the compatibility table.\n    Should be run manually while the release preparation.\n1. `pnpm wiki:build-docs` — updates wiki pages `about-scriptlets.md` and `about-redirects.md`.\n    They are being generated from JSDoc-type comments of corresponding scriptlets and redirects source files\n    due to `@scriptlet`/`@redirect` and `@description` tags. Runs automatically while the release build.\n\n## \u003ca name=\"usage\"\u003e\u003c/a\u003e Usage\n\n### \u003ca name=\"corelibs\"\u003e\u003c/a\u003e CoreLibs\n\nFor CoreLibs usage you should use `dist/scriptlets.corelibs.json` and `dist/redirects.json`.\n\nFile example:\n\n```json\n{\n    \"version\": \"1.0.0\",\n    \"scriptlets\": [\n        {\n            \"names\": [\n                \"abort-on-property-read\",\n                \"ubo-abort-on-property-read.js\",\n                \"abp-abort-on-property-read\"\n            ],\n            \"scriptlet\": \"function() { ...code... }\"\n        }\n    ]\n}\n```\n\nSchema:\n\n```json\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"version\": {\n            \"type\": \"string\"\n        },\n        \"scriptlets\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"names\": {\n                        \"type\": \"array\",\n                        \"items\": {\n                            \"type\": \"string\"\n                        }\n                    },\n                    \"scriptlet\": {\n                        \"type\": \"string\"\n                    }\n                }\n            }\n        }\n    }\n}\n```\n\n### \u003ca name=\"npm-module\"\u003e\u003c/a\u003e NPM module\n\n#### Installation\n\nYou can install the library using\n\n- [Yarn][yarn-pkg-manager-url]: `yarn add @adguard/scriptlets`\n- [NPM][npm-pkg-manager-url]: `npm install @adguard/scriptlets`\n- [PNPM][pnpm-pkg-manager-url]: `pnpm add @adguard/scriptlets`\n\n## \u003ca name=\"api-description\"\u003e\u003c/a\u003e API description\n\n### \u003ca name=\"scriptlets-api\"\u003e\u003c/a\u003e Scriptlets API\n\nYou are welcome to use scriptlets as a CJS modules or ESM modules:\n\n```typescript\nconst { scriptlets } = require('@adguard/scriptlets');\n// or\nimport { scriptlets } from '@adguard/scriptlets';\n```\n\n#### \u003ca name=\"scriptlets-api--invoke\"\u003e\u003c/a\u003e `invoke()`\n\n```typescript\n/**\n * Returns scriptlet code by `source`.\n *\n * @param source Scriptlet properties.\n *\n * @returns Scriptlet code.\n * @throws An error on unknown scriptlet name.\n */\ndeclare function getScriptletCode(source: Source): string;\ndeclare const scriptlets: {\n    invoke: typeof getScriptletCode;\n};\n```\n\nwhere `Source` is:\n\n```typescript\ninterface Source {\n    /**\n     * Scriptlet name\n     */\n    name: string;\n    /**\n     * Arguments for scriptlet function\n     */\n    args: string[];\n    /**\n     * {'extension'|'corelibs'} engine Defines the final form of scriptlet string presentation\n     */\n    engine: string;\n    /**\n     * Version\n     */\n    version: string;\n    /**\n     * flag to enable printing to console debug information\n     */\n    verbose: boolean;\n    /**\n     * Source rule text is used for debugging purposes.\n     *\n     * @deprecated since it is not used in the code anymore.\n     */\n    ruleText?: string;\n    /**\n     * Domain name, used to improve logging\n     */\n    domainName?: string;\n    /**\n     * Optional unique identifier for a scriptlet instance.\n     *\n     * This identifier is used to prevent multiple executions of the same scriptlet on the page.\n     * If provided, this `uniqueId` will be combined with the scriptlet's `name` and `args`\n     * to create a unique identifier for the scriptlet call. This identifier is\n     * stored in the `Window.prototype.toString` object to ensure the scriptlet\n     * is not executed more than once in the same context.\n     *\n     * By avoiding multiple executions, it helps in reducing redundant operations and\n     * potential side effects that might occur if the same scriptlet is called multiple times.\n     *\n     * If `uniqueId` is not specified, no such unique identifier is created, and the\n     * scriptlet can be called multiple times.\n     */\n    uniqueId?: string;\n}\n```\n\n#### \u003ca name=\"scriptlets-api--getScriptletFunction\"\u003e\u003c/a\u003e `getScriptletFunction()`\n\n```typescript\n/**\n * Returns scriptlet function by `name`.\n *\n * @param {string} name Scriptlet name\n *\n * @returns {Function} — Scriptlet function.\n */\ndeclare function getScriptletFunction(name: any): string;\ndeclare const scriptlets: {\n    getScriptletFunction: typeof getScriptletFunction;\n};\n```\n\n#### \u003ca name=\"scriptlets-api-properties\"\u003e\u003c/a\u003e Properties\n\n##### \u003ca name=\"scriptlets-api--version\"\u003e\u003c/a\u003e `SCRIPTLETS_VERSION`\n\ntype: `string`\n\nCurrent version of scriptlets library.\n\n### \u003ca name=\"redirects-api\"\u003e\u003c/a\u003e Redirects API\n\nYou are welcome to use redirects as a CJS modules or ESM modules:\n\n```javascript\nconst { Redirects } = require('@adguard/scriptlets/redirects');\n// or\nimport { Redirects, getRedirectFilename } from '@adguard/scriptlets/redirects';\n```\n\n\n#### \u003ca name=\"redirects-api--redirects-class\"\u003e\u003c/a\u003e Redirects class\n\n```typescript\nimport { Redirects } from '@adguard/scriptlets';\n\n/**\n * Converts rawYaml into JS object with sources titles used as keys\n */\nconst redirects = new Redirects(rawYaml)\n```\n\nwhere `rawYaml` is a string with YAML content located in `dist/redirects.yml`.\n\n#### \u003ca name=\"redirects-api--getRedirect\"\u003e\u003c/a\u003e `getRedirect()`\n\n```typescript\n/**\n * Returns redirect source object by title\n */\nconst redirect = redirects.getRedirect('noopjs');\n\n/**\n * Redirect is an object with following props:\n * {\n *     title: 1x1-transparent.gif\n *     comment: http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever\n *     contentType: image/gif;base64\n *     content: R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\n * }\n */\n```\n\n#### \u003ca name=\"redirects-api--isBlocking\"\u003e\u003c/a\u003e `isBlocking()`\n\n```typescript\n/**\n * Check if redirect is blocking, e.g. click2load.html\n */\nconst isBlocking = redirect.isBlocking('click2load.html');\n```\n\n\n#### \u003ca name=\"redirects-api--getRedirectFilename\"\u003e\u003c/a\u003e `getRedirectFilename()`\n\n```typescript\nimport { getRedirectFilename } from '@adguard/scriptlets/redirects';\n/**\n * For a given name or alias of redirect returns the corresponding filename\n * @param name Name or alias of redirect\n * @returns Redirect's filename with extension\n */\ndeclare function getRedirectFilename(name: string): string;\n```\n\n### \u003ca name=\"validators-api\"\u003e\u003c/a\u003e Validators API\n\n#### \u003ca name=\"validators-api--isValidScriptletName\"\u003e\u003c/a\u003e `isValidScriptletName()`\n\n```typescript\nimport { isValidScriptletName } from '@adguard/scriptlets/validators';\n\n/**\n * Checks whether the `name` is valid scriptlet name.\n * Uses cache for better performance.\n *\n * @param name Scriptlet name.\n * @returns True if scriptlet name is a valid one or an empty string,\n * otherwise false.\n */\ndeclare function isValidScriptletName(name: string | null): boolean;\n```\n\n#### \u003ca name=\"validators-api--isValidScriptletRule\"\u003e\u003c/a\u003e `isValidScriptletRule()`\n\n```typescript\n/**\n * 1. For ADG scriptlet checks whether the scriptlet syntax and name are valid.\n * 2. For UBO and ABP scriptlet first checks their compatibility with ADG\n * by converting them into ADG syntax, and after that checks the name.\n *\n * ADG or UBO rules are \"single-scriptlet\", but ABP rule may contain more than one snippet\n * so if at least one of them is not valid — whole `ruleText` rule is not valid too.\n *\n * @param rule Any scriptlet rule — ADG or UBO or ABP.\n *\n * @returns True if scriptlet name is valid in rule.\n */\ndeclare function isValidScriptletRule(rule: string | ScriptletInjectionRule): boolean;\n```\n\n\u003c!-- markdownlint-disable-next-line --\u003e\n#### \u003ca name=\"scriptlets-api--is-Abg-Ubo-Abp-ScriptletRule\"\u003e\u003c/a\u003e `isAdgScriptletRule()`, `isUboScriptletRule()`, `isAbpSnippetRule()`\n\n```typescript\n/**\n * Checks if the `rule` is AdGuard scriptlet rule\n *\n * @param rule - rule text\n * @returns true if given rule is adg rule\n */\ndeclare function isAdgScriptletRule(rule: string): boolean;\n\n/**\n * Checks if the `rule` is uBO scriptlet rule\n *\n * @param rule rule text\n * @returns true if given rule is ubo rule\n */\ndeclare function isUboScriptletRule(rule: string): boolean;\n\n/**\n * Checks if the `rule` is AdBlock Plus snippet\n *\n * @param rule rule text\n * @returns true if given rule is abp rule\n */\ndeclare function isAbpSnippetRule(rule: string): boolean;\n```\n\n#### \u003ca name=\"redirects-api--isValidAdgRedirectRule\"\u003e\u003c/a\u003e `isValidAdgRedirectRule()`\n\n```typescript\n/**\n * Checks if the `rule` is **valid** AdGuard redirect resource rule\n *\n * @param rule - rule text\n * @returns true if given rule is valid adg redirect\n */\ndeclare function isValidAdgRedirectRule(rule: string): boolean\n```\n\n#### \u003ca name=\"redirects-api--isRedirectResourceCompatibleWithAdg\"\u003e\u003c/a\u003e `isRedirectResourceCompatibleWithAdg()`\n\n```typescript\n/**\n * Checks if the specified redirect resource is compatible with AdGuard\n *\n * @param redirectName - Redirect resource name to check\n * @returns - true if the redirect resource is compatible with AdGuard\n */\ndeclare function isRedirectResourceCompatibleWithAdg(redirectName: string): boolean;\n```\n\n### \u003ca name=\"converters-api\"\u003e\u003c/a\u003e Converters API\n\n```typescript\nimport {\n    convertUboToAdg,\n    convertAbpToAdg,\n    convertScriptletToAdg,\n    convertAdgToUbo\n} from '@adguard/scriptlets/converters';\n```\n\n#### \u003ca name=\"converters-api--convertUboToAdg\"\u003e\u003c/a\u003e `convertUboToAdg()`\n\n```typescript\n/**\n * Converts string of UBO scriptlet rule to AdGuard scriptlet rule\n *\n * @param rule UBO scriptlet rule\n * @returns array with one AdGuard scriptlet rule\n *\n * @deprecated\n */\ndeclare function convertUboToAdg(rule: string | ScriptletInjectionRule): string[];\n```\n\n\u003e Note that parameters in UBO rule should be separated by comma + space. Otherwise, the rule is not valid.\n\n#### \u003ca name=\"converters-api--convertAbpToAdg\"\u003e\u003c/a\u003e `convertAbpToAdg()`\n\n```typescript\n/**\n * Convert string of ABP snippet rule to AdGuard scriptlet rule\n *\n * @param rule ABP snippet rule\n * @returns array of AdGuard scriptlet rules, one or few items depends on Abp-rule\n */\ndeclare function convertAbpToAdg(rule: string | ScriptletInjectionRule): string[];\n```\n\n#### \u003ca name=\"converters-api--convertScriptletToAdg\"\u003e\u003c/a\u003e `convertScriptletToAdg()`\n\n```typescript\n/**\n * Converts any scriptlet rule into AdGuard syntax rule.\n * Comments and non-scriptlet rules are returned without changes.\n *\n * @param rule Rule.\n *\n * @returns Array of AdGuard scriptlet rules: one array item for ADG and UBO or few items for ABP.\n * For the ADG `rule` validates its syntax, and returns an empty array if it is invalid.\n */\ndeclare function convertScriptletToAdg(rule: string | ScriptletInjectionRule): string[];\n```\n\n#### \u003ca name=\"converters-api--convertAdgToUbo\"\u003e\u003c/a\u003e `convertAdgToUbo()`\n\n```typescript\n/**\n * Converts AdGuard scriptlet rule to UBO syntax.\n *\n * @param rule AdGuard scriptlet rule\n * @returns UBO scriptlet rule\n * or undefined if `rule` is not valid AdGuard scriptlet rule.\n */\ndeclare function convertAdgToUbo(rule: string | ScriptletInjectionRule): string | undefined;\n```\n\n#### \u003ca name=\"converters-api--convertAdgRedirectToUbo\"\u003e\u003c/a\u003e `convertAdgRedirectToUbo()`\n\n```typescript\n/**\n * Converts Adg redirect rule to Ubo one\n * 1. Checks if there is Ubo analog for Adg rule\n * 2. Parses the rule and checks if there are any source type modifiers which are required by Ubo\n *    and if there are no one we add it manually to the end.\n *    Source types are chosen according to redirect name\n *    e.g. ||ad.com^$redirect=\u003cname\u003e,important  -\u003e\u003e  ||ad.com^$redirect=\u003cname\u003e,important,script\n * 3. Replaces Adg redirect name by Ubo analog\n *\n * Note: if adg redirect uses UBO's priority syntax, it will be lost on conversion, e.g:\n * ||example.com$redirect=noopjs:99 =\u003e ||example.com$redirect=noop.js\n *\n * @param rule adg rule\n * @returns converted ubo rule\n * @throws on incompatible rule\n */\ndeclare function convertAdgRedirectToUbo(rule: string): string;\n```\n\n## \u003ca name=\"browser-compatibility\"\u003e Browser Compatibility\n\n| Browser               | Version |\n|-----------------------|:--------|\n| Chrome                | ✅ 55    |\n| Firefox               | ✅ 52    |\n| Edge                  | ✅ 15    |\n| Opera                 | ✅ 42    |\n| Safari                | ✅ 13    |\n| Internet Explorer     | ❌       |\n\n## \u003ca name=\"used-by\"\u003e Projects using Scriptlets\n\n- [CoreLibs](https://github.com/AdguardTeam/CoreLibs) (updates automatically)\n- [TSUrlFilter](https://github.com/AdguardTeam/tsurlfilter)\n- [FiltersCompiler](https://github.com/AdguardTeam/FiltersCompiler)\n  (`tsurlfilter`'s update might be required as well)\n- [AdguardBrowserExtension](https://github.com/AdguardTeam/AdguardBrowserExtension)\n  (`tsurlfilter` also should be updated)\n- [AdguardForSafari](https://github.com/AdguardTeam/AdGuardForSafari) (`adguard-resources` should be updated)\n- [AdguardForiOS](https://github.com/AdguardTeam/AdguardForiOS)\n  (`tsurlfilter` should be updated in `advanced-adblocker-web-extension`)\n\n[ubo-redirect]: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#redirect\n[kb-basic-rules]: https://adguard.com/kb/general/ad-filtering/create-own-filters/#basic-rules\n[kb-redirect-priority]: https://adguard.com/kb/general/ad-filtering/create-own-filters/#redirect-rule-priorities\n[yarn-pkg-manager-url]: https://yarnpkg.com/en/docs/install\n[npm-pkg-manager-url]: https://www.npmjs.com/get-npm\n[pnpm-pkg-manager-url]: https://pnpm.io/installation\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAdguardTeam%2FScriptlets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAdguardTeam%2FScriptlets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAdguardTeam%2FScriptlets/lists"}