From afebd93f19ff391e24417e7f3d960b45d160f737 Mon Sep 17 00:00:00 2001 From: CMLiussss <24787744+cmliu@users.noreply.github.com> Date: Tue, 30 Apr 2024 02:36:59 +0800 Subject: [PATCH] Update _worker.js --- _worker.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/_worker.js b/_worker.js index 249133e..3abc863 100644 --- a/_worker.js +++ b/_worker.js @@ -37,7 +37,8 @@ export default { */ async fetch(request, env, ctx) { try { - const userAgent = request.headers.get('User-Agent').toLowerCase(); + const UA = request.headers.get('User-Agent') || 'null'; + const userAgent = UA.toLowerCase(); userID = (env.UUID || userID).toLowerCase(); proxyIP = env.PROXYIP || proxyIP; const proxyIPs = await ADD(proxyIP); @@ -69,7 +70,7 @@ export default { case '/': return new Response(JSON.stringify(request.cf, null, 4), { status: 200 }); case `/${userID}`: { - const vlessConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, userAgent, RproxyIP); + const vlessConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, UA, RproxyIP, url); const now = Date.now(); const timestamp = Math.floor(now / 1000); const expire = 4102329600;//2099-12-31 @@ -81,6 +82,8 @@ export default { status: 200, headers: { "Content-Type": "text/plain;charset=utf-8", + "Profile-Update-Interval": "6", + "Subscription-Userinfo": `upload=${UD}; download=${UD}; total=${24 * 1099511627776}; expire=${expire}`, } }); } else { @@ -896,19 +899,22 @@ function 配置信息(UUID, 域名地址) { return [v2ray,clash]; } +let subParams = ['sub','base64','b64','clash','singbox','sb']; + /** * @param {string} userID * @param {string | null} hostName * @param {string} sub - * @param {string} userAgent + * @param {string} UA * @returns {Promise} */ -async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) { +async function getVLESSConfig(userID, hostName, sub, UA, RproxyIP, _url) { + const userAgent = UA.toLowerCase(); const Config = 配置信息(userID , hostName); const v2ray = Config[0]; const clash = Config[1]; // 如果sub为空,则显示原始内容 - if (!sub || sub === '') { + if ((!sub || sub === '') && !subParams.some(_searchParams => _url.searchParams.has(_searchParams))) { return ` ################################################################ @@ -923,13 +929,26 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) { --------------------------------------------------------------- ################################################################ `; - } else if (sub && userAgent.includes('mozilla') && !userAgent.includes('linux x86')) { + } else if (sub && userAgent.includes('mozilla') && !subParams.some(_searchParams => _url.searchParams.has(_searchParams))) { return ` ################################################################ Subscribe / sub 订阅地址, 支持 Base64、clash-meta、sing-box 订阅格式, 您的订阅内容由 ${sub} 提供维护支持, 自动获取ProxyIP: ${RproxyIP}. --------------------------------------------------------------- + 快速自适应订阅地址: https://${hostName}/${userID} + + Base64订阅地址: + https://${hostName}/${userID}?sub + https://${hostName}/${userID}?b64 + https://${hostName}/${userID}?base64 + + clash订阅地址: + https://${hostName}/${userID}?clash + + singbox订阅地址: + https://${hostName}/${userID}?sb + https://${hostName}/${userID}?singbox --------------------------------------------------------------- ################################################################ v2ray @@ -967,9 +986,9 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) { let url = `https://${sub}/sub?host=${fakeHostName}&uuid=${fakeUserID}&edgetunnel=cmliu&proxyip=${RproxyIP}`; let isBase64 = false; - if (userAgent.includes('clash') && !userAgent.includes('nekobox')) { + if ((userAgent.includes('clash') && !userAgent.includes('nekobox')) || ( _url.searchParams.has('clash') && !userAgent.includes('subconverter'))) { url = `https://${subconverter}/sub?target=clash&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`; - } else if (userAgent.includes('sing-box') || userAgent.includes('singbox')) { + } else if (userAgent.includes('sing-box') || userAgent.includes('singbox') || (( _url.searchParams.has('singbox') || _url.searchParams.has('sb')) && !userAgent.includes('subconverter'))) { url = `https://${subconverter}/sub?target=singbox&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`; } else { isBase64 = true; @@ -978,7 +997,7 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) { try { const response = await fetch(url ,{ headers: { - 'User-Agent': 'CF-Workers-edgetunnel/cmliu' + 'User-Agent': `${UA} CF-Workers-edgetunnel/cmliu` }}); const content = await response.text(); return revertFakeInfo(content, userID, hostName, isBase64);