// https://docs.cfw.lbyczf.com/contents/parser.html#%E8%BF%9B%E9%98%B6%E6%96%B9%E6%B3%95-javascript module.exports.parse = async(raw, utils, meta) => { const { axios, yaml, notify, console } = utils const { name, url, interval, selected } = meta const obj = yaml.parse(raw) try { await configPrependRules(utils, obj) } catch (e) { throw new Error(e) } return yaml.stringify(obj) } // 配置预先规则 async function configPrependRules(utils, obj) { const { axios,console } = utils const proxyGroupName = getProxyGroupName(obj) const directGroupName = getDirectGroupName(obj) try { const directResponse = await axios.get('https://git.yevpt.com/vpt/public-data/raw/branch/master/direct') const directs = directResponse.data const prependDirectRules = directs.split(`\n`).map(item => `DOMAIN-SUFFIX,${item},${directGroupName}`) const proxyResponse = await axios.get('https://git.yevpt.com/vpt/public-data/raw/branch/master/proxy') const proxys = proxyResponse.data console.log('proxys',proxys.split(`\n`).slice(-5)) const prependProxyRules = proxys.split(`\n`).map(item => `DOMAIN-SUFFIX,${item},${proxyGroupName}`) const prependRules = [...prependDirectRules, ...prependProxyRules] obj.rules = [...prependRules, ...obj.rules] } catch (e) { throw new Error(e) } } // 获取代理组的名称 function getProxyGroupName(obj) { const nodeSelectName = obj['proxy-groups'].find(item => item.name.includes('节点选择')) if (nodeSelectName) { return nodeSelectName.name } return obj['proxy-groups'].find(item => item.name.includes('手动切换')).name } // 获取直连组的名称 function getDirectGroupName(obj) { return 'DIRECT' }