mihomo-party-org / mihomo-party

:electron: Another Mihomo GUI.
https://mihomo.party
GNU General Public License v3.0
4.32k stars 188 forks source link

[Feature] 在覆写中填写 [include-all: true] 这类导入所有节点的操作后,分组内节点会自动按字母顺序排序 #232

Closed imbalaomao closed 1 week ago

imbalaomao commented 1 week ago

Verify steps

操作系统

Windows

描述

如花云的节点,默认情况下0.2倍率节点在最前,然而在覆写中填写如[常用覆写仓库]()中的布丁狗订阅转换,就会将所有分组中的节点自动按照字母ABCD这样的顺序排序,经排查后发现是配置里有 include-all: true 这样的操作,如果是像下面的操作就不会重新排序节点:

const rules = [
  // 日本流媒体
  "DOMAIN-SUFFIX,jp,日本媒体",
  "DOMAIN-KEYWORD,asobistage,日本媒体",
  "DOMAIN-KEYWORD,bandainamco,日本媒体",
  "GEOSITE,abema,日本媒体",
  "GEOSITE,niconico,日本媒体",
  "GEOSITE,dmm,日本媒体",
  "GEOSITE,pixiv,日本媒体",
  "GEOSITE,apple,日本媒体",
  "GEOSITE,twitter,日本媒体",
  "GEOSITE,tiktok,日本媒体",
  // 成人网站
  "GEOSITE,category-porn,成人网站",
  "DOMAIN-SUFFIX,18comic.vip,成人网站",
  "DOMAIN-SUFFIX,jmcomic.me,成人网站",
  "DOMAIN-SUFFIX,jm365.work,成人网站",
  "DOMAIN-SUFFIX,loli.net,成人网站",
  // AI应用
  "GEOSITE,openai,AI应用",
  "GEOSITE,anthropic,AI应用",
  "DOMAIN-SUFFIX,deepseek.com,国内直连",
  // 国外代理集合
  /// GEOSITE
  "GEOSITE,category-porn,成人网站",
  "GEOSITE,tracker,国内直连",
  "GEOSITE,youtube,谷歌服务",
  "GEOSITE,google,谷歌服务",
  "GEOSITE,twitch,Twitch",
  "GEOSITE,biliintl,全球代理",
  "GEOSITE,xbox,全球代理",
  "GEOSITE,microsoft@cn,国内直连",
  "GEOSITE,microsoft,全球代理",
  "GEOSITE,telegram,电报消息",
  "GEOSITE,private,国内直连",
  "DOMAIN-SUFFIX,steamusercontent.com,全球代理",
  "GEOSITE,steam@cn,国内直连",
  "GEOSITE,steam,全球代理",
  "GEOSITE,steamunlocked,全球代理",
  "GEOSITE,category-game-accelerator-cn,国内直连",
  "GEOSITE,epicgames,国内直连",
  "DOMAIN-SUFFIX,cn,国内直连",
  "GEOSITE,geolocation-!cn,全球代理",
  "GEOSITE,cn,国内直连",
  "GEOIP,private,国内直连,no-resolve",
  "GEOIP,telegram,电报消息,no-resolve",
  "GEOIP,google,全球代理,no-resolve",
  "GEOIP,twitter,全球代理,no-resolve",
  "GEOIP,cn,国内直连,no-resolve",
  "MATCH,全球代理"
];
// 程序入口
function main(config) {
  const proxyCount = config?.proxies?.length ?? 0;
  const proxyProviderCount =
    typeof config?.["proxy-providers"] === "object" ? Object.keys(config["proxy-providers"]).length : 0;
  if (proxyCount === 0 && proxyProviderCount === 0) {
    throw new Error("配置文件中未找到任何代理");
  }
  // 节点筛选
  // 所有地区
  const allRegex = /自动|故障|流量|官网|套餐|机场|订阅/;
  const allProxies = config.proxies
    .filter((e) => !allRegex.test(e.name))
    .map((e) => e.name);
  // Google
  const googleRegex = /香港|🇭🇰|HK|HongKong|Hong Kong|港|新加坡|SG|狮城|坡|Singapore|SGP|🇸🇬|美|美国|US|United States|America|🇺🇸|Los Angeles|San Jose|Phoenix|洛杉矶|圣何塞|凤凰城|斯巴达|UnitedStates/;
  const googleProxies = config.proxies
    .filter((e) => googleRegex.test(e.name))
    .map((e) => e.name);
  // Emby
  const embyRegex = /美|美国|US|United States|America|🇺🇸|Los Angeles|San Jose|Phoenix|洛杉矶|圣何塞|凤凰城|斯巴达|UnitedStates/;
  const embyProxies = config.proxies
    .filter((e) => embyRegex.test(e.name))
    .map((e) => e.name);
  // Twitch
  const twitchRegex = /香港|🇭🇰|HK|HongKong|港/;
  const twitchProxies = config.proxies
    .filter((e) => twitchRegex.test(e.name))
    .map((e) => e.name);
  // 日本媒体
  const japanRegex = /日本|JP|Japan|🇯🇵|Tokyo|Osaka|霓虹|小日子/;
  const japanProxies = config.proxies
    .filter((e) => japanRegex.test(e.name))
    .map((e) => e.name);
  // 成人网址
  const pornRegex = /香港|🇭🇰|HK|HongKong|Hong Kong|港|新加坡|SG|狮城|坡|Singapore|SGP|🇸🇬/;
  const pornProxies = config.proxies
    .filter((e) => pornRegex.test(e.name))
    .map((e) => e.name);
  // Telegram
  const telegramRegex = /新加坡|SG|狮城|坡|Singapore|SGP|🇸🇬/;
  const telegramProxies = config.proxies
    .filter((e) => telegramRegex.test(e.name))
    .map((e) => e.name);
  // AIGC
  const aigcRegex = /日本|JP|Japan|Osaka|Tokyo|樱花|霓虹|xtom|🇯🇵|新加坡|SG|狮城|坡|Singapore|SGP|🇸🇬|美国|US|UnitedStates|United States|凤凰城|洛杉矶|圣何塞|San Jose|Los Angeles|Phoenix|🇺🇸|韩国|Korea|KR|🇰🇷|GPT/;
  const aigcProxies = config.proxies
    .filter((e) => aigcRegex.test(e.name))
    .map((e) => e.name);

  // 节点组
  // 节点选择
  const Proxy = {
    name: "全球代理",
    type: "select",
    icon: 'https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/Global.png',
    proxies: allProxies.length > 0 ? allProxies : ["DIRECT"]
  };
  const Google = {
    name: "谷歌服务",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/Google.png",
    proxies: googleProxies.length > 0 ? googleProxies : ["全球代理"]
  };
  // 日本流媒体
  const JMedia = {
    name: "日本媒体",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/JP.png",
    proxies: japanProxies.length > 0 ? japanProxies : ["全球代理"]
  };
  // Twitch
  const Twitch = {
    name: "Twitch",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Alpha/Twich.png",
    proxies: twitchProxies.length > 0 ? twitchProxies : ["全球代理"]
  };
  // Emby
  const Emby = {
    name: "Emby媒体",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/Emby.png",
    proxies: embyProxies.length > 0 ? embyProxies : ["全球代理"]
  };
  // 成人网站
  const Porn = {
    name: "成人网站",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/Pornhub.png",
    lazy: true,
    proxies: pornProxies.length > 0 ? pornProxies : ["全球代理"]
  };
  // 电报消息
  const Telegram = {
    name: "电报消息",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/SG.png",
    proxies: telegramProxies.length > 0 ? telegramProxies : ["全球代理"]
  };
  // AI应用
  const AIGC = {
    name: "AI应用",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/OpenAI.png",
    proxies: aigcProxies.length > 0 ? aigcProxies : ["全球代理"]
  };
  // 广告屏蔽
  const AdBlock = {
    name: "广告屏蔽",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/Adblock.png",
    proxies: ["REJECT"]
  };
  // 国内直连
  const Direct = {
    name: "国内直连",
    type: "select",
    icon: "https://gcore.jsdelivr.net/gh/Orz-3/mini/Color/CN.png",
    proxies: ["DIRECT"]
  };
  const groups = config["proxy-groups"] = [];

  // 覆盖原配置中的规则
  config["rules"] = rules;
  // 插入分组
  groups.unshift(Proxy, Google, JMedia, Twitch, Emby, Porn, Telegram, AIGC, AdBlock, Direct)
  // 返回修改后的配置
  return config
}

除了这种预先筛选节点的操作外,还有什么操作可以更加灵活的导入节点而不进行重排序吗?其实感觉像布丁狗的这套配置也挺好的,如果能够修改为不自动重排序节点就好了,提前感谢各位大佬分享心得。

xishang0128 commented 1 week ago

这不是一个功能请求,该issues将被关闭