-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTelegramProxyCrawler-API.js
More file actions
40 lines (30 loc) · 1.03 KB
/
TelegramProxyCrawler-API.js
File metadata and controls
40 lines (30 loc) · 1.03 KB
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
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url);
const channel = url.searchParams.get('channel');
if (!channel) {
return new Response('Channel parameter is missing', { status: 400 });
}
const proxies = await getProxies(channel);
const responseBody = JSON.stringify({ proxies });
return new Response(responseBody, {
headers: { 'Content-Type': 'application/json' },
});
}
async function getProxies(channel) {
const response = await fetch("https://t.me/s/" + channel);
const html = await response.text();
const proxyRegex1 = /href="(.*?\/proxy\?.*?)"/g;
const proxyRegex2 = /class="tgme_widget_message_inline_button url_button" href="(.*?\/proxy\?.*?)"/g;
let proxies = [];
let match;
while (match = proxyRegex1.exec(html)) {
proxies.push(match[1].replace(/;/g, "&"));
}
while (match = proxyRegex2.exec(html)) {
proxies.push(match[1].replace(/;/g, "&"));
}
return proxies;
}