♻️ refactor(substore): 提取重构公共工具 common.js 并新增 liangxin 脚本
This commit is contained in:
@@ -3,7 +3,28 @@
|
||||
* 负责清理推荐、用途、hy2、倍率、线路特征和提供商等 PeiQian 节点文案。
|
||||
*/
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
function operator(proxies) {
|
||||
const COMMON_SCRIPT_URL = 'https://git.orionc.me/orion/script/raw/branch/main/substore/common.js';
|
||||
|
||||
async function loadRenameUtils() {
|
||||
if (typeof globalThis !== 'undefined' && 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))();
|
||||
return globalThis.SubStoreRenameUtils;
|
||||
}
|
||||
|
||||
async function operator(proxies) {
|
||||
const utils = await loadRenameUtils();
|
||||
|
||||
return proxies.map(proxy => {
|
||||
if (typeof proxy.name !== 'string') {
|
||||
return proxy;
|
||||
@@ -11,7 +32,6 @@ function operator(proxies) {
|
||||
|
||||
proxy.name = proxy.name
|
||||
.replace(/AWS\s*(?=新加坡)/gi, '')
|
||||
.replace(/^([\u{1F1E6}-\u{1F1FF}]{2}|🏴☠️)\s*/u, '$1 ')
|
||||
.replace(/\s*\|\s*合适下载使用\s*-\s*(\d+(?:\.\d+)?)倍/gi, ' $1x')
|
||||
.replace(/\s*\|\s*合适下载使用/gi, '')
|
||||
.replace(/\s*\|\s*避免晚高峰使用/gi, '')
|
||||
@@ -21,8 +41,8 @@ function operator(proxies) {
|
||||
.replace(/(\d+(?:\.\d+)?)倍/gi, '$1x')
|
||||
.replace(/\s*\[(?:专线|移联|电联|三网|HY2)(?:\s+(?:专线|移联|电联|三网|HY2))*\]/gi, '')
|
||||
.replace(/\s+\[/g, ' [')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
.trim();
|
||||
.replace(/\s{2,}/g, ' ');
|
||||
proxy.name = utils.normalizeLeadingFlagSpacing(proxy.name);
|
||||
|
||||
return proxy;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user