1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 15:24:42 -05:00

Auto detect if need country group

This commit is contained in:
Nite07 2024-10-01 12:45:55 +08:00
parent 59a258f4ef
commit 5fea337b6c
3 changed files with 10 additions and 4 deletions

View File

@ -21,13 +21,15 @@ data 为 base64 URL 编码(将编码字符串中`/`替换为`_``+`替换为`-
"template": "模板路径/网络地址",
"delete": "",
"rename": {"原文本": "新文本"},
"group": false,
"group-type": "selector",
"sort": "name",
"sort-type": "asc"
}
```
该 JSON 同时可用于 `convert``--config` 参数,以便本地生成 sing-box 配置。
例如将上方 JSON 内容存放于 `config.json` 后执行 `sub2sing-box convert -c ./config.json` 即可生成 sing-box 配置,免去每次生成时重复设置参数
## Template 占位符
- `<all-proxy-tags>`: 插入所有节点标签

View File

@ -19,7 +19,6 @@ var (
output string
delete string
rename map[string]string
group bool
groupType string
sortKey string
sortType string
@ -33,7 +32,6 @@ func init() {
convertCmd.Flags().StringVarP(&output, "output", "o", "", "output file path")
convertCmd.Flags().StringVarP(&delete, "delete", "d", "", "delete proxy with regex")
convertCmd.Flags().StringToStringVarP(&rename, "rename", "r", nil, "rename proxy with regex")
convertCmd.Flags().BoolVarP(&group, "group", "g", false, "group proxies by country")
convertCmd.Flags().StringVarP(&groupType, "group-type", "G", "selector", "group type, selector or urltest")
convertCmd.Flags().StringVarP(&sortKey, "sort", "S", "tag", "sort key, tag or num")
convertCmd.Flags().StringVarP(&sortType, "sort-type", "T", "asc", "sort type, asc or desc")

View File

@ -90,7 +90,13 @@ func Convert(
return "", err
}
reg := regexp.MustCompile("\"<[A-Za-z]{2}>\"")
if reg.MatchString(templateDate) || strings.Contains(templateDate, constant.AllCountryTags) {
group := false
for _, v := range model.CountryEnglishName {
if strings.Contains(templateDate, v) {
group = true
}
}
if reg.MatchString(templateDate) || strings.Contains(templateDate, constant.AllCountryTags) || group {
outbounds = AddCountryGroup(outbounds, groupType, sortKey, sortType)
}
var template model.Config