Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 94 additions & 11 deletions box/chavy.boxjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
<v-list-item-content>
<v-select
:items="[{text: 'English', value: 'en-US'}, {text: '简体中文', value: 'zh-CN'}]"
autofocus
hide-details
label="Language"
v-model="box.usercfgs.lang"
Expand All @@ -252,7 +251,6 @@
<v-select
:items="[{text: $t('prefs.appearances.auto'), value: 'auto'}, {text: $t('prefs.appearances.dark'), value: 'dark'}, {text: $t('prefs.appearances.light'), value: 'light'}]"
:label="$t('prefs.appearance')"
autofocus
hide-details
v-model="box.usercfgs.theme"
>
Expand Down Expand Up @@ -589,7 +587,7 @@
</v-list-item>
<v-divider v-if="favApps.length > 1"></v-divider>
<v-list-item dense @click="favApp(app.id)">
<v-list-item-title>{{ $t('base.sort.unStar') }}</v-list-item-title>
<v-list-item-title>{{ $t('apps.unStar') }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
Expand Down Expand Up @@ -795,8 +793,8 @@
</v-chip-group>
</v-card-text>
<v-card-actions>
<!-- <v-btn text small color="red" @click="">抹掉数据</v-btn> -->
<v-spacer></v-spacer>
<v-btn small class="mr-2" @click="switchView('viewer')"> {{ $t('profile.dataviewer')}} </v-btn>
<v-dialog v-model="ui.impGlobalBakDialog.show">
<template #activator="{ on }">
<v-btn small v-on="on">{{ $t('profile.imp') }}</v-btn>
Expand Down Expand Up @@ -843,6 +841,47 @@
</template>
</v-card>
</v-container>
<!-- 数据查看 -->
<v-container fluid v-show="view === 'viewer'">
<v-card class="mb-4">
<v-subheader>
{{ $t('viewer.dataViewer') }}
<v-spacer></v-spacer>
<v-btn color="primary" small @click="copy(ui.viewer.key)"> {{ $t('base.cmd.cp') }} </v-btn>
</v-subheader>
<v-card-text>
<v-text-field
:hint="$t('viewer.dataKeyDesc')"
:label="$t('viewer.dataKey')"
persistent-hint
placeholder="boxjs_host"
v-model="ui.viewer.key"
>
</v-text-field>
</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<!-- TODO 列出最近查询过的 key -->
<v-spacer></v-spacer>
<v-btn small text color="primary" @click="queryData">{{ $t('base.dialog.view') }}</v-btn>
</v-card-actions>
</v-card>
<v-card class="mb-4">
<v-subheader>
{{ $t('viewer.dataEditor') }}
<v-spacer></v-spacer>
<v-btn color="primary" small @click="copy(ui.viewer.val)"> {{ $t('base.cmd.cp') }} </v-btn>
</v-subheader>
<v-card-text>
<v-textarea v-model="ui.viewer.val" :row="3" :label="$t('viewer.dataVal')"> </v-textarea>
</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn small text color="primary" @click="saveData">{{ $t('base.dialog.save') }}</v-btn>
</v-card-actions>
</v-card>
</v-container>
<!-- 代码编辑 -->
<v-container fluid v-show="view === 'coding'">
<v-card rounded="0" flat style="width: inherit">
Expand Down Expand Up @@ -1133,11 +1172,7 @@ <h2 :style="appTitleStyle">{{curbak.name}}</h2>
<v-btn color="primary" small @click="revertGlobalBak"> {{ $t('base.cmd.recovery') }} </v-btn>
</v-subheader>
<v-card class="mb-4">
<v-subheader>
{{ $t('bakDetail.title') }}
<v-spacer></v-spacer>
<v-btn color="primary" small @click="copy(JSON.stringify(curbak.bak))"> {{ $t('base.cmd.cp') }} </v-btn>
</v-subheader>
<v-subheader> {{ $t('bakDetail.title') }} </v-subheader>
<v-card-text>
<v-text-field :label="$t('bakDetail.id')" v-model="curbak.id" readonly> </v-text-field>
<v-text-field :label="$t('bakDetail.name')" v-model="curbak.name" @change="updateGlobalBak"> </v-text-field>
Expand All @@ -1148,6 +1183,13 @@ <h2 :style="appTitleStyle">{{curbak.name}}</h2>
<v-btn small text color="error" @click="delGlobalBak">{{ $t('base.cmd.del') }}</v-btn>
</v-card-actions>
</v-card>
<v-card class="mb-4">
<v-subheader>
{{ $t('bakDetail.dataTitle') }}
<v-spacer></v-spacer>
<v-btn color="primary" small @click="copy(JSON.stringify(curbak.bak))"> {{ $t('base.cmd.cp') }} </v-btn>
</v-subheader>
</v-card>
</v-container>
</v-main>
<!-- 底部 -->
Expand Down Expand Up @@ -1290,6 +1332,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
dialog: {
apply: 'Apply',
save: 'Save',
view: 'View',
close: 'Close'
},
sort: {
Expand Down Expand Up @@ -1391,6 +1434,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
},
profile: {
leaveName: 'Leave a name',
dataviewer: 'Data Viewer',
editor: {
title: 'Profile',
name: 'Name',
Expand All @@ -1415,10 +1459,18 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
note: 'Note: ',
id: 'Backup Index',
name: 'Backup Name',
title: 'Backup Informations'
title: 'Backup Informations',
dataTitle: 'Backup Datas'
},
codding: {
title: 'Script Editor'
},
viewer: {
dataViewer: 'Data Viewer',
dataKey: 'Data Key',
dataKeyDesc: 'Input the data key',
dataEditor: 'Data Editor',
dataVal: 'Data Value'
}
},
'zh-CN': {
Expand Down Expand Up @@ -1523,6 +1575,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
},
profile: {
leaveName: '大侠, 请留名!',
dataviewer: '数据查看器',
editor: {
title: '个人资源',
name: '昵称',
Expand All @@ -1546,10 +1599,18 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
bakDetail: {
id: '备份索引',
name: '备份名称',
title: '备份信息'
title: '备份信息',
dataTitle: '备份数据'
},
codding: {
title: '脚本编辑器'
},
viewer: {
dataViewer: '数据查看器',
dataKey: '数据键 (Key)',
dataKeyDesc: '输入要查询的数据键, 如: boxjs_host',
dataEditor: '数据编辑器',
dataVal: '数据内容'
}
}
}
Expand Down Expand Up @@ -1584,6 +1645,10 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
hideDetails: true,
solo: true
},
viewer: {
key: '',
val: ''
},
searchDialog: { show: false },
versionsheet: { show: false },
updatesheet: { show: false },
Expand Down Expand Up @@ -2705,6 +2770,24 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
}
})
},
// 查询数据
queryData() {
const key = this.ui.viewer.key
this.ui.viewer.key = key ? key : 'boxjs_host'
axios.get(`/query/data/${this.ui.viewer.key}`).then((resp) => {
this.ui.viewer.val = resp.data.val
this.box.usercfgs.viewkeys.unshift(this.ui.viewer.key)
})
},
saveData() {
const key = this.ui.viewer.key
const val = this.ui.viewer.val
if (key) {
axios.post('/api/saveData/', { key, val }).then((resp) => {
this.ui.viewer.val = resp.data.val
})
}
},
// 对比版本号
compareVersion(v1, v2) {
var _v1 = v1.split('.'),
Expand Down
26 changes: 22 additions & 4 deletions box/chavy.boxjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const $ = new Env('BoxJs')
// 为 eval 准备的上下文环境
const $eval_env = {}

$.version = '0.7.88'
$.version = '0.7.90'
$.versionType = 'beta'

// 发出的请求需要需要 Surge、QuanX 的 rewrite
Expand Down Expand Up @@ -205,10 +205,16 @@ async function handleQuery() {
$.json = getBoxData()
} else if (/^\/baks/.test(query)) {
const [, backupId] = query.split('/baks/')
console.log(backupId)
$.json = $.getjson(backupId)
} else if (/^\/versions$/.test(query)) {
await getVersions(true)
} else if (/^\/data/.test(query)) {
// TODO 记录每次查询的 key 至 usercfgs.viewkeys
const [, dataKey] = query.split('/data/')
$.json = {
key: dataKey,
val: $.getdata(dataKey)
}
}
}

Expand Down Expand Up @@ -236,6 +242,8 @@ async function handleApi() {
await apiRevertGlobalBak()
} else if (api === '/runScript') {
await apiRunScript()
} else if (api === '/saveData') {
await apiSaveData()
}
}

Expand Down Expand Up @@ -314,13 +322,13 @@ function getSystemApps() {
settings: [
{ id: '@chavy_boxjs_userCfgs.httpapis', name: 'HTTP-API (Surge)', val: '', type: 'textarea', placeholder: ',examplekey@127.0.0.1:6166', autoGrow: true, rows: 2, persistentHint:true, desc: '示例: ,examplekey@127.0.0.1:6166! 注意: 以逗号开头, 逗号分隔多个地址, 可加回车' },
{ id: '@chavy_boxjs_userCfgs.httpapi_timeout', name: 'HTTP-API Timeout (Surge)', val: 20, type: 'number', persistentHint:true, desc: '如果脚本作者指定了超时时间, 会优先使用脚本指定的超时时间.' },
{ id: '@chavy_boxjs_userCfgs.http_backend', name: 'HTTP Backend (Quantumult X)', val: '', type: 'text',placeholder: 'http://127.0.0.1:9999', persistentHint:true, desc: '示例: http://127.0.0.1:9999 ! 注意: 必须是以 http 开头的完整路径, 不能是 / 结尾' },
{ id: '@chavy_boxjs_userCfgs.bgimgs', name: '背景图片清单', val: '无,\n跟随系统,跟随系统\nlight,http://api.btstu.cn/sjbz/zsy.php\ndark,https://uploadbeta.com/api/pictures/random\n妹子,http://api.btstu.cn/sjbz/zsy.php', type: 'textarea', placeholder: '无,{回车} 跟随系统,跟随系统{回车} light,图片地址{回车} dark,图片地址{回车} 妹子,图片地址', persistentHint:true, autoGrow: true, rows: 2, desc: '逗号分隔名字和链接, 回车分隔多个地址' },
{ id: '@chavy_boxjs_userCfgs.bgimg', name: '背景图片', val: '', type: 'text', placeholder: 'http://api.btstu.cn/sjbz/zsy.php', persistentHint:true, desc: '输入背景图标的在线链接' },
{ id: '@chavy_boxjs_userCfgs.changeBgImgEnterDefault', name: '手势进入壁纸模式默认背景图片', val: '', type: 'text', placeholder: '填写上面背景图片清单的值', persistentHint:true, desc: '' },
{ id: '@chavy_boxjs_userCfgs.changeBgImgOutDefault', name: '手势退出壁纸模式默认背景图片', val: '', type: 'text', placeholder: '填写上面背景图片清单的值', persistentHint:true, desc: '' },
{ id: '@chavy_boxjs_userCfgs.color_light_primary', name: '明亮色调', canvas: true, val: '#F7BB0E', type: 'colorpicker', desc: '' },
{ id: '@chavy_boxjs_userCfgs.color_dark_primary', name: '暗黑色调', canvas: true, val: '#2196F3', type: 'colorpicker', desc: '' },
{ id: '@chavy_boxjs_userCfgs.http_backend', name: 'HTTP Backend (Quantumult X)', val: '', type: 'text',placeholder: 'http://127.0.0.1:9999', persistentHint:true, desc: '示例: http://127.0.0.1:9999 ! 注意: 必须是以 http 开头的完整路径, 不能是 / 结尾' },
{ id: '@chavy_boxjs_userCfgs.color_dark_primary', name: '暗黑色调', canvas: true, val: '#2196F3', type: 'colorpicker', desc: '' }
],
scripts: [
{
Expand Down Expand Up @@ -380,6 +388,7 @@ function getUserCfgs() {
const defcfgs = {
favapps: [],
appsubs: [],
viewkeys: [],
isPinedSearchBar: true,
httpapi: 'examplekey@127.0.0.1:6166',
http_backend: ''
Expand Down Expand Up @@ -636,6 +645,15 @@ async function apiRunScript() {
}
}

async function apiSaveData() {
const { key: dataKey, val: dataVal } = $.toObj($request.body)
$.setdata(dataVal, dataKey)
$.json = {
key: dataKey,
val: $.getdata(dataKey)
}
}

/**
* ===================================
* 工具类函数
Expand Down
24 changes: 24 additions & 0 deletions box/release/box.release.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
{
"releases": [
{
"version": "0.7.90",
"tags": ["beta"],
"author": "@chavyleung",
"msg": "fix(boxjs): backup data display bug",
"notes": [
{
"name": "修复",
"descs": ["备份数据太大导致无法进入备份详情"]
}
]
},
{
"version": "0.7.89",
"tags": ["beta"],
"author": "@chavyleung",
"msg": "feat(boxjs): add data viewer",
"notes": [
{
"name": "新增",
"descs": ["数据编辑 & 查看器"]
}
]
},
{
"version": "0.7.88",
"tags": ["beta"],
Expand Down
24 changes: 24 additions & 0 deletions box/release/box.release.tf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
{
"releases": [
{
"version": "0.7.90",
"tags": ["beta"],
"author": "@chavyleung",
"msg": "fix(boxjs): backup data display bug",
"notes": [
{
"name": "修复",
"descs": ["备份数据太大导致无法进入备份详情"]
}
]
},
{
"version": "0.7.89",
"tags": ["beta"],
"author": "@chavyleung",
"msg": "feat(boxjs): add data viewer",
"notes": [
{
"name": "新增",
"descs": ["数据编辑 & 查看器"]
}
]
},
{
"version": "0.7.88",
"tags": ["beta"],
Expand Down
Loading