const { type, name } = $arguments const compatible_outbound = { tag: 'COMPATIBLE', type: 'direct', } let compatible let config = JSON.parse($files[0]) let proxies = await produceArtifact({ name, type: /^1$|col/i.test(type) ? 'collection' : 'subscription', platform: 'sing-box', produceType: 'internal', }) config.outbounds.push(...proxies) config.outbounds.map(i => { if (['all', 'all-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies)) } if (['hk', 'hk-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies, /ζΈ―|hk|hongkong|kong kong|πŸ‡­πŸ‡°/i)) } if (['tw', 'tw-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies, /台|tw|taiwan|πŸ‡ΉπŸ‡Ό/i)) } if (['jp', 'jp-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies, /ζ—₯本|jp|japan|πŸ‡―πŸ‡΅/i)) } if (['sg', 'sg-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies, /^(?!.*(?:us)).*(ζ–°|sg|singapore|πŸ‡ΈπŸ‡¬)/i)) } if (['us', 'us-auto'].includes(i.tag)) { i.outbounds.push(...getTags(proxies, /美|us|unitedstates|united states|πŸ‡ΊπŸ‡Έ/i)) } }) config.outbounds.forEach(outbound => { if (Array.isArray(outbound.outbounds) && outbound.outbounds.length === 0) { if (!compatible) { config.outbounds.push(compatible_outbound) compatible = true } outbound.outbounds.push(compatible_outbound.tag); } }); $content = JSON.stringify(config, null, 2) function getTags(proxies, regex) { return (regex ? proxies.filter(p => regex.test(p.tag)) : proxies).map(p => p.tag) }