From 605ff5a0bb5e389fc8ee7403a9bce38c825d03a3 Mon Sep 17 00:00:00 2001 From: vpt Date: Tue, 10 Jan 2023 15:53:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'clash.js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clash | 2 -- clash.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) delete mode 100644 clash create mode 100644 clash.js diff --git a/clash b/clash deleted file mode 100644 index 4f20050..0000000 --- a/clash +++ /dev/null @@ -1,2 +0,0 @@ -prepend-rules: - - DOMAIN-SUFFIX,mxwljsq.com,๐Ÿš€ ่Š‚็‚น้€‰ๆ‹ฉ \ No newline at end of file diff --git a/clash.js b/clash.js new file mode 100644 index 0000000..2fd103e --- /dev/null +++ b/clash.js @@ -0,0 +1,41 @@ +// 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 } = 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 + 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) { + return obj['proxy-groups'].find(item => item.name.includes('่Š‚็‚น้€‰ๆ‹ฉ')).name +} + +// ่Žทๅ–็›ด่ฟž็ป„็š„ๅ็งฐ +function getDirectGroupName(obj) { + return 'DIRECT' +}