-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmihomoScript.js
More file actions
1479 lines (1319 loc) · 49.8 KB
/
Copy pathmihomoScript.js
File metadata and controls
1479 lines (1319 loc) · 49.8 KB
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
/**
* mihomo配置覆写脚本(全量版)
* 作者:AIsouler
* 源仓库:https://github.com/AIsouler/MyClash
* 脚本链接:https://raw.githubusercontent.com/AIsouler/MyClash/main/Script/mihomoScript.js
* 友情推荐,非常好用、省电且内存占用低的代理软件:https://github.com/appshubcc/Bettbox
*/
// --- 静态配置区域 ---
// 适配 Bettbox 自定义配置参数
const Compatible_With_Bettbox = { ruleOptionsEnable: true };
/**
* 自定义配置选项
* true = 启用
* false = 禁用
*/
const ruleOptionsEnable = {
// 基础策略组
手动选择: true, // 是否启用手动选择策略组
自动选择: true, // 是否启用自动选择策略组
负载均衡: true, // 是否启用负载均衡策略组
// 以下为分流策略配置
AI: true, // 国外AI服务
Media: true, // 国外视频平台
FCM: true, // GoogleFCM服务
Google: true, // Google服务
Microsoft: true, // Microsoft服务
Apple: true, // Apple服务
Telegram: true, // Telegram通讯软件
Steam: true, // Steam游戏平台
TikTok: true, // TikTok视频平台
Twitter: true, // Twitter社交平台
Emby: true, // Emby媒体服务
PikPak: true, // PikPak网盘服务
Spotify: true, // Spotify音乐服务
Crypto: true, // 加密货币相关服务
EHentai: true, // E-Hentai网站
AdBlock: true, // 广告拦截
// 以下为非分流策略配置
生成地区自动选择组: true, // 是否生成地区自动选择策略组
隐藏地区手动选择组: false, // 是否隐藏地区手动选择策略组
生成倍率组: true, // 是否生成低倍率/高倍率策略组
分流组添加所有节点: false, // 是否为分流策略组添加所有节点
过滤高倍率节点: false, // 是否过滤高倍率节点
过滤非地区节点: true, // 是否过滤非地区节点
屏蔽国外QUIC: true, // 是否屏蔽国外QUIC流量
链式代理: false, // 是否启用链式代理(自定义节点作为落地节点,经“链式中转”策略组中转)
};
// 定义前置规则
const prefixRules = [
// 私有网络直连
'RULE-SET,private,直连',
// 国内直连
'RULE-SET,games_cn,直连', // 已包含 steam 下载域名
'RULE-SET,epicgames,直连',
'RULE-SET,nvidia_cn,直连',
'RULE-SET,apple_cn,直连',
'RULE-SET,microsoft_cn,直连',
'DOMAIN,fsend.cn,直连',
'DOMAIN,international-gfe.download.nvidia.com,直连',
'DOMAIN-SUFFIX,hdslb.com,直连',
];
// 此处添加自定义节点,填入下方[]内(可选,留空则不生成“自建节点”策略组)
// 自定义节点不参与节点过滤与 hosts 改写;与订阅节点(标准化后)重名时自动添加“自建-”前缀
// 示例:
// const customizeProxies = [
// {
// name: '自建-日本-01',
// type: 'vmess',
// server: '5.6.7.8',
// port: 443,
// uuid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// alterId: 0,
// cipher: 'auto',
// tls: true,
// servername: 'example.com',
// network: 'ws',
// 'ws-opts': {
// path: '/path',
// headers: { Host: 'example.com' },
// },
// },
// ];
const customizeProxies = [];
// 链式代理启用时,自定义节点的 dialer-proxy 引用目标
const dialerProxyName = '链式中转';
// 定义全局排除节点的正则表达式,用于排除非地区节点
const excludeFilter =
/群|返利|循环|官网|客服|网站|网址|获取|订阅|流量|到期|机场|下次|版本|官址|备用|过期|已用|联系|邮箱|工单|贩卖|通知|倒卖|防止|国内|地址|频道|无法|说明|使用|提示|访问|支持|教程|关注|更新|作者|加入|超时|收藏|福利|邀请|好友|失联|选择|剩余|公益|发布|DIZTNA|通路|登录|禁止|定时|渠道|牢记|永久|余额|阁下|本站|刷新|导航|建议|重置|以下|⚠️|@|\bexpire\b|\bhttps?:\/\/|\.com|\btraffic\b/iu;
// 屏蔽国外QUIC
const blockForeignQuic = [
'AND,((NETWORK,UDP),(DST-PORT,443),(NOT,((OR,((RULE-SET,cn_additional),(RULE-SET,cn_ip,no-resolve)))))),REJECT',
];
// 直连节点
const directProxies = [
{
name: '🇨🇳 直连 | 双栈',
type: 'direct',
},
{
name: '🇨🇳 直连 | IPv4优先',
type: 'direct',
'ip-version': 'ipv4-prefer',
},
{
name: '🇨🇳 直连 | IPv6优先',
type: 'direct',
'ip-version': 'ipv6-prefer',
},
];
// 定义地区策略组
const regionDefinitions = [
{
name: '香港',
flag: '🇭🇰',
regex: /🇭🇰|香港|(?<![A-Za-z])HKG?(?![A-Za-z])|hong\s*kong/i,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Hong_Kong.png',
},
{
name: '日本',
flag: '🇯🇵',
regex: /🇯🇵|日本|(?<![A-Za-z])JPN?(?![A-Za-z])|japan/i,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Japan.png',
},
{
name: '美国',
flag: '🇺🇸',
regex: /🇺🇸|美国|(?<![A-Za-z])USA?(?![A-Za-z])|america|united\s*states/i,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/United_States.png',
},
{
name: '新加坡',
flag: '🇸🇬',
regex: /🇸🇬|新加坡|狮城|(?<![A-Za-z])SGP?(?![A-Za-z])|singapore/i,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Singapore.png',
},
{
name: '台湾省',
flag: '🇹🇼',
regex: /🇹🇼|台湾|(?<![A-Za-z])TWN?(?![A-Za-z])|taiwan/i,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Taiwan.png',
},
];
// 定义倍率策略组
const lowRateRegionName = '低倍率节点';
const highRateRegionName = '高倍率节点';
const rateRegionDefinitions = [
{
name: lowRateRegionName,
regex: /^(?!.*(?:剩|期|客户端|软件)).*(?:(?<!\d)0\.[0-5]|下载|低倍)/,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Available_1.png',
},
{
name: highRateRegionName,
regex:
/(?:[*×xX✕✖⨉]\s*(?:[2-9]\d*|[1-9]\d+)(?:\.\d+)?)|(?:(?<![\d.])(?:[2-9]\d*|[1-9]\d+)(?:\.\d+)?\s*(?:倍|[*×xX✕✖⨉]))/u,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Airport.png',
},
];
// 全部策略组定义(地区 + 倍率),统一用于节点匹配与归类
const allRegionDefinitions = [...regionDefinitions, ...rateRegionDefinitions];
// Rule Providers 通用配置
const ruleProviderCommonDomain = {
type: 'http',
format: 'mrs',
interval: 86400,
behavior: 'domain',
};
const ruleProviderCommonIpcidr = {
type: 'http',
format: 'mrs',
interval: 86400,
behavior: 'ipcidr',
};
// 定义基础 Rule Providers
const baseRuleProviders = {
// --- 直连规则集 ---
private: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/private.mrs',
path: './ruleset/private.mrs',
'path-in-bundle': 'geo/geosite/private.mrs',
},
private_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/private.mrs',
path: './ruleset/private_ip.mrs',
'path-in-bundle': 'geo/geoip/private.mrs',
},
games_cn: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/category-games@cn.mrs',
path: './ruleset/category-games@cn.mrs',
'path-in-bundle': 'geo/geosite/category-games@cn.mrs',
},
epicgames: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/epicgames.mrs',
path: './ruleset/epicgames.mrs',
'path-in-bundle': 'geo/geosite/epicgames.mrs',
},
nvidia_cn: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/nvidia@cn.mrs',
path: './ruleset/nvidia@cn.mrs',
'path-in-bundle': 'geo/geosite/nvidia@cn.mrs',
},
apple_cn: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/apple@cn.mrs',
path: './ruleset/apple@cn.mrs',
'path-in-bundle': 'geo/geosite/apple@cn.mrs',
},
microsoft_cn: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/microsoft@cn.mrs',
path: './ruleset/microsoft@cn.mrs',
'path-in-bundle': 'geo/geosite/microsoft@cn.mrs',
},
'geolocation-cn': {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/geolocation-cn.mrs',
path: './ruleset/geolocation-cn.mrs',
'path-in-bundle': 'geo/geosite/geolocation-cn.mrs',
},
cn_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/cn.mrs',
path: './ruleset/cn_ip.mrs',
'path-in-bundle': 'geo/geoip/cn.mrs',
},
// --- 代理规则集 ---
gfw: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/gfw.mrs',
path: './ruleset/gfw.mrs',
'path-in-bundle': 'geo/geosite/gfw.mrs',
},
// --- 其他规则集 ---
fakeip_filter: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/wwqgtxx/clash-rules@release/fakeip-filter.mrs',
path: './ruleset/fakeip-filter.mrs',
'path-in-bundle': 'geo/geosite/private.mrs',
},
cn_additional: {
...ruleProviderCommonDomain,
url: 'https://static-file-global.353355.xyz/rules/cn-additional-list.mrs',
path: './ruleset/cn-additional-list.mrs',
'path-in-bundle': 'geo/geosite/cn.mrs',
},
cn: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/wwqgtxx/clash-rules@release/direct.mrs',
path: './ruleset/cn.mrs',
'path-in-bundle': 'geo/geosite/cn.mrs',
},
};
// 策略组公共配置
const groupBaseOption = {
interval: 600,
timeout: 3000,
url: 'https://g.cn/generate_204',
lazy: true,
'max-failed-times': 3,
'empty-fallback': 'REJECT',
};
// select策略组通用配置
const selectBaseOption = {
...groupBaseOption,
type: 'select',
};
// url-test策略组通用配置
const urlTestBaseOption = {
...groupBaseOption,
type: 'url-test',
tolerance: 50,
'exclude-type': 'DIRECT',
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Auto.png',
hidden: true,
};
// load-balance策略组通用配置
const loadBalanceBaseOption = {
...groupBaseOption,
type: 'load-balance',
strategy: 'sticky-sessions',
'exclude-type': 'DIRECT',
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Round_Robin.png',
hidden: true,
};
// 定义基础策略组
const baseGroups = [
{
name: '手动选择',
baseOption: selectBaseOption,
includeAll: true,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Static.png',
},
{
name: '自动选择',
baseOption: urlTestBaseOption,
includeAll: true,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Auto.png',
},
{
name: '负载均衡',
baseOption: loadBalanceBaseOption,
includeAll: true,
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Round_Robin.png',
},
];
// 定义分流策略组配置
const serviceConfigs = [
...baseGroups,
{
name: 'AI',
baseOption: selectBaseOption,
defaultSelected: '美国',
providers: {
ai: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/category-ai-!cn.mrs',
path: './ruleset/ai.mrs',
'path-in-bundle': 'geo/geosite/category-ai-!cn.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/ChatGPT.png',
rules: ['RULE-SET,ai,AI'],
},
{
name: 'Media',
baseOption: selectBaseOption,
defaultSelected: '日本',
providers: {
youtube: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/youtube.mrs',
path: './ruleset/youtube.mrs',
'path-in-bundle': 'geo/geosite/youtube.mrs',
},
instagram: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/instagram.mrs',
path: './ruleset/instagram.mrs',
'path-in-bundle': 'geo/geosite/instagram.mrs',
},
netflix: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/netflix.mrs',
path: './ruleset/netflix.mrs',
'path-in-bundle': 'geo/geosite/netflix.mrs',
},
netflix_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/netflix.mrs',
path: './ruleset/netflix_ip.mrs',
'path-in-bundle': 'geo/geoip/netflix.mrs',
},
hbo: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/hbo.mrs',
path: './ruleset/hbo.mrs',
'path-in-bundle': 'geo/geosite/hbo.mrs',
},
twitch: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/twitch.mrs',
path: './ruleset/twitch.mrs',
'path-in-bundle': 'geo/geosite/twitch.mrs',
},
disney: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/disney.mrs',
path: './ruleset/disney.mrs',
'path-in-bundle': 'geo/geosite/disney.mrs',
},
niconico: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/niconico.mrs',
path: './ruleset/niconico.mrs',
'path-in-bundle': 'geo/geosite/niconico.mrs',
},
bbc: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/bbc.mrs',
path: './ruleset/bbc.mrs',
'path-in-bundle': 'geo/geosite/bbc.mrs',
},
pornhub: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/pornhub.mrs',
path: './ruleset/pornhub.mrs',
'path-in-bundle': 'geo/geosite/pornhub.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/ForeignMedia.png',
rules: [
'RULE-SET,youtube,Media',
'RULE-SET,instagram,Media',
'RULE-SET,netflix,Media',
'RULE-SET,netflix_ip,Media,no-resolve',
'RULE-SET,hbo,Media',
'RULE-SET,twitch,Media',
'RULE-SET,disney,Media',
'RULE-SET,niconico,Media',
'RULE-SET,bbc,Media',
'RULE-SET,pornhub,Media',
],
},
{
name: 'FCM',
baseOption: selectBaseOption,
direct: true,
defaultSelected: '直连',
providers: {
googlefcm: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/googlefcm.mrs',
path: './ruleset/googlefcm.mrs',
'path-in-bundle': 'geo/geosite/googlefcm.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/MiToverG422/Qure@master/IconSet/Color/fcm.png',
rules: ['RULE-SET,googlefcm,FCM'],
},
{
name: 'Google',
baseOption: selectBaseOption,
providers: {
google: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/google.mrs',
path: './ruleset/google.mrs',
'path-in-bundle': 'geo/geosite/google.mrs',
},
google_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/google.mrs',
path: './ruleset/google_ip.mrs',
'path-in-bundle': 'geo/geoip/google.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Google_Search.png',
rules: ['RULE-SET,google,Google', 'RULE-SET,google_ip,Google,no-resolve'],
},
{
name: 'Microsoft',
baseOption: selectBaseOption,
direct: true,
providers: {
github: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/github.mrs',
path: './ruleset/github.mrs',
'path-in-bundle': 'geo/geosite/github.mrs',
},
microsoft: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/microsoft.mrs',
path: './ruleset/microsoft.mrs',
'path-in-bundle': 'geo/geosite/microsoft.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Microsoft.png',
rules: ['RULE-SET,github,默认代理', 'RULE-SET,microsoft,Microsoft'],
},
{
name: 'Apple',
baseOption: selectBaseOption,
direct: true,
providers: {
apple: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/apple.mrs',
path: './ruleset/apple.mrs',
'path-in-bundle': 'geo/geosite/apple.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Apple.png',
rules: ['RULE-SET,apple,Apple'],
},
{
name: 'Telegram',
baseOption: selectBaseOption,
providers: {
telegram: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/telegram.mrs',
path: './ruleset/telegram.mrs',
'path-in-bundle': 'geo/geosite/telegram.mrs',
},
telegram_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/telegram.mrs',
path: './ruleset/telegram_ip.mrs',
'path-in-bundle': 'geo/geoip/telegram.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Telegram.png',
rules: ['RULE-SET,telegram,Telegram', 'RULE-SET,telegram_ip,Telegram,no-resolve'],
},
{
name: 'Steam',
baseOption: selectBaseOption,
direct: true,
providers: {
steam: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/steam.mrs',
path: './ruleset/steam.mrs',
'path-in-bundle': 'geo/geosite/steam.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Steam.png',
rules: ['RULE-SET,steam,Steam'],
},
{
name: 'TikTok',
baseOption: selectBaseOption,
defaultSelected: '日本',
providers: {
tiktok: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/tiktok.mrs',
path: './ruleset/tiktok.mrs',
'path-in-bundle': 'geo/geosite/tiktok.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/TikTok.png',
rules: ['RULE-SET,tiktok,TikTok'],
},
{
name: 'Twitter',
baseOption: selectBaseOption,
providers: {
twitter: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/twitter.mrs',
path: './ruleset/twitter.mrs',
'path-in-bundle': 'geo/geosite/twitter.mrs',
},
twitter_ip: {
...ruleProviderCommonIpcidr,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geoip/twitter.mrs',
path: './ruleset/twitter_ip.mrs',
'path-in-bundle': 'geo/geoip/twitter.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Twitter.png',
rules: ['RULE-SET,twitter,Twitter', 'RULE-SET,twitter_ip,Twitter,no-resolve'],
},
{
name: 'Emby',
baseOption: selectBaseOption,
direct: true,
providers: {
emby: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/666OS/rules@release/mihomo/domain/Emby.mrs',
path: './ruleset/emby.mrs',
'path-in-bundle': 'geo/geosite/category-emby.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Emby.png',
rules: [
'RULE-SET,emby,Emby',
'DOMAIN-SUFFIX,mb3admin.com,Emby',
'DOMAIN-SUFFIX,nubebelle.com,Emby',
'DOMAIN-KEYWORD,emby,Emby',
'PROCESS-NAME,com.mb.android,Emby',
'PROCESS-NAME,tv.emby.embyatv,Emby',
'PROCESS-NAME,com.hush.yamby,Emby',
'PROCESS-NAME,com.jellycine.app,Emby',
'PROCESS-NAME,com.mountains.hills,Emby',
'PROCESS-NAME,RodelPlayer.App.exe,Emby',
'PROCESS-NAME,com.feifeiduck.capyplayer,Emby',
],
},
{
name: 'PikPak',
baseOption: selectBaseOption,
direct: true,
providers: {
pikpak: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/pikpak.mrs',
path: './ruleset/pikpak.mrs',
'path-in-bundle': 'geo/geosite/pikpak.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/lige47/QuanX-icon-rule@main/icon/03CNSoft/pikpak.png',
rules: ['RULE-SET,pikpak,PikPak'],
},
{
name: 'Spotify',
baseOption: selectBaseOption,
direct: true,
providers: {
spotify: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/spotify.mrs',
path: './ruleset/spotify.mrs',
'path-in-bundle': 'geo/geosite/spotify.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Spotify.png',
rules: ['RULE-SET,spotify,Spotify'],
},
{
name: 'Crypto',
baseOption: selectBaseOption,
defaultSelected: '日本',
providers: {
cryptocurrency: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/category-cryptocurrency.mrs',
path: './ruleset/cryptocurrency.mrs',
'path-in-bundle': 'geo/geosite/category-cryptocurrency.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/lige47/QuanX-icon-rule@main/icon/04ProxySoft/Bitcoin.png',
rules: ['RULE-SET,cryptocurrency,Crypto'],
},
{
name: 'EHentai',
baseOption: selectBaseOption,
defaultSelected: '美国',
providers: {
ehentai: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@meta/geo/geosite/ehentai.mrs',
path: './ruleset/ehentai.mrs',
'path-in-bundle': 'geo/geosite/ehentai.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/lige47/QuanX-icon-rule@main/icon/04ProxySoft/exhentai.png',
rules: ['RULE-SET,ehentai,EHentai'],
},
{
name: 'AdBlock',
baseOption: selectBaseOption,
reject: true,
providers: {
adblockmihomolite: {
...ruleProviderCommonDomain,
url: 'https://fastly.jsdelivr.net/gh/217heidai/adblockfilters@main/rules/adblockmihomolite.mrs',
path: './ruleset/adblockmihomolite.mrs',
'path-in-bundle': 'geo/geosite/category-ads-all.mrs',
},
},
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Advertising.png',
rules: ['RULE-SET,adblockmihomolite,AdBlock'],
},
];
// ---节点过滤、重命名及验证---
/**
* 节点匹配缓存,避免重复执行正则
*/
const regionMatchCache = new Map();
function getMatchedRegions(proxyName) {
if (regionMatchCache.has(proxyName)) {
return regionMatchCache.get(proxyName);
}
const regions = allRegionDefinitions.filter((region) => region.regex.test(proxyName));
regionMatchCache.set(proxyName, regions);
return regions;
}
/**
* 标准化节点名称:补全地区国旗、折叠多余空格,并预缓存匹配结果
*/
const flagRegex = /[\u{1F1E6}-\u{1F1FF}]{2}/u;
function normalizeProxyName(proxy) {
const originalName = proxy.name;
// 提取节点原有国旗
const flag = originalName.match(flagRegex)?.[0];
// 有国旗时移除国旗,再移除多余空格
const nameWithoutFlag = (flag ? originalName.replace(flag, '') : originalName).replace(/\s+/g, ' ').trim();
const matchedRegions = getMatchedRegions(originalName);
// 如果已有国旗则直接使用原国旗
// 如果没有国旗,则从地区匹配结果中取地区国旗
const regionFlag = flag || matchedRegions.find((region) => region.flag)?.flag;
const normalizedName = regionFlag ? `${regionFlag} ${nameWithoutFlag}` : nameWithoutFlag;
// 预缓存标准化后的节点名称,供后续构建策略组复用
if (normalizedName !== originalName) {
regionMatchCache.set(normalizedName, matchedRegions);
}
return normalizedName === originalName ? proxy : { ...proxy, name: normalizedName };
}
/**
* 修复 dialer-proxy 引用:目标被重命名则更新,被移除或不存在则删除引用
*/
function fixDialerProxy(proxy, renameMap, normalizedProxyNames) {
const target = proxy['dialer-proxy'];
if (!target) return proxy;
// 目标节点被重命名 → 更新引用为标准化后的名称
if (renameMap.has(target)) {
return { ...proxy, 'dialer-proxy': renameMap.get(target) };
}
// 目标节点被保留且未重命名 → 引用依然有效
if (normalizedProxyNames.has(target)) {
return proxy;
}
// 目标节点被过滤移除(或引用目标本就不存在)→ 删除引用,避免引用不存在的节点
const copy = { ...proxy };
delete copy['dialer-proxy'];
return copy;
}
/**
* 过滤并标准化节点:剔除内置/信息节点、按配置过滤、去重、修复 dialer-proxy 引用,空列表时抛错
*/
function filterAndNormalizeProxies(config) {
// 清空缓存,避免上次运行残留的旧名称
regionMatchCache.clear();
const filterHighRateProxiesEnabled = ruleOptionsEnable.过滤高倍率节点;
const filterNonRegionProxiesEnabled = ruleOptionsEnable.过滤非地区节点;
const highRateRegex = filterHighRateProxiesEnabled
? rateRegionDefinitions.find((r) => r.name === highRateRegionName)?.regex
: null;
const originalProxies = config.proxies || [];
// 过滤节点列表(尚未重命名)
const filteredRawProxies = originalProxies.filter((proxy) => {
const type = String(proxy.type ?? '').toLowerCase();
if (type === 'direct' || type === 'reject' || type === 'rematch') return false;
if (highRateRegex?.test(proxy.name)) return false;
if (!filterNonRegionProxiesEnabled) return true;
const isRegionProxy = getMatchedRegions(proxy.name).some((region) => regionDefinitions.includes(region));
return isRegionProxy || !excludeFilter.test(proxy.name);
});
// 重命名映射:原名称 -> 标准化后的名称
const renameMap = new Map();
// 标准化节点名称并去重(保留首个同名节点)
const normalizedProxies = [];
const uniqueNames = new Set();
for (const rawProxy of filteredRawProxies) {
const normalized = normalizeProxyName(rawProxy);
if (normalized.name !== rawProxy.name) {
renameMap.set(rawProxy.name, normalized.name);
}
if (!uniqueNames.has(normalized.name)) {
uniqueNames.add(normalized.name);
normalizedProxies.push(normalized);
}
}
// 标准化后的节点名称集合(用于判断 dialer-proxy 引用目标是否仍有效)
const normalizedProxyNames = new Set(normalizedProxies.map((p) => p.name));
// 修复 dialer-proxy 引用
const filteredProxies = normalizedProxies.map((proxy) => fixDialerProxy(proxy, renameMap, normalizedProxyNames));
// 验证节点列表是否存在代理节点
if (!filteredProxies.length) {
throw new Error('配置文件中未找到任何代理节点,请使用机场提供的配置文件进行覆写');
}
return filteredProxies;
}
// ---构建地区组和倍率组---
/**
* 构建地区策略组,可附带自动选择组
*/
function createRegionGroup(name, icon, proxies) {
const generateRegionAutoSelectEnabled = ruleOptionsEnable.生成地区自动选择组;
const hideManualSelectGroupEnabled = ruleOptionsEnable.隐藏地区手动选择组;
if (generateRegionAutoSelectEnabled) {
const urlTestName = `${name}-自动选择`;
return [
{
...urlTestBaseOption,
name: urlTestName,
proxies,
},
{
...selectBaseOption,
name,
icon,
proxies: [urlTestName, ...proxies],
hidden: hideManualSelectGroupEnabled,
},
];
}
return [
{
...selectBaseOption,
name,
icon,
proxies,
hidden: hideManualSelectGroupEnabled,
},
];
}
/**
* 将节点按地区/倍率归类,构建地区策略组、倍率策略组与“其他节点”组
*/
function buildRegionGroups(filteredProxies) {
const generateRateGroupEnabled = ruleOptionsEnable.生成倍率组;
// 节点分类
const regionGroups = Object.fromEntries(allRegionDefinitions.map(({ name }) => [name, []]));
const otherProxies = [];
for (const proxy of filteredProxies) {
const matchedRegions = getMatchedRegions(proxy.name);
const isRegionProxy = matchedRegions.some((region) => regionDefinitions.includes(region));
for (const region of matchedRegions) {
regionGroups[region.name].push(proxy.name);
}
if (!isRegionProxy) {
otherProxies.push(proxy.name);
}
}
// 构建 地区/倍率 策略组
const generatedRegionGroups = allRegionDefinitions
.filter((r) => regionGroups[r.name].length > 0 && (generateRateGroupEnabled || !rateRegionDefinitions.includes(r)))
.flatMap((r) => createRegionGroup(r.name, r.icon, regionGroups[r.name]));
if (otherProxies.length > 0) {
generatedRegionGroups.push(
...createRegionGroup(
'其他节点',
'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/World_Map.png',
otherProxies,
),
);
}
return generatedRegionGroups;
}
// ---构建自定义节点组---
/**
* 处理自定义节点:标准化名称、与订阅节点重名时添加“自建-”前缀、内部去重,
* 并构建“自建节点”策略组。
* 自定义节点不参与订阅节点过滤,也不参与 hosts 改写及 DNS 域名处理。
*/
function buildCustomizeGroups(filteredProxies, customizeList = customizeProxies) {
const chainEnabled = ruleOptionsEnable.链式代理;
// 未配置自定义节点时直接返回空结果
if (!customizeList.length) {
if (chainEnabled) {
throw new Error('启用失败,请在脚本中添加自定义节点后尝试');
}
return { customProxies: [], customProxyNames: [], customGroup: null };
}
// 订阅节点标准化后的名称集合,用于重名判断
const usedNames = new Set(filteredProxies.map((p) => p.name));
// 重名时使用的前缀
const customPrefix = '自建-';
// 标准化自定义节点并解决重名冲突(与订阅节点重名或自定义节点间重名)
const customProxies = [];
for (const proxy of customizeList) {
const normalized = normalizeProxyName(proxy);
let name = normalized.name;
// 重名时添加前缀并重新标准化(国旗自动回到最前),直至名称唯一;
// 标准化会重建“国旗 + 空格 + 名称”格式,这里去掉前缀后多余的空格
while (usedNames.has(name)) {
name = normalizeProxyName({ name: `${customPrefix}${name}` }).name.replace(`${customPrefix} `, customPrefix);
}
usedNames.add(name);
let customProxy = name === normalized.name ? normalized : { ...normalized, name };
// 链式代理启用时强制添加/覆盖 dialer-proxy,使自定义节点经“链式中转”策略组中转
if (chainEnabled && customProxy['dialer-proxy'] !== dialerProxyName) {
customProxy = { ...customProxy, 'dialer-proxy': dialerProxyName };
}
customProxies.push(customProxy);
}
// 自建节点/链式落地 策略组
const customGroup = {
...selectBaseOption,
name: chainEnabled ? '链式落地' : '自建节点',
proxies: customProxies.map((p) => p.name),
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Server.png',
};
return {
customProxies,
customProxyNames: customProxies.map((p) => p.name),
customGroup,
};
}
// ---构建基础策略组和分流策略组---
/**
* 构建基础/分流策略组、GLOBAL 组与规则集,并汇总分流规则
*/
function buildFunctionalGroups(filteredProxies, generatedRegionGroups, customizeInfo) {
const blockForeignQuicEnabled = ruleOptionsEnable.屏蔽国外QUIC;
const addAllNodesToServiceGroupsEnabled = ruleOptionsEnable.分流组添加所有节点;
const chainEnabled = ruleOptionsEnable.链式代理;
const hideManualSelectGroupEnabled = ruleOptionsEnable.隐藏地区手动选择组;
const functionalGroups = [];
const functionalRules = [];
const finalRuleProviders = { ...baseRuleProviders };
// cn_additional 规则集仅服务于 “屏蔽国外QUIC” 规则,关闭该选项时无需生成
if (!blockForeignQuicEnabled) {
delete finalRuleProviders.cn_additional;
}
// 自定义节点信息(未配置自定义节点时为空)
const { customProxyNames = [], customGroup = null } = customizeInfo || {};
// 筛选后的节点名称列表(不含自定义节点)
const filteredProxyNames = filteredProxies.map((p) => p.name);
// 获取所有节点名称(自定义节点优先,便于在基础策略组中查看)
const allProxiesNames = [...customProxyNames, ...filteredProxyNames];
// 筛选类型为 select 的地区策略组
const groupNamesOfSelect = generatedRegionGroups.filter((g) => g.type === 'select').map((g) => g.name);
// 获取基础策略组名称
const baseGroupNames = baseGroups.filter((g) => ruleOptionsEnable[g.name]).map((g) => g.name);
// 自建节点策略组名称(未配置自定义节点时为空数组)
const customGroupNames = customGroup ? [customGroup.name] : [];
functionalGroups.push({
...selectBaseOption,
name: '默认代理',
proxies: [...groupNamesOfSelect, ...baseGroupNames, ...customGroupNames],
icon: 'https://fastly.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/Proxy.png',
});
// 分流规则与规则集收集(AdBlock 规则优先,避免广告域名被其他分流规则抢先匹配)
const orderedServiceConfigs = [
...serviceConfigs.filter((svc) => svc.name === 'AdBlock'),