-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource-parser.js
3762 lines (3525 loc) · 182 KB
/
resource-parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
☑️ 资源解析器 ©𝐒𝐡𝐚𝐰𝐧 ⟦2023-08-21 12:40⟧
----------------------------------------------------------
🛠 发现 𝐁𝐔𝐆 请反馈: https://t.me/Shawn_Parser_Bot
⛳️ 关注 🆃🅶 相关频道: https://t.me/QuanX_API
📖 使用 教程: https://tinyurl.com/2jyygfom
🗣 🆃🄷🄰🄽🄺🅂 🆃🄾 @Jamie CHIEN, @M**F**, @c0lada, @Peng-YM, @vinewx, @love4taylor, @shadowdogy
🤖 主要功能:
❶ 将其它格式的⟦服务器订阅⟧解析成 𝐐𝐮𝐚𝐧𝐭𝐮𝐦𝐮𝐥𝐭 𝐗 格式
☑︎ 支持 𝐕2𝐫𝐚𝐲𝐍/𝗦𝗦(𝗥/𝗗)/𝗛𝗧𝗧𝗣(𝗦)/𝗧𝗿𝗼𝗷𝗮𝗻/𝗤𝘂𝗮𝗻𝘁𝘂𝗺𝘂𝗹𝘁(𝗫)/𝗦𝘂𝗿𝗴𝗲/𝐂𝐥𝐚𝐬𝐡/𝐒𝐡𝐚𝐝𝐨𝐰𝐫𝐨𝐜𝐤𝐞𝐭/𝐋𝐨𝐨𝐧 格式
☑︎ 提供说明 1⃣️ 中的可选个性化参数(筛选、重命名 等)
❷ 𝗿𝗲𝘄𝗿𝗶𝘁𝗲(重写) & 𝗳𝗶𝗹𝘁𝗲𝗿(分流) 的 转换 & 筛选
☑︎ 用于禁用/修改远程引用中某(几)项 𝗿𝗲𝘄𝗿𝗶𝘁𝗲/𝗵𝗼𝘀𝘁𝗻𝗮𝗺𝗲/𝗳𝗶𝗹𝘁𝗲𝗿
☑︎ 𝐒𝐮𝐫𝐠𝐞/𝐂𝐥𝐚𝐬𝐡 类型规则 𝗹𝗶𝘀𝘁 与 模块 𝐦𝐨𝐝𝐮𝐥𝐞 的解析使用
----------------------------------------------------------
0️⃣ 在 ⟦订阅链接⟧ 后加 "#" 使用, 不同参数用 "&" 连接
⚠️ ☞ "你的订阅连接#emoji=1&tfo=1&in=香港+台湾"
❖ 本地资源片段引用, 请将参数如 "#in=xxx&out=yyy" 填入资源片段的第 ① 行
❖ 🚦 支持中文, "操作" 以下特殊字符时请先替换(URL-Encode) 🚦
∎ "+"⇒"%2B", 空格⇒"%20", "@"⇒"%40", "&"⇒"%26", "."⇒"\.", ","⇒"%2C"
1️⃣ ⟦𝐬𝐞𝐫𝐯𝐞𝐫 节点⟧ ➠ 参数说明:
⦿ emoji=1(国行设备用2)/-1, 添加/删除节点名内地区旗帜;
⦿ udp=1/-1, tfo=1/-1, 分别强制开启(关闭) 𝐮𝐝𝐩-𝐫𝐞𝐥𝐚𝐲/𝐟𝐚𝐬𝐭-𝐨𝐩𝐞𝐧;
⦿ uot=1, 开启 udp-over-tcp=true选项(仅限SS(R))
⦿ cert=1/-1, 分别开启/关闭 𝐭𝐥𝐬 证书验证(默认关闭);
❖ csha/psha, tls-cert-sha256 以及 tls-pubkey-sha256 参数
❖ alpn, 指定over-tls类型节点的alpn参数
⦿ in, out, regex, regout 分别为 保留、删除、正则保留、正则删除 节点;
❖ in/out 仅对节点名匹配生效, 多参数(逻辑"或")用 "+", 逻辑"与"用 "." 表示;
❖ regex/regout 对节点的完整信息进行匹配(类型、端口、加密等);
❖ 示范: "in=香港.0\.2倍率+台湾&out=BGP®ex=iplc"
⦿ rename 重命名, "旧名@新名", "前缀@", "@后缀", 用 "+" 连接多个参数;
❖ 删除字段: "字段1.字段2☠️", 想删除 "." 时用 "\." 替代
❖ 示范: "rename=香港@𝐇𝐊+[𝐒𝐒]@+@[1𝐗]+流量.0\.2☠️"
❖ 默认 emoji 先生效, 如想调换顺序, 请用 rrname 参数
⦿ replace 正则替换节点中字段, 可用于重命名/更改加密方式等
❖ replace=regex1@𝘀𝘁𝗿1+regex2@𝘀𝘁𝗿2
⦿ ptn/npt=1-8, 将节点名英文/数字替换成样式 ⇒ 🅰/🄰/𝐀/𝗮/𝔸/𝕒/ᵃ/ᴬ, ①\❶\⓵\𝟙\¹\₁\𝟏\𝟷
⦿ delreg, 利用正则表达式来删除 "节点名" 中的字段(⚠️ 慎用)
⦿ aead=-1, 关闭 Vmess 的 AEAD 参数
⦿ host=xxx, 修改已有 host , 如要增加host,请用☠️结尾
⦿ obfs=vhttp/shttp, 指定 obfs=shadowsocks-http 或 obfs=vmess-http 的特殊需求
⦿ tsession=0/1/2, 0/1 代表关闭 tls-session-ticket/reuse,2 表示全部关闭
⦿ checkurl=xxx , 指定 server_check_url 参数
⦿ sort=1/-1/x/参数规则, 按节点名 正/逆/随机/参数规则 排序
❖ 参数规则是正则表达式或简单关键词, 用"<" 或 ">" 连接
❖ sort=🇭🇰>🇸🇬>🇯🇵>🇺🇸 , 靠前排序
❖ sort=IEPL<IPLC<BGP , 靠后排序
⦿ info=1, 开启通知提示机场 ✈️ 流量信息(如有提供);
⦿ flow=2022-06-02:1000:54, 订阅到期时间:总流量:已用流量
⦿ 占位符,可用于 rename/replace 等操作
❖ $type0/1/2/3/4/5/6/7 占位符,将节点类型(ss/ssr/vmess 等)作为可操作参数,如
∎ rename=@|$type2
∎ 样式分别为 "𝐬𝐬","𝐒𝐒","🅢🅢","🆂🆂","ⓢⓢ","🅂🅂","𝕊𝕊","ˢˢ"
❖ $index0/1/2/3/4/5/6/7/8 占位符,将节点的序号作为可操作参数,如
∎ rename=@「$index1」
∎ 样式分别为 1\①\❶\⓵\𝟙\¹\₁\𝟏\𝟷
❖ $emoji1/2 占位符, 将emoji(🇭🇰 等)作为可操作参数
∎ rename=@「$emoji1」
❖ $tag 占位符,将订阅的 tag 作为可操作参数,如
∎ 可接数字以单独给 tag 添加字母/数字样式
∎ rename=@「$tag34」, 样式同下边的 ptn/npt
⦿ ⟦进阶参数⟧: 𝘀𝗳𝗶𝗹𝘁𝗲𝗿/𝘀𝗿𝗲𝗻𝗮𝗺𝗲, 传入一段 base64 编码的脚本, 可用于更为复杂的[过滤/重命名] 需求
❖ 说明: https://github.com/KOP-XIAO/QuantumultX/pull/9
2⃣️ ⟦𝐫𝐞𝐰𝐫𝐢𝐭𝐞 重写⟧/⟦𝐟𝐢𝐥𝐭𝐞𝐫 分流⟧ ➠ 参数说明:
⦿ in, out, 根据关键词 保留/禁用 相关分流、重写规则;
⦿ inhn, outhn, “保留/删除”主机名(𝒉𝒐𝒔𝒕𝒏𝒂𝒎𝒆);
❖ 示范: 禁用 "淘宝比价" 及 "weibo" 的 js 同主机名
𝐡𝐭𝐭𝐩𝐬://𝐦𝐲𝐥𝐢𝐬𝐭#out=tb_price.js+wb_ad.js&outhn=weibo
⦿ regex/regout, 正则保留/删除, 请自行折腾正则表达式;
❖ 可与 in(hn)/out(hn) 一起使用,in(hn)/out(hn) 会优先执行;
❖ 对 𝒉𝒐𝒔𝒕𝒏𝒂𝒎𝒆 & 𝐫𝐞𝐰𝐫𝐢𝐭𝐞/𝐟𝐢𝐥𝐭𝐞𝐫 同时生效(⚠️ 慎用)
⦿ policy 参数, 用于直接指定策略组,或为 𝐒𝐮𝐫𝐠𝐞 类型 𝗿𝘂𝗹𝗲-𝘀𝗲𝘁 生成策略组(默认"𝐒𝐡𝐚𝐰𝐧"策略组);
⦿ pset=regex1@policy1+regex2@policy2, 为同一分流规则中不同关键词(允许正则表达式)指定不同策略组;
⦿ replace 参数, 正则替换 𝐟𝐢𝐥𝐭𝐞𝐫/𝐫𝐞𝐰𝐫𝐢𝐭𝐞 内容, regex@newregex;
❖ 将淘宝比价中脚本替换成 lite 版本(如有此版本的脚本)
∎ replace=(price)(.*)@$1_lite$2
⦿ dst=rewrite/filter,分别为将 𝐦𝐨𝐝𝐮𝐥𝐞&𝗿𝘂𝗹𝗲-𝘀𝗲𝘁 转换成 重写/分流;
❖ ⚠️ 默认将 𝐦𝐨𝐝𝐮𝐥𝐞 转换到重写, 𝗿𝘂𝗹𝗲-𝘀𝗲𝘁 转成分流
❖ ⚠️ 把 𝗿𝘂𝗹𝗲-𝘀𝗲𝘁 中 url-regex 转成重写时, 必须要加 dst=rewrite;
❖ ⚠️ 把 𝐦𝐨𝐝𝐮𝐥𝐞 中的分流规则转换时, 必须要加 dst=filter
⦿ cdn=1, 将 github 脚本的地址转换成免翻墙 fastly.jsdelivr.net/gh
⦿ fcr=1/2/3, 为分流规则添加 force-cellular/multi-interface/multi-interface-balance 参数,强制移动数据/混合数据/负载均衡
⦿ via=接口, 为分流规则添加 via-interface 参数, 0 表示 via-interface=%TUN%
⦿ relay=目标策略名, 批量将节点订阅转换为ip/host规则,用于实现代理链
3⃣️ 其他参数
⦿ 通知参数 ntf=0/1, 用于 关闭/打开 资源解析器的提示通知
❖ 𝗿𝗲𝘄𝗿𝗶𝘁𝗲/𝗳𝗶𝗹𝘁𝗲𝗿 默认“开启”通知提示, 以防规则误删除
❖ 𝘀𝗲𝗿𝘃𝗲𝗿 资源解析则默认”关闭“通知提示
⦿ 类型参数 type=domain-set/rule/module/list/nodes
❖ 当解析器未能正确识别类型时, 可尝试使用此参数强制指定
⦿ 隐藏参数 hide=0, 禁用筛除的分流/重写,默认方式为删除
⦿ profile=111 , URL-Scheme 添加 QuanX 类型配置中远程资源
----------------------------------------------------------
*/
/**
* 使用说明,
0️⃣ 在QuantumultX 配置文件中[general] 部分,加入
resource_parser_url = https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/resource-parser.js
⚠️⚠️如提示"没有自定义解析器",请长按右下角图标后点击左侧刷新按钮,更新资源,后台退出 app,直到出现解析器说明
------------------------------
*/
//beginning 解析器正常使用,調試註釋此部分
let [link0, content0, subinfo] = [$resource.link, $resource.content, $resource.info]
let version = typeof $environment != "undefined" ? Number($environment.version.split("build")[1]): 0 // 版本号
let Perror = 0 //错误类型
const subtag = typeof $resource.tag != "undefined" ? $resource.tag : "";
////// 非 raw 链接的沙雕情形
content0 = content0.indexOf("DOCTYPE html") != -1 && link0.indexOf("github.com") != -1 ? ToRaw(content0) : content0 ;
//ends 正常使用部分,調試註釋此部分
var para = /^(http|https)\:\/\//.test(link0) ? link0 : content0.split("\n")[0];
var para1 = para.slice(para.indexOf("#") + 1).replace(/\$type/g,"node_type_para_prefix").replace(/\$emoji/g,"node_emoji_flag_prefix").replace(/\$tag/g,"node_tag_prefix").replace(/\$index/g,"node_index_prefix") //防止参数中其它位置也存在"#"
var mark0 = para.indexOf("#") != -1 ? true : false; //是否有參數需要解析
var Pinfo = mark0 && para1.indexOf("info=") != -1 ? para1.split("info=")[1].split("&")[0] : 0;
var ntf_flow = 0;
//常用量
const Base64 = new Base64Code();
const escapeRegExp = str => str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); //处理特殊符号以便正则匹配使用
var link1 = link0.split("#")[0]
const qxpng = "https://raw.githubusercontent.com/crossutility/Quantumult-X/master/quantumult-x.png" // server sub-info link
const subinfo_link = { "open-url": "https://t.me/QuanX_API", "media-url": "https://shrtm.nu/ebAr" };
const subinfo_link1 = { "open-url": link1, "media-url": "https://shrtm.nu/uo13" } // server sub-info link(fake-nodes)
const rwrite_link = { "open-url": link1, "media-url": "https://shrtm.nu/x3o2" } // rewrite filter link
const rwhost_link = { "open-url": link1, "media-url": "https://shrtm.nu/0n5J" } // hostname filter link
const rule_link = { "open-url": link1, "media-url": "https://shrtm.nu/cpHD" } // rule filter link
const nan_link = { "open-url": link1, "media-url": qxpng } // nan error link
const bug_link = { "open-url": "https://t.me/Shawn_Parser_Bot", "media-url": "https://shrtm.nu/obcB" } // bug link
const sub_link = { "open-url": link1, "media-url": "https://shrtm.nu/ebAr" } // server link
const update_link = {"open-url" : "https://apps.apple.com/us/app/quantumult-x/id1443988620", "media-url": qxpng}
const plink0 = {"open-url" : link0, "media-url": qxpng} // 跳转订阅链接
if(version == 0) { $notify("⚠️ 请更新 Quantumult X 至最新商店版本\n","🚦 当前版本可能无法正常使用部分功能","\n👉 点击跳转商店链接更新",update_link) }
const ADDRes = `quantumult-x:///add-resource?remote-resource=url-encoded-json`
var RLink0 = {
"filter_remote": [],
"rewrite_remote": [],
"server_remote": [],
}
const Field = {
"filter" : "filter_remote",
"rewrite": "rewrite_remote",
"server" : "server_remote"
}
SubFlow() //流量通知
// 参数获取
var Pin0 = mark0 && para1.indexOf("in=") != -1 ? (para1.split("in=")[1].split("&")[0].split("+")).map(decodeURIComponent) : null;
var Pout0 = mark0 && (para.indexOf("#out=") != -1 || para.indexOf("&out=") != -1)? ((para.indexOf("#out=")!=-1? para.split("#out="): para.split("&out="))[1].split("&")[0].split("+")).map(decodeURIComponent) : null;
var Psfilter = mark0 && para1.indexOf("sfilter=") != -1 ? Base64.decode(para1.split("sfilter=")[1].split("&")[0]) : null; // script filter
var Preg = mark0 && para1.indexOf("regex=") != -1 ? decodeURIComponent(para1.split("regex=")[1].split("&")[0]).replace(/\,/g,",") : null; //server正则过滤参数
var Pregout = mark0 && para1.indexOf("regout=") != -1 ? decodeURIComponent(para1.split("regout=")[1].split("&")[0]).replace(/\,/g,",") : null; //server正则删除参数
var Pregdel = mark0 && para1.indexOf("delreg=") != -1 ? decodeURIComponent(para1.split("delreg=")[1].split("&")[0]).replace(/\,/g,",") : null; // 正则删除参数
var Phin0 = mark0 && para1.indexOf("inhn=") != -1 ? (para1.split("inhn=")[1].split("&")[0].split("+")).map(decodeURIComponent) : null; //hostname
var Phout0 = mark0 && para1.indexOf("outhn=") != -1 ? (para1.split("outhn=")[1].split("&")[0].split("+")).map(decodeURIComponent) : null; //hostname
var Preplace = mark0 && para1.indexOf("replace=") != -1 ? para1.split("replace=")[1].split("&")[0] : null; //filter/rewrite 正则替换
var Pemoji = mark0 && para1.indexOf("emoji=") != -1 ? para1.split("emoji=")[1].split("&")[0] : null;
var Pdbg = mark0 && para1.indexOf("dbg=") != -1 ? para1.split("dbg=")[1].split("&")[0] : null;
var Pudp0 = mark0 && para1.indexOf("udp=") != -1 ? para1.split("udp=")[1].split("&")[0] : 0;
var Ptfo0 = mark0 && para1.indexOf("tfo=") != -1 ? para1.split("tfo=")[1].split("&")[0] : 0;
//var Prname = mark0 && para1.indexOf("rename=") != -1 ? para1.split("rename=")[1].split("&")[0].split("+") : null;
var Prname = mark0 && /(^|\&)rename=/.test(para1) ? para1.split(/(^|\&)rename\=/)[2].split("&")[0].split("+") : null;
var Psrename = mark0 && para1.indexOf("srename=") != -1 ? Base64.decode(para1.split("srename=")[1].split("&")[0]) : null; // script rename
var Prrname = mark0 && para1.indexOf("rrname=") != -1 ? para1.split("rrname=")[1].split("&")[0].split("+") : null;
var Psuffix = mark0 && para1.indexOf("suffix=") != -1 ? para1.split("suffix=")[1].split("&")[0] : 0;
var Ppolicy = mark0 && para1.indexOf("policy=") != -1 ? decodeURIComponent(para1.split("policy=")[1].split("&")[0]) : "Shawn";
var Ppolicyset = mark0 && para1.indexOf("pset=") != -1 ? decodeURIComponent(para1.split("pset=")[1].split("&")[0]) : "";
var Pcert0 = mark0 && para1.indexOf("cert=") != -1 ? para1.split("cert=")[1].split("&")[0] : 0;
var Psort0 = mark0 && para1.indexOf("sort=") != -1 ? para1.split("sort=")[1].split("&")[0] : 0;
var PsortX = mark0 && para1.indexOf("sortx=") != -1 ? para1.split("sortx=")[1].split("&")[0] : 0;
var PTls13 = mark0 && para1.indexOf("tls13=") != -1 ? para1.split("tls13=")[1].split("&")[0] : 0;
var Pntf0 = mark0 && para1.indexOf("ntf=") != -1 ? para1.split("ntf=")[1].split("&")[0] : 2;
var Phide = mark0 && para1.indexOf("hide=") != -1 ? para1.split("hide=")[1].split("&")[0] : 1;
var Pb64 = mark0 && para1.indexOf("b64=") != -1 ? para1.split("b64=")[1].split("&")[0] : 0;
var emojino = [" 0️⃣ ", " 1⃣️ ", " 2⃣️ ", " 3⃣️ ", " 4⃣️ ", " 5⃣️ ", " 6⃣️ ", " 7⃣️ ", " 8⃣️ ", " 9⃣️ ", " 🔟 "]
var pfi = mark0 &&Pin0 ? "in=" + Pin0.join(", ") + ", " : ""
var pfo = mark0 &&Pout0 ? "out=" + Pout0.join(", ") : ""
var pfihn = mark0 &&Phin0 ? "inhn=" + Phin0.join(", ") + ", " : ""
var pfohn = mark0 &&Phout0 ? "outhn=" + Phout0.join(", ") : ""
var Pcnt = mark0 &¶1.indexOf("cnt=") != -1 ? para1.split("cnt=")[1].split("&")[0] : 0;
var Pcap = mark0 &¶1.indexOf("cap=") != -1 ? para1.split("cap=")[1].split("&")[0] : "";
var Pptn = mark0 &¶1.indexOf("ptn=") != -1 ? para1.split("ptn=")[1].split("&")[0] : ""; //花式英文字符
var Pnptn = mark0 &¶1.indexOf("npt=") != -1 ? para1.split("npt=")[1].split("&")[0] : ""; //花式数字
var Pcdn = mark0 &¶1.indexOf("cdn=") != -1 ? para1.split("cdn=")[1].split("&")[0] : "";
let [flow, exptime, errornode, total] = "";
var Pdel = mark0 && para1.indexOf("del=") != -1 ? para1.split("del=")[1].split("&")[0] : 0; //删除重复节点
var typeU = mark0 && para1.indexOf("type=") != -1 ? para1.split("type=")[1].split("&")[0] : "";
var Pfcr = mark0 && para1.indexOf("fcr=") != -1 ? para1.split("fcr=")[1].split("&")[0] : ""; // force-cellular 等参数
var Pvia = mark0 && para1.indexOf("via=") != -1 ? para1.split("via=")[1].split("&")[0] : ""; // via-interface 参数
var Paead = mark0 && para1.indexOf("aead=") != -1 ? para1.split("aead=")[1].split("&")[0] : ""; // vmess aead 参数
var Phost = mark0 && ( para.indexOf("#host=") != -1 || para.indexOf("&host=") != -1) ? (para.indexOf("#host=")!=-1? para.split("#host="): para.split("&host="))[1].split("&")[0] : ""; // host 混淆参数
var Pcsha256 = mark0 && para1.indexOf("csha=") != -1 && version >= 646? para1.split("csha=")[1].split("&")[0] : ""; // cert-sha256 混淆参数
var Ppsha256 = mark0 && para1.indexOf("psha=") != -1 && version >= 646? para1.split("psha=")[1].split("&")[0] : ""; // pubkey-sha256 混淆参数
var typeQ = $resource.type? $resource.type:"unsupported" //返回 field 类型参数
var PRelay =mark0 && para1.indexOf("relay=") != -1 ? decodeURIComponent(para1.split("relay=")[1].split("&")[0]) : ""; // 节点 relay 参数, 用于实现代理链功能
var PUOT = mark0 && para1.indexOf("uot=") != -1 && version >= 665? para1.split("uot=")[1].split("&")[0] : ""; // 节点 udp-over-tcp 开启
var PcheckU = mark0 && para1.indexOf("checkurl=") != -1 ? decodeURIComponent(para1.split("checkurl=")[1].split("&")[0]) : ""; // 节点 server_check_url 参数
typeQ = PRelay!=""? "server":typeQ
var typec="" //check result type
var Pflow=mark0 && para1.indexOf("flow=") != -1 ? para1.split("flow=")[1].split("&")[0] : 0; // 流量时间等参数
var PProfile = mark0 && para1.indexOf("profile=") != -1 ? para1.split("profile=")[1].split("&")[0] : 0; // 通过URL-Scheme导入完整配置参数
var Palpn = mark0 && para1.indexOf("alpn=") != -1 && version >= 712? para1.split("alpn=")[1].split("&")[0] : ""; // over-tls 类型,alpn参数
var Pobfs = mark0 && para1.indexOf("obfs=") != -1 && version >= 770? para1.split("obfs=")[1].split("&")[0] : ""; // 指定特殊情况下的 obfs=xx-http 类型
var Psession = mark0 && para1.indexOf("tsession=") != -1 && version >= 771? para1.split("tsession=")[1].split("&")[0] : "";//tls-no-session-ticket and tls-no-session-reuse
// 0/1 代表关闭 session-ticket/reuse,2 表示全部关闭。
var RegoutList= [] ;//用于 regout参数删选提醒
// URL-Scheme 增加配置
var ADDres = `quantumult-x:///add-resource?remote-resource=url-encoded-json`
var RLink = `{
"server_remote": [
sremoteposition
],
"filter_remote": [
fremoteposition
],
"rewrite_remote": [
rremoteposition
]
}`
var ProfileInfo = {
"server":"",
"filter":"",
"rewrite":""
}
function VCheck(cnt) {
cnts=cnt.split("\n").filter(Boolean).map(item=>item.trim()).filter(item => /^http/.test(item)).map(item=>"\""+item+"\"")
cnts=cnts.join(",\n")
//console.log(cnts)
return cnts
}
function Profile_Handle() {
let a = content0
PProfile= PProfile==1? "001":PProfile
PProfile= PProfile==8? "010": PProfile
PProfile= PProfile==9? "011": PProfile
srm = a.split("[server_remote]")[1] && String(PProfile)[0]=="1"? VCheck(a.split("[server_remote]")[1].split("[")[0]) : ""
frm = a.split("[filter_remote]")[1] && String(PProfile)[1]=="1"? VCheck(a.split("[filter_remote]")[1].split("[")[0]) : ""
rrm = a.split("[rewrite_remote]")[1] && String(PProfile)[2]=="1"? VCheck(a.split("[rewrite_remote]")[1].split("[")[0]) : ""
RLink=RLink.replace("sremoteposition",srm).replace("fremoteposition",frm).replace("rremoteposition",rrm)
ADDres=ADDres.replace("url-encoded-json",encodeURIComponent(RLink))
}
//
//流量信息
//{bytes_used: 1073741824, bytes_remaining: 2147483648, expire_date: 1653193966}}
var Finfo={}
if (Pflow!=0) {
Pflow = Pflow.split(":")
var Bdate=Date.parse(new Date(Pflow[0]))/1000
var Btotal=Pflow[1]? Pflow[1]*1024*1024*1024 : 0
var Bused=Pflow[2]? Pflow[2]*1024*1024*1024 : 0
var Bremain=Btotal !=0 ? Btotal-Bused : 1
var BJson={bytes_used: Bused, bytes_remaining: Bremain, expire_date: Bdate}
//$notify("Flow","",JSON.strigify(BJson))
Finfo = BJson
}
//花漾字 pattern
var pat=[]
pat[0] = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","k","r","s","t","u","v","w","x","y","z"]
pat[1] = ["🅰","🅱","🅲","🅳","🅴","🅵","🅶","🅷","🅸","🅹","🅺","🅻","🅼","🅽","🅾","🅿","🅺","🆁","🆂","🆃","🆄","🆅","🆆","🆇","🆈","🆉"]
pat[2] = ["🄰","🄱","🄲","🄳","🄴","🄵","🄶","🄷","🄸","🄹","🄺","🄻","🄼","🄽","🄾","🄿","🄺","🅁","🅂","🅃","🅄","🅅","🅆","🅇","🅈","🅉"]
pat[3] = ["𝐀","𝐁","𝐂","𝐃","𝐄","𝐅","𝐆","𝐇","𝐈","𝐉","𝐊","𝐋","𝐌","𝐍","𝐎","𝐏","𝐊","𝐑","𝐒","𝐓","𝐔","𝐕","𝐖","𝐗","𝐘","𝐙"]
pat[4] = ["𝗮","𝗯","𝗰","𝗱","𝗲","𝗳","𝗴","𝗵","i","𝗷","𝗸","𝗹","𝗺","𝗻","𝗼","𝗽","𝗸","𝗿","𝘀","𝐭","𝘂","𝘃","𝘄","𝘅","𝘆","𝘇"]
pat[5] = ["𝔸","𝔹","ℂ","𝔻","𝔼","𝔽","𝔾","ℍ","𝕀","𝕁","𝕂","𝕃","𝕄","ℕ","𝕆","ℙ","𝕂","ℝ","𝕊","𝕋","𝕌","𝕍","𝕎","𝕏","𝕐","ℤ"]
pat[6] = ["𝕒","𝕓","𝕔","𝕕","𝕖","𝕗","𝕘","𝕙","𝕚","𝕛","𝕜","𝕝","𝕞","𝕟","𝕠","𝕡","𝕜","𝕣","𝕤","𝕥","𝕦","𝕧","𝕨","𝕩","𝕪","𝕫"]
pat[7] = ["ᵃ","ᵇ","ᶜ","ᵈ","ᵉ","ᶠ","ᵍ","ʰ","ⁱ","ʲ","ᵏ","ˡ","ᵐ","ⁿ","ᵒ","ᵖ","ᵒ⃒","ʳ","ˢ","ᵗ","ᵘ","ᵛ","ʷ","ˣ","ʸ","ᙆ"]
pat[8] = ["ᴬ","ᴮ","ᒼ","ᴰ","ᴱ","ᶠ","ᴳ","ᴴ","ᴵ","ᴶ","ᴷ","ᴸ","ᴹ","ᴺ","ᴼ","ᴾ","ᴼ̴","ᴿ","ˢ","ᵀ","ᵁ","ᵛ","ᵂ","ˣ","ʸ","ᙆ"]
// 花式数字
var patn=[]
patn[0] = ["0","1","2","3","4","5","6","7","8","9"]
patn[1] = [ '⓪', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨' ]
patn[2] = [ '⓪', '❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾' ]
patn[3] = [ '⓪', '⓵', '⓶', '⓷', '⓸', '⓹', '⓺', '⓼', '⓻', '⓽' ]
patn[4] = [ '𝟘', '𝟙', '𝟚', '𝟛', '𝟜', '𝟝', '𝟞', '𝟟', '𝟠', '𝟡' ]
patn[5] = [ '⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹' ]
patn[6] = [ '₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉' ]
patn[7] = ["𝟎","𝟏","𝟐","𝟑","𝟒","𝟓","𝟔","𝟳","𝟖","𝟗"]
patn[8] = ["𝟶","𝟷","𝟸","𝟹","𝟺","𝟻","𝟼","𝟽","𝟾","𝟿"]
//避免json undefined错误的 函数
const getValue = (fn, defaultVaule) => {
try {
return fn();
} catch (error) {
return defaultVaule;
}
};
var type0=""
//flag=1,2,3分别为 server、rewrite、rule 类型
var flag = 1
function Parser() {
type0 = Type_Check(content0); // 类型判断
//$notify(type0)
if (type0 != "web" && type0 != "wrong-field" && type0 != "JS-0"){
try {
//$notify(type0,"hh")
if (Pdbg){
$notify(link0,type0,content0)
}
total = ResourceParse();
} catch (err) {
if(Perror == 0) {
$notify("❌ 解析出现错误", "⚠️ 请点击通知,发送订阅链接进行反馈", err, bug_link);
}
}
} else if (type0 == "wrong-field"){
if (version >= 670 && typec!="") { //尝试跳转到正确类型
RLink0[Field[typec]].push($resource.link+", opt-parser=true, tag=下次添加资源🉑️长点❤️8⃣️") // 跳转URI-Scheme
var flink = ADDRes.replace(/url-encoded-json/,encodeURIComponent(JSON.stringify(RLink0)))
const bug_linkx = { "open-url": flink, "media-url": "https://shrtm.nu/obcB" } // bug linkx
$notify( "⚠️ 请点击通知跳转尝试添加到正确类型中","❌ 检测类型["+typec+"]"+"与填入类型"+"["+typeQ+"]冲突", "如果跳转添加仍旧失败,请发送链接反馈解析器bot\n"+$resource.link, bug_linkx)
} else {//旧版本
$notify("❌ 检测类型「"+typec+" 」"+"与目标类型"+" 「"+typeQ+" 」冲突", "⚠️ 请自行检查链接内容,或点击通知发送链接进行反馈", $resource.link, bug_link)
}
total=""
} else {
total=""
}
$done({ content: total });
}
if (typeof($resource)!=="undefined" && PProfile == 0) {
Parser()
$done({ content: total, info: Finfo })
} else if (PProfile != 0) {
try {
Profile_Handle()
} catch (err) {
if(Perror == 0) {
$notify("❌ 解析出现错误", "⚠️ 请点击通知,发送订阅链接进行反馈", err, bug_link);
}
}
openlink = {"open-url": ADDres}
$notify("⚠️请忽略报错提示, 点击此通知跳转", "添加配置中的有效远程资源👇 ["+ PProfile+"]", ADDres,openlink)
total = ProfileInfo[typeQ]
$done({content:total})
}
/**
# 以下为具体的 function
*/
function ParseUnknown(cnt){
try {
cnt = JSON.parse(cnt)
if(cnt) {
$notify("⚠️ 链接返回内容并非有效订阅"+ "⟦" + subtag + "⟧","⁉️ 请自行检查原始链接,返回内容 👇️👇️",JSON.stringify(cnt), bug_link)
}
} catch(err) {
if (!/error|block|invalid|support/.test(cnt.toLowerCase())) {
$notify("😭 未能识别订阅 " + "⟦" + subtag + "⟧ 的内容", "⚠️ 将尝试直接导入Quantumult X \n 如认为是 BUG, 请点通知跳转并 [发送链接] 反馈", "订阅返回内容: 👇 \n"+cnt, bug_link);
} else {
$notify("💢 ⟦" + subtag + "⟧ 返回内容无效", "😠 请自行检查订阅,不要跑来反馈", "订阅返回内容: 👇 \n"+cnt, plink0);
}
}
}
function ResourceParse() {
//预处理,分流/重写等处理完成
if (type0 == "Subs-B64Encode") { // subs2QX 负责所有节点的转换
if (Pdbg) {$notify("original content", "node-b64", content0)}
total = Subs2QX(Base64.decode(content0), Pudp0, Ptfo0, Pcert0, PTls13);
} else if (type0 == "Subs") {
//$notify("subs","",content0+Pudp0+Ptfo0+Pcert0+PTls13)
total = Subs2QX(content0, Pudp0, Ptfo0, Pcert0, PTls13);
} else if (type0 == "QuanX" || type0 == "Clash" || type0 == "Surge") {
total = Subs2QX(isQuanX(content0).join("\n"), Pudp0, Ptfo0, Pcert0, PTls13);
} else if (type0 == "sgmodule") { // surge module 模块/含 url-regex 的 rule-set
//2023-03-06 考虑模块重写与quanx类型重写的混搭
flag = 2
//total = SGMD2QX(content0) // 转换
total = Rewrite_Filter(isQuanXRewrite(content0.split("\n")), Pin0, Pout0,Preg,Pregout);//Rewrite_Filter(total, Pin0, Pout0,Preg,Pregout); // 筛选过滤
if (Preplace) { total = ReplaceReg(total, Preplace) }
total = total.filter( (ele,pos)=>total.indexOf(ele) == pos); //重写重复检查
if (Pcdn) {total = CDN(total)
} else { total = total.join("\n")}
} else if (type0 == "rewrite") { // rewrite 类型
flag = 2;
total = Rewrite_Filter(isQuanXRewrite(content0.split("\n")), Pin0, Pout0,Preg,Pregout);
if (Preplace) { total = ReplaceReg(total, Preplace) }
// rewrite重复检测
total = total.filter( (ele,pos)=>total.indexOf(ele) == pos);
if (Pcdn) {total = CDN(total)
} else {total = total.join("\n")}
} else if (type0 == "Rule") { // rule 类型, 已处理完毕
flag = 3;
total = Rule_Handle(content0.split("\n").map(item=>item.trim()).filter(Boolean), Pout0, Pin0).filter(Boolean);
if (Preg && total.length!=0) { // 正则筛选规则 filter
total = total.map(Regex).filter(Boolean)
RegCheck(total, "分流引用", "regex", Preg)
}
if (Pregout && total.length!=0) { // 正则删除规则 filter
total = total.map(RegexOut).filter(Boolean)
RegCheck(total, "分流引用", "regout", Pregout)
}
if (Preplace) { total = ReplaceReg(total, Preplace) }
if (Ppolicyset) {total = policy_sets(total, Ppolicyset)}
// filter 重复检测
total = total.length<100? total.filter( (ele,pos)=>total.indexOf(ele) == pos) : total
total = total.join("\n")
} else if (content0.trim() == "") {
$notify("‼️ 引用" + "⟦" + subtag + "⟧" + " 返回內容为空", "⁉️ 点通知跳转以确认链接是否失效", para.split("#")[0], nan_link);
flag = 0;
} else if (type0 == "sub-http") {
let url = VCheck(String(Base64.decode(content0.split("sub://")[1].split("#")[0])+", opt-parser=true, tag="+(new Date()).getTime()))
RLink = RLink.replace("sremoteposition",url).replace("fremoteposition","").replace("rremoteposition","")
let ADDres0 = ADDres.replace("url-encoded-json",encodeURIComponent(RLink))
openlink = {"open-url": ADDres0}
$notify("⚠️ 该链接为节点订阅, 请点击此通知跳转添加", url, ADDres0,openlink)
flag = -1
total = ""
} else if (type0 == "unknown") {
ParseUnknown(content0)
flag = -1;
} else if (type0 == "profile") {
PProfile = "111" //默认添加所有部分
Profile_Handle()
openlink = {"open-url": ADDres}
$notify("⚠️ 该链接为完整配置文件, 请点击此通知跳转", "添加配置中的有效远程资源👇 ["+ PProfile+"]", ADDres, openlink)
flag = -1;
total = ""
} else if (type0 == "JS-0") {
total = ""
}
//开始处理
if (flag == 1) { //server 类型统一处理
total = isQuanX(total.filter(Boolean).join("\n"))
if (Pinfo == 1 && ntf_flow == 0) { //假节点类型的流量通知
flowcheck(total)
}
if (Pin0 || Pout0) { total = Filter(total, Pin0, Pout0) } // in & out
if (Preg) { total = total.map(Regex).filter(Boolean) // regex
RegCheck(total, "节点订阅", "regex", Preg)}
if (Pregout) { total = total.map(RegexOut).filter(Boolean) // regex out
RegCheck(total, "节点订阅", "regout", Pregout)}
if (Psfilter) { total = FilterScript(total, Psfilter) }
if (Prrname) {
Prn = Prrname;
total = total.map(Rename);
}
//if (Pemoji) { total = emoji_handle(total, Pemoji); }
if (Pregdel) {
delreg = Pregdel
total = total.map(DelReg)
}
//script rename 置于其它参数之前
if (Psrename) { total = RenameScript(total, Psrename) }
if (Preplace) { // server 类型也可用 replace 参数进行重命名操作
total = ReplaceReg(total, Preplace)
}
if (Prname) {
Prn = Prname;
total = total.map(Rename);
if(Pdbg==1) {$notify("rename","content",total)}
}
//2023-07-10 调整emoji操作顺序
if (Pemoji) { total = emoji_handle(total, Pemoji); }
if (total.length > 0){
if (Psuffix==1 || Psuffix==-1) {total = Psuffix == 1? total.map(type_suffix):total.map(type_prefix)
}
total = total.map(type_handle).map(emoji_prefix_handle).map(tag_handle) //各类节点名操作
if (Psort0) { //排序操作
total = QXSort(total, Psort0);
}
total = para1.indexOf("node_index_prefix")!=-1 ?index_handle(total):total // 节点序号操作
//$notify("before","haha",total)
total = TagCheck_QX(total).join("\n") //节点名检查
if (PUOT==1) { total = total.split("\n").map(UOT).join("\n")}
if (Pcnt == 1) {$notify("⟦" + subtag + "⟧"+"解析后最终返回内容" , "节点数量: " +total.split("\n").length, total)}
total = PRelay==""? Base64.encode(total) : ServerRelay(total.split("\n"),PRelay) //强制节点类型 base64 加密后再导入 Quantumult X, 如果是relay,则转换成分流类型
if(Pflow==1) {
//$notify("添加流量信息","xxx","xxxx")
$done({ content: total, info: {bytes_used: 3073741824, bytes_remaining: 2147483648, expire_date: 1854193966}});
//$notify("done?","strange")
} else { $done({ content: total });}
} else {
if(Perror == 0) {
$notify("❓❓ 友情提示 ➟ "+ "⟦" + subtag + "⟧", "⚠️⚠️ 解析后无有效内容", "🚥🚥 请自行检查相关参数, 或者点击通知跳转并发送链接反馈", bug_link)
}
total = errornode
$done({ content: errornode })
}
} else if (flag == 0){ //空/错误类型
total = errornode
$done({ content: errornode })
} else if (flag == -1){ //未知类型
total = content0
$done({ content: content0 })
}
if (Pcnt == 1 && flag !=1) {$notify("解析后最终返回内容" , "总数量: " +total.split("\n").length, total)}
return total
}
//响应头流量处理部分
function SubFlow() {
if (Pinfo == 1 && subinfo) {
var sinfo = subinfo.replace(/ /g, "").toLowerCase();
var total = "总流量: " + (parseFloat(sinfo.split("total=")[1].split(",")[0]) / (1024 ** 3)).toFixed(2) + "GB";
var usd = "已用流量: " + ((parseFloat(sinfo.indexOf("upload")!=-1?sinfo.split("upload=")[1].split(",")[0]:"0") + parseFloat(sinfo.split("download=")[1].split(",")[0])) / (1024 ** 3)).toFixed(2) + "GB"
var left = "剩余流量: " + ((parseFloat(sinfo.split("total=")[1].split(",")[0]) / (1024 ** 3)) - ((parseFloat(sinfo.indexOf("upload")!=-1?sinfo.split("upload=")[1].split(",")[0]:"0") + parseFloat(sinfo.split("download=")[1].split(",")[0])) / (1024 ** 3))).toFixed(2) + "GB"
if (sinfo.indexOf("expire=") != -1) {
var epr = new Date(parseFloat(sinfo.split("expire=")[1].split(",")[0]) * 1000);
var year = epr.getFullYear(); // 获取完整的年份(4位,1970)
var mth = epr.getMonth() + 1 < 10 ? '0' + (epr.getMonth() + 1) : (epr.getMonth() + 1); // 获取月份(0-11,0代表1月,用的时候记得加上1)
var day = epr.getDate() < 10 ? "0" + (epr.getDate()) : epr.getDate();
epr = "过期时间: " + year + "-" + mth + "-" + day
} else {
epr = ""; //"过期时间: ✈️ 未提供該信息" //没过期时间的显示订阅链接
}
var message = total + "\n" + usd + ", " + left;
ntf_flow = 1;
$notify("流量信息: ⟦" + subtag + "⟧", epr, message, subinfo_link)
}
// } else if (Pinfo ==1){
// $notify("流量信息: ⟦" + subtag + "⟧", "", "⚠️ 该订阅链接未返回任何流量信息", subinfo_link)
// }
}
//flowcheck-fake-server
function flowcheck(cnt) {
for (var i = 0; i < cnt.length; i++) {
var item = cnt[i];
var nl = item.slice(item.indexOf("tag"))
var nm = nl.slice(nl.indexOf("=") + 1)
if (item.indexOf("剩余流量") != -1) {
flow = nm
} else if (item.indexOf("期时间") != -1) {
exptime = nm
}
}
flow = flow? flow:"⚠️ 该订阅未返回任何流量信息"
exptime = exptime? exptime:"⚠️ 该订阅未返回套餐时间信息"
if (flow != "") { $notify("流量信息: ⟦" + subtag + "⟧", flow, exptime, subinfo_link1) }
}
// regex 后的检查
function RegCheck(total, typen, paraname,regpara) {
if(total.length == 0){
$notify("‼️ " + typen + " ➟ " + "⟦" + subtag + "⟧", "⛔️ 筛选正则: " + paraname + "=" + regpara, "⚠️ 筛选后剩余项为 0️⃣ , 请检查正则参数及原始链接", nan_link)
}else if((typen != "节点订阅" && Pntf0 !=0) || (typen == "节点订阅" && Pntf0 ==1)){
var nolist = total.length <= 10 ? emojino[total.length] : total.length
$notify("🤖 " + typen + " ➟ " + "⟦" + subtag + "⟧", "⛔️ 筛选正则: " + paraname + "=" + regpara, "⚠️ 筛选后剩余以下" + nolist + "个匹配项 \n ⨷ " + total.join("\n ⨷ "), sub_link)
}
}
//判断订阅类型
function Type_Check(subs) {
var type = "unknown"
var RuleK = ["host,", "-suffix,", "domain,", "-keyword,", "ip-cidr,", "ip-cidr6,", "geoip,", "user-agent,", "ip6-cidr,", "ip-asn"];
var DomainK = ["domain-set,"]
var QuanXK = ["shadowsocks=", "trojan=", "vmess=", "http=", "socks5="];
var SurgeK = ["=ss,", "=vmess,", "=trojan,", "=http,", "=custom,", "=https,", "=shadowsocks", "=shadowsocksr", "=sock5", "=sock5-tls"];
var ClashK = ["proxies:"]
var SubK = ["dm1lc3M", "c3NyOi8v", "CnNzOi8", "dHJvamFu", "c3M6Ly", "c3NkOi8v", "c2hhZG93", "aHR0cDovLw", "aHR0cHM6L", "CnRyb2phbjo", "aHR0cD0", "aHR0cCA","U1RBVFVT"];
var RewriteK = [" url 302", " url 307", " url reject", " url script", " url req", " url res", " url echo", " url-and-header 302", " url-and-header 307", " url-and-header reject", " url-and-header script", " url-and-header req", " url-and-header res", " url-and-header echo"] // quantumult X 类型 rewrite
var SubK2 = ["ss://", "vmess://", "ssr://", "trojan://", "ssd://", "\nhttps://", "\nhttp://","socks://","ssocks://"];
var ModuleK = ["[Script]", "[Rule]", "[URL Rewrite]", "[Map Local]", "\nhttp-r", "script-path"]
var QXProfile = ["[filter_local]","[filter_remote]","[server_local]","[server_remote]"]
var html = "DOCTYPE html"
var subi = subs.replace(/ /g, "")
const RuleCheck = (item) => subi.toLowerCase().indexOf(item) != -1;
const NodeCheck = (item) => subi.toLowerCase().indexOf(item.toLowerCase()) != -1;
const NodeCheck1 = (item) => subi.toLowerCase().indexOf(item.toLowerCase()) != -1; //b64加密的订阅类型
const NodeCheck2 = (item) => subi.toLowerCase().indexOf(item.toLowerCase()) != -1; //URI 类型
const RewriteCheck = (item) => subs.indexOf(item) != -1 ; // quanx 重写判定
const ProfileCheck = (item) => subs.indexOf(item) != -1; //是否为quanx配置文件
var subsn = subs.split("\n")
if ( (subs.indexOf(html) != -1 || subs.indexOf("doctype html") != -1) && link0.indexOf("github.com" == -1)) {
$notify("‼️ 该链接返回为无效网页内容"+ " ➟ " + "⟦" + subtag + "⟧", "⁉️ 点通知跳转以确认链接是否失效\n"+link0, "返回内容如下⬇️:\n"+subs, nan_link);
type = "web";
} else if (typeU == "nodes" && typeQ=="server") { //指定为节点类型
type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field"
} else if (ClashK.some(NodeCheck) || typeU == "clash"){ // Clash 类型节点转换
type = (typeQ == "unsupported" || typeQ =="server")? "Clash":"wrong-field";
typec = "server"
content0 = Clash2QX(subs)
} else if ( (((ModuleK.some(RewriteCheck) || para1.indexOf("dst=rewrite") != -1) && (para1.indexOf("dst=filter") == -1) && subs.indexOf("[Proxy]") == -1) || typeU == "module") && typeU != "nodes" && typeU != "rule" && typeQ !="filter") { // Surge 类型 module /rule-set(含url-regex) 类型
typec="rewrite"
type = (typeQ == "unsupported" || typeQ =="rewrite")? "sgmodule" : "wrong-field"
} else if ((/(^hostname|\nhostname)\s*\=/.test(subi) || RewriteK.some(RewriteCheck)) && para1.indexOf("dst=filter")==-1 && subi.indexOf("securehostname") == -1 && !/module|nodes|rule/.test(typeU) && !(RuleK.some(RuleCheck) && typeQ == "filter") && !(typeQ!= "rewrite" && QXProfile.some(ProfileCheck))) {
// 2022-07-20 remove constrain && !/\[(Proxy|filter_local)\]/.test(subs)
typec = "rewrite"
type = (typeQ == "unsupported" || typeQ =="rewrite")? "rewrite":"wrong-field" //Quantumult X 类型 rewrite/ Surge Script/
} else if (((RuleK.some(RuleCheck) && subs.indexOf(html) == -1 ) || typeU == "rule" || para1.indexOf("dst=filter")!=-1) && typeU != "nodes" && !(typeQ == "server" && (QuanXK.some(NodeCheck) || SurgeK.some(NodeCheck))) ) {
// rule/filter类型
// 2022-07-20 remove constrain && !/\[(Proxy|server_local)\]/.test(subs) adter html
typec = "filter"
type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
} else if (typeU == "domain-set") {// 仅限用户指定为 domain-set;((DomainK.some(RuleCheck) || typeU == "domain-set") && subs.indexOf("[Proxy]") == -1 && typeU != "nodes") {
typec = "filter-domain-set"
type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
content0 = Domain2Rule(content0) // 转换 domain-set
} else if (typeQ == "filter" && subs.indexOf("payload:")==-1) { // 纯 list类型?
typec = "filter-list"
type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
content0 = content0.split("\n").map(rule_list_handle).join("\n")
} else if (subi.indexOf("sub://") == 0) { // sub:// 类型
typec = "sub-http"
type = "sub-http"
} else if (typeQ == "filter" && subs.indexOf("payload:")!=-1) { // clash-provider 类型?
typec = "Clash-Provider"
type = (typeQ == "unsupported" || typeQ =="filter")? "Rule":"wrong-field";
} else if (subsn.length >= 1 && SubK2.some(NodeCheck2) && !/\[(Proxy|filter_local)\]/.test(subs)) { //未b64加密的多行URI 组合订阅
typec = "server-uri"
type= (typeQ == "unsupported" || typeQ =="server" || typeQ =="uri") ? "Subs":"wrong-field"
} else if ((subi.indexOf("tag=") != -1 && QuanXK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU =="list") {
typec = "server-quanx"
type = (typeQ == "unsupported" || typeQ =="server" || typeQ =="uri")? "Subs":"wrong-field" // QuanX list
} else if (subs.indexOf("[Proxy]") != -1) {
typec= "server-surge"
type = (typeQ == "unsupported" || typeQ =="server" || typeQ =="uri")? "Surge":"wrong-field"; // Surge Profiles
content0 = Surge2QX(content0).join("\n");
} else if ((SurgeK.some(NodeCheck) && !/\[(Proxy|filter_local)\]/.test(subs)) || typeU == "list") {
typec="server-surge"
type = (typeQ == "unsupported" || typeQ =="server" || typeQ =="uri")? "Subs":"wrong-field" // Surge proxy list
} else if (subs.indexOf("[server_local]") != -1 && QuanXK.some(NodeCheck)) {
//type = "QuanX" // QuanX Profile
typec="server-quanx"
type = (typeQ == "unsupported" || typeQ =="server"|| typeQ =="uri")? "Subs":"wrong-field"
} else if (content0.indexOf("server") !=-1 && content0.indexOf("server_port") !=-1) { //SIP008
//type = "QuanX"
typec= "server-sip008"
type = (typeQ == "unsupported" || typeQ =="server")? "Subs":"wrong-field"
content0 = SIP2QuanX(content0)
} else if (SubK.some(NodeCheck1)) { //b64加密的订阅类型
typec="server-b64"
type = (typeQ == "unsupported" || typeQ =="server")? "Subs-B64Encode":"wrong-field"
if (content0.split("\n").length >= 2) { // local snippet and first line remarks
let tmp = content0.split("\n")[1]
if (Pdbg) {$notify("local", "node", "\ntmp:\n"+tmp)}
if (SubK.some((item) => tmp.toLowerCase().indexOf(item.toLowerCase()) != -1))
content0 = tmp
}
} else if (QXProfile.every(ProfileCheck)) {
typec = "profile"
type = "profile" //默认配置类型
}else if (/\.js/.test(link0)) { // xjb添加js脚本的行为
Perror = 1 ; // 无需反馈
$notify("⚠️ 你导入的链接内容为 JS 脚本","🚥 脚本内未有重写规则,无法解析使用", " 请⚠️不要⚠️跑来解析器🤖️反馈 \n"+link0)
type = "JS-0"
} else if (typeQ =="server" && subs.length>100) { // 一些未知的b64 encode server case
typec="server-b64-unknown"
type = (typeQ == "unsupported" || typeQ =="server")? "Subs-B64Encode":"wrong-field"
} //else if (typeQ == "URI")
// 用于通知判断类型,debug
if(typeU == "X"){
$notify("该链接判定类型",type+" : " +typec, subs)
}
//$notify(type)
return type
}
// 检查节点名字(重复以及空名)等QuanX 不允许的情形,以及多个空格等“不规范”方式
function TagCheck_QX(content) {
typefix = {"shadowsocks":["𝐬𝐬","𝐒𝐒","🅢🅢","🆂🆂","ⓢⓢ","🅂🅂","SS"],"shadowsocksr":["𝐬𝐬𝐫","𝐒𝐒𝐑","🅢🅢🅡","🆂🆂🆁","ⓢⓢⓡ","🅂🅂🅁","SSR"],"vmess":["𝐯𝐦𝐞𝐬𝐬","𝐕𝐌𝐄𝐒𝐒","🅥🅜🅔🅢🅢","🆅🅼🅴🆂🆂","ⓥⓜⓔⓢⓢ","🅅🄼🄴🅂🅂","VMESS"],"trojan":["𝐭𝐫𝐨𝐣𝐚𝐧","𝐓𝐑𝐎𝐉𝐀𝐍","🅣🅡🅞🅙🅐🅝","🆃🆁🅾🅹🅰🅽","ⓣⓡⓞⓙⓐⓝ","🅃🅁🄾🄹🄰🄽","TROJAN"],"http":["𝐡𝐭𝐭𝐩","𝐇𝐓𝐓𝐏","🅗🅣🅣🅟","🅷🆃🆃🅿","ⓗⓣⓣⓟ","🄷🅃🅃🄿","HTTP"],"socks5":["𝐬𝐨𝗰𝗸𝐬","𝐒𝐎𝐂𝐊𝐒","🅢🅞🅒🅚🅢","🆂🅾🅲🅺🆂","ⓢⓄⒸⓀⓢ","🅂🄾🄲🄺🅂","SOCKS"]}
console.log(content)
var Olist = content.map(item =>item.trim())//.replace(/\s{2,}/g," "))
//$notify("","",Olist)
var [Nlist, nmlist] = [ [], [] ]
var [nulllist,duplist] = [ [], [] ]; //记录空名字节点&重名节点
var no=0 ;
for (var i = 0; i < Olist.length; i++) {
var item = Olist[i] ? Olist[i] : ""
typefix["shadowsocks"]=item.indexOf("ssr-protocol")!=-1? typefix["shadowsocksr"] : typefix["shadowsocks"]
if (item.replace(/ /gm, "").indexOf("tag=") != -1) {
var nl = item.slice(item.indexOf("tag"))
var nm = nl.slice(nl.indexOf("=") + 1)
if (nm == "") { //空名
tp = typefix[item.split("=")[0].trim()][3]
nm = tp + " | " + item.split("=")[1].split(",")[0].split(":")[0]
item = item.split("tag")[0] + "tag=" + nm.replace("shadowsocks", "ss")
nulllist.push(nm.replace("shadowsocks", "ss"))
}
var ni = 0
while (nmlist.indexOf(nm) != -1) { //重名情形
//$notify("重名",nm,nmlist)
nm = ni==0? nm+ NoReplace(ni+1):nm.split(" ").slice(0,nm.split(" ").length-2).join(" ") + NoReplace(ni+1)
item = Pdel != 1 ? item.split("tag")[0] + "tag=" + nm : ""
ni = ni + 1
}
if (ni != 0) { duplist.push(nm) }
nmlist.push(nm)
if (Pcap) {
item = Capitalize(item,Pcap)
console.log(item)
}
if (Pptn || Pnptn) {
item = Pattern(item,Pptn,Pnptn)
console.log(item)
}
ni = 0
if (item) {
Nlist.push(item)
}
}// if "tag="
} // for
// 增加 server_check_url 参数
if (PcheckU != "") {
Nlist = Nlist.map(Add_URL)
}
if (nulllist.length >= 1) {
no = nulllist.length <= 10 ? emojino[nulllist.length] : nulllist.length;
$notify("⚠️ 引用" + "⟦" + subtag + "⟧" + " 内有" + no + "个空节点名 ", "✅ 已将节点“类型+IP”设为节点名", " ⨁ " + nulllist.join("\n ⨁ "), nan_link)
}
if (duplist.length >= 1) {
no = duplist.length <= 10 ? emojino[duplist.length] : duplist.length;
if (Pdel!=1 && Pntf0 != 0){
$notify("⚠️ 引用" + "⟦" + subtag + "⟧" + " 内有" + no + "个名字重复的节点 ", "✅ 已添加数字区分, 删除请添加参数 del=1:", " ⨁ " + duplist.join("\n ⨁ "), nan_link)
} else if (Pdel ==1 && Pntf0 != 0) {
$notify("⚠️ 引用" + "⟦" + subtag + "⟧" + " 内有" + no + "个名字重复的节点 ", "❌️ 已全部删除,如需保留请去除参数 del=1:", " ⨁ " + duplist.join("\n ⨁ "), nan_link)
}
}
return Nlist
}
// 为节点添加 server-check-url参数
function Add_URL(cnt) {
if (cnt) {
cnt = cnt +", server_check_url="+PcheckU
}
return cnt
}
//节点名重名时添加数字序号替换
function NoReplace(cnt) {
if(cnt){
for (var i=0;i<10;i++) {
cnt = cnt.toString().replace(new RegExp(patn[0][i], "gmi"),patn[5][i])
}
return " " + cnt + " "
}
}
// 对节点名pattern化操作
function PatternN(cnt, para,npara) {
if(cnt){
if(para!=""){//字符
for (var i=0;i<26;i++) {
cnt = cnt.toLowerCase()
cnt = cnt.replace(new RegExp(pat[0][i], "gmi"),pat[para][i])
}
}
if(npara!=""){ //数字
for (var i=0;i<10;i++) {
cnt = cnt.replace(new RegExp(patn[0][i], "gmi"),patn[npara][i])
}
}
console.log(cnt)
return cnt
}
}
function Pattern(cnt,para,npara) {
if (para != "" || npara != "") {
cnt = cnt.split("tag=")[0] +"tag="+ PatternN(cnt.split("tag=")[1],para,npara)
}
return cnt
}
//大小写
function Capitalize(cnt,para) {
if (para == 1) {
cnt = cnt.split("tag=")[0] +"tag="+ cnt.split("tag=")[1].toUpperCase()
} else if (para == -1) {
cnt = cnt.split("tag=")[0] +"tag="+ cnt.split("tag=")[1].toLowerCase()
} else if (para == 0) {
cnt =cnt.split("tag=")[0] +"tag="+titleCase(cnt.split("tag=")[1])
}
return cnt
}
function titleCase(str) {
var newStr = str.split(" ");
for(var i = 0; i<newStr.length; i++){
newStr[i] = newStr[i].slice(0,1).toUpperCase() + newStr[i].slice(1).toLowerCase();
} return newStr.join(" ");
}
// 类型前缀/后缀
function type_prefix(item) {
if(item.trim()!="") {
typefix = {"shadowsocks":"「𝐬𝐬」","vmess":"「𝐯𝐦𝐞𝐬𝐬」","trojan":"「𝐭𝐫𝐨𝐣𝐚𝐧」","http":"「𝐡𝐭𝐭𝐩」","socks5":"「𝐬𝐨𝗰𝗸𝐬」"}
typefix["shadowsocks"]=item.indexOf("ssr-protocol")!=-1? "「𝐬𝐬𝐫」" : "「𝐬𝐬」"
tp = typefix[item.split("=")[0].trim()]
return [[item.split("tag=")[0]+
"tag=", tp, item.split("tag=")[1]].join(" ")].join(" ")
}
}
function type_suffix(item) {
if(item.trim()!=""){
typefix={"shadowsocks":"「𝐬𝐬」","vmess":"「𝐯𝐦𝐞𝐬𝐬」","trojan":"「𝐭𝐫𝐨𝐣𝐚𝐧」","http":"「𝐡𝐭𝐭𝐩」"}
typefix["shadowsocks"]=item.indexOf("ssr-protocol")!=-1? "「𝐬𝐬𝐫」" : "「𝐬𝐬」"
tp = typefix[item.split("=")[0].trim()]
return [item, tp].join(" ")
}
}
//获取类型
function getnode_type(item,ind) {
if(item.trim()!="" && item.indexOf("tag=")!=-1) {
ind = !/^(0|1|2|3|4|5|6|7)$/.test(ind) ? 8 : ind
typefix = {"shadowsocks":["𝐬𝐬","𝐒𝐒","🅢🅢","🆂🆂","ⓢⓢ","🅂🅂","𝕊𝕊","ˢˢ","SS"],"shadowsocksr":["𝐬𝐬𝐫","𝐒𝐒𝐑","🅢🅢🅡","🆂🆂🆁","ⓢⓢⓡ","🅂🅂🅁","𝕊𝕊ℝ","ˢˢʳ","SSR"],"vmess":["𝐯𝐦𝐞𝐬𝐬","𝐕𝐌𝐄𝐒𝐒","🅥🅜🅔🅢🅢","🆅🅼🅴🆂🆂","ⓥⓜⓔⓢⓢ","🅅🄼🄴🅂🅂","𝕍𝕞𝕖𝕤𝕤","ᵛᵐᵉˢˢ","VMESS"],"trojan":["𝐭𝐫𝐨𝐣𝐚𝐧","𝐓𝐑𝐎𝐉𝐀𝐍","🅣🅡🅞🅙🅐🅝","🆃🆁🅾🅹🅰🅽","ⓣⓡⓞⓙⓐⓝ","🅃🅁🄾🄹🄰🄽","𝕋𝕣𝕠𝕛𝕒𝕟","ᵀʳᵒʲᵃⁿ","TROJAN"],"http":["𝐡𝐭𝐭𝐩","𝐇𝐓𝐓𝐏","🅗🅣🅣🅟","🅷🆃🆃🅿","ⓗⓣⓣⓟ","🄷🅃🅃🄿","𝕙𝕥𝕥𝕡","ʰᵗᵗᵖ","HTTP"],"socks5":["𝐬𝐨𝗰𝗸𝐬","𝐒𝐎𝐂𝐊𝐒","🅢🅞🅒🅚🅢","🆂🅾🅲🅺🆂","ⓢⓞⓒⓚⓢ","🅂🄾🄲🄺🅂","𝕤𝕠𝕔𝕜𝕤","ˢᵒᶜᵏˢ","SOCKS"]}
typefix["shadowsocks"]=item.indexOf("ssr-protocol")!=-1? typefix["shadowsocksr"] : typefix["shadowsocks"]
tp = typefix[item.split("=")[0].trim()][ind]
return tp
}
}
// 操作節點類型佔位符
function type_handle(item) {
if(item.indexOf("node_type_para_prefix")!=-1) {
item = item.replace(/node_type_para_prefix(\d{0,1})/g,getnode_type(item,item.split("node_type_para_prefix")[1][0]))
}
return item
}
// 节点序号占位符处理
function index_handle(item) {
items = item.map(item=>item.trim()).filter(Boolean)
let b=Array.from(new Array(items.length),(val,index)=>index+1);
//console.log(b[0])
for (var i=0; i< items.length;i++){
//$notify("rename"+i,Prname,items[i])
if (items[i].indexOf("node_index_prefix") != -1) { // 以免占位符被错误地replace
ind = items[i].split("node_index_prefix")[1][0]
ind = !/^(0|1|2|3|4|5|6|7|8)$/.test(ind) ? 0 : ind
console.log("handle index"+ind)
items[i] = items[i].replace(/node_index_prefix(\d{0,1})/g,PatternN((i+1).toString(),"",ind))
}
}
console.log(items)
return items
}
// 操作emoji占位符
function emoji_prefix_handle(item) {
if(item.indexOf("node_emoji_flag_prefix")!=-1) {
item = item.replace(/node_emoji_flag_prefix\d{0,1}/g,getnode_emoji(item,item.split("node_emoji_flag_prefix")[1][0]))
//console.log(item)
}
return item
}
// 获取emoji
function getnode_emoji(item,ind){
ind = !/^(1|2)$/.test(ind) ? 2 : ind
if(item.indexOf("tag=")!=-1) {
return get_emoji(ind,item.split("tag=")[1])[1]
}
}
// 操作订阅的 tag
function tag_handle(item) {
if(item.indexOf("node_tag_prefix")!=-1) {
//item = item.replace(/node_tag_prefix/g,subtag)
//console.log(item.split("node_tag_prefix")[1][1])
ptnn = /\d/.test(item.split("node_tag_prefix")[1][0])? item.split("node_tag_prefix")[1][0]:""
nptnn = /\d/.test(item.split("node_tag_prefix")[1][1])? item.split("node_tag_prefix")[1][1]:""
//console.log(ptnn)
item = item.replace(/node_tag_prefix\d{0,2}/g,PatternN(subtag,ptnn,nptnn))
}
return item
}
// 用于单条 URI 的 tag 参数, 直接指定节点名
function URI_TAG(cnt0,tag0) {
cnt0 = cnt0.split("tag=")[0] + "tag=" + tag0
return cnt0
}
// 方便代理链的实现
function ServerRelay(src,dst) {
var rsts=[]
for (var i=0; i<src.length; i++) {
serverA = src[i].indexOf("-host")==-1? src[i].split("=")[1].split(":")[0].trim() : src[i].split("-host")[1].split("=")[1].split(",")[0].trim()
type = /^[a-z]/.test(serverA) || /[a-z]$/.test(serverA)? "host":"ip"
rst = type == "ip"? "ip-cidr,"+serverA+"/32,"+dst : "host-suffix,"+serverA+","+dst
rsts.push(rst)
}
return rsts.join("\n")
}
// 用于某些奇葩用户不使用 raw 链接的问题
function rawtest(cnt) {
var Preg0 = RegExp(".*js-file-line\".*?\<\/td\>", "i")
if (Preg0.test(cnt)) {
return cnt.replace(/(.*js-file-line\"\>)(.*?)(\<\/td\>)/g,"$2").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").trim()
}
}
function ToRaw(cnt) {
cnt = cnt.split("\n").map(rawtest).filter(Boolean).join("\n")
var rawlink = link0.replace("github.com","raw.githubusercontent.com").replace("/blob","")
if (cnt) {
$notify( "⚠️⚠️ 将尝试解析该资源" + "⟦" + subtag + "⟧" , "🚥 请正确使用GitHub的 raw 链接" , "❌ 你的链接:"+link0+"\n✅ 正确链接:"+rawlink, {"open-url":rawlink})
} else if(content0.indexOf("gridcell")!=-1) {
$notify( "⚠️⚠️ 解析该资源" + " ⟦" + subtag + "⟧ 失败" , "🚥 你的链接似乎是目录,而不是文件" , "❌ 你的链接:"+link0, {"open-url":link0})
}
return cnt
}
function CDN(cnt) {
console.log("CDN start")
cnt = cnt.join("\n").replace(/https:\/\/raw.githubusercontent.com\/(.*?)\/(.*?)\/(.*)/gmi,"https://fastly.jsdelivr.net/gh/$1/$2@$3")
return cnt
}
// 指定节点 host 参数
function HOST_Handle(cnt,phost) {
phost="host="+phost+","
if (phost.indexOf("☠️") == -1) { //只替换已有host类型
cnt = cnt.replace(/host\s*\=(.*?)\,/,phost)
} else { // 为已有的替换,为没有的增加 obfs-host\tls-host
phost=phost.split("☠️")[0]
if (/-host\s*\=/.test(cnt)) {// 如已有 host 参数
cnt = cnt.replace(/host\s*\=(.*?)\,/,phost+", ")
} else if (/over-tls\s*\=\s*true/.test(cnt)) { // 如无host,但可以增加
cnt = cnt+", tls-"+phost
} else if (/obfs\s*\=/.test(cnt)) {
cnt = cnt + ", obfs-"+phost
}
}
return cnt
}
// 指定节点 obfs=xx-http 参数
function OBFS_Handle(cnt,pobfs) {
if (pobfs == "shttp") {
pobfs="obfs="+"shadowsocks-http"
} else if (pobfs == "vhttp") {
pobfs="obfs="+"vmess-http"
} else {
pobfs="invalid"
}
if (/obfs\s*\=\s*http/.test(cnt) && pobfs!="invalid") { //只替换有 obfs=http 参数
cnt = cnt.replace(/obfs\s*\=\s*http/,pobfs)
}
return cnt
}
// 指定节点 tls-no-session-ticket/reuse 参数
function Session_Handle(cnt,psession) {
let st = ", tls-no-session-ticket=true"
let sr = ", tls-no-session-reuse=true"
if (psession == 0) {
cnt =cnt + st
} else if (psession == 1) {
cnt =cnt + sr
} else if (psession == 2){
cnt =cnt + st + sr
}
return cnt
}
// 指定 cert-sha256 pubkey-sha256 参数
function SHA256_Handle(cnt,pcsha256,ppsha256) {
if (cnt.indexOf("over-tls=true")!=-1 || cnt.indexOf("obfs=wss")!=-1) {
cnt = cnt.replace(/tls-verification\s*\=\s*false(\s*)\,/,"") //去除 tls-verification=false
//$notify("SHA256",cnt,Pcsha256+Ppsha256)
cnt = pcsha256!=""? cnt.replace(/tag\s*\=/,"tls-cert-sha256="+pcsha256+", tag=") : cnt
cnt = ppsha256!=""? cnt.replace(/tag\s*\=/,"tls-pubkey-sha256="+ppsha256+", tag=") : cnt
}
return cnt
}