forked from xiaobaikeji831/cfDAIMA
/
CF.WORKERS
147 lines (128 loc) · 6.8 KB
/
CF.WORKERS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
// 定义要发送请求的地址数组,每个元素包含一个 url 和一个处理函数
const sites = [
{ url: "https://www.gitlabip.xyz/Alvin9999/pac2/master/hysteria/1/config.json", type: "hysteria" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/hysteria/config.json", type: "hysteria" },
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/hysteria/config.json", type: "hysteria" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/hysteria/config.json", type: "hysteria" },
{ url: "https://www.gitlabip.xyz/Alvin9999/pac2/master/hysteria/13/config.json", type: "hysteria" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/hysteria/2/config.json", type: "hysteria" },
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/hysteria/2/config.json", type: "hysteria" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/hysteria/2/config.json", type: "hysteria" },
//hy2
{ url: 'https://www.gitlabip.xyz/Alvin9999/pac2/master/hysteria2/1/config.json', type: "hysteria2" },
{ url: 'https://gitlab.com/free9999/ipupdate/-/raw/master/hysteria2/config.json', type: "hysteria2" },
{ url: 'https://www.githubip.xyz/Alvin9999/pac2/master/hysteria2/config.json', type: "hysteria2" },
{ url: 'https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/hysteria2/config.json', type: "hysteria2" },
{ url: 'https://www.gitlabip.xyz/Alvin9999/pac2/master/hysteria2/13/config.json', type: "hysteria2" },
{ url: 'https://gitlab.com/free9999/ipupdate/-/raw/master/hysteria2/2/config.json', type: "hysteria2" },
{ url: 'https://www.githubip.xyz/Alvin9999/pac2/master/hysteria2/2/config.json', type: "hysteria2" },
{ url: 'https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/hysteria2/2/config.json', type: "hysteria2" },
//xray
{ url: 'https://www.gitlabip.xyz/Alvin9999/pac2/master/xray/1/config.json',type: "xray" },
{ url: 'https://gitlab.com/free9999/ipupdate/-/raw/master/xray/config.json',type: "xray"},
{ url: 'https://www.githubip.xyz/Alvin9999/pac2/master/xray/config.json',type: "xray"},
{ url: 'https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/xray/config.json',type: "xray"},
{ url: 'https://www.gitlabip.xyz/Alvin9999/pac2/master/xray/3/config.json',type: "xray"},
{ url: 'https://gitlab.com/free9999/ipupdate/-/raw/master/xray/2/config.json',type: "xray"},
{ url: 'https://www.githubip.xyz/Alvin9999/pac2/master/xray/2/config.json',type: "xray"},
//singbox
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/singbox/config.json",type: "singbox"},
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/singbox/config.json",type: "singbox"},
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/singbox/config.json", type: "singbox"},
{ url: "https://www.gitlabip.xyz/Alvin9999/pac2/master/singbox/1/config.json", type: "singbox"}
// 添加更多的网站地址和类型...
];
// 存储拼接后的字符串,用于去重
const uniqueStrings = new Set();
// 发送请求并处理响应
async function fetchData(site) {
try {
const response = await fetch(site.url);
const data = await response.json();
// 根据网站类型选择对应的处理函数
let formattedString ;
if(site.type === "hysteria") {
formattedString = processHysteri(data)
}
else if(site.type === "hysteria2") {
formattedString = processHysteria2(data)
}
else if(site.type === "xray"){
formattedString = processXray(data)
}
else {
formattedString = processSingbox(data)
}
// 将拼接的字符串添加到集合中
uniqueStrings.add(formattedString);
} catch (error) {
console.error(`Error fetching data from ${site.url}: ${error}`);
}
}
// 处理类型1的数据
function processHysteri(data) {
// 从 JSON 数据中提取字段,并按指定格式拼接字符串
const up_mps = data.up_mbps;
const down_mps = data.down_mbps;
const auth_Str = data.auth_str;
const server_name = data.server_name;
const alpn = data.alpn;
const server = data.server;
return `hysteria://${server}?upmbps=${up_mps}&downmbps=${down_mps}&auth=${auth_Str}&insecure=1&peer=${server_name}&alpn=${alpn}`;
}
// 处理类型2的数据
function processHysteria2(data) {
// 根据类型2的数据提取字段,并按指定格式拼接字符串
// 这里提供一个示例,实际情况需要根据实际数据结构调整
// 从 JSON 数据中提取所需字段
const auth = data.auth || '';
const server = data.server || '';
// 根据 data.insecure 的值设置 insecure
const insecure = data.tls.insecure ? 1 : 0;
const sni = data.tls.sni || '';
return `hy2://${auth}@${server}?insecure=${insecure}&sni=${sni}`;
}
// 处理xray的数据
function processXray(data) {
let protocol, address, port, id, encryption, type, security, sni, fp, path, host;
let outboundConfig = data.outbounds[0];
protocol = outboundConfig.protocol;
id = outboundConfig.settings?.vnext?.[0]?.users?.[0]?.id;
address = outboundConfig.settings?.vnext?.[0]?.address;
port = outboundConfig.settings?.vnext?.[0]?.port;
encryption = outboundConfig.settings?.vnext?.[0]?.users?.[0]?.encryption;
type = outboundConfig?.streamSettings?.network;
security = outboundConfig?.streamSettings?.security;
sni = outboundConfig?.streamSettings?.tlsSettings?.serverName;
fp = outboundConfig?.streamSettings?.tlsSettings?.fingerprint;
path = outboundConfig?.streamSettings?.wsSettings?.path;
host = outboundConfig?.streamSettings?.wsSettings?.headers?.Host;
return `${protocol}://${id}@${address}:${port}?security=${security}&sni=${sni}&fp=${fp}&type=${type}&path=${path}&host=${host}`;
}
// 处理singbox的数据
function processSingbox(data) {
const outbounds = data.outbounds[0];
const up_mps = outbounds.up_mbps;
const down_mps = outbounds.down_mbps;
const auth_Str = outbounds.auth_str;
const server_name = outbounds.tls.server_name;
const alpn = outbounds.tls.alpn[0];
const server = outbounds.server;
const port = outbounds.server_port;
return `hysteria://${server}:${port}?upmbps=${up_mps}&downmbps=${down_mps}&auth=${auth_Str}&insecure=1&peer=${server_name}&alpn=${alpn}`;
}
// 遍历所有地址并发送请求
const promises = sites.map(site => fetchData(site));
await Promise.all(promises);
// 构建最终字符串
const finalStrings = [...uniqueStrings];
// 生成 HTML 页面内容
const htmlContent = finalStrings.map(str => `<p>${str}</p>`).join('\n');
return new Response(htmlContent, {
headers: { 'Content-Type': 'text/html' },
});
}