modify rules order
This commit is contained in:
parent
50588b2b0e
commit
2e30d8b9b7
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"proxyrules/src/aclgit"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -114,6 +115,7 @@ func GenerateConfig() {
|
||||
addedDirectProxyList := append([]string{"DIRECT", "PROXY"}, proxyNameList...)
|
||||
addedProxyList := append([]string{"PROXY", "DIRECT"}, proxyNameList...)
|
||||
banProxyList := append([]string{"REJECT", "PROXY", "DIRECT"}, proxyNameList...)
|
||||
|
||||
// 添加 "DIRECT" 和 "PROXY"
|
||||
|
||||
requireChoseList = RemoveDuplicates(requireChoseList)
|
||||
@ -141,6 +143,9 @@ func GenerateConfig() {
|
||||
proxyGroups = append(proxyGroups, proxyGroup)
|
||||
}
|
||||
orderedGroupNames := []string{"AutoSelect", "PROXY", "Final", "OpenAi", "Claude", "ClaudeAI", "Gemini", "Telegram", "Bilibili", "BilibiliHMT", "Steam", "SteamCN", "SteamRegionCheck", "Porn", "Pornhub", "Pixiv", "JetBrains", "PrivateTracker", "Microsoft", "Bing", "Apple", "AppleNews", "AppleTV", "Github", "Google", "GoogleCNProxyIP", "GoogleEarth", "GoogleFCM", "Youtube", "YoutubeMusic", "Tiktok", "Instagram", "Line", "LineTV", "Wikipedia", "Zoom", "Epic", "MIUIPrivacy", "MI"}
|
||||
|
||||
dealOrder(rulesList, orderedGroupNames)
|
||||
|
||||
proxyGroups = ReorderProxyGroups(proxyGroups, orderedGroupNames)
|
||||
// 更新配置中的 ProxyGroups
|
||||
config.ProxyGroups = proxyGroups
|
||||
@ -315,6 +320,37 @@ func dealUserAgent(input []string) []string {
|
||||
}
|
||||
return output
|
||||
}
|
||||
func getNameOrder(str string, order map[string]int) int {
|
||||
// 分割字符串
|
||||
parts := strings.Split(str, ",")
|
||||
for j := range parts {
|
||||
parts[j] = strings.TrimSpace(parts[j]) // 去除空格
|
||||
}
|
||||
|
||||
key := ""
|
||||
// 获取排序键
|
||||
if len(parts) >= 3 {
|
||||
key = parts[2] // 如果有第三部分,使用第三部分作为排序依据
|
||||
}
|
||||
|
||||
// 如果存在于 order 中,返回值;否则返回最大值+1
|
||||
if val, exists := order[key]; exists {
|
||||
return val
|
||||
} else {
|
||||
// 返回最大值+1
|
||||
maxVal := len(order) + 1
|
||||
return maxVal
|
||||
}
|
||||
}
|
||||
func dealOrder(input []string, orderList []string) {
|
||||
order := make(map[string]int)
|
||||
for priv, name := range orderList {
|
||||
order[name] = priv + 1
|
||||
}
|
||||
sort.Slice(input, func(i, j int) bool {
|
||||
return getNameOrder(input[i], order) < getNameOrder(input[j], order)
|
||||
})
|
||||
}
|
||||
func Contains(slice []string, item string) bool {
|
||||
for _, element := range slice {
|
||||
if element == item {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user