Anywhere-converter 是一个通用的 Loon / Surge 插件、模块、JavaScript rewrite 和规则集转换器,用来生成 Anywhere 可导入的 .amrs / .arrs。
它会优先把稳定能力转换为 Anywhere 原生规则;远程脚本默认会下载并尝试识别,能静态确认的 JSON/请求改写会被提升为原生规则,无法安全提升的脚本会通过兼容层保留。二进制、protobuf、大型混合脚本和强应用语义的脚本会标记为需要样本或实机验证,而不是盲目承诺等价。
为了个人用户使用方便,也为了避免公开服务被大量远程脚本下载、动态订阅刷新和重复转换请求拖慢,建议自行部署一个属于自己的转换器实例。
作者部署的公开转换器可以用于体验和临时转换,但不建议把它作为长期订阅转换服务。自部署的好处是:
- 转换请求、远程脚本下载和缓存都由自己的 Worker 承担。
- 动态订阅链接可以稳定跟随上游模块更新。
- 可以按自己的需求调整大小限制、缓存时间和速率限制。
- 避免公开服务限流或不可用时影响自己的规则更新。
- Loon / Surge 模块、插件转换为 Anywhere MITM 规则
.amrs - Loon / Surge 规则集转换为 Anywhere 路由规则
.arrs [MITM] hostname、[Rule]、[Rewrite]、[Header Rewrite]、[Map Local]、[Body Rewrite]、[Argument]等常见配置转换- 远程
script-path下载、脚本合并、参数替换、兼容层包装 - 高置信度 JavaScript 原生化,例如 JSON 删除、替换、数组过滤、固定响应、静态请求改写
- 可选增强 JS 原生化模式
- Cloudflare Worker 在线 UI、API、动态订阅链接
- 浏览器端下载单个
.amrs/.arrs或打包 zip,减少后续 Worker 访问
本地部署适合开发、测试或临时转换。需要 Node.js 18+。
git clone https://github.com/chikacya/anywhere-converter.git
cd anywhere-converter
npm install启动本地网页:
npm run dev默认会启动 Wrangler 本地服务,通常地址是:
http://localhost:8787/
本地 CLI 转换:
npm run convert -- --input path/to/module.plugin --out-dir ./out转换独立规则集时,需要指定规则集类型和路由:
npm run convert -- \
--input path/to/ad.list \
--source-kind ruleset \
--rule-set-routing reject \
--out-dir ./out-ruleset启用增强 JS 原生化:
npm run convert -- \
--input path/to/module.plugin \
--mode aggressive \
--out-dir ./out-aggressive覆盖模块参数:
npm run convert -- \
--input path/to/module.plugin \
--argument smzdm_enable=false当远程脚本无法下载时,可以手动提供脚本文本:
npm run convert -- \
--input path/to/module.plugin \
--script-text 'https://example.com/script.js=/path/to/script.js' \
--out-dir ./outCloudflare Worker 部署适合长期使用,可以生成在线转换页面、API 和动态订阅链接。
- Fork 或创建自己的仓库,并推送本项目代码。
- 打开 Cloudflare Dashboard。
- 进入
Workers & Pages。 - 选择
Create application。 - 选择
Pages或支持 GitHub 部署的 Worker 项目入口。 - 连接自己的 GitHub 仓库。
- 构建命令留空或使用默认 Node 环境即可,本项目 Worker 入口是
src/worker.mjs。 - 如果 Dashboard 要求 Worker 配置,请确认使用
wrangler.toml。 - 部署完成后,打开 Cloudflare 分配的域名即可使用。
建议绑定 KV,用于保存快照链接:
- 在 Cloudflare Dashboard 创建 KV namespace,例如
CONVERTER_KV。 - 把 namespace 绑定到 Worker,变量名填
CONVERTER_KV。 - 如果使用
wrangler.toml,把自己的 namespace id 填入kv_namespaces。
可配置环境变量:
| 变量 | 作用 | 默认建议 |
|---|---|---|
MAX_INPUT_BYTES |
模块/规则集最大输入大小 | 524288 |
MAX_SCRIPT_BYTES |
单个远程脚本最大大小 | 1048576 |
MAX_TOTAL_SCRIPT_BYTES |
单次转换远程脚本总大小 | 5242880 |
MAX_SCRIPT_FETCHES |
单次转换最多下载多少个唯一远程脚本,0 表示不主动限制 |
45 |
FETCH_CACHE_TTL_SECONDS |
上游模块/脚本 fetch 缓存时间 | 900 |
DYNAMIC_CACHE_TTL_SECONDS |
动态订阅转换结果缓存时间 | 900 |
RATE_LIMIT_PER_MINUTE |
每分钟请求限制,0 表示关闭 |
60 |
git clone https://github.com/chikacya/anywhere-converter.git
cd anywhere-converter
npm install
npx wrangler login创建 KV:
npx wrangler kv namespace create CONVERTER_KV把输出的 namespace id 写入 wrangler.toml:
[[kv_namespaces]]
binding = "CONVERTER_KV"
id = "your_namespace_id"部署:
npm run deploy部署完成后,Wrangler 会输出 Worker URL。
- 打开自己的 Worker URL。
- 粘贴 Loon / Surge 模块内容,或填入远程模块 URL。
- 如模块包含
[Argument],点击读取配置后按需调整参数。 - 保持
下载并保留远程脚本开启,转换器会下载远程 JS 并尝试原生化。 - 需要更激进的静态 JSON 脚本提升时,再开启
增强 JS 原生化。 - 点击
转换。 - 使用
导入 Anywhere直接导入,或使用下载文件/下载全部保存到本地。
URL 输入转换时,结果会优先生成 /sub/* 动态订阅链接。这类链接保留原始上游 URL,Worker 会在缓存过期后重新拉取上游并转换,适合需要跟随上游更新的模块。
示例:
https://<worker-host>/sub/mitm.amrs?url=<module-url>
独立规则集示例:
https://<worker-host>/sub/reject.arrs?url=<ruleset-url>&sourceKind=ruleset&ruleSetRouting=reject
如果你只想减轻 Worker 压力,不需要动态跟随上游更新,可以在网页转换后下载生成文件,并自行导入或托管。
curl -sS https://<worker-host>/api/convert \
-H 'content-type: application/json' \
-d '{"url":"https://example.com/module.plugin","includeContent":false,"includeSource":true}'规则集 API:
curl -sS https://<worker-host>/api/convert \
-H 'content-type: application/json' \
-d '{"url":"https://example.com/ad.list","sourceKind":"ruleset","ruleSetRouting":"reject","includeContent":false}'npm test
node --check src/core.mjs
node --check src/worker.mjs
node --check src/ui.mjs
node --check bin/cli.mjs- 兼容层覆盖常见
$request、$response、$done、$argument、$persistentStore、$prefs、Env helper、$httpClient、$task.fetch、fetch等,但不是完整 Loon / Surge 运行时。 - protobuf / 二进制脚本会保留并标记为需要样本验证,通用转换器不会自动推断字段语义。
- 大型混合脚本、动态代码、复杂外部请求和强应用语义脚本仍可能需要人工转换。
- 手工转换产物用于验证通用转换器能力,不会被固化为逐模块硬编码输出。
Anywhere-converter is a generic converter for Loon / Surge plugins, modules, JavaScript rewrites, and rule sets. It generates .amrs / .arrs files that can be imported into Anywhere.
The converter is intentionally conservative. Stable Loon / Surge features are mapped to native Anywhere rules first. Remote JavaScript is fetched by default; high-confidence JSON and request rewrite patterns are lifted to native rules, while the remaining scripts are preserved through a compatibility wrapper. Binary, protobuf, large mixed bundles, and app-specific dynamic behavior are marked as needing samples or real-device validation instead of being guessed.
For personal use, self-deployment is strongly recommended. The maintainer's public converter is useful for demos and occasional conversions, but it should not be treated as a long-term shared subscription service.
Self-deployment is better because:
- Your own Worker handles conversion requests and remote script fetching.
- Dynamic subscription links can follow upstream module updates reliably.
- You can control size limits, cache TTLs, and rate limits.
- Your rule updates will not depend on public service availability or throttling.
- Convert Loon / Surge modules and plugins to Anywhere MITM
.amrs - Convert Loon / Surge rule sets to Anywhere routing
.arrs - Support common sections such as
[MITM],[Rule],[Rewrite],[Header Rewrite],[Map Local],[Body Rewrite], and[Argument] - Fetch remote
script-pathfiles, merge scripts, substitute arguments, and wrap compatibility scripts - Lift high-confidence JavaScript patterns into native Anywhere rules
- Optional aggressive JavaScript native-lift mode
- Cloudflare Worker UI, API, and dynamic subscription links
- Browser-side file and zip download to reduce repeated Worker hits
Local deployment is useful for development, testing, and one-off conversions. Node.js 18+ is recommended.
git clone https://github.com/chikacya/anywhere-converter.git
cd anywhere-converter
npm installStart the local web UI:
npm run devThe local URL is usually:
http://localhost:8787/
Run the CLI converter:
npm run convert -- --input path/to/module.plugin --out-dir ./outConvert a standalone rule set:
npm run convert -- \
--input path/to/ad.list \
--source-kind ruleset \
--rule-set-routing reject \
--out-dir ./out-rulesetEnable aggressive JavaScript lifting:
npm run convert -- \
--input path/to/module.plugin \
--mode aggressive \
--out-dir ./out-aggressiveOverride module arguments:
npm run convert -- \
--input path/to/module.plugin \
--argument smzdm_enable=falseProvide trusted script text when a remote script cannot be fetched:
npm run convert -- \
--input path/to/module.plugin \
--script-text 'https://example.com/script.js=/path/to/script.js' \
--out-dir ./outCloudflare Worker deployment is recommended for long-term use. It provides an online UI, API endpoints, and dynamic subscription links.
- Fork this repository or push it to your own GitHub repository.
- Open the Cloudflare Dashboard.
- Go to
Workers & Pages. - Create a new application.
- Connect your GitHub repository.
- Use the project configuration from
wrangler.toml; the Worker entry issrc/worker.mjs. - Deploy and open the generated Worker URL.
KV is recommended for durable snapshot links:
- Create a KV namespace, for example
CONVERTER_KV. - Bind it to the Worker with the variable name
CONVERTER_KV. - If you use
wrangler.toml, put your namespace id underkv_namespaces.
Environment variables:
| Variable | Purpose | Suggested default |
|---|---|---|
MAX_INPUT_BYTES |
Maximum module/rule-set input size | 524288 |
MAX_SCRIPT_BYTES |
Maximum size for one remote script | 1048576 |
MAX_TOTAL_SCRIPT_BYTES |
Maximum total remote script bytes per conversion | 5242880 |
MAX_SCRIPT_FETCHES |
Maximum unique remote scripts fetched per conversion; 0 disables the converter-side cap |
45 |
FETCH_CACHE_TTL_SECONDS |
Upstream source/script fetch cache TTL | 900 |
DYNAMIC_CACHE_TTL_SECONDS |
Dynamic subscription conversion cache TTL | 900 |
RATE_LIMIT_PER_MINUTE |
Per-client rate limit; 0 disables it |
60 |
git clone https://github.com/chikacya/anywhere-converter.git
cd anywhere-converter
npm install
npx wrangler loginCreate KV:
npx wrangler kv namespace create CONVERTER_KVPut the namespace id into wrangler.toml:
[[kv_namespaces]]
binding = "CONVERTER_KV"
id = "your_namespace_id"Deploy:
npm run deployWrangler will print the Worker URL after deployment.
- Open your Worker URL.
- Paste a Loon / Surge module, or enter a remote module URL.
- If the module has
[Argument], click读取配置and adjust the generated form. - Keep
下载并保留远程脚本enabled so remote JavaScript can be fetched and converted or preserved. - Enable
增强 JS 原生化only when you want extra static JSON cleanup lifting. - Click
转换. - Import directly into Anywhere, or download the generated files.
URL-based conversions prefer /sub/* dynamic subscription links. These links keep the original upstream URL, so the Worker can refresh and convert updated upstream content after the cache expires.
Example:
https://<worker-host>/sub/mitm.amrs?url=<module-url>
Standalone rule-set example:
https://<worker-host>/sub/reject.arrs?url=<ruleset-url>&sourceKind=ruleset&ruleSetRouting=reject
If you want to reduce Worker traffic and do not need automatic upstream updates, download the generated files from the web UI and import or host them yourself.
curl -sS https://<worker-host>/api/convert \
-H 'content-type: application/json' \
-d '{"url":"https://example.com/module.plugin","includeContent":false,"includeSource":true}'Rule-set API:
curl -sS https://<worker-host>/api/convert \
-H 'content-type: application/json' \
-d '{"url":"https://example.com/ad.list","sourceKind":"ruleset","ruleSetRouting":"reject","includeContent":false}'npm test
node --check src/core.mjs
node --check src/worker.mjs
node --check src/ui.mjs
node --check bin/cli.mjs- The compatibility wrapper covers common Loon / Surge APIs, but it is not a full Loon / Surge runtime.
- Protobuf and binary scripts are preserved and marked as needing validation. The generic converter does not infer schema semantics.
- Large mixed bundles, dynamic code, complex external HTTP workflows, and app-specific behavior may still need manual conversion.
- Hand-converted modules are used as validation references, not as hard-coded templates for generated output.