diff --git a/mihomo_editor.py b/mihomo_editor.py index 4792d5e..7a56d8e 100644 --- a/mihomo_editor.py +++ b/mihomo_editor.py @@ -250,6 +250,7 @@ def insert_proxy_logic(content, proxy_name, target_groups): if is_new_group: if in_proxies_list and current_group_name in target_groups and current_group_name not in inserted_in_group: + # End of list section prefix = " " * (proxies_list_indent + 2) new_lines.append(prefix + '- "' + proxy_name + '"') inserted_in_group.add(current_group_name) @@ -268,6 +269,26 @@ def insert_proxy_logic(content, proxy_name, target_groups): current_group_name = raw_name.strip("'").strip('"') if current_group_name in target_groups and stripped.startswith('proxies:'): + # Check for inline list style: proxies: [a, b] + if '[' in stripped and stripped.rstrip().endswith(']'): + start = line.find('[') + end = line.rfind(']') + if start != -1 and end != -1: + content_inner = line[start + 1:end] + # Check if proxy already exists in the list + # Simple check: name in text (robust enough for simple cases) + if proxy_name not in content_inner: + sep = ", " if content_inner.strip() else "" + new_content = content_inner + sep + f'"{proxy_name}"' + new_line = line[:start + 1] + new_content + line[end:] + new_lines.append(new_line) + inserted_in_group.add(current_group_name) + continue + else: + new_lines.append(line) + inserted_in_group.add(current_group_name) + continue + in_proxies_list = True proxies_list_indent = indent new_lines.append(line) @@ -303,7 +324,7 @@ HTML_TEMPLATE = """
-