mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 18:24:58 +00:00
Add option to change style of proxies section in Clash subscriptions
This commit is contained in:
5 files changed
+37
-1
No files matched your search
@@ -47,6 +47,7 @@ node_pref:
|
|||||||
filter_deprecated_nodes: false
|
filter_deprecated_nodes: false
|
||||||
append_sub_userinfo: true
|
append_sub_userinfo: true
|
||||||
clash_use_new_field_name: true
|
clash_use_new_field_name: true
|
||||||
|
clash_proxies_style: flow
|
||||||
rename_node:
|
rename_node:
|
||||||
# - {match: "\\(?((x|X)?(\\d+)(\\.?\\d+)?)((\\s?倍率?)|(x|X))\\)?", replace: "$1x"}
|
# - {match: "\\(?((x|X)?(\\d+)(\\.?\\d+)?)((\\s?倍率?)|(x|X))\\)?", replace: "$1x"}
|
||||||
# - {script: "function rename(node){}"}
|
# - {script: "function rename(node){}"}
|
||||||
|
|||||||
@@ -103,6 +103,14 @@ filter_deprecated_nodes=false
|
|||||||
append_sub_userinfo=true
|
append_sub_userinfo=true
|
||||||
clash_use_new_field_name=true
|
clash_use_new_field_name=true
|
||||||
|
|
||||||
|
;Generate style of the proxies section of Clash subscriptions.
|
||||||
|
;Supported styles: block, flow, compact
|
||||||
|
;Block: - name: name1 Flow: - {name: name1, key: value} Compact: [{name: name1, key: value},{name: name2, key: value}]
|
||||||
|
; key: value - {name: name2, key: value}
|
||||||
|
; - name: name2
|
||||||
|
; key: value
|
||||||
|
clash_proxies_style=flow
|
||||||
|
|
||||||
;Rename remarks with the following patterns. Supports regular expression.
|
;Rename remarks with the following patterns. Supports regular expression.
|
||||||
;Format: Search_Pattern@Replace_Pattern
|
;Format: Search_Pattern@Replace_Pattern
|
||||||
;rename_node=IPLC@专线
|
;rename_node=IPLC@专线
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ bool add_emoji = false, remove_old_emoji = false, append_proxy_type = false, fil
|
|||||||
tribool udp_flag, tfo_flag, scv_flag, tls13_flag, enable_insert;
|
tribool udp_flag, tfo_flag, scv_flag, tls13_flag, enable_insert;
|
||||||
bool do_sort = false, config_update_strict = false;
|
bool do_sort = false, config_update_strict = false;
|
||||||
bool clash_use_new_field_name = false;
|
bool clash_use_new_field_name = false;
|
||||||
|
std::string clash_proxies_style = "flow";
|
||||||
std::string proxy_config, proxy_ruleset, proxy_subscription;
|
std::string proxy_config, proxy_ruleset, proxy_subscription;
|
||||||
int config_update_interval = 0;
|
int config_update_interval = 0;
|
||||||
std::string sort_script, filter_script;
|
std::string sort_script, filter_script;
|
||||||
@@ -745,6 +746,7 @@ void readYAMLConf(YAML::Node &node)
|
|||||||
section["filter_deprecated_nodes"] >> filter_deprecated;
|
section["filter_deprecated_nodes"] >> filter_deprecated;
|
||||||
section["append_sub_userinfo"] >> append_userinfo;
|
section["append_sub_userinfo"] >> append_userinfo;
|
||||||
section["clash_use_new_field_name"] >> clash_use_new_field_name;
|
section["clash_use_new_field_name"] >> clash_use_new_field_name;
|
||||||
|
section["clash_proxies_style"] >> clash_proxies_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(section["rename_node"].IsSequence())
|
if(section["rename_node"].IsSequence())
|
||||||
@@ -983,6 +985,7 @@ void readConf()
|
|||||||
ini.GetBoolIfExist("filter_deprecated_nodes", filter_deprecated);
|
ini.GetBoolIfExist("filter_deprecated_nodes", filter_deprecated);
|
||||||
ini.GetBoolIfExist("append_sub_userinfo", append_userinfo);
|
ini.GetBoolIfExist("append_sub_userinfo", append_userinfo);
|
||||||
ini.GetBoolIfExist("clash_use_new_field_name", clash_use_new_field_name);
|
ini.GetBoolIfExist("clash_use_new_field_name", clash_use_new_field_name);
|
||||||
|
ini.GetIfExist("clash_proxies_style", clash_proxies_style);
|
||||||
if(ini.ItemPrefixExist("rename_node"))
|
if(ini.ItemPrefixExist("rename_node"))
|
||||||
{
|
{
|
||||||
ini.GetAll("rename_node", tempArray);
|
ini.GetAll("rename_node", tempArray);
|
||||||
@@ -1450,6 +1453,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
if((target == "clash" || target == "clashr") && clash_script.is_undef())
|
if((target == "clash" || target == "clashr") && clash_script.is_undef())
|
||||||
expand.define(true);
|
expand.define(true);
|
||||||
|
|
||||||
|
ext.clash_proxies_style = clash_proxies_style;
|
||||||
|
|
||||||
/// read preference from argument, assign global var if not in argument
|
/// read preference from argument, assign global var if not in argument
|
||||||
ext.tfo.parse(tfo).parse(tfo_flag);
|
ext.tfo.parse(tfo).parse(tfo_flag);
|
||||||
ext.udp.parse(udp).parse(udp_flag);
|
ext.udp.parse(udp).parse(udp_flag);
|
||||||
@@ -2072,6 +2077,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extra_settings ext = {true, true, dummy_str_array, dummy_str_array, false, false, false, false, do_sort, filter_deprecated, clash_use_new_field_name, false, "", "", "", udp_flag, tfo_flag, scv_flag, tls13_flag};
|
extra_settings ext = {true, true, dummy_str_array, dummy_str_array, false, false, false, false, do_sort, filter_deprecated, clash_use_new_field_name, false, "", "", "", udp_flag, tfo_flag, scv_flag, tls13_flag};
|
||||||
|
ext.clash_proxies_style = clash_proxies_style;
|
||||||
|
|
||||||
netchToClash(nodes, clash, dummy_str_array, false, ext);
|
netchToClash(nodes, clash, dummy_str_array, false, ext);
|
||||||
|
|
||||||
|
|||||||
+21
-1
@@ -1149,6 +1149,20 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, const stri
|
|||||||
std::vector<nodeInfo> nodelist;
|
std::vector<nodeInfo> nodelist;
|
||||||
bool tlssecure;
|
bool tlssecure;
|
||||||
string_array vArray, remarks_list, filtered_nodelist;
|
string_array vArray, remarks_list, filtered_nodelist;
|
||||||
|
/// proxies style
|
||||||
|
bool block = false, compact = false;
|
||||||
|
switch(hash_(ext.clash_proxies_style))
|
||||||
|
{
|
||||||
|
case "block"_hash:
|
||||||
|
block = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case "flow"_hash:
|
||||||
|
break;
|
||||||
|
case "compact"_hash:
|
||||||
|
compact = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for(nodeInfo &x : nodes)
|
for(nodeInfo &x : nodes)
|
||||||
{
|
{
|
||||||
@@ -1341,12 +1355,18 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, const stri
|
|||||||
|
|
||||||
if(udp)
|
if(udp)
|
||||||
singleproxy["udp"] = true;
|
singleproxy["udp"] = true;
|
||||||
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
|
if(block)
|
||||||
|
singleproxy.SetStyle(YAML::EmitterStyle::Block);
|
||||||
|
else
|
||||||
|
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
proxies.push_back(singleproxy);
|
proxies.push_back(singleproxy);
|
||||||
remarks_list.emplace_back(std::move(remark));
|
remarks_list.emplace_back(std::move(remark));
|
||||||
nodelist.emplace_back(x);
|
nodelist.emplace_back(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(compact)
|
||||||
|
proxies.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
|
||||||
if(ext.nodelist)
|
if(ext.nodelist)
|
||||||
{
|
{
|
||||||
YAML::Node provider;
|
YAML::Node provider;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ struct extra_settings
|
|||||||
tribool tls13 = tribool();
|
tribool tls13 = tribool();
|
||||||
bool clash_classical_ruleset = false;
|
bool clash_classical_ruleset = false;
|
||||||
std::string sort_script = "";
|
std::string sort_script = "";
|
||||||
|
std::string clash_proxies_style = "flow";
|
||||||
};
|
};
|
||||||
|
|
||||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);
|
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);
|
||||||
|
|||||||
Reference in new issue
Block a user