refactor(substore): 将通用工具函数迁移至公共库
- 从各个重命名脚本中移除重复的工具函数实现 - 将 multiplierOf、multiplierValueOf、stripSubscriptionSuffix 等函数统一到 common.js - 使用 utils.multiplierOf、utils.multiplierValueOf 替代本地实现 - 引入 utils.createSequenceCounter 替代手动计数逻辑 - 更新版本号从 20260608-1 到 20260702-1 - 移除重复的正则表达式匹配逻辑 - 标准化序列计数器实现方式 - 优化 yinyun-rename.js 中的信息节点过滤逻辑
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* - 不追加订阅后缀,整合订阅最后仍交给 rename.js 处理
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const COMMON_SCRIPT_VERSION = '20260608-1';
|
||||
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
|
||||
@@ -63,15 +63,6 @@ async function operator(proxies) {
|
||||
];
|
||||
const regionResolver = utils.createRegionResolver(regionAliases);
|
||||
|
||||
const stripExistingSuffix = name => name
|
||||
.replace(/\s+-\s*Alpha Air(?:\s+\d{2})?\s*$/i, '')
|
||||
.trim();
|
||||
|
||||
const multiplierOf = name => {
|
||||
const match = name.match(/\b(\d+(?:\.\d+)?)(?:\s*[xX]|倍)\b/i);
|
||||
return match ? `${match[1]}X` : '';
|
||||
};
|
||||
|
||||
const providerOf = name => {
|
||||
if (/SkyStroll/i.test(name)) return 'SkyStroll';
|
||||
if (/isif/i.test(name)) return 'ISIF';
|
||||
@@ -79,12 +70,6 @@ async function operator(proxies) {
|
||||
return '';
|
||||
};
|
||||
|
||||
const leadingRegionPrefixOf = name => {
|
||||
const match = name.match(/^([A-Z]{2})(?:\s+([A-Z]{3}))?(?=\s|$|-|\d|\|)/);
|
||||
if (!match) return '';
|
||||
return match[2] ? `${match[1]} ${match[2]}` : match[1];
|
||||
};
|
||||
|
||||
const alphaAirRegionPrefixOf = name => {
|
||||
if (/\bhk\b/i.test(name)) return 'HK';
|
||||
if (/\bsg\b/i.test(name)) return 'SG';
|
||||
@@ -99,20 +84,20 @@ async function operator(proxies) {
|
||||
if (/Hinet|Seednet/i.test(name)) return 'TW';
|
||||
|
||||
return alphaAirRegionPrefixOf(name) ||
|
||||
leadingRegionPrefixOf(name) ||
|
||||
utils.leadingRegionPrefixOf(name) ||
|
||||
flagRegionCode ||
|
||||
'';
|
||||
};
|
||||
|
||||
const normalizeProxy = (proxy, originalIndex) => {
|
||||
const rawName = typeof proxy.name === 'string' ? proxy.name : '';
|
||||
const cleanName = stripExistingSuffix(rawName);
|
||||
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 = multiplierOf(text);
|
||||
const multiplier = utils.multiplierOf(text);
|
||||
const provider = multiplier ? '' : providerOf(text);
|
||||
const normalizedFlag = utils.regionCodeToFlag(regionCode);
|
||||
|
||||
@@ -126,7 +111,7 @@ async function operator(proxies) {
|
||||
provider,
|
||||
multiplier,
|
||||
providerRank: provider ? 1 : 0,
|
||||
multiplierValue: multiplier ? Number(multiplier.replace(/X$/i, '')) : Number.NEGATIVE_INFINITY,
|
||||
multiplierValue: utils.multiplierValueOf(multiplier),
|
||||
normalizedName: [normalizedFlag, regionPrefix, provider, multiplier].filter(Boolean).join(' ').trim()
|
||||
};
|
||||
};
|
||||
@@ -166,18 +151,17 @@ async function operator(proxies) {
|
||||
return firstItem.originalIndex - secondItem.originalIndex;
|
||||
});
|
||||
|
||||
const currentCount = Object.create(null);
|
||||
const nextSequence = utils.createSequenceCounter();
|
||||
return normalizedItems.map(item => {
|
||||
if (!item.normalizedName || !item.countryCode) return item.proxy;
|
||||
|
||||
currentCount[item.countryCode] = (currentCount[item.countryCode] || 0) + 1;
|
||||
item.proxy.name = [
|
||||
item.normalizedFlag,
|
||||
item.regionPrefix,
|
||||
String(currentCount[item.countryCode]).padStart(2, '0'),
|
||||
nextSequence(item.countryCode),
|
||||
item.provider,
|
||||
item.multiplier
|
||||
].filter(Boolean).join(' ').trim();
|
||||
return item.proxy;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user