add function to mixin, support removed
This commit is contained in:
@@ -181,7 +181,9 @@ namespace clashN.Handler
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.Key.StartsWith("prepend-") || item.Key.StartsWith("append-"))
|
if (item.Key.StartsWith("prepend-")
|
||||||
|
|| item.Key.StartsWith("append-")
|
||||||
|
|| item.Key.StartsWith("removed-"))
|
||||||
{
|
{
|
||||||
ModifyContentMerge(fileContent, item.Key, item.Value);
|
ModifyContentMerge(fileContent, item.Key, item.Value);
|
||||||
}
|
}
|
||||||
@@ -207,6 +209,7 @@ namespace clashN.Handler
|
|||||||
private static void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
private static void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
||||||
{
|
{
|
||||||
bool blPrepend = false;
|
bool blPrepend = false;
|
||||||
|
bool blRemoved = false;
|
||||||
if (key.StartsWith("prepend-"))
|
if (key.StartsWith("prepend-"))
|
||||||
{
|
{
|
||||||
blPrepend = true;
|
blPrepend = true;
|
||||||
@@ -217,17 +220,33 @@ namespace clashN.Handler
|
|||||||
blPrepend = false;
|
blPrepend = false;
|
||||||
key = key.Replace("append-", "");
|
key = key.Replace("append-", "");
|
||||||
}
|
}
|
||||||
else
|
else if (key.StartsWith("removed-"))
|
||||||
{
|
{
|
||||||
return;
|
blRemoved = true;
|
||||||
|
key = key.Replace("removed-", "");
|
||||||
}
|
}
|
||||||
if (!fileContent.ContainsKey(key))
|
else
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var lstOri = (List<object>)fileContent[key];
|
var lstOri = (List<object>)fileContent[key];
|
||||||
var lstValue = (List<object>)value;
|
var lstValue = (List<object>)value;
|
||||||
|
|
||||||
|
if (blRemoved)
|
||||||
|
{
|
||||||
|
foreach (var item in lstValue)
|
||||||
|
{
|
||||||
|
lstOri.RemoveAll(t => t.ToString().StartsWith(item.ToString()));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileContent.ContainsKey(key))
|
||||||
|
{
|
||||||
|
fileContent.Add(key, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (blPrepend)
|
if (blPrepend)
|
||||||
{
|
{
|
||||||
lstValue.Reverse();
|
lstValue.Reverse();
|
||||||
|
|||||||
@@ -5,12 +5,16 @@
|
|||||||
#
|
#
|
||||||
# 使用clash配置文件关键字则覆盖原配置
|
# 使用clash配置文件关键字则覆盖原配置
|
||||||
#
|
#
|
||||||
|
# removed-rules 循环匹配rules数组每行,符合则移除当前行 (此规则请放最前面)
|
||||||
|
#
|
||||||
# append-rules 数组合并至原配置rules数组后
|
# append-rules 数组合并至原配置rules数组后
|
||||||
# prepend-rules 数组合并至原配置rules数组前
|
# prepend-rules 数组合并至原配置rules数组前
|
||||||
# append-proxies 数组合并至原配置proxies数组后
|
# append-proxies 数组合并至原配置proxies数组后
|
||||||
# prepend-proxies 数组合并至原配置proxies数组前
|
# prepend-proxies 数组合并至原配置proxies数组前
|
||||||
# append-proxy-groups 数组合并至原配置proxy-groups数组后
|
# append-proxy-groups 数组合并至原配置proxy-groups数组后
|
||||||
# prepend-proxy-groups 数组合并至原配置proxy-groups数组前
|
# prepend-proxy-groups 数组合并至原配置proxy-groups数组前
|
||||||
|
# append-rule-providers 数组合并至原配置rule-providers数组后
|
||||||
|
# prepend-rule-providers 数组合并至原配置rule-providers数组前
|
||||||
#
|
#
|
||||||
|
|
||||||
dns:
|
dns:
|
||||||
|
|||||||
Reference in New Issue
Block a user