-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhy2
196 lines (181 loc) · 9.18 KB
/
hy2
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request, env, ctx) {
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" },
//clash
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/clash.meta2/config.yaml", type: "clash" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/clash.meta2/config.yaml", type: "clash" },
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/clash.meta2/config.yaml", type: "clash" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/clash.meta2/config.yaml", type: "clash" },
{ url: "https://www.gitlabip.xyz/Alvin9999/pac2/master/clash.meta2/13/config.yaml", type: "clash" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/clash.meta2/2/config.yaml", type: "clash" },
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/clash.meta2/2/config.yaml", type: "clash" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/clash.meta2/2/config.yaml", type: "clash" },
{ url: "https://www.gitlabip.xyz/Alvin9999/pac2/master/clash.meta2/15/config.yaml", type: "clash" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/clash.meta2/3/config.yaml", type: "clash" },
{ url: "https://www.githubip.xyz/Alvin9999/pac2/master/clash.meta2/3/config.yaml", type: "clash" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/pac2@latest/clash.meta2/3/config.yaml", type: "clash" },
{ url: "https://raw.githubusercontent.com/Alvin9999/pac2/master/quick/4/config.yaml", type: "clash" },
{ url: "https://raw.githubusercontent.com/Alvin9999/pac2/master/quick/1/config.yaml", type: "clash" },
{ url: "https://raw.githubusercontent.com/Alvin9999/pac2/master/quick/config.yaml", type: "clash" },
{ url: "https://raw.githubusercontent.com/Alvin9999/pac2/master/quick/3/config.yaml", type: "clash" },
//naive
{ url: "https://www.gitlabip.xyz/Alvin9999/PAC/master/naiveproxy/1/config.json", type: "naiveh" },
{ url: "https://gitlab.com/free9999/ipupdate/-/raw/master/naiveproxy/config.json", type: "naive" },
{ url: "https://www.githubip.xyz/Alvin9999/PAC/master/naiveproxy/config.json", type: "naive" },
{ url: "https://fastly.jsdelivr.net/gh/Alvin9999/PAC@latest/naiveproxy/config.json", type: "naive" },
];
let responses = []; //订阅集合
for (const site of siteshy2) {
try {
let response = await fetch(site.url);
if (response.ok) {
let data = await response.json();
let processedData = await processHysteria2(data);
if (processedData) {
responses.push(processedData);
}
} else {
console.error(`Failed to fetch data from ${site.url}, status: ${response.status}`);
}
} catch (error) {
console.error(`Error fetching data from ${site.url}:`, error);
continue;
}
}
for (const site of siteshy) {
try {
let response = await fetch(site.url);
if (response.ok) {
let data = await response.json();
let processedData = await processHysteri(data);
if (processedData) {
responses.push(processedData);
}
} else {
console.error(`Failed to fetch data from ${site.url}, status: ${response.status}`);
}
} catch (error) {
console.error(`Error fetching data from ${site.url}:`, error);
continue;
}
}
for (const site of sitessb) {
try {
let response = await fetch(site.url);
if (response.ok) {
let data = await response.json();
let processedData = await processSingbox(data);
if (processedData) {
responses.push(processedData);
}
} else {
console.error(`Failed to fetch data from ${site.url}, status: ${response.status}`);
}
} catch (error) {
console.error(`Error fetching data from ${site.url}:`, error);
continue;
}
}
// 去重
let uniqueResponses = removeDuplicates(responses);
// 将去重后的数据合并成一个字符串
const combinedString = uniqueResponses.join('\n');
// 对合并后的字符串进行 Base64 编码
const base64EncodedString = btoa(unescape(encodeURIComponent(combinedString)));
return new Response(base64EncodedString, {
headers: { 'content-type': 'text/plain; charset=utf-8' },
});
}
async function processHysteria2(data) {
const auth = data.auth || '';
const server = data.server || '';
const insecure = data.tls.insecure ? 1 : 0;
const sni = data.tls.sni || '';
const match = server.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/);
const ip = match ? match[0] : '8.8.8.8';
if (ip) {
const locationInfo = await getLocationInfo(ip);
const locationInfoEncoded = encodeURIComponent(locationInfo);
return `hy2://${auth}@${server}?insecure=${insecure}&sni=${sni}#${locationInfoEncoded}`;
}
return null;
}
async function processHysteri(data) {
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;
const match = server.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/);
const ip = match ? match[0] : '8.8.8.8';
if (ip) {
const locationInfo = await getLocationInfo(ip);
const locationInfoEncoded = encodeURIComponent(locationInfo);
return `hysteria://${server}?upmbps=${up_mps}&downmbps=${down_mps}&auth=${auth_Str}&insecure=1&peer=${server_name}&alpn=${alpn}#${locationInfoEncoded}`;
}
return null;
}
async 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;
const locationInfo = await getLocationInfo(server);
const locationInfoEncoded = encodeURIComponent(locationInfo);
return `hysteria://${server}:${port}?upmbps=${up_mps}&downmbps=${down_mps}&auth=${auth_Str}&insecure=1&peer=${server_name}&alpn=${alpn}#${locationInfoEncoded}`;
}
async function getLocationInfo(ip) {
try {
let response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`);
if (response.ok) {
let data = await response.json();
if (data.status === "success") {
return `${data.country} ${data.regionName} ${data.as}`;
}
}
} catch (error) {
console.error(`Error fetching location data for IP ${ip}:`, error);
}
return '';
}
// 去重函数
function removeDuplicates(responses) {
return [...new Set(responses)];
}