♻️ refactor(core): 简化 Sub-Store 节点重命名逻辑
* 移除多个机场专用的独立重命名脚本 * 整合节点命名规范至 rename.js 统一处理 * 更新文档以反映全局统一命名规则与使用方式 * 统一输出格式为:国旗 国家缩写 序号 [倍率] - 机场名
This commit is contained in:
1 parent
f601a0155a
commit
66ac40a69e
10 files changed
+244
-1213
No files matched your search
+33
-207
@@ -1,214 +1,40 @@
|
||||
# Sub-Store 节点命名脚本
|
||||
|
||||
这个目录放的是一组 Sub-Store 节点处理脚本。推荐把“单订阅专属规则”和“整合订阅全局规则”分开使用,避免一个机场的关键词误伤其他机场。
|
||||
## 全局统一规则
|
||||
|
||||
`common.js` 是公共工具库,各处理脚本会按下面的 raw 地址自动加载:
|
||||
把 `rename.js` 放在整合订阅的最后。它不依赖各机场的专用脚本,统一输出:
|
||||
|
||||
```text
|
||||
国旗 国家/地区英文缩写 序号 [倍率] - 机场名
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```text
|
||||
🇭🇰 Hong Kong 01 [DIP China-Hongkong] - Nexitally
|
||||
=> 🇭🇰 HK 01 - Nexitally
|
||||
|
||||
🇭🇰 香港实验性 IEPL 专线 1 - Flower
|
||||
=> 🇭🇰 HK 02 [0.2x] - Flower
|
||||
|
||||
🇬🇹 HK03-GTM 0.5x - SNTP
|
||||
=> 🇭🇰 HK 03 [0.5x] - SNTP
|
||||
```
|
||||
|
||||
规则:
|
||||
|
||||
- 优先按节点名称识别国家/地区,名称没有线索时才使用原国旗,避免错误国旗干扰。
|
||||
- 同一国家/地区的节点集中排列,并按原相对顺序重新连续编号。
|
||||
- 倍率统一为 `[数字x]`;没有倍率则不显示;“实验性”节点固定为 `[0.2x]`。
|
||||
- 保留全部节点,通过新序号保证最终名称不重复,不会按显示名删除真实线路。
|
||||
- 台湾按 `TW` 识别和编号,显示为 `🇨🇳 TW`;Emby 无具体国家,显示为 `🏴☠️ EMBY`。
|
||||
- 无法识别国家/地区的节点保持原名并放到末尾。
|
||||
- 重复运行结果不变。
|
||||
|
||||
机场名优先取 Sub-Store 的 `_subName`;没有 `_subName` 时,从原名末尾的 ` - 机场名` 提取。
|
||||
|
||||
`common.js` 是公共工具库,`rename.js` 会自动加载:
|
||||
|
||||
```text
|
||||
https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=20260702-1
|
||||
```
|
||||
|
||||
## 推荐使用顺序
|
||||
|
||||
单订阅脚本先跑,整合订阅最后跑:
|
||||
|
||||
1. `sntp-rename.js`:放在 SNTP 单订阅里,注入线路标签。
|
||||
2. `yuetong-rename.js`:只清理 YueTong 的品牌前缀和装饰符号。
|
||||
3. `peiqian-rename.js`:只清理 PeiQian 的推荐/用途描述。
|
||||
4. `alphaair-rename.js`:只处理 Alpha Air 的供应商压缩、倍率排序和连续编号。
|
||||
5. `iriscloud-rename.js`:只处理 Iris Cloud 的入口/落地地区冲突和供应商特征。
|
||||
6. `liangxin-rename.js`:只清理 LiangXin 的高速、BGP、CMCU 等线路描述。
|
||||
7. `yinyun-rename.js`:只处理 YinYun 的中文地区名,并按地区连续编号。
|
||||
8. `rename.js`:整合订阅最后追加订阅后缀,并对仍然重名的节点编号。
|
||||
|
||||
如果某个订阅没有对应的专属脚本,直接进入最后的 `rename.js` 即可。
|
||||
|
||||
## 脚本职责
|
||||
|
||||
| 脚本 | 建议配置位置 | 作用 |
|
||||
| --- | --- | --- |
|
||||
| `sntp-rename.js` | SNTP 单订阅 | 注入 `[三网]`、`[CFW]`、`[直连]`、`[cn2]` 等线路标签 |
|
||||
| `yuetong-rename.js` | YueTong 单订阅 | 去掉 `悦·`、`💎`,把 `AI解锁` 压成 `AI` |
|
||||
| `peiqian-rename.js` | PeiQian 单订阅 | 压短 `电信联通推荐`、`移动联通推荐`、`高速专线`、`hy2`、倍率和用途描述 |
|
||||
| `alphaair-rename.js` | Alpha Air 单订阅 | 去掉提供者/三网/家宽文案,所有节点移除供应商标签,倍率节点保留倍率并连续编号 |
|
||||
| `iriscloud-rename.js` | Iris Cloud 单订阅 | 按 `SG`、`TYO`/`JP`、其余香港的专属规则重判落地地区,去掉入口线路和供应商文案并保留倍率 |
|
||||
| `liangxin-rename.js` | LiangXin 单订阅 | 去掉 `高速`、`BGP`、`CMCU`、`CM`、`CU`、`CT` 等线路描述 |
|
||||
| `yinyun-rename.js` | YinYun 单订阅 | 中文国家/地区名转短码,忽略 `优选`、原始编号和 `(T)`/`(R)`,按地区连续编号 |
|
||||
| `rename.js` | 整合订阅 | 保留原节点名,追加 `- _subName`,处理追加后仍然重名的节点 |
|
||||
| `common.js` | 公共依赖 | 被各处理脚本远程加载,不需要单独配置为处理器 |
|
||||
|
||||
## SNTP 规则
|
||||
|
||||
`sntp-rename.js` 建议挂在 SNTP 的单条订阅里使用。它不依赖 `_subName`,方便分享和复用;但像 `BGP`、`D`、`CT` 这类关键词比较短,不建议直接放到整合订阅里全局运行。
|
||||
|
||||
| 命中关键词 | 注入标签 |
|
||||
| --- | --- |
|
||||
| `GTM 0.5x` | `[三网]` |
|
||||
| `GTM` | `[三网]` |
|
||||
| `CT` | `[CFW]` |
|
||||
| `D` | `[直连]` |
|
||||
| `S1` | `[广移]` |
|
||||
| `S2` | `[广电]` |
|
||||
| `S3` | `[广移]` |
|
||||
| `S4` | `[广联]` |
|
||||
| `BGP` | `[cn2]` |
|
||||
| `Anytls` | `[直连]` |
|
||||
|
||||
示例:
|
||||
|
||||
```text
|
||||
🇭🇰 HK-CT-1 0.2x - SNTP
|
||||
=> 🇭🇰 HK 01 0.2x [CFW]-SNTP
|
||||
|
||||
🇯🇵 JP-D-1-0.2x - SNTP
|
||||
=> 🇯🇵 JP 01 0.2x [直连]-SNTP
|
||||
```
|
||||
|
||||
## YueTong 规则
|
||||
|
||||
`yuetong-rename.js` 建议挂在 YueTong 单条订阅里使用,不依赖 `_subName`:
|
||||
|
||||
```text
|
||||
🇯🇵 悦·日本专属2💎
|
||||
=> 🇯🇵日本1
|
||||
```
|
||||
|
||||
再经过 `rename.js` 后:
|
||||
|
||||
```text
|
||||
🇯🇵日本1
|
||||
=> 🇯🇵 JP 01 - YueTong
|
||||
```
|
||||
|
||||
## PeiQian 规则
|
||||
|
||||
`peiqian-rename.js` 建议挂在 PeiQian 单条订阅里使用,不依赖 `_subName`:
|
||||
|
||||
```text
|
||||
🇯🇵 日本东京03-0.1倍 | 电信联通推荐 - PeiQian
|
||||
=> 🇯🇵 日本东京03 0.1x - PeiQian
|
||||
|
||||
🇺🇸 美国01 | 合适下载使用-0.01倍 - PeiQian
|
||||
=> 🇺🇸 美国01 0.01x - PeiQian
|
||||
|
||||
🇼🇸 台湾 | 避免晚高峰使用 - PeiQian
|
||||
=> 🇼🇸 台湾 - PeiQian
|
||||
```
|
||||
|
||||
再经过 `rename.js` 后会变成:
|
||||
|
||||
```text
|
||||
🇯🇵 JP TYO 03 0.1X - PeiQian
|
||||
🇺🇸 US 01 0.01X - PeiQian
|
||||
🇼🇸 TW 01 - PeiQian
|
||||
```
|
||||
|
||||
## Alpha Air 规则
|
||||
|
||||
`alphaair-rename.js` 建议挂在 Alpha Air 单条订阅里使用。它会把 Alpha Air 的提供者和线路文案全部压掉;所有节点只保留地区,倍率节点额外保留倍率;之后再交给全局 `rename.js` 追加订阅后缀。
|
||||
|
||||
```text
|
||||
🇺🇸 4X|美国夏威夷家宽|三网1
|
||||
=> 🇺🇸 US HNL 4X 01
|
||||
=> 🇺🇸 US HNL 01 4X - Alpha Air
|
||||
|
||||
3X 🇨🇳 台湾家宽Hinet|COP
|
||||
=> 🇹🇼 TW 3X 01
|
||||
=> 🇹🇼 TW 01 3X - Alpha Air
|
||||
|
||||
🇭🇰 SkyStroll|毕业
|
||||
=> 🇭🇰 HK 01
|
||||
|
||||
香港HKT
|
||||
=> 🇭🇰 HK 01
|
||||
```
|
||||
|
||||
## Iris Cloud 规则
|
||||
|
||||
`iriscloud-rename.js` 建议挂在 Iris Cloud 单条订阅里使用。Iris Cloud 的节点名里 `HK` 可能只是入口或线路名,脚本会按落地关键词重新判断地区,压掉供应商/入口线路文案,并保留 `0.5x`、`2.69x` 这类倍率;无法识别为 Iris Cloud 节点的名称会原样放行,不参与排序和编号。
|
||||
|
||||
- 名称包含 `SG`:新加坡节点。
|
||||
- 名称包含 `TYO` 或 `JP`:日本节点。
|
||||
- 明确包含 `HK` 或 `iCable`:香港节点。
|
||||
|
||||
```text
|
||||
🇭🇰 SZ 03 HK-DataCamp-SG - Iris Cloud
|
||||
=> 🇸🇬 SG 01
|
||||
|
||||
🇭🇰 HZ 01 HK-DMIT-TYO - Iris Cloud
|
||||
=> 🇯🇵 JP TYO 01
|
||||
|
||||
🏴☠️ [Edge] iCable - Iris Cloud
|
||||
=> 🇭🇰 HK 01
|
||||
|
||||
🇭🇰 HK DMIT | 2.69x | HZBGP Aliyun
|
||||
=> 🇭🇰 HK 01 2.69X
|
||||
```
|
||||
|
||||
## LiangXin 规则
|
||||
|
||||
`liangxin-rename.js` 建议挂在 LiangXin 单条订阅里使用。它会删除内嵌的线路描述,以及 `|` 分隔出来的纯线路标签:
|
||||
|
||||
```text
|
||||
🇭🇰香港高速01|BGP|CMCU
|
||||
=> 🇭🇰 香港01
|
||||
```
|
||||
|
||||
再经过 `rename.js` 后:
|
||||
|
||||
```text
|
||||
🇭🇰 香港01
|
||||
=> 🇭🇰 HK 01 - LiangXin
|
||||
```
|
||||
|
||||
## YinYun 规则
|
||||
|
||||
`yinyun-rename.js` 建议挂在 YinYun 单条订阅里使用。YinYun 的节点名主要由中文地区名、`优选`/数字编号、`(T)`/`(R)` 线路标记和可选 `ᴮᴬᴷ` 备份标签组成;脚本会忽略这些原始线路细节,按地区出现顺序重新连续编号,最后再交给全局 `rename.js` 追加订阅后缀。
|
||||
|
||||
```text
|
||||
香港 优选(T)
|
||||
=> 🇭🇰 HK 01
|
||||
=> 🇭🇰 HK 01 - YinYun
|
||||
|
||||
香港 优选(R)
|
||||
=> 🇭🇰 HK 02
|
||||
=> 🇭🇰 HK 02 - YinYun
|
||||
|
||||
哈萨克斯坦 (T)
|
||||
=> 🇰🇿 KZ 01
|
||||
=> 🇰🇿 KZ 01 - YinYun
|
||||
|
||||
魔法节点 (R)
|
||||
=> MAGIC 01
|
||||
=> MAGIC 01 - YinYun
|
||||
|
||||
泰国 (T) ᴮᴬᴷ
|
||||
=> 🇹🇭 TH 01
|
||||
=> 🇹🇭 TH 01 - YinYun
|
||||
```
|
||||
|
||||
## 全局后缀
|
||||
|
||||
`rename.js` 适合放在整合订阅最后。它不会再修改节点原名、地区/线路标签或节点顺序,只处理订阅后缀和重名兜底:
|
||||
|
||||
- 先移除本次订阅已经存在的 `- _subName`(含重跑时的两位编号),再追加一次,避免重复运行叠加后缀。
|
||||
- 不同 `_subName` 的订阅即使原节点名相同,追加后缀后也会自然区分,不会互相编号。
|
||||
- 只有追加后仍然完全重名的节点,才在订阅后缀前追加两位编号。
|
||||
|
||||
示例:
|
||||
|
||||
```text
|
||||
Hong Kong 01
|
||||
=> Hong Kong 01 - Example
|
||||
|
||||
重复节点
|
||||
=> 重复节点 01 - Example
|
||||
=> 重复节点 02 - Example
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- `sntp-rename.js` 不带 `_subName` 判断,适合挂在 SNTP 单订阅里;如果放进整合订阅,可能会误伤其他带 `BGP`、`D`、`CT` 的节点。
|
||||
- `yuetong-rename.js`、`peiqian-rename.js`、`liangxin-rename.js` 和 `yinyun-rename.js` 也不带 `_subName` 判断,适合挂在对应单订阅里;如果放进整合订阅,需要确认规则不会误伤其他订阅。
|
||||
- `rename.js` 会剥离并重新追加 `- _subName`,重复运行不会叠加订阅后缀。
|
||||
- 如果新增订阅里出现很短、很泛的关键词,例如 `D`、`CT`、`BGP`、`S1`,或像 Alpha Air 这种强绑定单机场的供应商压缩规则,优先拆成单订阅脚本,不建议放进全局 `rename.js`。
|
||||
@@ -1,166 +0,0 @@
|
||||
/**
|
||||
* Alpha Air 专用节点清理脚本
|
||||
* - 压掉提供者、三网、家宽等 Alpha Air 专属文案
|
||||
* - 所有节点都移除供应商标签,倍率节点额外保留倍率
|
||||
* - 按地区内“普通 -> 倍率 -> 高级”排序并连续编号
|
||||
* - 不追加订阅后缀,整合订阅最后仍交给 rename.js 处理
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const regionAliases = [
|
||||
['美国夏威夷', 'US HNL'],
|
||||
['家宽夏威夷', 'US HNL'],
|
||||
['夏威夷', 'US HNL'],
|
||||
['Hawaii', 'US HNL'],
|
||||
['United States', 'US'],
|
||||
['America', 'US'],
|
||||
['USA', 'US'],
|
||||
['美国', 'US'],
|
||||
['美西', 'US'],
|
||||
['Japan', 'JP'],
|
||||
['日本', 'JP'],
|
||||
['Taiwan', 'TW'],
|
||||
['台湾', 'TW'],
|
||||
['Hong Kong', 'HK'],
|
||||
['香港', 'HK'],
|
||||
['Singapore', 'SG'],
|
||||
['新加坡', 'SG'],
|
||||
['Netherlands', 'NL'],
|
||||
['荷兰', 'NL'],
|
||||
['Korea', 'KR'],
|
||||
['韩国', 'KR'],
|
||||
['Germany', 'DE'],
|
||||
['德国', 'DE'],
|
||||
['United Kingdom', 'UK'],
|
||||
['英国', 'UK']
|
||||
];
|
||||
const regionResolver = utils.createRegionResolver(regionAliases);
|
||||
|
||||
const providerOf = name => {
|
||||
if (/SkyStroll/i.test(name)) return 'SkyStroll';
|
||||
if (/isif/i.test(name)) return 'ISIF';
|
||||
if (/搬瓦工|Bandwagon|BWH|BWG/i.test(name)) return 'BWH';
|
||||
return '';
|
||||
};
|
||||
|
||||
const alphaAirRegionPrefixOf = name => {
|
||||
if (/\bhk\b/i.test(name)) return 'HK';
|
||||
if (/\bsg\b/i.test(name)) return 'SG';
|
||||
if (/\bjp\b/i.test(name)) return 'JP';
|
||||
if (/\btw\b/i.test(name)) return 'TW';
|
||||
if (/\bus\b/i.test(name)) return 'US';
|
||||
|
||||
return regionResolver.aliasRegionPrefixOf(name);
|
||||
};
|
||||
|
||||
const regionPrefixOf = (name, flagRegionCode) => {
|
||||
if (/Hinet|Seednet/i.test(name)) return 'TW';
|
||||
|
||||
return alphaAirRegionPrefixOf(name) ||
|
||||
utils.leadingRegionPrefixOf(name) ||
|
||||
flagRegionCode ||
|
||||
'';
|
||||
};
|
||||
|
||||
const normalizeProxy = (proxy, originalIndex) => {
|
||||
const rawName = typeof proxy.name === 'string' ? proxy.name : '';
|
||||
const cleanName = utils.stripSubscriptionSuffix(rawName, 'Alpha Air');
|
||||
const { flag, text } = utils.splitLeadingOrInlineFlag(cleanName);
|
||||
const flagRegionCode = utils.flagToRegionCode(flag);
|
||||
const regionPrefix = regionPrefixOf(text, flagRegionCode);
|
||||
const regionCode = regionPrefix.split(/\s+/)[0];
|
||||
const cityCode = regionPrefix.split(/\s+/)[1] || '';
|
||||
const multiplier = utils.multiplierOf(text);
|
||||
const provider = multiplier ? '' : providerOf(text);
|
||||
const normalizedFlag = utils.regionCodeToFlag(regionCode);
|
||||
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
countryCode: regionCode,
|
||||
cityCode,
|
||||
normalizedFlag,
|
||||
regionPrefix,
|
||||
provider,
|
||||
multiplier,
|
||||
providerRank: provider ? 1 : 0,
|
||||
multiplierValue: utils.multiplierValueOf(multiplier),
|
||||
normalizedName: [normalizedFlag, regionPrefix, provider, multiplier].filter(Boolean).join(' ').trim()
|
||||
};
|
||||
};
|
||||
|
||||
const countryOrder = Object.create(null);
|
||||
let countryOrderCount = 0;
|
||||
const normalizedItems = proxies.map((proxy, proxyIndex) => {
|
||||
const normalizedItem = normalizeProxy(proxy, proxyIndex);
|
||||
if (
|
||||
normalizedItem.countryCode &&
|
||||
countryOrder[normalizedItem.countryCode] === undefined
|
||||
) {
|
||||
countryOrder[normalizedItem.countryCode] = countryOrderCount++;
|
||||
}
|
||||
return normalizedItem;
|
||||
});
|
||||
|
||||
normalizedItems.sort((firstItem, secondItem) => {
|
||||
if (!firstItem.countryCode || !secondItem.countryCode) {
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
}
|
||||
|
||||
const firstOrder = countryOrder[firstItem.countryCode];
|
||||
const secondOrder = countryOrder[secondItem.countryCode];
|
||||
if (firstOrder !== secondOrder) return firstOrder - secondOrder;
|
||||
if (firstItem.providerRank !== secondItem.providerRank) {
|
||||
return firstItem.providerRank - secondItem.providerRank;
|
||||
}
|
||||
if (firstItem.multiplierValue !== secondItem.multiplierValue) {
|
||||
return firstItem.multiplierValue - secondItem.multiplierValue;
|
||||
}
|
||||
|
||||
const firstCityRank = firstItem.cityCode ? 1 : 0;
|
||||
const secondCityRank = secondItem.cityCode ? 1 : 0;
|
||||
if (firstCityRank !== secondCityRank) return firstCityRank - secondCityRank;
|
||||
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
});
|
||||
|
||||
const nextSequence = utils.createSequenceCounter();
|
||||
return normalizedItems.map(item => {
|
||||
if (!item.normalizedName || !item.countryCode) return item.proxy;
|
||||
|
||||
item.proxy.name = [
|
||||
item.normalizedFlag,
|
||||
item.regionPrefix,
|
||||
nextSequence(item.countryCode),
|
||||
item.multiplier
|
||||
].filter(Boolean).join(' ').trim();
|
||||
return item.proxy;
|
||||
});
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/**
|
||||
* Iris Cloud 专用节点清理脚本
|
||||
* - Iris Cloud 名称里 HK 是入口/线路名的一部分,落地以尾部 SG、TYO、HKG 等标识为准
|
||||
* - 包含 SG 的节点归新加坡,包含 TYO/JP 的节点归日本,明确 HK/iCable 的节点归香港
|
||||
* - 无法识别为 Iris Cloud 节点的名称原样放行,不参与排序和编号
|
||||
* - 去掉 SZ/HZ/[Edge] 入口标签,保留倍率,压掉供应商和入口线路特征
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
|
||||
const landingPrefixOf = name => {
|
||||
if (/^(?:US)(?:$|[\s|.-])/i.test(name)) return 'US';
|
||||
if (/(?:^|[-\s])SG(?:$|[-\s.])/i.test(name)) return 'SG';
|
||||
if (/(?:^|[-\s])TYO(?:$|[-\s])/i.test(name)) return 'JP TYO';
|
||||
if (/(?:^|[-\s])JP(?:$|[-\s])/i.test(name)) return 'JP';
|
||||
if (/(?:^|[-\s])HK(?:$|[-\s])/i.test(name)) return 'HK';
|
||||
if (/iCable/i.test(name)) return 'HK';
|
||||
return '';
|
||||
};
|
||||
|
||||
const cleanCoreName = name => {
|
||||
const { text } = utils.splitLeadingOrInlineFlag(name);
|
||||
return utils.stripSubscriptionSuffix(text, 'Iris Cloud')
|
||||
.replace(/^\s*(?:SZ|HZ)\s+\d{1,2}\s+/i, '')
|
||||
.replace(/^\s*\[Edge]\s*/i, '')
|
||||
.trim();
|
||||
};
|
||||
|
||||
const normalizedItems = proxies.map((proxy, originalIndex) => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
regionPrefix: ''
|
||||
};
|
||||
}
|
||||
|
||||
const coreName = cleanCoreName(proxy.name);
|
||||
const regionPrefix = landingPrefixOf(coreName);
|
||||
if (!regionPrefix) {
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
regionPrefix: ''
|
||||
};
|
||||
}
|
||||
|
||||
const regionCode = regionPrefix.split(/\s+/)[0];
|
||||
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
regionPrefix,
|
||||
regionCode,
|
||||
multiplier: utils.multiplierOf(coreName),
|
||||
flag: utils.regionCodeToFlag(regionCode)
|
||||
};
|
||||
});
|
||||
|
||||
const regionOrder = Object.create(null);
|
||||
let regionOrderCount = 0;
|
||||
normalizedItems.forEach(item => {
|
||||
if (!item.regionPrefix || regionOrder[item.regionPrefix] !== undefined) return;
|
||||
regionOrder[item.regionPrefix] = regionOrderCount++;
|
||||
});
|
||||
|
||||
normalizedItems.sort((firstItem, secondItem) => {
|
||||
if (!firstItem.regionPrefix || !secondItem.regionPrefix) {
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
}
|
||||
|
||||
const firstRegionOrder = regionOrder[firstItem.regionPrefix];
|
||||
const secondRegionOrder = regionOrder[secondItem.regionPrefix];
|
||||
if (firstRegionOrder !== secondRegionOrder) return firstRegionOrder - secondRegionOrder;
|
||||
const firstMultiplierValue = utils.multiplierValueOf(firstItem.multiplier);
|
||||
const secondMultiplierValue = utils.multiplierValueOf(secondItem.multiplier);
|
||||
if (firstMultiplierValue !== secondMultiplierValue) {
|
||||
return firstMultiplierValue - secondMultiplierValue;
|
||||
}
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
});
|
||||
|
||||
const nextSequence = utils.createSequenceCounter();
|
||||
return normalizedItems.map(item => {
|
||||
if (!item.regionPrefix) return item.proxy;
|
||||
|
||||
item.proxy.name = [
|
||||
item.flag,
|
||||
item.regionPrefix,
|
||||
nextSequence(item.regionPrefix),
|
||||
item.multiplier
|
||||
].filter(Boolean).join(' ').trim();
|
||||
return item.proxy;
|
||||
});
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* LiangXin 专用节点清理脚本
|
||||
* 负责去掉高速、BGP、CMCU 等 LiangXin 线路描述,保留地区、序号和倍率。
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const lineDescriptorKeywords = [
|
||||
'CMCU',
|
||||
'CUCM',
|
||||
'CMCT',
|
||||
'CTCM',
|
||||
'CUCT',
|
||||
'CTCU',
|
||||
'BGP',
|
||||
'CMI',
|
||||
'CUG',
|
||||
'CN2',
|
||||
'IEPL',
|
||||
'IPLC',
|
||||
'9929',
|
||||
'4837',
|
||||
'CM',
|
||||
'CU',
|
||||
'CT',
|
||||
'高速',
|
||||
'极速',
|
||||
'专线',
|
||||
'中转',
|
||||
'直连',
|
||||
'隧道',
|
||||
'三网',
|
||||
'移动',
|
||||
'联通',
|
||||
'电信'
|
||||
];
|
||||
|
||||
return proxies.map(proxy => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
proxy.name = utils.stripLineDescriptors(proxy.name, lineDescriptorKeywords);
|
||||
return proxy;
|
||||
});
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* PeiQian 专用节点清理脚本
|
||||
* 负责清理推荐、用途、hy2、倍率、线路特征和提供商等 PeiQian 节点文案。
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
|
||||
return proxies.map(proxy => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
proxy.name = proxy.name
|
||||
.replace(/AWS\s*(?=新加坡)/gi, '')
|
||||
.replace(/\s*\|\s*合适下载使用\s*-\s*(\d+(?:\.\d+)?)倍/gi, ' $1x')
|
||||
.replace(/\s*\|\s*合适下载使用/gi, '')
|
||||
.replace(/\s*\|\s*避免晚高峰使用/gi, '')
|
||||
.replace(/\s*\|\s*(?:电信联通移动|电信联通|移动联通|三网)推荐(?:\s*-\s*hy2)?/gi, '')
|
||||
.replace(/\s*\|\s*高速专线(?:推荐)?(?:\s*-\s*hy2)?/gi, '')
|
||||
.replace(/\s*\[(?:专线|移联|电联|三网|HY2)(?:\s+(?:专线|移联|电联|三网|HY2))*\]/gi, '')
|
||||
.replace(/\s+\[/g, ' [')
|
||||
.replace(/\s{2,}/g, ' ');
|
||||
proxy.name = utils.normalizeMultiplierText(proxy.name);
|
||||
proxy.name = utils.normalizeLeadingFlagSpacing(proxy.name);
|
||||
|
||||
return proxy;
|
||||
});
|
||||
}
|
||||
+205
-149
@@ -1,17 +1,87 @@
|
||||
/**
|
||||
* Sub-Store 整合订阅后缀脚本
|
||||
* - 保留节点原名,只追加当前订阅的 `_subName`
|
||||
* - 按节点名里最先出现的国家/地区标识重置开头国旗
|
||||
* - 重复执行不会叠加相同的订阅后缀
|
||||
* - 同名节点追加两位编号,避免节点名重复
|
||||
* Sub-Store 整合订阅统一重命名脚本
|
||||
* - 输出:国旗 国家/地区缩写 序号 [倍率] - 机场名
|
||||
* - 同一国家/地区连续编号并集中排序
|
||||
* - 实验性节点固定为 0.2x
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
// 部分客户端无法渲染台湾地区旗帜,显示层回退到中国国旗;地区识别仍保留为 TW。
|
||||
|
||||
// 台湾节点仍用 TW 识别和编号,仅显示层沿用中国国旗,兼容不支持台湾旗帜的客户端。
|
||||
const REGION_FLAG_DISPLAY_OVERRIDES = {
|
||||
TW: 'CN'
|
||||
};
|
||||
|
||||
const ISO_REGION_CODES = `
|
||||
AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ
|
||||
CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO
|
||||
FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE
|
||||
JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO
|
||||
MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW
|
||||
PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM
|
||||
TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW
|
||||
`.trim().split(/\s+/);
|
||||
|
||||
const REGION_ALIASES = [
|
||||
['AT&T', 'US'],
|
||||
['United States of America', 'US'], ['United States', 'US'], ['U.S.A.', 'US'], ['USA', 'US'],
|
||||
['United Arab Emirates', 'AE'], ['UAE', 'AE'],
|
||||
['United Kingdom', 'UK'], ['Great Britain', 'UK'], ['Britain', 'UK'], ['England', 'UK'], ['UK', 'UK'],
|
||||
['Russian Federation', 'RU'], ['Russia', 'RU'],
|
||||
['Republic of Korea', 'KR'], ['South Korea', 'KR'], ['Korea', 'KR'],
|
||||
['North Korea', 'KP'], ['DPRK', 'KP'],
|
||||
['Hong Kong', 'HK'], ['Hongkong', 'HK'], ['HK', 'HK'],
|
||||
['Macau', 'MO'], ['Macao', 'MO'],
|
||||
['Taiwan', 'TW'], ['TW', 'TW'],
|
||||
['Singapore', 'SG'], ['SG', 'SG'],
|
||||
['Japan', 'JP'], ['JP', 'JP'],
|
||||
['Australia', 'AU'], ['AU', 'AU'],
|
||||
['US', 'US'],
|
||||
['香港', 'HK'], ['澳门', 'MO'], ['澳門', 'MO'],
|
||||
['台湾', 'TW'], ['台灣', 'TW'], ['臺灣', 'TW'],
|
||||
['新加坡', 'SG'], ['狮城', 'SG'], ['獅城', 'SG'],
|
||||
['日本', 'JP'], ['美国', 'US'], ['美國', 'US'], ['美西', 'US'], ['美东', 'US'], ['美東', 'US'],
|
||||
['英国', 'UK'], ['英國', 'UK'], ['阿联酋', 'AE'], ['阿聯酋', 'AE'],
|
||||
['韩国', 'KR'], ['韓國', 'KR'], ['南韩', 'KR'], ['南韓', 'KR'],
|
||||
['朝鲜', 'KP'], ['朝鮮', 'KP'], ['俄罗斯', 'RU'], ['俄羅斯', 'RU'],
|
||||
['中国', 'CN'], ['中國', 'CN'], ['澳大利亚', 'AU'], ['澳大利亞', 'AU'], ['澳洲', 'AU'],
|
||||
['Netherlands', 'NL'], ['Holland', 'NL'], ['荷兰', 'NL'], ['荷蘭', 'NL'],
|
||||
['Switzerland', 'CH'], ['瑞士', 'CH'], ['France', 'FR'], ['法国', 'FR'], ['法國', 'FR'],
|
||||
['Germany', 'DE'], ['德国', 'DE'], ['德國', 'DE'], ['Sweden', 'SE'], ['瑞典', 'SE'],
|
||||
['Bulgaria', 'BG'], ['保加利亚', 'BG'], ['保加利亞', 'BG'],
|
||||
['Austria', 'AT'], ['奥地利', 'AT'], ['奧地利', 'AT'],
|
||||
['Ireland', 'IE'], ['爱尔兰', 'IE'], ['愛爾蘭', 'IE'],
|
||||
['Turkey', 'TR'], ['Türkiye', 'TR'], ['土耳其', 'TR'],
|
||||
['Hungary', 'HU'], ['匈牙利', 'HU'], ['Canada', 'CA'], ['加拿大', 'CA'],
|
||||
['Italy', 'IT'], ['意大利', 'IT'], ['義大利', 'IT'], ['Spain', 'ES'], ['西班牙', 'ES'],
|
||||
['New Zealand', 'NZ'], ['新西兰', 'NZ'], ['新西蘭', 'NZ'],
|
||||
['Thailand', 'TH'], ['泰国', 'TH'], ['泰國', 'TH'], ['Vietnam', 'VN'], ['越南', 'VN'],
|
||||
['Pakistan', 'PK'], ['巴基斯坦', 'PK'], ['Israel', 'IL'], ['以色列', 'IL'],
|
||||
['Philippines', 'PH'], ['菲律宾', 'PH'], ['菲律賓', 'PH'],
|
||||
['Malaysia', 'MY'], ['马来西亚', 'MY'], ['馬來西亞', 'MY'],
|
||||
['Egypt', 'EG'], ['埃及', 'EG'], ['Nigeria', 'NG'], ['尼日利亚', 'NG'], ['尼日利亞', 'NG'],
|
||||
['Moldova', 'MD'], ['摩尔多瓦', 'MD'], ['摩爾多瓦', 'MD'],
|
||||
['Ukraine', 'UA'], ['乌克兰', 'UA'], ['烏克蘭', 'UA'],
|
||||
['Brazil', 'BR'], ['巴西', 'BR'], ['Chile', 'CL'], ['智利', 'CL'],
|
||||
['Argentina', 'AR'], ['阿根廷', 'AR'], ['India', 'IN'], ['印度', 'IN'],
|
||||
['Indonesia', 'ID'], ['印度尼西亚', 'ID'], ['印度尼西亞', 'ID'], ['印尼', 'ID'],
|
||||
['Mexico', 'MX'], ['墨西哥', 'MX'],
|
||||
['North Macedonia', 'MK'], ['Macedonia', 'MK'], ['北马其顿', 'MK'], ['北馬其頓', 'MK'], ['马其顿', 'MK'], ['馬其頓', 'MK'],
|
||||
['Lithuania', 'LT'], ['立陶宛', 'LT'], ['Saudi Arabia', 'SA'], ['沙特阿拉伯', 'SA'], ['沙特', 'SA'],
|
||||
['Czechia', 'CZ'], ['Czech', 'CZ'], ['捷克', 'CZ'], ['South Africa', 'ZA'], ['南非', 'ZA'],
|
||||
['Denmark', 'DK'], ['丹麦', 'DK'], ['丹麥', 'DK'], ['Togo', 'TG'], ['多哥', 'TG'],
|
||||
['Norway', 'NO'], ['挪威', 'NO'], ['Morocco', 'MA'], ['摩洛哥', 'MA'], ['卡萨布兰卡', 'MA'], ['卡薩布蘭卡', 'MA'],
|
||||
['Azerbaijan', 'AZ'], ['阿塞拜疆', 'AZ'], ['Romania', 'RO'], ['罗马尼亚', 'RO'], ['羅馬尼亞', 'RO'],
|
||||
['Colombia', 'CO'], ['哥伦比亚', 'CO'], ['哥倫比亞', 'CO'],
|
||||
['Kazakhstan', 'KZ'], ['哈萨克斯坦', 'KZ'], ['哈薩克斯坦', 'KZ'],
|
||||
['Kyrgyzstan', 'KG'], ['吉尔吉斯斯坦', 'KG'], ['吉爾吉斯斯坦', 'KG'],
|
||||
['Nepal', 'NP'], ['尼泊尔', 'NP'], ['尼泊爾', 'NP'],
|
||||
['Bangladesh', 'BD'], ['孟加拉国', 'BD'], ['孟加拉國', 'BD'],
|
||||
['Myanmar', 'MM'], ['Burma', 'MM'], ['缅甸', 'MM'], ['緬甸', 'MM'],
|
||||
['Cambodia', 'KH'], ['柬埔寨', 'KH']
|
||||
];
|
||||
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
@@ -36,79 +106,31 @@ async function loadRenameUtils() {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const ISO_REGION_CODES = `
|
||||
AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ
|
||||
CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO
|
||||
FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE
|
||||
JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO
|
||||
MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW
|
||||
PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM
|
||||
TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW
|
||||
`.trim().split(/\s+/);
|
||||
const normalizeRegionCode = regionCode => regionCode === 'GB' ? 'UK' : regionCode;
|
||||
|
||||
const EXTRA_REGION_ALIASES = [
|
||||
['EU', 'EU'], ['Europe', 'EU'], ['European Union', 'EU'], ['欧洲', 'EU'], ['歐洲', 'EU'],
|
||||
['XK', 'XK'], ['Kosovo', 'XK'], ['科索沃', 'XK'],
|
||||
['UK', 'UK'], ['United Kingdom', 'UK'], ['Britain', 'UK'], ['Great Britain', 'UK'], ['England', 'UK'], ['英国', 'UK'], ['英國', 'UK'],
|
||||
['USA', 'US'], ['U.S.A.', 'US'], ['United States', 'US'], ['United States of America', 'US'], ['America', 'US'], ['美国', 'US'], ['美國', 'US'], ['美西', 'US'], ['美东', 'US'], ['美東', 'US'],
|
||||
['UAE', 'AE'], ['United Arab Emirates', 'AE'], ['阿联酋', 'AE'], ['阿聯酋', 'AE'],
|
||||
['Russia', 'RU'], ['Russian Federation', 'RU'], ['俄罗斯', 'RU'], ['俄羅斯', 'RU'],
|
||||
['South Korea', 'KR'], ['Korea', 'KR'], ['Republic of Korea', 'KR'], ['韩国', 'KR'], ['韓國', 'KR'], ['南韩', 'KR'], ['南韓', 'KR'],
|
||||
['North Korea', 'KP'], ['DPRK', 'KP'], ['朝鲜', 'KP'], ['北韩', 'KP'], ['北韓', 'KP'],
|
||||
['Hong Kong', 'HK'], ['香港', 'HK'],
|
||||
['Macau', 'MO'], ['Macao', 'MO'], ['澳门', 'MO'], ['澳門', 'MO'],
|
||||
['Taiwan', 'TW'], ['台湾', 'TW'], ['台灣', 'TW'], ['臺灣', 'TW'],
|
||||
['Singapore', 'SG'], ['新加坡', 'SG'], ['狮城', 'SG'], ['獅城', 'SG'],
|
||||
['Japan', 'JP'], ['日本', 'JP'],
|
||||
['China', 'CN'], ['中国', 'CN'], ['中國', 'CN'],
|
||||
['Australia', 'AU'], ['澳大利亚', 'AU'], ['澳大利亞', 'AU'], ['澳洲', 'AU'],
|
||||
['Canada', 'CA'], ['加拿大', 'CA'],
|
||||
['Germany', 'DE'], ['德国', 'DE'], ['德國', 'DE'],
|
||||
['France', 'FR'], ['法国', 'FR'], ['法國', 'FR'],
|
||||
['Netherlands', 'NL'], ['Holland', 'NL'], ['荷兰', 'NL'], ['荷蘭', 'NL'],
|
||||
['Switzerland', 'CH'], ['瑞士', 'CH'],
|
||||
['Sweden', 'SE'], ['瑞典', 'SE'],
|
||||
['Norway', 'NO'], ['挪威', 'NO'],
|
||||
['Finland', 'FI'], ['芬兰', 'FI'], ['芬蘭', 'FI'],
|
||||
['Denmark', 'DK'], ['丹麦', 'DK'], ['丹麥', 'DK'],
|
||||
['Ireland', 'IE'], ['爱尔兰', 'IE'], ['愛爾蘭', 'IE'],
|
||||
['Italy', 'IT'], ['意大利', 'IT'], ['義大利', 'IT'],
|
||||
['Spain', 'ES'], ['西班牙', 'ES'],
|
||||
['Portugal', 'PT'], ['葡萄牙', 'PT'],
|
||||
['Poland', 'PL'], ['波兰', 'PL'], ['波蘭', 'PL'],
|
||||
['Ukraine', 'UA'], ['乌克兰', 'UA'], ['烏克蘭', 'UA'],
|
||||
['Turkey', 'TR'], ['Türkiye', 'TR'], ['土耳其', 'TR'],
|
||||
['India', 'IN'], ['印度', 'IN'],
|
||||
['Indonesia', 'ID'], ['印度尼西亚', 'ID'], ['印尼', 'ID'],
|
||||
['Malaysia', 'MY'], ['马来西亚', 'MY'], ['馬來西亞', 'MY'],
|
||||
['Thailand', 'TH'], ['泰国', 'TH'], ['泰國', 'TH'],
|
||||
['Vietnam', 'VN'], ['Viet Nam', 'VN'], ['越南', 'VN'],
|
||||
['Philippines', 'PH'], ['菲律宾', 'PH'], ['菲律賓', 'PH'],
|
||||
['Brazil', 'BR'], ['巴西', 'BR'],
|
||||
['Mexico', 'MX'], ['墨西哥', 'MX'],
|
||||
['Argentina', 'AR'], ['阿根廷', 'AR'],
|
||||
['Chile', 'CL'], ['智利', 'CL'],
|
||||
['South Africa', 'ZA'], ['南非', 'ZA'],
|
||||
['Israel', 'IL'], ['以色列', 'IL'],
|
||||
['Saudi Arabia', 'SA'], ['沙特', 'SA'], ['沙特阿拉伯', 'SA']
|
||||
];
|
||||
|
||||
const createFirstCountryResolver = utils => {
|
||||
const createRegionResolver = utils => {
|
||||
const aliases = [];
|
||||
const seenAliases = Object.create(null);
|
||||
const addAlias = (alias, regionCode) => {
|
||||
const cleanAlias = String(alias || '').trim();
|
||||
const cleanRegionCode = String(regionCode || '').trim().toUpperCase();
|
||||
if (!cleanAlias || !cleanRegionCode) return;
|
||||
const cleanRegionCode = normalizeRegionCode(String(regionCode || '').trim().toUpperCase());
|
||||
if (!cleanAlias || !cleanRegionCode || cleanAlias.toUpperCase() === cleanRegionCode) return;
|
||||
|
||||
const seenKey = `${cleanAlias.toLowerCase()}\u0000${cleanRegionCode}`;
|
||||
if (seenAliases[seenKey]) return;
|
||||
seenAliases[seenKey] = true;
|
||||
const key = `${cleanAlias.toLowerCase()}\u0000${cleanRegionCode}`;
|
||||
if (seenAliases[key]) return;
|
||||
seenAliases[key] = true;
|
||||
aliases.push([cleanAlias, cleanRegionCode]);
|
||||
};
|
||||
|
||||
ISO_REGION_CODES.forEach(regionCode => addAlias(regionCode, regionCode));
|
||||
EXTRA_REGION_ALIASES.forEach(([alias, regionCode]) => addAlias(alias, regionCode));
|
||||
REGION_ALIASES.forEach(([alias, regionCode]) => {
|
||||
const cleanAlias = String(alias).trim();
|
||||
const cleanRegionCode = normalizeRegionCode(regionCode);
|
||||
const key = `${cleanAlias.toLowerCase()}\u0000${cleanRegionCode}`;
|
||||
if (!seenAliases[key]) {
|
||||
seenAliases[key] = true;
|
||||
aliases.push([cleanAlias, cleanRegionCode]);
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof Intl !== 'undefined' && typeof Intl.DisplayNames === 'function') {
|
||||
['en', 'zh-CN', 'zh-Hans', 'zh-TW', 'zh-Hant'].forEach(locale => {
|
||||
@@ -116,26 +138,39 @@ const createFirstCountryResolver = utils => {
|
||||
const displayNames = new Intl.DisplayNames([locale], { type: 'region' });
|
||||
ISO_REGION_CODES.forEach(regionCode => addAlias(displayNames.of(regionCode), regionCode));
|
||||
} catch (error) {
|
||||
// 部分 Sub-Store 运行环境没有完整 Intl 数据,静态别名仍可覆盖国家码。
|
||||
// 静态别名和国旗回退仍可完成识别。
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const compiledAliases = aliases.map(([alias, regionCode]) => {
|
||||
const escapedAlias = utils.escapeRegex(alias);
|
||||
const isLatinAlias = /^[A-Za-z][A-Za-z\s.'()-]*$/.test(alias);
|
||||
const usesLatinBoundary = /^[A-Za-z0-9].*[A-Za-z0-9]$/.test(alias);
|
||||
return {
|
||||
alias,
|
||||
aliasLength: alias.length,
|
||||
regionCode,
|
||||
regex: isLatinAlias
|
||||
regex: usesLatinBoundary
|
||||
? new RegExp(`(^|[^A-Za-z])(${escapedAlias})(?=$|[^A-Za-z])`, 'i')
|
||||
: new RegExp(`(${escapedAlias})`, 'i')
|
||||
};
|
||||
});
|
||||
const regionCodeRegex = new RegExp(
|
||||
`(^|[^A-Za-z])(${[...ISO_REGION_CODES, 'UK'].join('|')})(?=$|[^A-Za-z])`,
|
||||
'g'
|
||||
);
|
||||
|
||||
return name => {
|
||||
let firstMatch = null;
|
||||
return (name, leadingFlag) => {
|
||||
const cleanName = String(name || '');
|
||||
let bestMatch = null;
|
||||
const consider = (index, aliasLength, regionCode) => {
|
||||
if (
|
||||
!bestMatch ||
|
||||
index < bestMatch.index ||
|
||||
(index === bestMatch.index && aliasLength > bestMatch.aliasLength)
|
||||
) {
|
||||
bestMatch = { index, aliasLength, regionCode: normalizeRegionCode(regionCode) };
|
||||
}
|
||||
};
|
||||
|
||||
compiledAliases.forEach(item => {
|
||||
const match = cleanName.match(item.regex);
|
||||
@@ -143,93 +178,114 @@ const createFirstCountryResolver = utils => {
|
||||
|
||||
const aliasText = match[2] || match[1] || match[0];
|
||||
const prefixLength = match[2] ? match[0].length - aliasText.length : 0;
|
||||
const index = match.index + prefixLength;
|
||||
if (
|
||||
!firstMatch ||
|
||||
index < firstMatch.index ||
|
||||
(index === firstMatch.index && item.alias.length > firstMatch.aliasLength)
|
||||
) {
|
||||
firstMatch = {
|
||||
index,
|
||||
aliasLength: item.alias.length,
|
||||
regionCode: item.regionCode
|
||||
};
|
||||
}
|
||||
consider(match.index + prefixLength, item.aliasLength, item.regionCode);
|
||||
});
|
||||
|
||||
return firstMatch ? firstMatch.regionCode : '';
|
||||
regionCodeRegex.lastIndex = 0;
|
||||
for (const match of cleanName.matchAll(regionCodeRegex)) {
|
||||
const prefixLength = match[1] ? match[1].length : 0;
|
||||
const matchIndex = match.index + prefixLength;
|
||||
// 国家短码应出现在名称前部,避免把后面的线路商缩写误判为国家。
|
||||
if (matchIndex > 24) continue;
|
||||
consider(matchIndex, match[2].length, match[2]);
|
||||
}
|
||||
|
||||
if (bestMatch) return bestMatch.regionCode;
|
||||
return normalizeRegionCode(utils.flagToRegionCode(leadingFlag));
|
||||
};
|
||||
};
|
||||
|
||||
const multiplierOf = name => {
|
||||
if (/(?:实验性|實驗性|experimental)/i.test(name)) return '0.2x';
|
||||
|
||||
const numberBeforeUnit = String(name).match(/(^|[^\d.])(\d+(?:\.\d+)?)\s*(?:[xX]|倍)(?=$|[^A-Za-z])/i);
|
||||
const numberAfterUnit = String(name).match(/(^|[^A-Za-z])[xX]\s*(\d+(?:\.\d+)?)(?=$|[^\d.])/i);
|
||||
const rawMultiplier = numberAfterUnit ? numberAfterUnit[2] : numberBeforeUnit ? numberBeforeUnit[2] : '';
|
||||
if (!rawMultiplier) return '';
|
||||
|
||||
const multiplierValue = Number(rawMultiplier);
|
||||
return Number.isFinite(multiplierValue) ? `${multiplierValue}x` : '';
|
||||
};
|
||||
|
||||
const splitAirportSuffix = (name, declaredAirport, utils) => {
|
||||
const cleanName = utils.normalizeLeadingMojibakeFlag(String(name || '')).trim();
|
||||
const cleanAirport = String(declaredAirport || '').trim();
|
||||
if (cleanAirport) {
|
||||
const suffixRegex = new RegExp(`\\s*-\\s*${utils.escapeRegex(cleanAirport)}\\s*$`, 'i');
|
||||
return {
|
||||
airport: cleanAirport,
|
||||
coreName: cleanName.replace(suffixRegex, '').trim()
|
||||
};
|
||||
}
|
||||
|
||||
const separatorIndex = cleanName.lastIndexOf(' - ');
|
||||
if (separatorIndex === -1) return { airport: '', coreName: cleanName };
|
||||
return {
|
||||
airport: cleanName.slice(separatorIndex + 3).trim(),
|
||||
coreName: cleanName.slice(0, separatorIndex).trim()
|
||||
};
|
||||
};
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const stripSubscriptionSuffix = utils.stripSubscriptionSuffix || ((name, subName) => {
|
||||
const cleanSubName = String(subName || '').trim();
|
||||
if (!cleanSubName) return String(name);
|
||||
const regionCodeOf = createRegionResolver(utils);
|
||||
const regionOrder = Object.create(null);
|
||||
const normalizedItems = [];
|
||||
const passthroughItems = [];
|
||||
let nextRegionOrder = 0;
|
||||
|
||||
const escapeRegex = utils.escapeRegex || (value => String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
||||
return String(name)
|
||||
.replace(new RegExp(`\\s+-\\s*${escapeRegex(cleanSubName)}(?:\\s+\\d{2})?\\s*$`, 'i'), '')
|
||||
.trim();
|
||||
});
|
||||
const firstCountryCodeOf = createFirstCountryResolver(utils);
|
||||
const withFirstCountryFlag = name => {
|
||||
const cleanName = utils.normalizeLeadingMojibakeFlag
|
||||
? utils.normalizeLeadingMojibakeFlag(name)
|
||||
: String(name);
|
||||
const splitName = utils.splitLeadingFlag
|
||||
? utils.splitLeadingFlag(cleanName)
|
||||
: { flag: '', text: cleanName.replace(/^([\u{1F1E6}-\u{1F1FF}]{2})\s*/u, '').trim() };
|
||||
const regionCode = firstCountryCodeOf(splitName.text || cleanName);
|
||||
if (!regionCode) return name;
|
||||
|
||||
const displayRegionCode = REGION_FLAG_DISPLAY_OVERRIDES[regionCode] || regionCode;
|
||||
const flag = utils.regionCodeToFlag(displayRegionCode);
|
||||
return flag ? `${flag} ${splitName.text}`.trim() : name;
|
||||
};
|
||||
const nameCounts = Object.create(null);
|
||||
const currentCounts = Object.create(null);
|
||||
const baseNames = new Array(proxies.length);
|
||||
const coreNames = new Array(proxies.length);
|
||||
const subNames = new Array(proxies.length);
|
||||
|
||||
proxies.forEach((proxy, proxyIndex) => {
|
||||
// 非对象或非字符串名称不参与处理,避免改动无效节点数据。
|
||||
proxies.forEach((proxy, originalIndex) => {
|
||||
if (!proxy || typeof proxy !== 'object' || typeof proxy.name !== 'string') {
|
||||
baseNames[proxyIndex] = null;
|
||||
passthroughItems.push({ originalIndex, proxy });
|
||||
return;
|
||||
}
|
||||
|
||||
const proxyName = proxy.name;
|
||||
const subName = proxy && typeof proxy._subName === 'string'
|
||||
? proxy._subName.trim()
|
||||
: '';
|
||||
// 只在原后缀逻辑前补齐/修正首国旗,后缀与去重逻辑保持不变。
|
||||
const coreName = withFirstCountryFlag(subName ? stripSubscriptionSuffix(proxyName, subName) : proxyName);
|
||||
const baseName = subName
|
||||
? (coreName ? `${coreName} - ${subName}` : subName)
|
||||
: coreName;
|
||||
const declaredAirport = typeof proxy._subName === 'string' ? proxy._subName : '';
|
||||
const { airport, coreName } = splitAirportSuffix(proxy.name, declaredAirport, utils);
|
||||
const { flag: leadingFlag, text } = utils.splitLeadingFlag(coreName);
|
||||
|
||||
baseNames[proxyIndex] = baseName;
|
||||
coreNames[proxyIndex] = coreName;
|
||||
subNames[proxyIndex] = subName;
|
||||
nameCounts[baseName] = (nameCounts[baseName] || 0) + 1;
|
||||
});
|
||||
|
||||
return proxies.map((proxy, proxyIndex) => {
|
||||
const baseName = baseNames[proxyIndex];
|
||||
if (baseName === null || !proxy || typeof proxy !== 'object') return proxy;
|
||||
|
||||
if (nameCounts[baseName] > 1) {
|
||||
currentCounts[baseName] = (currentCounts[baseName] || 0) + 1;
|
||||
const duplicateNumber = String(currentCounts[baseName]).padStart(2, '0');
|
||||
proxy.name = subNames[proxyIndex]
|
||||
? `${coreNames[proxyIndex]} ${duplicateNumber} - ${subNames[proxyIndex]}`
|
||||
: `${baseName} ${duplicateNumber}`;
|
||||
} else {
|
||||
proxy.name = baseName;
|
||||
if (/\bEmby\b/i.test(text)) {
|
||||
const regionCode = 'EMBY';
|
||||
if (regionOrder[regionCode] === undefined) regionOrder[regionCode] = nextRegionOrder++;
|
||||
normalizedItems.push({ airport, coreName, originalIndex, proxy, regionCode });
|
||||
return;
|
||||
}
|
||||
|
||||
return proxy;
|
||||
const regionCode = regionCodeOf(text, leadingFlag);
|
||||
if (!regionCode) {
|
||||
passthroughItems.push({ originalIndex, proxy });
|
||||
return;
|
||||
}
|
||||
|
||||
if (regionOrder[regionCode] === undefined) regionOrder[regionCode] = nextRegionOrder++;
|
||||
normalizedItems.push({ airport, coreName, originalIndex, proxy, regionCode });
|
||||
});
|
||||
|
||||
normalizedItems.sort((firstItem, secondItem) => (
|
||||
regionOrder[firstItem.regionCode] - regionOrder[secondItem.regionCode] ||
|
||||
firstItem.originalIndex - secondItem.originalIndex
|
||||
));
|
||||
|
||||
const sequenceCounts = Object.create(null);
|
||||
normalizedItems.forEach(item => {
|
||||
sequenceCounts[item.regionCode] = (sequenceCounts[item.regionCode] || 0) + 1;
|
||||
const sequence = String(sequenceCounts[item.regionCode]).padStart(2, '0');
|
||||
const multiplier = multiplierOf(item.coreName);
|
||||
const regionLabel = item.regionCode === 'EMBY' ? 'EMBY' : item.regionCode;
|
||||
const flag = item.regionCode === 'EMBY'
|
||||
? '🏴☠️'
|
||||
: utils.regionCodeToFlag(REGION_FLAG_DISPLAY_OVERRIDES[item.regionCode] || item.regionCode);
|
||||
|
||||
item.proxy.name = [
|
||||
[flag, regionLabel, sequence].filter(Boolean).join(' '),
|
||||
multiplier ? `[${multiplier}]` : '',
|
||||
item.airport ? `- ${item.airport}` : ''
|
||||
].filter(Boolean).join(' ');
|
||||
});
|
||||
|
||||
passthroughItems.sort((firstItem, secondItem) => firstItem.originalIndex - secondItem.originalIndex);
|
||||
return [
|
||||
...normalizedItems.map(item => item.proxy),
|
||||
...passthroughItems.map(item => item.proxy)
|
||||
];
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/**
|
||||
* Sub-Store 节点名称属性注入脚本 (全自动配置驱动版)
|
||||
* 核心架构:动态按长度排序编译正则 + 智能边界识别 + O(1) 映射提取
|
||||
* 维护说明:仅需修改 featureMap 字典即可,底部逻辑永远无需改动。
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
|
||||
// ================= 唯一配置区 =================
|
||||
// 在这里新增或修改关键词。格式:"节点关键词": "想要注入的标签"
|
||||
// 支持大小写混合,支持包含空格或特殊符号。
|
||||
// 日后如果要加 IEPL,只需在这里写 "IEPL": "专线"
|
||||
const featureMap = {
|
||||
"GTM 0.5x": "三网",
|
||||
"GTM": "三网",
|
||||
"CT": "CFW",
|
||||
"S1": "广移",
|
||||
"S2": "广电",
|
||||
"S3": "广移",
|
||||
"S4": "广联",
|
||||
"BGP": "cn2",
|
||||
"D": "直连",
|
||||
"Anytls": "直连",
|
||||
"Hy2": "直连"
|
||||
};
|
||||
|
||||
// 已经由标签表达含义的特征码,会自动从展示名中移除。
|
||||
// 维护方式:只改 featureMap 即可,这里不需要单独配置隐藏词。
|
||||
// 示例:🇭🇰 HK06-GTM Oilguy专线 [三网] - SNTP
|
||||
// 输出:🇭🇰 HK 06 O专线 [三网]-SNTP
|
||||
// ==============================================
|
||||
|
||||
|
||||
// ================= 核心逻辑区 (无需修改) =================
|
||||
|
||||
// 1. 初始化预处理:生成稳定的查找字典 (全大写+去空格)
|
||||
// 目的:无论节点名叫 "gtm 0.5x" 还是 "GTM0.5X",都能稳定映射
|
||||
const normalizedFeatureMap = {};
|
||||
const featureKeywords = Object.keys(featureMap);
|
||||
const normalizeFeatureKeyword = keyword => keyword.toUpperCase().replace(/\s+/g, '');
|
||||
const normalizeHiddenFeatureKeyword = keyword => keyword.trim().replace(/\s+\d+(?:\.\d+)?x$/i, '');
|
||||
for (const featureKeyword of featureKeywords) {
|
||||
normalizedFeatureMap[normalizeFeatureKeyword(featureKeyword)] = featureMap[featureKeyword];
|
||||
}
|
||||
|
||||
const buildKeywordPattern = keyword => {
|
||||
const keywordPattern = keyword.trim().split(/\s+/).filter(Boolean).map(utils.escapeRegex).join('\\s*');
|
||||
const trimmedKeyword = keyword.trim();
|
||||
if (/^[A-Za-z0-9]/.test(trimmedKeyword) && /[A-Za-z0-9]$/.test(trimmedKeyword)) {
|
||||
return `\\b${keywordPattern}\\b`;
|
||||
}
|
||||
return keywordPattern;
|
||||
};
|
||||
|
||||
const hiddenFeatureKeywords = [...new Set(featureKeywords.map(normalizeHiddenFeatureKeyword))];
|
||||
const hiddenFeatureRegexList = [...hiddenFeatureKeywords]
|
||||
.sort((firstKeyword, secondKeyword) => secondKeyword.length - firstKeyword.length)
|
||||
.map(hiddenFeatureKeyword => new RegExp(`(^|[\\s-]+)${buildKeywordPattern(hiddenFeatureKeyword)}(?=$|[\\s-]+)`, 'ig'));
|
||||
|
||||
const stripHiddenFeatureKeywords = proxyName => hiddenFeatureRegexList
|
||||
.reduce((strippedName, hiddenFeatureRegex) => strippedName.replace(hiddenFeatureRegex, ''), proxyName)
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.replace(/\s+-/g, '-')
|
||||
.replace(/-\s+/g, ' ')
|
||||
.replace(/^-+|-+$/g, '')
|
||||
.trim();
|
||||
|
||||
const abbreviateDedicatedLineProvider = proxyName => proxyName.replace(
|
||||
/\b([A-Za-z])[A-Za-z]*\s*专线/g,
|
||||
(match, providerInitial) => `${providerInitial.toUpperCase()}专线`
|
||||
);
|
||||
|
||||
const normalizeDisplayName = proxyName => abbreviateDedicatedLineProvider(
|
||||
utils.normalizeRegionSequence(proxyName.replace(/\b(\d+(?:\.\d+)?)x\b/gi, '$1X'))
|
||||
.replace(/\b(\d+(?:\.\d+)?)X\b/g, '$1x')
|
||||
);
|
||||
|
||||
// 2. 动态构建复合正则表达式 (核心引擎)
|
||||
// 按字符串长度降序排序,彻底解决 "短路匹配" (Short-Circuit) 问题
|
||||
const sortedFeatureKeywords = [...featureKeywords].sort(
|
||||
(firstFeatureKeyword, secondFeatureKeyword) => secondFeatureKeyword.length - firstFeatureKeyword.length
|
||||
);
|
||||
|
||||
const featureRegexParts = sortedFeatureKeywords.map(featureKeyword => {
|
||||
// 自动转义正则特殊字符 (防注入报错)
|
||||
return buildKeywordPattern(featureKeyword);
|
||||
});
|
||||
|
||||
// 动态拼接出类似: /(GTM\s*0\.5x|\bAnytls\b|\bBGP\b|...)/i
|
||||
const featureRegex = new RegExp(`(${featureRegexParts.join('|')})`, 'i');
|
||||
|
||||
// 缓存后缀匹配正则,避免循环内重复创建
|
||||
const suffixRegex = /\s*-\s*(SNTP.*)$/i;
|
||||
const normalizeSntpSuffixSpacing = proxyName => proxyName.replace(suffixRegex, '-$1');
|
||||
const normalizeCloudflareLabel = proxyName => proxyName
|
||||
.replace(/\s*\[(?:CF|Cloudflare)]\s*/gi, ' [CFW] ')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.trim();
|
||||
|
||||
// 3. 执行节点遍历与注入
|
||||
return proxies.map(proxy => {
|
||||
if (typeof proxy.name !== 'string') return proxy;
|
||||
let proxyName = normalizeCloudflareLabel(normalizeSntpSuffixSpacing(proxy.name));
|
||||
|
||||
// 单次复合正则扫描提取
|
||||
const featureMatch = proxyName.match(featureRegex);
|
||||
if (!featureMatch) {
|
||||
proxy.name = normalizeDisplayName(proxyName);
|
||||
return proxy; // 未命中配置库,仅保留缩写结果后放行
|
||||
}
|
||||
|
||||
// 清洗提取到的特征词,并去 O(1) 字典中取值
|
||||
const normalizedMatchedKeyword = normalizeFeatureKeyword(featureMatch[1]);
|
||||
const injectedFeatureLabel = normalizedFeatureMap[normalizedMatchedKeyword];
|
||||
|
||||
if (!injectedFeatureLabel) return proxy; // 兜底安全校验
|
||||
|
||||
proxyName = normalizeDisplayName(stripHiddenFeatureKeywords(proxyName));
|
||||
|
||||
// 格式化组装与幂等校验 (防重复注入 Bug)
|
||||
const formattedFeatureLabel = ` [${injectedFeatureLabel}]`;
|
||||
if (proxyName.includes(formattedFeatureLabel)) {
|
||||
proxy.name = proxyName;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
// 实施中缀注入 (Infix Injection)
|
||||
if (suffixRegex.test(proxyName)) {
|
||||
proxy.name = proxyName.replace(suffixRegex, `${formattedFeatureLabel}-$1`);
|
||||
} else {
|
||||
// 纯净节点无后缀时,直接挂载在末尾
|
||||
proxy.name = proxyName + formattedFeatureLabel;
|
||||
}
|
||||
|
||||
return proxy;
|
||||
});
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/**
|
||||
* YinYun 专用节点清理脚本
|
||||
* - 将中文地区名压成国家短码并补齐国旗
|
||||
* - 忽略 YinYun 原始的 优选、数字编号和 (T)/(R) 线路标记
|
||||
* - 按地区出现顺序连续编号,方便全局 rename.js 再追加订阅后缀
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const regionAliases = [
|
||||
['哈萨克斯坦', 'KZ'],
|
||||
['印度尼西亚', 'ID'],
|
||||
['孟加拉国', 'BD'],
|
||||
['澳大利亚', 'AU'],
|
||||
['保加利亚', 'BG'],
|
||||
['格鲁吉亚', 'GE'],
|
||||
['立陶宛', 'LT'],
|
||||
['俄罗斯', 'RU'],
|
||||
['新加坡', 'SG'],
|
||||
['马来西亚', 'MY'],
|
||||
['罗马尼亚', 'RO'],
|
||||
['亚美尼亚', 'AM'],
|
||||
['葡萄牙', 'PT'],
|
||||
['拉脱维亚', 'LV'],
|
||||
['加拿大', 'CA'],
|
||||
['澳洲', 'AU'],
|
||||
['捷克', 'CZ'],
|
||||
['南非', 'ZA'],
|
||||
['芬兰', 'FI'],
|
||||
['瑞士', 'CH'],
|
||||
['墨西哥', 'MX'],
|
||||
['瑞典', 'SE'],
|
||||
['比利时', 'BE'],
|
||||
['阿联酋', 'AE'],
|
||||
['法国', 'FR'],
|
||||
['波兰', 'PL'],
|
||||
['荷兰', 'NL'],
|
||||
['奥地利', 'AT'],
|
||||
['巴西', 'BR'],
|
||||
['土耳其', 'TR'],
|
||||
['以色列', 'IL'],
|
||||
['意大利', 'IT'],
|
||||
['西班牙', 'ES'],
|
||||
['乌克兰', 'UA'],
|
||||
['德国', 'DE'],
|
||||
['英国', 'UK'],
|
||||
['印度', 'IN'],
|
||||
['泰国', 'TH'],
|
||||
['香港', 'HK'],
|
||||
['美国', 'US'],
|
||||
['日本', 'JP'],
|
||||
['韩国', 'KR'],
|
||||
['台湾', 'TW']
|
||||
];
|
||||
const regionResolver = utils.createRegionResolver(regionAliases);
|
||||
|
||||
const stripBackupLabel = name => String(name)
|
||||
.replace(/\s*(?:ᴮᴬᴷ|BAK|BACKUP)\s*$/iu, '')
|
||||
.trim();
|
||||
|
||||
const stripLineType = name => String(name)
|
||||
.replace(/\s*[((]\s*[TR]\s*[))]\s*$/i, '')
|
||||
.trim();
|
||||
|
||||
const regionPrefixOf = name => {
|
||||
if (/魔法节点/i.test(name)) return 'MAGIC';
|
||||
return regionResolver.aliasRegionPrefixOf(name) || utils.leadingRegionPrefixOf(name);
|
||||
};
|
||||
|
||||
const nextSequence = utils.createSequenceCounter();
|
||||
|
||||
return proxies.map(proxy => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
const cleanName = utils.stripSubscriptionSuffix(proxy.name, 'YinYun');
|
||||
const { text } = utils.splitLeadingOrInlineFlag(cleanName);
|
||||
const coreName = stripLineType(stripBackupLabel(text));
|
||||
const regionPrefix = regionPrefixOf(coreName);
|
||||
if (!regionPrefix) {
|
||||
proxy.name = coreName;
|
||||
return proxy;
|
||||
}
|
||||
|
||||
const regionCode = regionPrefix.split(/\s+/)[0];
|
||||
const flag = regionPrefix === 'MAGIC' ? '' : utils.regionCodeToFlag(regionCode);
|
||||
proxy.name = [
|
||||
flag,
|
||||
regionPrefix,
|
||||
nextSequence(regionPrefix)
|
||||
].filter(Boolean).join(' ').trim();
|
||||
|
||||
return proxy;
|
||||
});
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/**
|
||||
* YueTong 专用节点清理脚本
|
||||
* 负责去掉“悦·”品牌前缀、钻石、专属/家宽等线路标识,以及压短 AI 解锁文案。
|
||||
* 按地区稳定归并后重新连续编号,避免专属/普通节点撞号。
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260702-1';
|
||||
const COMMON_SCRIPT_URL = `https://git.orionc.me/orion/script/raw/branch/main/substore/common.js?v=${COMMON_SCRIPT_VERSION}`;
|
||||
const hasCurrentRenameUtils = utils => Boolean(
|
||||
utils && utils.version === COMMON_SCRIPT_VERSION
|
||||
);
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
const cache = typeof scriptResourceCache !== 'undefined' ? scriptResourceCache : null;
|
||||
let script = cache && cache.get(COMMON_SCRIPT_URL);
|
||||
if (!script) {
|
||||
const response = await $substore.http.get({ url: COMMON_SCRIPT_URL });
|
||||
script = response && (response.body || response.data || response);
|
||||
if (cache) cache.set(COMMON_SCRIPT_URL, script);
|
||||
}
|
||||
|
||||
new Function(String(script))();
|
||||
if (!hasCurrentRenameUtils(globalThis.SubStoreRenameUtils)) {
|
||||
throw new Error('Loaded common.js is missing current rename utilities');
|
||||
}
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
const regionAliases = [
|
||||
['Hong Kong', 'HK'],
|
||||
['香港', 'HK'],
|
||||
['HK', 'HK'],
|
||||
['Japan', 'JP'],
|
||||
['日本', 'JP'],
|
||||
['JP', 'JP'],
|
||||
['Singapore', 'SG'],
|
||||
['新加坡', 'SG'],
|
||||
['狮城', 'SG'],
|
||||
['SG', 'SG'],
|
||||
['Taiwan', 'TW'],
|
||||
['台湾', 'TW'],
|
||||
['台灣', 'TW'],
|
||||
['TW', 'TW'],
|
||||
['United States', 'US'],
|
||||
['America', 'US'],
|
||||
['USA', 'US'],
|
||||
['美国', 'US'],
|
||||
['美國', 'US'],
|
||||
['美西', 'US'],
|
||||
['美东', 'US'],
|
||||
['美東', 'US'],
|
||||
['US', 'US'],
|
||||
['Korea', 'KR'],
|
||||
['韩国', 'KR'],
|
||||
['韓國', 'KR'],
|
||||
['KR', 'KR'],
|
||||
['United Kingdom', 'UK'],
|
||||
['Britain', 'UK'],
|
||||
['英国', 'UK'],
|
||||
['英國', 'UK'],
|
||||
['UK', 'UK'],
|
||||
['Germany', 'DE'],
|
||||
['德国', 'DE'],
|
||||
['德國', 'DE'],
|
||||
['DE', 'DE'],
|
||||
['Netherlands', 'NL'],
|
||||
['荷兰', 'NL'],
|
||||
['荷蘭', 'NL'],
|
||||
['NL', 'NL']
|
||||
];
|
||||
const { regionCodeOf } = utils.createRegionResolver(regionAliases);
|
||||
|
||||
const withFreshRegionSequence = (name, sequenceNumber) => {
|
||||
const { flag, text } = utils.splitLeadingFlag(name);
|
||||
const sequenceText = String(sequenceNumber);
|
||||
let core = text.trim();
|
||||
let feature = '';
|
||||
|
||||
core = core.replace(/\s*AI\s*\d+(?!\d)(?!\s*(?:[xX倍]|\.\d))/, () => {
|
||||
feature = 'AI';
|
||||
return '';
|
||||
});
|
||||
if (!feature) {
|
||||
core = core.replace(/\s+AI\b|AI$/, () => {
|
||||
feature = 'AI';
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
core = core
|
||||
.replace(/\s*\d+(?!\d)(?!\s*(?:[xX倍]|\.\d))(?=\s|$)/, '')
|
||||
.replace(/\s{2,}/g, ' ');
|
||||
|
||||
return utils.normalizeWhitespace(`${flag}${core}${sequenceText}${feature ? ` ${feature}` : ''}`);
|
||||
};
|
||||
|
||||
const normalizedItems = proxies.map((proxy, originalIndex) => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
regionCode: ''
|
||||
};
|
||||
}
|
||||
|
||||
proxy.name = proxy.name
|
||||
.replace(/悦[·・]\s*/g, '')
|
||||
.replace(/AI解锁/g, 'AI')
|
||||
.replace(/\s*(?:专属|家宽|高速|专线)(?:\s*(\d+)(?!\s*(?:[xX倍]|\.\d)))?/g, '$1')
|
||||
.replace(/💎/gu, '')
|
||||
.replace(/([\u4e00-\u9fff])AI\b/g, '$1 AI')
|
||||
.replace(/\s{2,}/g, ' ');
|
||||
proxy.name = utils.normalizeWhitespace(proxy.name);
|
||||
|
||||
return {
|
||||
proxy,
|
||||
originalIndex,
|
||||
regionCode: regionCodeOf(proxy.name)
|
||||
};
|
||||
});
|
||||
|
||||
const regionOrder = Object.create(null);
|
||||
const groupOrder = normalizedItems.map(item => {
|
||||
if (!item.regionCode) return item.originalIndex;
|
||||
if (regionOrder[item.regionCode] === undefined) {
|
||||
regionOrder[item.regionCode] = item.originalIndex;
|
||||
}
|
||||
return regionOrder[item.regionCode];
|
||||
});
|
||||
|
||||
normalizedItems.sort((firstItem, secondItem) => {
|
||||
const firstGroupOrder = groupOrder[firstItem.originalIndex];
|
||||
const secondGroupOrder = groupOrder[secondItem.originalIndex];
|
||||
if (firstGroupOrder !== secondGroupOrder) return firstGroupOrder - secondGroupOrder;
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
});
|
||||
|
||||
const nextSequence = utils.createSequenceCounter();
|
||||
return normalizedItems.map(item => {
|
||||
if (!item.regionCode) return item.proxy;
|
||||
|
||||
item.proxy.name = withFreshRegionSequence(item.proxy.name, nextSequence(item.regionCode));
|
||||
return item.proxy;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user