@url-sanitize/adguard 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/data.json +1 -1
- package/data/metadata.json +3 -3
- package/dist/adapter.d.ts +5 -6
- package/dist/adapter.js +173 -6
- package/dist/index.d.ts +9 -9
- package/dist/index.js +7 -18
- package/dist/raw-CMXWFj4b.js +17 -0
- package/dist/raw.d.ts +5 -6
- package/dist/raw.js +1 -8
- package/dist/types.d.ts +10 -10
- package/dist/types.js +1 -0
- package/package.json +4 -4
- package/dist/chunk-4TYKAH2R.js +0 -192
- package/dist/chunk-ADSSKPI2.js +0 -22
package/data/metadata.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
3
|
-
"hash": "
|
|
4
|
-
"fetchedAt": "2026-10-
|
|
2
|
+
"version": "f8cc23fb470a",
|
|
3
|
+
"hash": "f8cc23fb470ad6485331031b567d1a4a0359872e48193104be4645c0e410ec55",
|
|
4
|
+
"fetchedAt": "2026-10-30T10:54:37.652Z",
|
|
5
5
|
"upstream": "https://raw.githubusercontent.com/AdguardTeam/FiltersRegistry/master/filters/filter_17_TrackParam/filter.txt",
|
|
6
6
|
"license": "LGPL-3.0-only"
|
|
7
7
|
}
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare function adguardToCatalog(data: AdguardData, meta: AdguardMetadata): SanitizerCatalog;
|
|
5
|
-
|
|
6
|
-
export { adguardToCatalog };
|
|
1
|
+
import { AdguardData, AdguardMetadata } from "./types.js";
|
|
2
|
+
import { SanitizerCatalog } from "@url-sanitize/core";
|
|
3
|
+
//#region src/adapter.d.ts
|
|
4
|
+
export declare function adguardToCatalog(data: AdguardData, meta: AdguardMetadata): SanitizerCatalog;
|
|
5
|
+
//#endregion
|
package/dist/adapter.js
CHANGED
|
@@ -1,6 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/adapter.ts
|
|
2
|
+
function adguardToCatalog(data, meta) {
|
|
3
|
+
const rules = [];
|
|
4
|
+
const lines = preprocessConditionals(data.text);
|
|
5
|
+
let index = 0;
|
|
6
|
+
for (const line of lines) {
|
|
7
|
+
const parsed = parseLine(line, index);
|
|
8
|
+
if (!parsed) continue;
|
|
9
|
+
index++;
|
|
10
|
+
const rule = {
|
|
11
|
+
kind: "strip-param",
|
|
12
|
+
source: "adguard",
|
|
13
|
+
provider: parsed.provider,
|
|
14
|
+
paramPattern: parsed.paramPattern,
|
|
15
|
+
exceptions: parsed.exceptions
|
|
16
|
+
};
|
|
17
|
+
if (parsed.urlPattern) rule.urlPattern = parsed.urlPattern;
|
|
18
|
+
if (parsed.valuePattern) rule.valuePattern = parsed.valuePattern;
|
|
19
|
+
rules.push(rule);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
version: meta.version,
|
|
23
|
+
generatedAt: meta.fetchedAt,
|
|
24
|
+
sources: [{
|
|
25
|
+
name: "adguard",
|
|
26
|
+
version: meta.version,
|
|
27
|
+
hash: meta.hash,
|
|
28
|
+
license: meta.license,
|
|
29
|
+
upstream: meta.upstream
|
|
30
|
+
}],
|
|
31
|
+
rules
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function preprocessConditionals(text) {
|
|
35
|
+
const activeStack = [true];
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
38
|
+
const line = rawLine.trim();
|
|
39
|
+
if (!line) continue;
|
|
40
|
+
if (line.startsWith("!#if")) {
|
|
41
|
+
const condition = line.slice(4).trim();
|
|
42
|
+
activeStack.push(activeStack.at(-1) === true && evalCondition(condition));
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (line.startsWith("!#else")) {
|
|
46
|
+
if (activeStack.length > 1) {
|
|
47
|
+
const parentActive = activeStack.at(-2) === true;
|
|
48
|
+
const branchWasActive = activeStack.at(-1) === true;
|
|
49
|
+
activeStack[activeStack.length - 1] = parentActive && !branchWasActive;
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (line.startsWith("!#endif")) {
|
|
54
|
+
if (activeStack.length > 1) activeStack.pop();
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (line.startsWith("!")) continue;
|
|
58
|
+
if (activeStack.at(-1) !== true) continue;
|
|
59
|
+
out.push(line);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
function evalCondition(condition) {
|
|
64
|
+
return condition.replace(/\badguard_ext_chromium_mv3\b/g, "false").replace(/\bext_ublock\b/g, "false").split("||").some((orPart) => orPart.split("&&").every((andPart) => {
|
|
65
|
+
const part = andPart.trim().replace(/^\(|\)$/g, "");
|
|
66
|
+
if (part.startsWith("!")) return !booleanToken(part.slice(1));
|
|
67
|
+
return booleanToken(part);
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
function booleanToken(token) {
|
|
71
|
+
return token.trim() === "true";
|
|
72
|
+
}
|
|
73
|
+
function parseLine(line, index) {
|
|
74
|
+
const modifierIndex = modifierStart(line);
|
|
75
|
+
if (modifierIndex === -1) return null;
|
|
76
|
+
const prefix = line.slice(0, modifierIndex);
|
|
77
|
+
const modifiers = parseModifiers(line.slice(modifierIndex + 1));
|
|
78
|
+
const removeParam = modifiers.get("removeparam") ?? deriveParamFromPrefix(prefix);
|
|
79
|
+
if (!removeParam) return null;
|
|
80
|
+
const pattern = parseRemoveParam(removeParam);
|
|
81
|
+
if (!pattern) return null;
|
|
82
|
+
const domainModifier = modifiers.get("domain");
|
|
83
|
+
const denyallow = modifiers.get("denyallow");
|
|
84
|
+
const positives = domainModifier ? domainModifier.split("|").filter((domain) => domain.length > 0 && !domain.startsWith("~")) : [];
|
|
85
|
+
const negatives = [...domainModifier ? domainModifier.split("|").filter((domain) => domain.startsWith("~")).map((domain) => domain.slice(1)) : [], ...denyallow ? denyallow.split("|").filter(Boolean) : []];
|
|
86
|
+
const urlPattern = positives.length > 0 ? domainsPattern(positives) : prefixPattern(prefix);
|
|
87
|
+
const parsed = {
|
|
88
|
+
provider: `adguard-${index}`,
|
|
89
|
+
paramPattern: pattern.paramPattern,
|
|
90
|
+
exceptions: negatives.map(domainPattern)
|
|
91
|
+
};
|
|
92
|
+
if (urlPattern) parsed.urlPattern = urlPattern;
|
|
93
|
+
if (pattern.valuePattern) parsed.valuePattern = pattern.valuePattern;
|
|
94
|
+
return parsed;
|
|
95
|
+
}
|
|
96
|
+
function modifierStart(line) {
|
|
97
|
+
const indexes = ["$removeparam", "$denyallow"].map((candidate) => line.indexOf(candidate)).filter((i) => i >= 0);
|
|
98
|
+
return indexes.length === 0 ? -1 : Math.min(...indexes);
|
|
99
|
+
}
|
|
100
|
+
function parseModifiers(raw) {
|
|
101
|
+
const out = /* @__PURE__ */ new Map();
|
|
102
|
+
for (const part of splitModifiers(raw)) {
|
|
103
|
+
const eq = part.indexOf("=");
|
|
104
|
+
if (eq === -1) out.set(part.toLowerCase(), "");
|
|
105
|
+
else out.set(part.slice(0, eq).toLowerCase(), part.slice(eq + 1).replace(/\\,/g, ","));
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
function splitModifiers(raw) {
|
|
110
|
+
const out = [];
|
|
111
|
+
let current = "";
|
|
112
|
+
let inRegex = false;
|
|
113
|
+
let escaped = false;
|
|
114
|
+
for (const char of raw) {
|
|
115
|
+
if (escaped) {
|
|
116
|
+
current += char;
|
|
117
|
+
escaped = false;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (char === "\\") {
|
|
121
|
+
current += char;
|
|
122
|
+
escaped = true;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (char === "/") inRegex = !inRegex;
|
|
126
|
+
if (char === "," && !inRegex) {
|
|
127
|
+
out.push(current);
|
|
128
|
+
current = "";
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
current += char;
|
|
132
|
+
}
|
|
133
|
+
if (current) out.push(current);
|
|
134
|
+
return out.filter(Boolean);
|
|
135
|
+
}
|
|
136
|
+
function parseRemoveParam(value) {
|
|
137
|
+
if (value.startsWith("/") && value.lastIndexOf("/") > 0) {
|
|
138
|
+
const body = value.slice(1, value.lastIndexOf("/")).replace(/\\,/g, ",");
|
|
139
|
+
const eq = body.indexOf("=");
|
|
140
|
+
if (eq > 0) return {
|
|
141
|
+
paramPattern: stripAnchors(body.slice(0, eq)),
|
|
142
|
+
valuePattern: body.slice(eq + 1)
|
|
143
|
+
};
|
|
144
|
+
return { paramPattern: body };
|
|
145
|
+
}
|
|
146
|
+
return { paramPattern: escapeRegExp(value) };
|
|
147
|
+
}
|
|
148
|
+
function stripAnchors(value) {
|
|
149
|
+
return value.replace(/^\^/, "").replace(/\$$/, "");
|
|
150
|
+
}
|
|
151
|
+
function deriveParamFromPrefix(prefix) {
|
|
152
|
+
const match = /[?&;/]([^?&;/*=]+)=?\*?$/.exec(prefix);
|
|
153
|
+
return match?.[1] ? escapeRegExp(match[1]) : null;
|
|
154
|
+
}
|
|
155
|
+
function prefixPattern(prefix) {
|
|
156
|
+
if (!prefix) return void 0;
|
|
157
|
+
if (prefix.startsWith("||")) return domainPattern(prefix.slice(2).replace(/\^.*$/, ""));
|
|
158
|
+
return globPattern(prefix.replace(/\^/g, "*"));
|
|
159
|
+
}
|
|
160
|
+
function domainsPattern(domains) {
|
|
161
|
+
return domains.map(domainPattern).join("|");
|
|
162
|
+
}
|
|
163
|
+
function domainPattern(domain) {
|
|
164
|
+
return `^https?:\\/\\/([^/?#]+\\.)?${escapeRegExp(domain.replace(/^\|\|/, "").replace(/\^$/, ""))}(?::[0-9]+)?(?:[/?#]|$)`;
|
|
165
|
+
}
|
|
166
|
+
function globPattern(glob) {
|
|
167
|
+
return escapeRegExp(glob).replace(/\\\*/g, ".*");
|
|
168
|
+
}
|
|
169
|
+
function escapeRegExp(value) {
|
|
170
|
+
return value.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { adguardToCatalog };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const adguardCatalog: SanitizerCatalog;
|
|
7
|
-
declare const sanitize: Sanitizer;
|
|
8
|
-
|
|
9
|
-
export {
|
|
1
|
+
import { AdguardData, AdguardMetadata } from "./types.js";
|
|
2
|
+
import { adguardToCatalog } from "./adapter.js";
|
|
3
|
+
import { adguardMetadata, adguardRawData } from "./raw.js";
|
|
4
|
+
import { Sanitizer, SanitizerCatalog } from "@url-sanitize/core";
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
export declare const adguardCatalog: SanitizerCatalog;
|
|
7
|
+
export declare const sanitize: Sanitizer;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type AdguardData, type AdguardMetadata, adguardMetadata, adguardRawData, adguardToCatalog };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-4TYKAH2R.js";
|
|
4
|
-
import {
|
|
5
|
-
adguardMetadata,
|
|
6
|
-
adguardRawData
|
|
7
|
-
} from "./chunk-ADSSKPI2.js";
|
|
8
|
-
|
|
9
|
-
// src/index.ts
|
|
1
|
+
import { adguardToCatalog } from "./adapter.js";
|
|
2
|
+
import { n as adguardRawData, t as adguardMetadata } from "./raw-CMXWFj4b.js";
|
|
10
3
|
import { compileSanitizer } from "@url-sanitize/core";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
adguardRawData,
|
|
17
|
-
adguardToCatalog,
|
|
18
|
-
sanitize
|
|
19
|
-
};
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const adguardCatalog = adguardToCatalog(adguardRawData, adguardMetadata);
|
|
6
|
+
const sanitize = compileSanitizer(adguardCatalog);
|
|
7
|
+
//#endregion
|
|
8
|
+
export { adguardCatalog, adguardMetadata, adguardRawData, adguardToCatalog, sanitize };
|