From aa60cce51b11fde7821338a2b947ad8a0e802b36 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sun, 4 Dec 2022 16:44:06 +0900 Subject: [PATCH] update docs --- README.md | 6 +- {examples/docs => docs}/Build_Linux.md | 1 + {examples/docs => docs}/Build_Windows.md | 0 docs/HookJS.md | 106 +++++++++++++++++++++++ {examples/docs => docs}/Run_Linux.md | 0 docs/readme.md | 1 + 6 files changed, 111 insertions(+), 3 deletions(-) rename {examples/docs => docs}/Build_Linux.md (96%) rename {examples/docs => docs}/Build_Windows.md (100%) create mode 100644 docs/HookJS.md rename {examples/docs => docs}/Run_Linux.md (100%) create mode 100644 docs/readme.md diff --git a/README.md b/README.md index 63bc287..7aa8893 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ https://matsuridayo.github.io ## Linux 运行 -[Linux 运行教程](examples/docs/Run_Linux.md) +[Linux 运行教程](docs/Run_Linux.md) ## 编译教程 -[Linux](examples/docs/Build_Linux.md) +[Linux](docs/Build_Linux.md) -[Windows](examples/docs/Build_Windows.md) +[Windows](docs/Build_Windows.md) ## 捐助 / Donate diff --git a/examples/docs/Build_Linux.md b/docs/Build_Linux.md similarity index 96% rename from examples/docs/Build_Linux.md rename to docs/Build_Linux.md index a3166c7..8af1a20 100644 --- a/examples/docs/Build_Linux.md +++ b/docs/Build_Linux.md @@ -38,6 +38,7 @@ ninja | NKR_NO_QHOTKEY | | 不包含qhotkey | | NKR_NO_ZXING | | 不包含zxing | | NKR_NO_GRPC | | 不包含gRPC | +| NKR_NO_QUICKJS | | 不包含quickjs | #### C++ 部分 diff --git a/examples/docs/Build_Windows.md b/docs/Build_Windows.md similarity index 100% rename from examples/docs/Build_Windows.md rename to docs/Build_Windows.md diff --git a/docs/HookJS.md b/docs/HookJS.md new file mode 100644 index 0000000..7d0c9e5 --- /dev/null +++ b/docs/HookJS.md @@ -0,0 +1,106 @@ +# hook.js 使用 +## 如何启用 + +1. 打开 `基本设置 - 安全 - 启用 hook.js 功能` +2. js 代码请放置于 `config/hook.nekoray.js` 或 `config/hook.nekobox.js` + +## 技术信息 + +* JS Engine: QuickJS ES2020 +* 提供的接口:如下面代码所示 + +## 示例代码 (typescript) + +```ts +const globalAny: any = globalThis + +// 目前提供的方法 +interface nekoray_in { + log(...a: any): void +} + +// 目前提供的 hook 点 +interface nekoray_hook { + hook_core_config(config: string): string + hook_vpn_config(config: string): string + hook_vpn_script(script: string): string + hook_import(content: string): string +} + +class my_hook implements nekoray_hook { + private nekoray = globalAny.nekoray as nekoray_in + + hook_core_config(config: string): string { + var json = JSON.parse(config) + var my_rule = { + "geosite": "cn", + "server": "dns-direct", + "disable_cache": true + } + json["dns"]["rules"].push(my_rule) + return JSON.stringify(json) + } + + hook_vpn_config(config: string): string { + return config // 返回输入,表示不修改 + } + + hook_vpn_script(script: string): string { + console.log("Script") // 输出到 stdout + this.nekoray.log("Script:", script) // 输出到日志 + return script + } + + hook_import(content: string): string { + var newContent: Array = [] + content.split("\n").forEach((line: any) => { + if (line.startsWith("vmess://")) { + newContent.push(line) + } + }) + return newContent.join("\n") + } +} + +globalAny.hook = new my_hook +``` + +## 示例代码 (javascript) + +```js +var globalAny = globalThis; +var my_hook = /** @class */ (function () { + function my_hook() { + this.nekoray = globalAny.nekoray; + } + my_hook.prototype.hook_core_config = function (config) { + var json = JSON.parse(config); + var my_rule = { + "geosite": "cn", + "server": "dns-direct", + "disable_cache": true + }; + json["dns"]["rules"].push(my_rule); + return JSON.stringify(json); + }; + my_hook.prototype.hook_vpn_config = function (config) { + return config; // 返回输入,表示不修改 + }; + my_hook.prototype.hook_vpn_script = function (script) { + console.log("Script"); // 输出到 stdout + this.nekoray.log("Script:", script); // 输出到日志 + return script; + }; + my_hook.prototype.hook_import = function (content) { + var newContent = []; + content.split("\n").forEach(function (line) { + if (line.startsWith("vmess://")) { + newContent.push(line); + } + }); + return newContent.join("\n"); + }; + return my_hook; +}()); +globalAny.hook = new my_hook; +``` diff --git a/examples/docs/Run_Linux.md b/docs/Run_Linux.md similarity index 100% rename from examples/docs/Run_Linux.md rename to docs/Run_Linux.md diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..fe206e1 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1 @@ +# 技术文档