支持
https://xxx.xxx.workers.dev/订阅链接
和
https://xxx.xxx.workers.dev/?link=订阅链接
两种调用方式
但是只支持yaml格式的订阅链接,如果你的订阅链接是vmess的base64加密,那么不支持
规则来自https://github.com/Loyalsoldier/clash-rules
代码如下
[ol]addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
console.log(url)
let subscriptionLink = url.searchParams.get('link')
// 如果没有通过查询参数提供订阅链接,则尝试从完整的 URL 中获取
if (!subscriptionLink) {
const hrefParts = request.url.split('/')
if (hrefParts.length > 3) {
subscriptionLink = hrefParts.slice(3).join('/')
}
}
// 如果仍然没有订阅链接,则使用默认链接
if (!subscriptionLink) {
subscriptionLink = 'https://default-subscription-link.com'
}
const config = `proxy-providers:
CNIX:
type: http
url: "${subscriptionLink}"
path: ./cnix.yaml
interval: 7200
mixed-port: 7890
allow-lan: false
mode: rule
log-level: debug
ipv6: false
external-controller: 0.0.0.0:9090
dns:
enable: true
listen: 0.0.0.0:53
ipv6: false
default-nameserver:
- 223.5.5.5
- 114.114.114.114
nameserver:
- 223.5.5.5
- 114.114.114.114
- 119.29.29.29
- 180.76.76.76
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
fake-ip-filter:
- "*.lan"
- "*.localdomain"
- "*.example"
- "*.invalid"
- "*.localhost"
- "*.test"
- "*.local"
- "*.home.arpa"
- router.asus.com
- localhost.sec.qq.com
- localhost.ptlogin2.qq.com
- "+.msftconnecttest.com"
tun:
enable: true
stack: system
auto-route: true
auto-detect-interface: true
dns-hijack:
- 114.114.114.114
- 180.76.76.76
- 119.29.29.29
- 223.5.5.5
- 8.8.8.8
- 8.8.4.4
- 1.1.1.1
- 1.0.0.1
proxy-groups:
- name: PROXY
type: select
proxies:
- CNIX
- DIRECT
- name: CNIX
type: select
use:
- CNIX
rule-providers:
reject:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt"
path: ./ruleset/reject.yaml
interval: 36000
icloud:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt"
path: ./ruleset/icloud.yaml
interval: 36000
apple:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt"
path: ./ruleset/apple.yaml
interval: 36000
google:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt"
path: ./ruleset/google.yaml
interval: 36000
proxy:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt"
path: ./ruleset/proxy.yaml
interval: 36000
direct:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt"
path: ./ruleset/direct.yaml
interval: 36000
private:
type: http
behavior: domain
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt"
path: ./ruleset/private.yaml
interval: 36000
telegramcidr:
type: http
behavior: ipcidr
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt"
path: ./ruleset/telegramcidr.yaml
interval: 36000
cncidr:
type: http
behavior: ipcidr
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt"
path: ./ruleset/cncidr.yaml
interval: 36000
lancidr:
type: http
behavior: ipcidr
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt"
path: ./ruleset/lancidr.yaml
interval: 36000
applications:
type: http
behavior: classical
url: "https://testingcf.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt"
path: ./ruleset/applications.yaml
interval: 36000
rules:
- RULE-SET,applications,DIRECT
- DOMAIN,clash.razord.top,DIRECT
- DOMAIN,yacd.haishan.me,DIRECT
- RULE-SET,private,DIRECT
- RULE-SET,reject,REJECT
- DOMAIN,www.icloud.com,PROXY
- DOMAIN-SUFFIX,icloud-content.com,PROXY
- RULE-SET,icloud,DIRECT
- RULE-SET,apple,PROXY
- RULE-SET,google,PROXY
- RULE-SET,proxy,PROXY
- RULE-SET,direct,DIRECT
- RULE-SET,lancidr,DIRECT
- RULE-SET,cncidr,DIRECT
- RULE-SET,telegramcidr,PROXY
- MATCH,PROXY`
return new Response(config.trim(), {
headers: { 'content-type': 'text/plain' },
})
}
[/ol]复制代码