@
nothing2 addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const baseUrls = [
'
https://pub-api-1.bianyuan.xyz',
'https://api.wcc.best',
'
https://sub.id9.cc',
'
https://sub.xeton.dev',
'
https://api.dler.io',
'
https://sub.maoxiongnet.com'
// 这些是订阅转换的后端,可以直接用,也可以添加自建的,也可以去网上找,代码逻辑是将每个订阅以此放进去,直到获取能用的节点信息
];
const urls = [
'
https://jichang1.com/api/v1/client/subscribe?token=28614cc6481a7cec2a1d430a9409a6b4', //机场 1
'
https://jichang2.com/api/v1/client/subscribe?token=28614cc6481a7cec2a1d430a9409a6b4', //机场 2
'
https://jichang3.com/api/v1/client/subscribe?token=28614cc6481a7cec2a1d430a9409a6b4' //机场 3
// 这些是 vmess 订阅链接,也是按需添加
];
try {
let plainTextContent = '';
let firstContent = true; // Flag to track the first successful content
for (const url of urls) {
for (const baseUrl of baseUrls) {
const apiUrl = `${baseUrl}/sub?target=clash&url=${encodeURIComponent(url)}&insert=false&exclude=%E4%B8%B4%E6%97%B6&emoji=true&list=true&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
const response = await fetch(apiUrl);
if (response.ok) {
let content = await response.text();
// Check if the first line of content includes "proxies:"
const firstLine = content.split('\n')[0];
if (firstLine.includes('proxies:')) {
// Remove the first line if not the first successful content
if (!firstContent) {
content = content.replace(/^.*[\r\n]+/, '');
} else {
firstContent = false; // Set flag to false after capturing the first content
}
plainTextContent += `${content}\n`;
break;
}
}
}
}
// 这是所有节点都获取失败后的备用节点
if (!plainTextContent.trim()) {
plainTextContent = `proxies:\n` +
`- {name: 备用节点, server:
abc.com, port: 80, type: vmess, uuid: 3b2b88bf-191a-4b94-a1f9-5r30a762fe7e, alterId: 0, cipher: auto, tls: false, skip-cert-verify: false, network: ws, ws-opts: {path: /qqadb}}`;
}
return new Response(plainTextContent, {
headers: {
'Content-Type': 'text/plain; charset=UTF-8',
},
});
} catch (error) {
return new Response('Error occurred: ' + error, { status: 500 });
}
}