-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thanks to DefinitelyTyped/DefinitelyTyped#65416 for the initial version
- Loading branch information
1 parent
2948b35
commit dc2a4fa
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/// <reference lib="es2020" /> | ||
|
||
declare interface MimeType { | ||
mime: string; | ||
} | ||
|
||
export interface Resource { | ||
name: string; | ||
aliases: string[]; | ||
kind: MimeType | "template"; | ||
content: string; | ||
dependencies?: string[]; | ||
permission?: number; | ||
} | ||
|
||
export interface FilterListMetadata { | ||
homepage?: string; | ||
title?: string; | ||
expires?: number; | ||
redirect?: string; | ||
} | ||
|
||
export interface ParseOptions { | ||
format: typeof FilterFormat; | ||
rule_types: typeof RuleTypes; | ||
} | ||
|
||
declare interface BlockerResult { | ||
matched: boolean, | ||
important: boolean, | ||
redirect?: string, | ||
rewritten_url?: string, | ||
exception?: string, | ||
filter?: string, | ||
} | ||
|
||
export class Engine { | ||
constructor(rules: FilterSet, debug: boolean); | ||
addResource(resource: Resource): boolean; | ||
check(url: string, source_url: string, request_type: string, debug?: false): boolean; | ||
check(url: string, source_url: string, request_type: string, debug: true): BlockerResult; | ||
clearTags(): null; | ||
deserialize(serialized_handle: ArrayBuffer): null; | ||
enableTag(tag: string): null; | ||
getResource(name: string): Resource; | ||
serializeCompressed(): ArrayBuffer; | ||
serializeRaw(): ArrayBuffer; | ||
tagExists(tag: string): boolean; | ||
useResources(resources: Resource[]): null; | ||
} | ||
|
||
type CbType = | ||
'block' | | ||
'block-cookies' | | ||
'css-display-none' | | ||
'ignore-previous-rules' | | ||
'make-https'; | ||
|
||
declare interface CbAction { | ||
type: CbType, | ||
selector?: string, | ||
} | ||
|
||
type CbResourceType = | ||
'document' | | ||
'image' | | ||
'style-sheet' | | ||
'script' | | ||
'font' | | ||
'raw' | | ||
'svg-document' | | ||
'media' | | ||
'popup'; | ||
|
||
type CbLoadType = | ||
'first-party' | | ||
'third-party'; | ||
|
||
declare interface CbTrigger { | ||
'url-filter': string, | ||
'url-filter-is-case-sensitive'?: boolean, | ||
'if-domain'?: string[], | ||
'unless-domain'?: string[], | ||
'resource-type'?: Record<string, CbResourceType>, | ||
'load-type'?: CbLoadType[], | ||
'if-top-url'?: string[], | ||
'unless-top-url'?: string[], | ||
} | ||
|
||
declare interface CbRule { | ||
action: CbAction, | ||
trigger: CbTrigger, | ||
} | ||
|
||
declare interface ContentBlockingConversionResult { | ||
content_blocking_rules: CbRule[], | ||
filters_used: string[], | ||
} | ||
|
||
export class FilterSet { | ||
constructor(debug: boolean); | ||
addFilter(filter: string, opts?: ParseOptions): null; | ||
addFilters(rules: string[], opts?: ParseOptions): FilterListMetadata; | ||
intoContentBlocking(): ContentBlockingConversionResult | undefined; | ||
} | ||
|
||
export const FilterFormat: { | ||
HOSTS: string; | ||
STANDARD: string; | ||
}; | ||
|
||
export const RuleTypes: { | ||
ALL: string; | ||
COSMETIC_ONLY: string; | ||
NETWORK_ONLY: string; | ||
}; | ||
|
||
export function uBlockResources( | ||
web_accessible_resource_dir: string, | ||
redirect_resources_path: string, | ||
scriptlets_path?: string, | ||
): Resource[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"rust" | ||
], | ||
"main": "js/index.js", | ||
"types": "js/index.d.ts", | ||
"author": "Anton Lazarev <[email protected]>", | ||
"contributors": [ | ||
"Andrius Aucinas" | ||
|