自用clash verge的 js脚本配置分享

啊?我从全自动获取免费机场节点获取的订阅是有规则配置的啊

不过用楼主的js直接全覆盖了 也没问题。

note:
我用最新的verge这边新建只有remote和local诶。。木有脚本的选项,但是可以放在全局扩展脚本里

1 个赞

可以用我之前发的脚本

可以实现的效果:

  1. 看不懂
  2. 不加,以前加过,我的仓库中也有同步的adblock的esaylist相关文件,现在依旧是保持同步的,只是并没有加到配置里面,因为多做多错,我不希望我的分流配置,是一些人的疑难杂症bug的触发点
  3. 没有,因为我也做开发,当一个软件还没有经受住大量用户的考验的时候,我可能不会选择,一些软件(不是特指singbox)上来就说比A强,比B强,但是他永远不知道老牌软件面对过多面奇奇怪怪的用户操作,踩过多少疑难杂症的坑,我的目标是流畅的上网,而不是配置出来一个特别牛逼的代理软件
2 个赞

那是否可以将反广告作为可选附在博客内容后面?我真的很需要 求求啦

3 个赞

可能并不会加,我理解你的担忧,V3版本的Chrome扩展反广告能力下降,而V2版本即将不受支持。

我想说的是,

  1. V2还没有彻底停止支持,先用着没什么问题,让子弹再飞一会儿看看事情后续怎么发展,毕竟影响范围挺大,很多不更新但是又有很大作用的v2插件不支持势必会导致一部分用户的流失,因为edge、brave这些浏览器并不放弃支持v2,这个风险Chrome要怎么解决我们还要观望

  2. 不要指望Clash作为一个代理软件,能完美的解决去广告问题。你可以打开v2版本的ADGuard、Adblock,他们的去广告规则数量都是十几万甚至几十万的,Clash加载这么多规则是会占用不小的性能的,尤其是在一些高速下载场景,直接设备和断网了一样。一些网站是基于css选择器的去广告,这个也是Clash做不到的

  3. 我在文章里面也写了,这个只是一个可以让大部分人,无门槛快速配置成一个比较好的使用状态,算是面向大众的入门且不会犯错的指引,不是一个顶级的最优配置,他所依赖的订阅转换服务是我需要实打实的购买服务器去维护的,几十万条去广告配置显然会带来转换过程中很高的服务器负载,这个也是我不能接受的

所以,配置还是会保持一个尽量轻量、不会犯错的这么一个指向去做,不会加去广告,专业的事情交给专业的人去做

5 个赞

好的,谢谢

4 个赞

太强了 已配置

感谢佬分享

clash-verge-rev 用合并订阅会出现问题,在 GPT 的指导下,修改成这样应该就可以了。

主要是添加了 const proxyProviderNames = Object.keys(params["proxy-providers"] || {});

const proxyName = "🛜代理模式";

function main(params) {
  if (!params.proxies) return params;
  overwriteRules(params);
  overwriteProxyGroups(params);
  overwriteDns(params);
  return params;
}
//覆写规则
function overwriteRules(params) {
  const rules = [
    "RULE-SET,reject,⛔广告拦截",
    "RULE-SET,direct,DIRECT",
    "RULE-SET,cncidr,DIRECT",
    "RULE-SET,private,DIRECT",
    "RULE-SET,lancidr,DIRECT",
    "GEOIP,LAN,DIRECT,no-resolve",
    "GEOIP,CN,DIRECT,no-resolve",
    "RULE-SET,applications,DIRECT",
    "RULE-SET,tld-not-cn," + proxyName,
    "RULE-SET,google," + proxyName,
    "RULE-SET,icloud," + proxyName,
    "RULE-SET,apple," + proxyName,
    "RULE-SET,gfw," + proxyName,
    "RULE-SET,greatfire," + proxyName,
    "RULE-SET,telegramcidr," + proxyName,
    "RULE-SET,proxy," + proxyName,
    "MATCH,🐟漏网之鱼",
  ];
  const ruleProviders = {
    reject: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt",
      path: "./ruleset/reject.yaml",
      interval: 86400,
    },
    icloud: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt",
      path: "./ruleset/icloud.yaml",
      interval: 86400,
    },
    apple: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt",
      path: "./ruleset/apple.yaml",
      interval: 86400,
    },
    google: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt",
      path: "./ruleset/google.yaml",
      interval: 86400,
    },
    proxy: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt",
      path: "./ruleset/proxy.yaml",
      interval: 86400,
    },
    direct: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt",
      path: "./ruleset/direct.yaml",
      interval: 86400,
    },
    private: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt",
      path: "./ruleset/private.yaml",
      interval: 86400,
    },
    gfw: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt",
      path: "./ruleset/gfw.yaml",
      interval: 86400,
    },
    greatfire: {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/greatfire.txt",
      path: "./ruleset/greatfire.yaml",
      interval: 86400,
    },
    "tld-not-cn": {
      type: "http",
      behavior: "domain",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt",
      path: "./ruleset/tld-not-cn.yaml",
      interval: 86400,
    },
    telegramcidr: {
      type: "http",
      behavior: "ipcidr",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt",
      path: "./ruleset/telegramcidr.yaml",
      interval: 86400,
    },
    cncidr: {
      type: "http",
      behavior: "ipcidr",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt",
      path: "./ruleset/cncidr.yaml",
      interval: 86400,
    },
    lancidr: {
      type: "http",
      behavior: "ipcidr",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt",
      path: "./ruleset/lancidr.yaml",
      interval: 86400,
    },
    applications: {
      type: "http",
      behavior: "classical",
      url: "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt",
      path: "./ruleset/applications.yaml",
      interval: 86400,
    },
  };
  params["rule-providers"] = ruleProviders;
  params["rules"] = rules;
}
//覆写代理组
function overwriteProxyGroups(params) {
  // 所有代理
  const allProxies = params["proxies"].map((e) => e.name);
  const proxyProviderNames = Object.keys(params["proxy-providers"] || {});

  // 自动选择代理组,按地区分组选延迟最低
  const autoProxyGroupRegexs = [
    { name: "HK-自动选择", regex: /香港|HK|Hong|🇭🇰/ },
    { name: "TW-自动选择", regex: /台湾|TW|Taiwan|Wan|🇨🇳|🇹🇼/ },
    { name: "SG-自动选择", regex: /新加坡|狮城|SG|Singapore|🇸🇬/ },
    { name: "JP-自动选择", regex: /日本|JP|Japan|🇯🇵/ },
    { name: "US-自动选择", regex: /美国|US|United States|America|🇺🇸/ },
  ];

  const autoProxyGroups = autoProxyGroupRegexs
    .map((item) => ({
      name: item.name,
      type: "url-test",
      url: "http://www.gstatic.com/generate_204",
      interval: 300,
      tolerance: 50,
      proxies: getProxiesByRegex(params, item.regex),
      hidden: true,
    }))
    .filter((item) => item.proxies.length > 0);

  const groups = [
    {
      name: proxyName,
      type: "select",
      url: "http://www.gstatic.com/generate_204",
      //icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/adjust.svg",
      proxies: [
        "🤖自动选择",
        "🎯手动选择",
        "🔀负载均衡(散列)",
        "🔁负载均衡(轮询)",
        "DIRECT",
      ],
    },
    {
      name: "🎯手动选择",
      type: "select",
      proxies: allProxies,
      use: proxyProviderNames,
    },
    {
      name: "🤖自动选择",
      type: "select",
      //icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/speed.svg",
      proxies: ["ALL-自动选择"],
    },
    {
      name: "🔀负载均衡(散列)",
      type: "load-balance",
      url: "http://www.gstatic.com/generate_204",
      //icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/balance.svg",
      interval: 300,
      "max-failed-times": 3,
      strategy: "consistent-hashing",
      lazy: true,
      proxies: allProxies,
      use: proxyProviderNames,
    },
    {
      name: "🔁负载均衡(轮询)",
      type: "load-balance",
      url: "http://www.gstatic.com/generate_204",
      //icon: "https://fastly.jsdelivr.net/gh/clash-verge-rev/clash-verge-rev.github.io@main/docs/assets/icons/merry_go.svg",
      interval: 300,
      "max-failed-times": 3,
      strategy: "round-robin",
      lazy: true,
      proxies: allProxies,
      use: proxyProviderNames,
    },
    {
      name: "ALL-自动选择",
      type: "url-test",
      url: "http://www.gstatic.com/generate_204",
      interval: 300,
      tolerance: 50,
      proxies: allProxies,
      use: proxyProviderNames,
      hidden: true,
    },
    {
      name: "🐟漏网之鱼",
      type: "select",
      proxies: ["DIRECT", proxyName],
    },
    {
      name: "⛔广告拦截",
      type: "select",
      proxies: ["REJECT", "DIRECT", proxyName],
    },
  ];

  autoProxyGroups.length &&
    groups[2].proxies.unshift(...autoProxyGroups.map((item) => item.name));
  groups.push(...autoProxyGroups);
  params["proxy-groups"] = groups;
}
//防止dns泄露
function overwriteDns(params) {
  const cnDnsList = [
    "https://223.5.5.5/dns-query",
    "https://1.12.12.12/dns-query",
  ];
  const trustDnsList = [
    'quic://dns.cooluc.com',
    "https://1.0.0.1/dns-query",
    "https://1.1.1.1/dns-query",
  ];
  // const notionDns = 'tls://dns.jerryw.cn'
  // const notionUrls = [
  //     'http-inputs-notion.splunkcloud.com',
  //     '+.notion-static.com',
  //     '+.notion.com',
  //     '+.notion.new',
  //     '+.notion.site',
  //     '+.notion.so',
  // ]
  // const combinedUrls = notionUrls.join(',');
  const dnsOptions = {
    enable: true,
    "prefer-h3": true, // 如果DNS服务器支持DoH3会优先使用h3
    "default-nameserver": cnDnsList, // 用于解析其他DNS服务器、和节点的域名, 必须为IP, 可为加密DNS。注意这个只用来解析节点和其他的dns,其他网络请求不归他管
    nameserver: trustDnsList, // 其他网络请求都归他管

    // 这个用于覆盖上面的 nameserver
    "nameserver-policy": {
      //[combinedUrls]: notionDns,
      "geosite:cn": cnDnsList,
      "geosite:geolocation-!cn": trustDnsList,
      // 如果你有一些内网使用的DNS,应该定义在这里,多个域名用英文逗号分割
      // '+.公司域名.com, www.4399.com, +.baidu.com': '10.0.0.1'
    },
    fallback: trustDnsList,
    "fallback-filter": {
      geoip: true,
      //除了 geoip-code 配置的国家 IP, 其他的 IP 结果会被视为污染 geoip-code 配置的国家的结果会直接采用,否则将采用 fallback结果
      "geoip-code": "CN",
      //geosite 列表的内容被视为已污染,匹配到 geosite 的域名,将只使用 fallback解析,不去使用 nameserver
      geosite: ["gfw"],
      ipcidr: ["240.0.0.0/4"],
      domain: ["+.google.com", "+.facebook.com", "+.youtube.com"],
    },
  };

  // GitHub加速前缀
  const githubPrefix = "https://fastgh.lainbo.com/";

  // GEO数据GitHub资源原始下载地址
  const rawGeoxURLs = {
    geoip:
      "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat",
    geosite:
      "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat",
    mmdb: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb",
  };

  // 生成带有加速前缀的GEO数据资源对象
  const accelURLs = Object.fromEntries(
    Object.entries(rawGeoxURLs).map(([key, githubUrl]) => [
      key,
      `${githubPrefix}${githubUrl}`,
    ])
  );

  const otherOptions = {
    "unified-delay": true,
    "tcp-concurrent": true,
    profile: {
      "store-selected": true,
      "store-fake-ip": true,
    },
    sniffer: {
      enable: true,
      sniff: {
        TLS: {
          ports: [443, 8443],
        },
        HTTP: {
          ports: [80, "8080-8880"],
          "override-destination": true,
        },
      },
    },
    "geodata-mode": true,
    "geox-url": accelURLs,
  };

  params.dns = { ...params.dns, ...dnsOptions };
  Object.keys(otherOptions).forEach((key) => {
    params[key] = otherOptions[key];
  });
}

function getProxiesByRegex(params, regex) {
  return params.proxies.filter((e) => regex.test(e.name)).map((e) => e.name);
}

这个是合并订阅的 local profile:

proxy-providers:
  provider1:
    path: ./profiles/Name1.yml # 配置文件缓存的位置
    url: "..."
    type: http
    interval: 86400
    health-check:
      {
        enable: true,
        url: "https://www.gstatic.com/generate_204",
        interval: 300,
      }
    override:
      additional-prefix: "[provider1]"
  provider2:
    path: ./profiles/Name2.yml # 配置文件缓存的位置
    url: "..."
    type: http
    interval: 86400
    health-check:
      {
        enable: true,
        url: "https://www.gstatic.com/generate_204",
        interval: 300,
      }
    override:
      additional-prefix: "[provider2]"
4 个赞

给你我的小心心!!! :heart: :heart: :heart:

3 个赞

你的网站怎么打不开了, :joy: :joy:最新的配置有吗?大佬

话不多讲, mark 下

能打开啊,可能需要科学上网

3 个赞

配置好了,多谢哈,可能不稳定。 :joy: :joy:

1 个赞

反馈:https://www.gstatic.com/ 访问不到

2 个赞

感谢分享,谢谢

1 个赞

请问大佬只能使用 clash verge 吗,我目前用的 clash meta,没有见到能在哪里手动添加订阅… :tieba_009:

3 个赞

感谢,用上了,一直觉得机场的规则不好用

5 个赞

佬之牛吾不及也

6 个赞