♻️ refactor(core): 优化 substore 节点重命名与规范化逻辑
This commit is contained in:
+23
-21
@@ -5,7 +5,7 @@
|
|||||||
`common.js` 是公共工具库,各处理脚本会按下面的 raw 地址自动加载:
|
`common.js` 是公共工具库,各处理脚本会按下面的 raw 地址自动加载:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=20260603-2
|
||||||
```
|
```
|
||||||
|
|
||||||
## 推荐使用顺序
|
## 推荐使用顺序
|
||||||
@@ -54,10 +54,10 @@ https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
🇭🇰 HK-CT-1 0.2x - SNTP
|
🇭🇰 HK-CT-1 0.2x - SNTP
|
||||||
=> 🇭🇰 HK-CT-1 0.2x [CFW] - SNTP
|
=> 🇭🇰 HK 01 0.2x [CFW]-SNTP
|
||||||
|
|
||||||
🇯🇵 JP-D-1-0.2x - SNTP
|
🇯🇵 JP-D-1-0.2x - SNTP
|
||||||
=> 🇯🇵 JP-D-1-0.2x [直连] - SNTP
|
=> 🇯🇵 JP 01 0.2x [直连]-SNTP
|
||||||
```
|
```
|
||||||
|
|
||||||
## YueTong 规则
|
## YueTong 规则
|
||||||
@@ -65,15 +65,15 @@ https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
|||||||
`yuetong-rename.js` 建议挂在 YueTong 单条订阅里使用,不依赖 `_subName`:
|
`yuetong-rename.js` 建议挂在 YueTong 单条订阅里使用,不依赖 `_subName`:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
🇯🇵 悦·日本专属2💎 - YueTong
|
🇯🇵 悦·日本专属2💎
|
||||||
=> 🇯🇵 日本专属2 - YueTong
|
=> 🇯🇵日本1
|
||||||
```
|
```
|
||||||
|
|
||||||
再经过 `rename.js` 后:
|
再经过 `rename.js` 后:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
🇯🇵 日本专属2 - YueTong
|
🇯🇵日本1
|
||||||
=> 🇯🇵 JP 专属 2 - YueTong
|
=> 🇯🇵 JP 01 - YueTong
|
||||||
```
|
```
|
||||||
|
|
||||||
## PeiQian 规则
|
## PeiQian 规则
|
||||||
@@ -82,7 +82,7 @@ https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
🇯🇵 日本东京03-0.1倍 | 电信联通推荐 - PeiQian
|
🇯🇵 日本东京03-0.1倍 | 电信联通推荐 - PeiQian
|
||||||
=> 🇯🇵 日本东京03 0.1x [电联] - PeiQian
|
=> 🇯🇵 日本东京03 0.1x - PeiQian
|
||||||
|
|
||||||
🇺🇸 美国01 | 合适下载使用-0.01倍 - PeiQian
|
🇺🇸 美国01 | 合适下载使用-0.01倍 - PeiQian
|
||||||
=> 🇺🇸 美国01 0.01x - PeiQian
|
=> 🇺🇸 美国01 0.01x - PeiQian
|
||||||
@@ -94,9 +94,9 @@ https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
|||||||
再经过 `rename.js` 后会变成:
|
再经过 `rename.js` 后会变成:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
🇯🇵 JP TYO 03 0.1x [电联] - PeiQian
|
🇯🇵 JP TYO 03 0.1X - PeiQian
|
||||||
🇺🇸 US 01 0.01x - PeiQian
|
🇺🇸 US 01 0.01X - PeiQian
|
||||||
🇼🇸 TW - PeiQian
|
🇼🇸 TW 01 - PeiQian
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alpha Air 规则
|
## Alpha Air 规则
|
||||||
@@ -139,31 +139,33 @@ https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
|||||||
|
|
||||||
`rename.js` 适合放在整合订阅最后。它做的事情更通用:
|
`rename.js` 适合放在整合订阅最后。它做的事情更通用:
|
||||||
|
|
||||||
|
全局规则只按节点名结构、地区词、线路词和通用格式匹配,不按机场名或 `_subName` 分支处理;以后修改某个订阅的 `_subName` 不应影响全局规则命中。
|
||||||
|
|
||||||
- 国家/地区中文名、英文名转短码,例如 `香港` -> `HK`、`Japan` -> `JP`。
|
- 国家/地区中文名、英文名转短码,例如 `香港` -> `HK`、`Japan` -> `JP`。
|
||||||
- 常见城市转短码,例如 `Los Angeles` -> `LAX`、`San Jose` -> `SJC`、`Seattle` -> `SEA`、`东京` -> `TYO`。
|
- 常见城市转短码,例如 `Los Angeles` -> `LAX`、`San Jose` -> `SJC`、`Seattle` -> `SEA`、`东京` -> `TYO`。
|
||||||
- 国家/地区别名表覆盖常见英文、中文国家名;城市尽量使用三字 IATA/城市码,避免 `LA` 这类两字码被旗帜操作误识别为国家。
|
- 国家/地区别名表覆盖常见英文、中文国家名;城市尽量使用三字 IATA/城市码,避免 `LA` 这类两字码被旗帜操作误识别为国家。
|
||||||
- 支持国旗在中间的节点名,例如 `Pro-🇭🇰 Sharon|守夜人` -> `🇭🇰 HK Pro-Sharon|守夜人`。
|
- 支持国旗在中间的节点名,例如 `Pro-🇭🇰 Sharon|守夜人` -> `🇭🇰 HK Pro-Sharon|守夜人`。
|
||||||
- 支持保留连字符命名里的入口/落地特征,例如 `HK-Go-05-HostHatch` -> `HK 05 GO-HostHatch`。
|
- 支持保留连字符命名里的入口/落地特征,例如 `HK-Go-05-HostHatch` -> `HK 05 GO-HostHatch`。
|
||||||
- 将倍率移动到节点核心末尾、订阅后缀之前,例如 `US 2X 02 - Alpha Air` -> `US 02 2X - Alpha Air`。
|
- 将倍率移动到节点核心末尾、订阅后缀之前,例如 `US 2X 02 - Example` -> `US 02 2X - Example`。
|
||||||
- 清理 `[DIP China-Hongkong]` 为 `[DIP]`。
|
- 清理 `[DIP China-Hongkong]` 为 `[DIP]`。
|
||||||
- 清理 Alpha Flower 这类 `IEPL 专线 3`、`标准 1`、`高级 1` 的冗余线路尾号。
|
- 清理 `IEPL 专线 3`、`标准 1`、`高级 1` 这类冗余线路尾号。
|
||||||
- 追加订阅后缀 `- _subName`。
|
- 追加订阅后缀 `- _subName`。
|
||||||
- 对最终重名节点追加两位编号。
|
- 对最终重名节点追加两位编号。
|
||||||
|
|
||||||
示例:
|
示例:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
🇭🇰 Hong Kong 01 [DIP China-Hongkong] - Nexitally
|
🇭🇰 Hong Kong 01 [DIP China-Hongkong] - Example
|
||||||
=> 🇭🇰 HK 01 [DIP] - Nexitally
|
=> 🇭🇰 HK 01 [DIP] - Example
|
||||||
|
|
||||||
🇯🇵 日本高级 IEPL 专线 3 - Alpha Flower
|
🇯🇵 日本高级 IEPL 专线 3 - Example
|
||||||
=> 🇯🇵 JP 01 高级 - Alpha Flower
|
=> 🇯🇵 JP 01 高级 - Example
|
||||||
|
|
||||||
Pro-🇭🇰 Sharon|守夜人 - Alpha 8K Snell
|
Pro-🇭🇰 Sharon|守夜人 - Example
|
||||||
=> 🇭🇰 HK Pro-Sharon|守夜人 - Alpha 8K Snell
|
=> 🇭🇰 HK Pro-Sharon|守夜人 - Example
|
||||||
|
|
||||||
🇭🇰 HK-Go-05-HostHatch - VK
|
🇭🇰 HK-Go-05-HostHatch - Example
|
||||||
=> 🇭🇰 HK 05 GO-HostHatch - VK
|
=> 🇭🇰 HK 05 GO-HostHatch - Example
|
||||||
```
|
```
|
||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
* Sub-Store 节点命名公共工具
|
* Sub-Store 节点命名公共工具
|
||||||
*
|
*
|
||||||
* 远程引用地址:
|
* 远程引用地址:
|
||||||
* https://git.orionc.me/orion/script/raw/branch/main/substore/common.js
|
* https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=20260603-2
|
||||||
*/
|
*/
|
||||||
(function (root) {
|
(function (root) {
|
||||||
const regexSpecialChars = new Set(['.', '*', '+', '?', '^', '$', '{', '}', '(', ')', '|', '[', ']', '\\']);
|
const regexSpecialChars = new Set(['.', '*', '+', '?', '^', '$', '{', '}', '(', ')', '|', '[', ']', '\\']);
|
||||||
@@ -272,4 +272,4 @@
|
|||||||
splitLeadingOrInlineFlag,
|
splitLeadingOrInlineFlag,
|
||||||
stripLineDescriptors
|
stripLineDescriptors
|
||||||
};
|
};
|
||||||
})(typeof globalThis !== 'undefined' ? globalThis : this);
|
})(globalThis);
|
||||||
|
|||||||
+1
-38
@@ -26,43 +26,7 @@ async function loadRenameUtils() {
|
|||||||
|
|
||||||
async function operator(proxies) {
|
async function operator(proxies) {
|
||||||
const utils = await loadRenameUtils();
|
const utils = await loadRenameUtils();
|
||||||
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => {
|
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => name);
|
||||||
const hyphenatedMatch = String(name).match(/^([A-Z]{2})(?:\s+([A-Z]{3}))?-(.+)$/);
|
|
||||||
if (!hyphenatedMatch) return name;
|
|
||||||
|
|
||||||
const countryCode = hyphenatedMatch[1];
|
|
||||||
let regionCode = hyphenatedMatch[2]
|
|
||||||
? `${countryCode} ${hyphenatedMatch[2]}`
|
|
||||||
: countryCode;
|
|
||||||
const tokens = hyphenatedMatch[3].split('-').map(token => token.trim()).filter(Boolean);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!hyphenatedMatch[2] &&
|
|
||||||
tokens.length >= 2 &&
|
|
||||||
/^[A-Z]{3}$/.test(tokens[0]) &&
|
|
||||||
/^\d{1,2}$/.test(tokens[1])
|
|
||||||
) {
|
|
||||||
regionCode = `${countryCode} ${tokens.shift()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sequenceIndex = tokens.findIndex(token => /^\d{1,2}$/.test(token));
|
|
||||||
if (sequenceIndex === -1) return name;
|
|
||||||
|
|
||||||
const sequenceNumber = tokens[sequenceIndex].padStart(2, '0');
|
|
||||||
const ingressTokens = tokens
|
|
||||||
.slice(0, sequenceIndex)
|
|
||||||
.map(token => token.toUpperCase());
|
|
||||||
const egressTokens = tokens.slice(sequenceIndex + 1);
|
|
||||||
const featureText = ingressTokens.length && egressTokens.length
|
|
||||||
? `${ingressTokens.join('-')}-${egressTokens.join('-')}`
|
|
||||||
: [...ingressTokens, ...egressTokens].join('-');
|
|
||||||
|
|
||||||
return [regionCode, sequenceNumber, featureText]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(' ')
|
|
||||||
.replace(/\s{2,}/g, ' ')
|
|
||||||
.trim();
|
|
||||||
});
|
|
||||||
const globalCount = Object.create(null);
|
const globalCount = Object.create(null);
|
||||||
const currentCount = Object.create(null);
|
const currentCount = Object.create(null);
|
||||||
const baseNames = new Array(proxies.length);
|
const baseNames = new Array(proxies.length);
|
||||||
@@ -792,7 +756,6 @@ async function operator(proxies) {
|
|||||||
|
|
||||||
core = core
|
core = core
|
||||||
.replace(/^([A-Z]{2})\s*(实验性|标准|高级)\s+IEPL\s+专线\s*\d+(.*)$/i, '$1 $2$3')
|
.replace(/^([A-Z]{2})\s*(实验性|标准|高级)\s+IEPL\s+专线\s*\d+(.*)$/i, '$1 $2$3')
|
||||||
.replace(/搬瓦工荷兰/g, '搬瓦工')
|
|
||||||
.replace(/\s{2,}/g, ' ')
|
.replace(/\s{2,}/g, ' ')
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user