Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Aethersailor
Custom_OpenClash_Rules
Repository navigation
Code
Issues
Pull requests
Discussions
Actions
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Custom_OpenClash_Rules
/
overwrite
/
Rule_Provider_Format_Fix.conf
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
30 lines (28 loc) · 1.92 KB
main
Breadcrumbs
Custom_OpenClash_Rules
/
overwrite
/
Rule_Provider_Format_Fix.conf
Copy path
Top
File metadata and controls
Code
Blame
30 lines (28 loc) · 1.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!NAME = Rule_Provider_Format_Fix.conf
#!DESC = 根据 URL 或 path 的文件扩展名补全或修正 Rule Provider 的 format
#!CONFIG = all
#!CRON = off
[Overwrite]
# Author: Aethersailor
# Project: Custom_OpenClash_Rules
# Compatibility: 需 OpenClash 支持 [Overwrite] 与 ruby_edit,Mihomo 支持 rule-providers.format
# Action: 遍历顶层 rule-providers,并根据 .mrs、.yaml 或 .yml 后缀写入对应 format
# Conflicts: 识别到受支持扩展名时会覆盖与扩展名不一致的现有 format
# Verification: 在最终运行配置中检查目标 Rule Provider 的 format 是否与文件扩展名一致
#
# 功能:
# 1. 普通远程 Provider 优先根据 url 后缀判断,再回退检查 path
# 2. type: file 优先根据 path 后缀判断,再回退检查 url
# 3. .mrs 设置为 format: mrs
# 4. .yaml 或 .yml 设置为 format: yaml
# 5. 忽略 URL 查询参数和片段,扩展名匹配不区分大小写
# 6. 未识别到受支持扩展名时保持原配置不变
#
# 限制:
# - 只处理顶层 rule-providers
# - 只识别 .mrs、.yaml 和 .yml
# - 不修改 type、behavior、url 或 path
# - 不下载或校验 Rule Provider 的实际文件内容
# - 如果文件扩展名与实际内容不一致,仍会按照扩展名设置 format
# 使用字符串分割,兼容未补齐正则 AST 节点白名单的旧版 OpenClash。
ruby_edit "$CONFIG_FILE" "['rule-providers']" "Value['rule-providers'].is_a?(Hash) ? Value['rule-providers'].transform_values { |provider| provider.is_a?(Hash) ? (provider['type'].to_s == 'file' ? [provider['path'], provider['url']] : [provider['url'], provider['path']]).compact.map { |item| item.to_s.split('?').first.to_s.split('#').first.to_s.downcase }.find { |item| item.end_with?('.mrs') || item.end_with?('.yaml') || item.end_with?('.yml') }.then { |source| source ? provider.merge('format' => (source.end_with?('.mrs') ? 'mrs' : 'yaml')) : provider } : provider } : Value['rule-providers']"
You can’t perform that action at this time.