Skip to content

Commit 1f008ae

Browse files
committed
更新[BoxJs]: Surge、QuanX、Loon 都可以在 BoxJs 中手动运行脚本 (注意看 BoxJs 中的更新说明)
1 parent 7d69047 commit 1f008ae

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎box/release/box.release.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
{
22
"releases": [
3+
{
4+
"version": "0.6.5",
5+
"tags": ["beta"],
6+
"author": "@chavyleung",
7+
"icon": "https://avatars3.githubusercontent.com/u/29748519",
8+
"repo": "https://github.com/chavyleung",
9+
"notes": [
10+
{
11+
"name": "新增",
12+
"descs": ["Surge、QuanX、Loon 都可以在 BoxJs 中手动运行脚本"]
13+
},
14+
{
15+
"name": "说明",
16+
"descs": ["手动运行脚本采用 eval() 方案", "Surge 在配置了 http-api 参数下会使用 http-api 方案运行脚本", "因为手法有点特殊, 不保证所有脚本都能良好"]
17+
},
18+
{
19+
"name": "感谢",
20+
"descs": ["感谢 @NobyDa 野比大佬提醒可以使用 eval() 方案"]
21+
}
22+
]
23+
},
324
{
425
"version": "0.6.4",
526
"tags": ["beta"],

‎chavy.box.js‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const $ = new Env('BoxJs')
22
$.domain = '8.8.8.8'
33

4-
$.version = '0.6.4'
4+
$.version = '0.6.5'
55
$.versionType = 'beta'
66
$.KEY_sessions = 'chavy_boxjs_sessions'
77
$.KEY_versions = 'chavy_boxjs_versions'
@@ -469,10 +469,17 @@ async function handleApi() {
469469
// 运行脚本
470470
else if (data.cmd === 'runScript') {
471471
const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi')
472-
if (/.*?@.*?:[0-9]+/.test(httpapi)) {
472+
const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi)
473+
console.log(ishttpapi)
474+
if ($.isSurge() && ishttpapi) {
473475
await $.getScript(data.val.script).then((script) => $.runScript(script))
474476
} else {
475-
$.msg($.name, '请先设置 http-api !')
477+
await $.getScript(data.val.script).then((script) => {
478+
// 避免被执行脚本误认为是 rewrite 环境
479+
// 所以需要 `$request = undefined`
480+
$request = undefined
481+
eval(script)
482+
})
476483
}
477484
}
478485
}
@@ -1038,7 +1045,7 @@ function printHtml(data, curapp = null, curview = 'app') {
10381045
<v-subheader v-if="Array.isArray(ui.curapp.settings)">
10391046
应用设置 ({{ ui.curapp.settings.length }})
10401047
<v-spacer></v-spacer>
1041-
<v-btn v-if="box.syscfgs.env === 'Surge' && ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
1048+
<v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
10421049
</v-subheader>
10431050
<v-form class="pl-4 pr-4">
10441051
<template v-for="(setting, settingIdx) in ui.curapp.settings">
@@ -1067,7 +1074,7 @@ function printHtml(data, curapp = null, curview = 'app') {
10671074
<v-subheader>
10681075
当前会话 ({{ ui.curapp.datas.length }})
10691076
<v-spacer></v-spacer>
1070-
<v-btn v-if="box.syscfgs.env === 'Surge' && ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
1077+
<v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn>
10711078
<v-menu bottom left>
10721079
<template v-slot:activator="{ on }">
10731080
<v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
@@ -2012,13 +2019,17 @@ function printHtml(data, curapp = null, curview = 'app') {
20122019
})
20132020
},
20142021
onRunScript() {
2022+
this.ui.overlay.show = true
2023+
20152024
// const [key, addr] = this.box.usercfgs.httpapi.split('@')
20162025
// const url = 'http://' + addr + '/v1/scripting/evaluate'
20172026
// const body = { script_text: this.ui.curapp.script_text, mock_type: 'cron', timeout: 5 }
20182027
// const opts = {headers: { 'X-Key': key, 'Accept': '*/*' }}
20192028
// axios.post(url, body, opts)
20202029
2021-
axios.post('/api', JSON.stringify({ cmd: 'runScript', val: this.ui.curapp }))
2030+
axios.post('/api', JSON.stringify({ cmd: 'runScript', val: this.ui.curapp })).finally(() => {
2031+
this.ui.overlay.show = false
2032+
})
20222033
}
20232034
},
20242035
mounted: function () {

0 commit comments

Comments
 (0)