|
| 1 | +/// <reference lib="es2020" /> |
| 2 | + |
| 3 | +declare interface MimeType { |
| 4 | + mime: string; |
| 5 | +} |
| 6 | + |
| 7 | +export interface Resource { |
| 8 | + name: string; |
| 9 | + aliases: string[]; |
| 10 | + kind: MimeType | "template"; |
| 11 | + content: string; |
| 12 | + dependencies?: string[]; |
| 13 | + permission?: number; |
| 14 | +} |
| 15 | + |
| 16 | +export interface FilterListMetadata { |
| 17 | + homepage?: string; |
| 18 | + title?: string; |
| 19 | + expires?: number; |
| 20 | + redirect?: string; |
| 21 | +} |
| 22 | + |
| 23 | +export interface ParseOptions { |
| 24 | + format: typeof FilterFormat; |
| 25 | + rule_types: typeof RuleTypes; |
| 26 | +} |
| 27 | + |
| 28 | +declare interface BlockerResult { |
| 29 | + matched: boolean, |
| 30 | + important: boolean, |
| 31 | + redirect?: string, |
| 32 | + rewritten_url?: string, |
| 33 | + exception?: string, |
| 34 | + filter?: string, |
| 35 | +} |
| 36 | + |
| 37 | +export class Engine { |
| 38 | + constructor(rules: FilterSet, debug: boolean); |
| 39 | + addResource(resource: Resource): boolean; |
| 40 | + check(url: string, source_url: string, request_type: string, debug?: false): boolean; |
| 41 | + check(url: string, source_url: string, request_type: string, debug: true): BlockerResult; |
| 42 | + clearTags(): null; |
| 43 | + deserialize(serialized_handle: ArrayBuffer): null; |
| 44 | + enableTag(tag: string): null; |
| 45 | + getResource(name: string): Resource; |
| 46 | + serializeCompressed(): ArrayBuffer; |
| 47 | + serializeRaw(): ArrayBuffer; |
| 48 | + tagExists(tag: string): boolean; |
| 49 | + useResources(resources: Resource[]): null; |
| 50 | +} |
| 51 | + |
| 52 | +type CbType = |
| 53 | + 'block' | |
| 54 | + 'block-cookies' | |
| 55 | + 'css-display-none' | |
| 56 | + 'ignore-previous-rules' | |
| 57 | + 'make-https'; |
| 58 | + |
| 59 | +declare interface CbAction { |
| 60 | + type: CbType, |
| 61 | + selector?: string, |
| 62 | +} |
| 63 | + |
| 64 | +type CbResourceType = |
| 65 | + 'document' | |
| 66 | + 'image' | |
| 67 | + 'style-sheet' | |
| 68 | + 'script' | |
| 69 | + 'font' | |
| 70 | + 'raw' | |
| 71 | + 'svg-document' | |
| 72 | + 'media' | |
| 73 | + 'popup'; |
| 74 | + |
| 75 | +type CbLoadType = |
| 76 | + 'first-party' | |
| 77 | + 'third-party'; |
| 78 | + |
| 79 | +declare interface CbTrigger { |
| 80 | + 'url-filter': string, |
| 81 | + 'url-filter-is-case-sensitive'?: boolean, |
| 82 | + 'if-domain'?: string[], |
| 83 | + 'unless-domain'?: string[], |
| 84 | + 'resource-type'?: Record<string, CbResourceType>, |
| 85 | + 'load-type'?: CbLoadType[], |
| 86 | + 'if-top-url'?: string[], |
| 87 | + 'unless-top-url'?: string[], |
| 88 | +} |
| 89 | + |
| 90 | +declare interface CbRule { |
| 91 | + action: CbAction, |
| 92 | + trigger: CbTrigger, |
| 93 | +} |
| 94 | + |
| 95 | +declare interface ContentBlockingConversionResult { |
| 96 | + content_blocking_rules: CbRule[], |
| 97 | + filters_used: string[], |
| 98 | +} |
| 99 | + |
| 100 | +export class FilterSet { |
| 101 | + constructor(debug: boolean); |
| 102 | + addFilter(filter: string, opts?: ParseOptions): null; |
| 103 | + addFilters(rules: string[], opts?: ParseOptions): FilterListMetadata; |
| 104 | + intoContentBlocking(): ContentBlockingConversionResult | undefined; |
| 105 | +} |
| 106 | + |
| 107 | +export const FilterFormat: { |
| 108 | + HOSTS: string; |
| 109 | + STANDARD: string; |
| 110 | +}; |
| 111 | + |
| 112 | +export const RuleTypes: { |
| 113 | + ALL: string; |
| 114 | + COSMETIC_ONLY: string; |
| 115 | + NETWORK_ONLY: string; |
| 116 | +}; |
| 117 | + |
| 118 | +export function uBlockResources( |
| 119 | + web_accessible_resource_dir: string, |
| 120 | + redirect_resources_path: string, |
| 121 | + scriptlets_path?: string, |
| 122 | +): Resource[]; |
0 commit comments