Skip to content

Commit f43e34c

Browse files
committed
add function to mixin, support removed
1 parent 7955ff5 commit f43e34c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

clashN/clashN/Handler/CoreConfigHandler.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ private static void MixinContent(Dictionary<string, object> fileContent, Config
181181
continue;
182182
}
183183

184-
if (item.Key.StartsWith("prepend-") || item.Key.StartsWith("append-"))
184+
if (item.Key.StartsWith("prepend-")
185+
|| item.Key.StartsWith("append-")
186+
|| item.Key.StartsWith("removed-"))
185187
{
186188
ModifyContentMerge(fileContent, item.Key, item.Value);
187189
}
@@ -207,6 +209,7 @@ private static void ModifyContent(Dictionary<string, object> fileContent, string
207209
private static void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
208210
{
209211
bool blPrepend = false;
212+
bool blRemoved = false;
210213
if (key.StartsWith("prepend-"))
211214
{
212215
blPrepend = true;
@@ -217,16 +220,32 @@ private static void ModifyContentMerge(Dictionary<string, object> fileContent, s
217220
blPrepend = false;
218221
key = key.Replace("append-", "");
219222
}
223+
else if (key.StartsWith("removed-"))
224+
{
225+
blRemoved = true;
226+
key = key.Replace("removed-", "");
227+
}
220228
else
221229
{
222230
return;
223231
}
232+
var lstOri = (List<object>)fileContent[key];
233+
var lstValue = (List<object>)value;
234+
235+
if (blRemoved)
236+
{
237+
foreach (var item in lstValue)
238+
{
239+
lstOri.RemoveAll(t => t.ToString().StartsWith(item.ToString()));
240+
}
241+
return;
242+
}
243+
224244
if (!fileContent.ContainsKey(key))
225245
{
246+
fileContent.Add(key, value);
226247
return;
227248
}
228-
var lstOri = (List<object>)fileContent[key];
229-
var lstValue = (List<object>)value;
230249

231250
if (blPrepend)
232251
{

clashN/clashN/Sample/SampleMixin.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
#
66
# 使用clash配置文件关键字则覆盖原配置
77
#
8+
# removed-rules 循环匹配rules数组每行,符合则移除当前行 (此规则请放最前面)
9+
#
810
# append-rules 数组合并至原配置rules数组后
911
# prepend-rules 数组合并至原配置rules数组前
1012
# append-proxies 数组合并至原配置proxies数组后
1113
# prepend-proxies 数组合并至原配置proxies数组前
1214
# append-proxy-groups 数组合并至原配置proxy-groups数组后
1315
# prepend-proxy-groups 数组合并至原配置proxy-groups数组前
16+
# append-rule-providers 数组合并至原配置rule-providers数组后
17+
# prepend-rule-providers 数组合并至原配置rule-providers数组前
1418
#
1519

1620
dns:

0 commit comments

Comments
 (0)