|
|
@@ -1,5 +1,6 @@
|
|
|
/**
|
|
|
* 更新日期:2024-04-05 15:30:15
|
|
|
+ * 修改: 添加协议前缀功能 (H2/VL/VS/TR 等)
|
|
|
* 用法:Sub-Store 脚本操作添加
|
|
|
* rename.js 以下是此脚本支持的参数,必须以 # 为开头多个参数使用"&"连接,参考上述地址为例使用参数。 禁用缓存url#noCache
|
|
|
*
|
|
|
@@ -37,8 +38,46 @@
|
|
|
* [clear] 清理乱名
|
|
|
* [blpx] 如果用了上面的bl参数,对保留标识后的名称分组排序,如果没用上面的bl参数单独使用blpx则不起任何作用
|
|
|
* [blockquic] blockquic=on 阻止; blockquic=off 不阻止
|
|
|
+ *
|
|
|
+ *** 协议前缀 (新增)
|
|
|
+ * [proto] proto=true 开启协议前缀功能 (如 VS, VL, H2 等),默认为 false 不开启
|
|
|
+ * vmess→VS vless→VL trojan→TR ss→SS ssr→SSR
|
|
|
+ * hysteria→HY hysteria2→H2 tuic→TU wireguard→WG
|
|
|
+ * snell→SN http→HTTP https→HTTPS socks5→S5
|
|
|
+ * ssh→SSH anytls→AT
|
|
|
*/
|
|
|
|
|
|
+// ──────────────────────────────────────────────
|
|
|
+// 协议缩写映射 (新增)
|
|
|
+// ──────────────────────────────────────────────
|
|
|
+const PROTOCOL_MAP = {
|
|
|
+ vmess: "VS",
|
|
|
+ vless: "VL",
|
|
|
+ trojan: "TR",
|
|
|
+ ss: "SS",
|
|
|
+ ssr: "SSR",
|
|
|
+ hysteria: "HY",
|
|
|
+ hysteria2: "H2",
|
|
|
+ tuic: "TU",
|
|
|
+ wireguard: "WG",
|
|
|
+ snell: "SN",
|
|
|
+ http: "HTTP",
|
|
|
+ https: "HTTPS",
|
|
|
+ socks5: "S5",
|
|
|
+ ssh: "SSH",
|
|
|
+ anytls: "AT",
|
|
|
+};
|
|
|
+
|
|
|
+function getProtocolLabel(type) {
|
|
|
+ if (!type) return "";
|
|
|
+ const label = PROTOCOL_MAP[String(type).toLowerCase()];
|
|
|
+ return label || String(type).toUpperCase();
|
|
|
+}
|
|
|
+
|
|
|
+// ──────────────────────────────────────────────
|
|
|
+// 原始 Keywos rename.js
|
|
|
+// ──────────────────────────────────────────────
|
|
|
+
|
|
|
// const inArg = {'blkey':'iplc+GPT>GPTnewName+NF+IPLC', 'flag':true };
|
|
|
const inArg = $arguments; // console.log(inArg)
|
|
|
const nx = inArg.nx || false,
|
|
|
@@ -52,7 +91,8 @@ const nx = inArg.nx || false,
|
|
|
debug = inArg.debug || false,
|
|
|
clear = inArg.clear || false,
|
|
|
addflag = inArg.flag || false,
|
|
|
- nm = inArg.nm || false;
|
|
|
+ nm = inArg.nm || false,
|
|
|
+ addproto = inArg.proto || false; // 是否开启协议缩写前缀功能 (如 VS, VL, H2 等,默认为 false 不开启)
|
|
|
|
|
|
const FGF = inArg.fgf == undefined ? " " : decodeURI(inArg.fgf),
|
|
|
XHFGF = inArg.sn == undefined ? " " : decodeURI(inArg.sn),
|
|
|
@@ -171,6 +211,8 @@ function operator(pro) {
|
|
|
|
|
|
pro.forEach((e) => {
|
|
|
let bktf = false, ens = e.name
|
|
|
+ // 获取协议前缀 (新增)
|
|
|
+ const protoLabel = addproto ? getProtocolLabel(e.type) : "";
|
|
|
// 预处理 防止预判或遗漏
|
|
|
Object.keys(rurekey).forEach((ikey) => {
|
|
|
if (rurekey[ikey].test(e.name)) {
|
|
|
@@ -238,7 +280,7 @@ function operator(pro) {
|
|
|
// 正则 匹配倍率
|
|
|
if (bl) {
|
|
|
const match = e.name.match(
|
|
|
- /((倍率|X|x|×)\D?((\d{1,3}\.)?\d+)\D?)|((\d{1,3}\.)?\d+)(倍|X|x|×)/
|
|
|
+ /((倍率|X|x|×)\D?((\d{1,3}\.)?d+)\D?)|((\d{1,3}\.)?d+)(倍|X|x|×)/
|
|
|
);
|
|
|
if (match) {
|
|
|
const rev = match[0].match(/(\d[\d.]*)/)[0];
|
|
|
@@ -274,13 +316,15 @@ function operator(pro) {
|
|
|
usflag = usflag === "🇹🇼" ? "🇨🇳" : usflag;
|
|
|
}
|
|
|
}
|
|
|
+ // 插入协议前缀 protoLabel (新增: 在 nNames/firstName 之后、地区名之前)
|
|
|
keyover = keyover
|
|
|
- .concat(firstName, usflag, nNames, findKeyValue, retainKey, ikey, ikeys)
|
|
|
+ .concat(firstName, usflag, nNames, protoLabel, findKeyValue, retainKey, ikey, ikeys)
|
|
|
.filter((k) => k !== "");
|
|
|
e.name = keyover.join(FGF);
|
|
|
} else {
|
|
|
if (nm) {
|
|
|
- e.name = FNAME + FGF + e.name;
|
|
|
+ // 未匹配节点也加协议前缀 (新增)
|
|
|
+ e.name = [FNAME, protoLabel, e.name].filter(k => k !== "").join(FGF);
|
|
|
} else {
|
|
|
e.name = null;
|
|
|
}
|
|
|
@@ -301,4 +345,4 @@ function jxh(e) { const n = e.reduce((e, n) => { const t = e.find((e) => e.name
|
|
|
// prettier-ignore
|
|
|
function oneP(e) { const t = e.reduce((e, t) => { const n = t.name.replace(/[^A-Za-z0-9\u00C0-\u017F\u4E00-\u9FFF]+\d+$/, ""); if (!e[n]) { e[n] = []; } e[n].push(t); return e; }, {}); for (const e in t) { if (t[e].length === 1 && t[e][0].name.endsWith("01")) {/* const n = t[e][0]; n.name = e;*/ t[e][0].name= t[e][0].name.replace(/[^.]01/, "") } } return e; }
|
|
|
// prettier-ignore
|
|
|
-function fampx(pro) { const wis = []; const wnout = []; for (const proxy of pro) { const fan = specialRegex.some((regex) => regex.test(proxy.name)); if (fan) { wis.push(proxy); } else { wnout.push(proxy); } } const sps = wis.map((proxy) => specialRegex.findIndex((regex) => regex.test(proxy.name)) ); wis.sort( (a, b) => sps[wis.indexOf(a)] - sps[wis.indexOf(b)] || a.name.localeCompare(b.name) ); wnout.sort((a, b) => pro.indexOf(a) - pro.indexOf(b)); return wnout.concat(wis);}
|
|
|
+function fampx(pro) { const wis = []; const wnout = []; for (const proxy of pro) { const fan = specialRegex.some((regex) => regex.test(proxy.name)); if (fan) { wis.push(proxy); } else { wnout.push(proxy); } } const sps = wis.map((proxy) => specialRegex.findIndex((regex) => regex.test(proxy.name)) ); wis.sort( (a, b) => sps[wis.indexOf(a)] - sps[wis.indexOf(b)] || a.name.localeCompare(b.name) ); wnout.sort((a, b) => pro.indexOf(a) - pro.indexOf(b)); return wnout.concat(wis);}
|