Last active
April 7, 2023 12:00
-
-
Save log2c/6d2aab87dfe560fbcec3fd3b8c7830bd to your computer and use it in GitHub Desktop.
一些关于clash及surge 的脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.parse = ({ content, name, url }, { yaml, axios, notify }) => { | |
const remove_names = new Set(); | |
const allowList = [80, 8080, 443, 27833, 22]; // 待保留端口的节点 | |
const fallbackProxy = ["DIRECT", "REJECT"]; // proxies为空时自动追加__"自动选择" | |
if (Array.isArray(content.proxies)) { | |
content.proxies = content.proxies | |
.filter((proxy => { | |
if (allowList.indexOf(proxy.port) === -1) { | |
remove_names.add(proxy.name); | |
return false; | |
} else { | |
return true; | |
} | |
})); | |
} | |
const groups = content['proxy-groups'] || []; | |
if (Array.isArray(groups)) { | |
groups.forEach((group) => { | |
const proxies = group.proxies | |
.filter((proxy) => !remove_names.has(proxy)); | |
group.proxies = proxies; | |
// update 2022/4/8 | |
if ((group.proxies || []).length === 0) { | |
group.proxies = [...fallbackProxy]; | |
} | |
}); | |
} | |
return content | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
有了ChatGPT之后代码水平一日千里,分享一下从ChatGPT那里学来的代码:
const portList = [22,80,443,1080,8080,]; // 设置端口号匹配规则
const fallbackProxy = ['DIRECT','REJECT',]; // 分组无匹配结果的默认设置
content.proxies = content.proxies?.filter(proxy => portList.includes(proxy.port));
content['proxy-groups']?.forEach(group => {
group.proxies = group.proxies.filter( proxy =>
['DIRECT', 'REJECT', ...content.proxies?.map(proxy => proxy.name), ...content['proxy-groups'].map(group => group.name)].includes(proxy));
group.proxies = group.proxies.length ? group.proxies : fallbackProxy;
});