有没有好用的verge的全局扩展脚本

我网上找到一个 各位佬还有更好用的吗

// 规则集通用配置
const ruleProviderCommon = {
  type: "http",
  format: "yaml",
  interval: 86400,
};
// 规则集配置
const ruleProviders = {
  reject: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt",
    path: "./rulesets/loyalsoldier/reject.yaml",
  },
  icloud: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt",
    path: "./rulesets/loyalsoldier/icloud.yaml",
  },
  apple: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt",
    path: "./rulesets/loyalsoldier/apple.yaml",
  },
  google: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt",
    path: "./rulesets/loyalsoldier/google.yaml",
  },
  proxy: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt",
    path: "./rulesets/loyalsoldier/proxy.yaml",
  },
  direct: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt",
    path: "./rulesets/loyalsoldier/direct.yaml",
  },
  private: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt",
    path: "./rulesets/loyalsoldier/private.yaml",
  },
  gfw: {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt",
    path: "./rulesets/loyalsoldier/gfw.yaml",
  },
  "tld-not-cn": {
    ...ruleProviderCommon,
    behavior: "domain",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt",
    path: "./rulesets/loyalsoldier/tld-not-cn.yaml",
  },
  telegramcidr: {
    ...ruleProviderCommon,
    behavior: "ipcidr",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt",
    path: "./rulesets/loyalsoldier/telegramcidr.yaml",
  },
  cncidr: {
    ...ruleProviderCommon,
    behavior: "ipcidr",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt",
    path: "./rulesets/loyalsoldier/cncidr.yaml",
  },
  lancidr: {
    ...ruleProviderCommon,
    behavior: "ipcidr",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt",
    path: "./rulesets/loyalsoldier/lancidr.yaml",
  },
  applications: {
    ...ruleProviderCommon,
    behavior: "classical",
    url: "https://fastly.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt",
    path: "./rulesets/loyalsoldier/applications.yaml",
  },
};
// 规则
const rules = [
  // 自定义规则
  "DOMAIN-SUFFIX,googleapis.cn,节点选择", // Google服务
  "DOMAIN-SUFFIX,gstatic.com,节点选择", // Google静态资源
  "DOMAIN-SUFFIX,xn--ngstr-lra8j.com,节点选择", // Google Play下载服务
  "DOMAIN-SUFFIX,github.io,节点选择", // Github Pages
  "DOMAIN,v2rayse.com,节点选择", // V2rayse节点工具
  // Loyalsoldier 规则集
  "RULE-SET,reject,广告过滤",
  "RULE-SET,icloud,微软服务",
  "RULE-SET,apple,苹果服务",
  "RULE-SET,google,谷歌服务",
  "RULE-SET,proxy,节点选择",
  "RULE-SET,gfw,节点选择",
  "RULE-SET,tld-not-cn,节点选择",
  "RULE-SET,applications,全局直连",
  "RULE-SET,private,全局直连",
  "RULE-SET,direct,全局直连",
  "RULE-SET,lancidr,全局直连,no-resolve",
  "RULE-SET,cncidr,全局直连,no-resolve",
  "RULE-SET,telegramcidr,电报消息,no-resolve",
  // 其他规则
  "GEOIP,LAN,全局直连,no-resolve",
  "GEOIP,CN,全局直连,no-resolve",
  "MATCH,漏网之鱼",
];
// 代理组通用配置
const groupBaseOption = {
  interval: 300,
  timeout: 3000,
  url: "http://www.gstatic.com/generate_204",
  lazy: true,
  "max-failed-times": 3,
  hidden: false,
};

const options = {
    excludeHighPercentage: true,
    regions: [{
            name: "HK香港",
            regex: /港|🇭🇰|hk|hongkong|hong kong/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/hk.svg",
        },
        {
            name: "SG新加坡",
            regex: /新加坡|🇸🇬|sg|singapore/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/sg.svg",
        },
        {
            name: "TW台湾省",
            regex: /台湾|🇨🇳|tw|taiwan|tai wan/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/cn.svg",
        },
        {
            name: "JP日本",
            regex: /日本|🇯🇵|jp|japan/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/jp.svg",
        },
        {
            name: "KR韩国",
            regex: /韩|🇰🇷|kr|korea/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/kr.svg",
        },
        {
            name: "CN中国大陆",
            regex: /中国|🇨🇳|cn|china/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/cn.svg",
        },
        {
            name: "NA北美",
            regex: /美|🇺🇸|us|united state|america|加拿大|canada|墨西哥|mexico/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/us.svg",
        },
        {
            name: "EU欧洲",
            regex: /英|🇬🇧|uk|united kingdom|great britain|法|德|荷|西班牙/i,
            ratioLimit: 2,
            icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/eu.svg",
        },
    ],
};

// 程序入口
function main(config) {
  const proxyCount = config?.proxies?.length ?? 0;
  let proxyGroupsRegion = [];
  const proxyProviderCount =
    typeof config?.["proxy-providers"] === "object"
      ? Object.keys(config["proxy-providers"]).length
      : 0;
  if (proxyCount === 0 && proxyProviderCount === 0) {
    throw new Error("配置文件中未找到任何代理");
  }

  options.regions.forEach((region) => {
      /**
       * 提取倍率符合要求的代理节点
       * 判断倍率有问题的话,大概率是这个正则的问题,可以自行修改
       * 自己改正则的话记得必须把倍率的number值提取出来
       */
      let proxies = config.proxies
          .filter((a) => {
              const multiplier =
                  /(?<=[xX✕✖⨉倍率])([1-9]+(\.\d+)*|0{1}\.\d+)(?=[xX✕✖⨉倍率])*/i.exec(
                      a.name,
                  )?.[1];
              return (
                  a.name.match(region.regex) &&
                  parseFloat(multiplier || "0") <= region.ratioLimit
              );
          })
          .map((b) => {
              return b.name;
          });

      /**
       * 必须再判断一下有没有符合要求的代理节点
       * 没有的话,这个策略组就不应该存在
       * 我喜欢自动选择延迟最低的节点,喜欢轮询的可以自己修改
       */
      if (proxies.length > 0) {
          proxyGroupsRegion.push({
              ...groupBaseOption,
              name: region.name,
              type: "url-test",
              tolerance: 100,
              icon: region.icon,
              proxies: proxies,
          });
      }
  });

  /**
   * 当地区策略组存在是,再建立一个地区选择的策略组
   * 类型为手动选择,方便切换地区
   */
  if (proxyGroupsRegion.length > 0) {
      proxyGroupsRegion = [{
              ...groupBaseOption,
              name: "地区选择",
              type: "select",
              proxies: proxyGroupsRegion.map((item) => {
                  return item.name;
              }),
              icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/flags/un.svg",
          },
          ...proxyGroupsRegion,
      ];
  }

  // 覆盖原配置中的代理组
  config["proxy-groups"] = [
    {
      ...groupBaseOption,
      name: "节点选择",
      type: "select",
      proxies: [
        "延迟选优", 
        "故障转移", 
        "负载均衡(散列)", 
        "负载均衡(轮询)",
        ...proxyGroupsRegion.map((value) => {
            return value.name;
        }),
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/adjust.svg",
    },
    {
      ...groupBaseOption,
      name: "延迟选优",
      type: "url-test",
      tolerance: 100,
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/speed.svg",
    },
    {
      ...groupBaseOption,
      name: "故障转移",
      type: "fallback",
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/ambulance.svg",
    },
    {
      ...groupBaseOption,
      name: "负载均衡(散列)",
      type: "load-balance",
      strategy: "consistent-hashing",
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/merry_go.svg",
    },
    ...proxyGroupsRegion,
    {
      ...groupBaseOption,
      name: "负载均衡(轮询)",
      type: "load-balance",
      strategy: "round-robin",
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/balance.svg",
    },
    {
      ...groupBaseOption,
      name: "谷歌服务",
      type: "select",
      proxies: [
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
        "全局直连",
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/google.svg",
    },
    {
      ...groupBaseOption,
      name: "国外媒体",
      type: "select",
      proxies: [
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
        "全局直连",
        ...proxyGroupsRegion.map((value) => {
            return value.name;
        }),
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/youtube.svg",
    },
    {
      ...groupBaseOption,
      name: "电报消息",
      type: "select",
      proxies: [
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
        "全局直连",
        ...proxyGroupsRegion.map((value) => {
            return value.name;
        }),
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/telegram.svg",
    },
    {
      ...groupBaseOption,
      name: "苹果服务",
      type: "select",
      proxies: [
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
        "全局直连",
        ...proxyGroupsRegion.map((value) => {
            return value.name;
        }),
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/apple.svg",
    },
    {
      ...groupBaseOption,
      name: "微软服务",
      type: "select",
      proxies: [
        "全局直连",
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/microsoft.svg",
    },
    {
      ...groupBaseOption,
      name: "广告过滤",
      type: "select",
      proxies: ["REJECT", "DIRECT"],
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/bug.svg",
    },
    {
      ...groupBaseOption,
      name: "全局直连",
      type: "select",
      proxies: [
        "DIRECT",
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/link.svg",
    },
    {
      ...groupBaseOption,
      name: "全局拦截",
      type: "select",
      proxies: ["REJECT", "DIRECT"],
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/block.svg",
    },
    {
      ...groupBaseOption,
      name: "漏网之鱼",
      type: "select",
      proxies: [
        "节点选择",
        "延迟选优",
        "故障转移",
        "负载均衡(散列)",
        "负载均衡(轮询)",
        "全局直连",
      ],
      "include-all": true,
      icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/fish.svg",
    },
  ];

  // 覆盖原配置中的规则
  config["rule-providers"] = ruleProviders;
  config["rules"] = rules;

  // 返回修改后的配置
  return config;
}
3 个赞

mark下tieba_005

1 个赞

mark 下,感谢大佬!tieba_095

蹲守一个!!