Skip to content

Commit

Permalink
std filed in rules
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Apr 24, 2024
1 parent a6cd33d commit c38d4fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Purify URL: Remove redundant tracking parameters, skip redirecting pages, and ex
- 📃 Rule-based: Perform purification based on rules, making it more flexible.
- 🔄️ Async: Calling `purify` won't block your thread.
- 🔁 Iterative purification: If the URL still contains tracking parameters after a single purification (e.g. URLs returned by `redirect` rules), it will continue to be purified.
- ⚠️ Non-standard search parameters tolerance: Tolerate non-standard search parameters, which may include special characters or spaces.
- 📊 Statistics: You can track statistics of the purification process, including the number of links purified, the number of parameters removed, the number of URLs decoded, the number of URLs redirected, and the number of characters deleted, etc.

## 🤔 Usage
Expand Down Expand Up @@ -221,6 +220,7 @@ This table shows supported parameters for each mode:

| Param\Mode | `white` | `black` | `param` | `regex` | `redirect` | `lambda` |
| ---------- | -- | --- | -- | --- | -- | --- |
| `std` |||||||
| `params` |||||||
| `decode` |||||||
| `regex` |||||||
Expand All @@ -234,16 +234,18 @@ This table shows supported parameters for each mode:
| Param | Type | Default |
| --- | --- | --- |
| `params` | `string[]` | Required |
| `std` | `Boolean` | `false` |

Under Whitelist mode, only the parameters specified in `params` will be kept, and others will be removed. Note that only URLs with standard search string will be processed. Usually this is the most commonly used mode.
Under Whitelist mode, only the parameters specified in `params` will be kept, and others will be removed. `std` is for controlling whether the URL search string shall be deemed standard. Only if it is `true` or the URL search string is indeed standard will the URL be processed. Usually this is the most commonly used mode.

#### 🟠 Blacklist Mode `black`

| Param | Type | Default |
| --- | --- | --- |
| `params` | `string[]` | Required |
| `std` | `Boolean` | `false` |

Under Blacklist mode, the parameters specified in `params` will be removed, and others will be kept. Note that only URLs with standard search string will be processed.
Under Blacklist mode, the parameters specified in `params` will be removed, and others will be kept. `std` is for controlling whether the URL search string shall be deemed standard. Only if it is `true` or the URL search string is indeed standard will the URL be processed.

#### 🟤 Specific Parameter Mode `param`

Expand Down
8 changes: 5 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- 📃 基于规则:根据规则净化,更为灵活。
- 🔄️ 异步:调用 `purify` 不会阻塞您的线程。
- 🔁 迭代式净化:若单次净化后的 URL 仍包含跟踪参数 (例如 `redirect` 规则返回的 URL),将继续净化。
- ⚠️ 容忍非标准搜索参数:容忍非标准的搜索参数 (可能包括特殊字符或空格)
- 📊 统计数据:您可以跟踪净化过程中的统计数据,包括净化的链接数量、移除的参数数量、解码的网址数量、重定向的网址数量、删除的字符数量等。

## 🤔 使用
Expand Down Expand Up @@ -221,6 +220,7 @@ new Purlfy({

| 参数\模式 | `white` | `black` | `param` | `regex` | `redirect` | `lambda` |
| ---------- | -- | --- | -- | --- | -- | --- |
| `std` |||||||
| `params` |||||||
| `decode` |||||||
| `regex` |||||||
Expand All @@ -234,16 +234,18 @@ new Purlfy({
| 参数 | 类型 | 默认值 |
| --- | --- | --- |
| `params` | `string[]` | 必须 |
| `std` | `Boolean` | `false` |

白名单模式下,只有在 `params` 中指定的查询参数才会被保留,原网址中的其余查询参数会被删除。注意只有 URL 的查询参数符合标准时才会被处理。通常来说这是最常用的模式。
白名单模式下,只有在 `params` 中指定的查询参数才会被保留,原网址中的其余查询参数会被删除。`std` 控制是否假定 URL 的查询参数是符合标准的,只有它被设为为 `true` 或 URL 的查询参数确实符合标准时才会按规则处理此网址。通常来说这是最常用的模式。

#### 🟠 黑名单模式 `black`

| 参数 | 类型 | 默认值 |
| --- | --- | --- |
| `params` | `string[]` | 必须 |
| `std` | `Boolean` | `false` |

黑名单模式下,在 `params` 中指定的查询参数将会被删除,原网址中的其余查询参数会被保留。注意只有 URL 的查询参数符合标准时才会被处理
黑名单模式下,在 `params` 中指定的查询参数将会被删除,原网址中的其余查询参数会被保留。`std` 控制是否假定 URL 的查询参数是符合标准的,只有它被设为为 `true` 或 URL 的查询参数确实符合标准时才会按规则处理此网址

#### 🟤 特定参数模式 `param`

Expand Down
6 changes: 3 additions & 3 deletions purlfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Purlfy extends EventTarget {
switch (rule.mode) {
case "white":
case "black":
return Array.isArray(rule.params);
return Array.isArray(rule.params) && this.#udfOrType(rule.std, "boolean");
case "param":
return Array.isArray(rule.params) && (rule.decode === undefined || Array.isArray(rule.decode)) && this.#udfOrType(rule.continue, "boolean");
case "regex":
Expand Down Expand Up @@ -148,7 +148,7 @@ class Purlfy extends EventTarget {
let shallContinue = false;
switch (mode) { // Purifies `urlObj` based on the rule
case "white": { // Whitelist mode
if (!this.#isStandard(urlObj)) {
if (!rule.std && !this.#isStandard(urlObj)) {
logFunc("Non-standard URL search string:", urlObj.search);
break;
}
Expand All @@ -162,7 +162,7 @@ class Purlfy extends EventTarget {
break;
}
case "black": { // Blacklist mode
if (!this.#isStandard(urlObj)) {
if (!rule.std && !this.#isStandard(urlObj)) {
logFunc("Non-standard URL search string:", urlObj.search);
break;
}
Expand Down

0 comments on commit c38d4fa

Please sign in to comment.