@@ -8,6 +8,15 @@ $.KEY_userCfgs = 'chavy_boxjs_userCfgs'
88$ . KEY_globalBaks = 'chavy_boxjs_globalBaks'
99$ . KEY_curSessions = 'chavy_boxjs_cur_sessions'
1010
11+ /**
12+ * ===================================
13+ * 持久化属性: BoxJs 公开的数据结构
14+ * ===================================
15+ */
16+
17+ // 存储用户访问`BoxJs`时使用的域名
18+ $ . KEY_boxjs_host = 'boxjs_host'
19+
1120$ . json = $ . name
1221$ . html = $ . name
1322
@@ -51,6 +60,8 @@ $.html = $.name
5160 $ . logErr ( e )
5261 } )
5362 . finally ( ( ) => {
63+ // 记录当前使用哪个域名访问
64+ $ . setdata ( getHost ( $request . url ) , $ . KEY_boxjs_host )
5465 if ( $ . isapi ) {
5566 $ . done ( { body : $ . json } )
5667 } else {
@@ -64,16 +75,24 @@ $.html = $.name
6475 }
6576 } )
6677
78+ /**
79+ * http://boxjs.com/ => `http://boxjs.com`
80+ * http://boxjs.com/app/jd => `http://boxjs.com`
81+ */
82+ function getHost ( url ) {
83+ return url . slice ( 0 , url . indexOf ( '/' , 8 ) )
84+ }
85+
6786/**
6887 * https://dns.google/ => ``
6988 * https://dns.google/api => `/api`
7089 */
7190function getPath ( url ) {
7291 // 如果以`/`结尾, 去掉最后一个`/`
73- let end = url . lastIndexOf ( "/" ) === url . length - 1 ? - 1 : undefined
92+ const end = url . lastIndexOf ( '/' ) === url . length - 1 ? - 1 : undefined
7493 // slice第二个参数传 undefined 会直接截到最后
7594 // indexOf第二个参数用来跳过前面的 "https://"
76- return url . slice ( url . indexOf ( "/" , 8 ) , end )
95+ return url . slice ( url . indexOf ( '/' , 8 ) , end )
7796}
7897
7998function getSystemCfgs ( ) {
@@ -82,14 +101,42 @@ function getSystemCfgs() {
82101 version : $ . version ,
83102 versionType : $ . versionType ,
84103 envs : [
85- { id : 'Surge' , icons : [ 'https://raw.githubusercontent.com/Orz-3/mini/none/surge.png' , 'https://raw.githubusercontent.com/Orz-3/task/master/surge.png' ] } ,
86- { id : 'QuanX' , icons : [ 'https://raw.githubusercontent.com/Orz-3/mini/none/quanX.png' , 'https://raw.githubusercontent.com/Orz-3/task/master/quantumultx.png' ] } ,
87- { id : 'Loon' , icons : [ 'https://raw.githubusercontent.com/Orz-3/mini/none/loon.png' , 'https://raw.githubusercontent.com/Orz-3/task/master/loon.png' ] }
104+ {
105+ id : 'Surge' ,
106+ icons : [
107+ 'https://raw.githubusercontent.com/Orz-3/mini/none/surge.png' ,
108+ 'https://raw.githubusercontent.com/Orz-3/task/master/surge.png'
109+ ]
110+ } ,
111+ {
112+ id : 'QuanX' ,
113+ icons : [
114+ 'https://raw.githubusercontent.com/Orz-3/mini/none/quanX.png' ,
115+ 'https://raw.githubusercontent.com/Orz-3/task/master/quantumultx.png'
116+ ]
117+ } ,
118+ {
119+ id : 'Loon' ,
120+ icons : [
121+ 'https://raw.githubusercontent.com/Orz-3/mini/none/loon.png' ,
122+ 'https://raw.githubusercontent.com/Orz-3/task/master/loon.png'
123+ ]
124+ }
88125 ] ,
89- chavy : { id : 'Chavy Scripts' , icon : 'https://avatars3.githubusercontent.com/u/29748519' , repo : 'https://github.com/chavyleung/scripts' } ,
126+ chavy : {
127+ id : 'Chavy Scripts' ,
128+ icon : 'https://avatars3.githubusercontent.com/u/29748519' ,
129+ repo : 'https://github.com/chavyleung/scripts'
130+ } ,
90131 senku : { id : 'GideonSenku' , icon : 'https://avatars1.githubusercontent.com/u/39037656' , repo : 'https://github.com/GideonSenku' } ,
91132 orz3 : { id : 'Orz-3' , icon : 'https://raw.githubusercontent.com/Orz-3/task/master/Orz-3.png' , repo : 'https://github.com/Orz-3/' } ,
92- boxjs : { id : 'BoxJs' , show : false , icon : 'https://raw.githubusercontent.com/Orz-3/task/master/box.png' , icons : [ 'https://raw.githubusercontent.com/Orz-3/mini/master/box.png' , 'https://raw.githubusercontent.com/Orz-3/task/master/box.png' ] , repo : 'https://github.com/chavyleung/scripts' } ,
133+ boxjs : {
134+ id : 'BoxJs' ,
135+ show : false ,
136+ icon : 'https://raw.githubusercontent.com/Orz-3/task/master/box.png' ,
137+ icons : [ 'https://raw.githubusercontent.com/Orz-3/mini/master/box.png' , 'https://raw.githubusercontent.com/Orz-3/task/master/box.png' ] ,
138+ repo : 'https://github.com/chavyleung/scripts'
139+ } ,
93140 contributors : [ ]
94141 }
95142}
@@ -102,14 +149,32 @@ function getSystemApps() {
102149 descs : [ '可设置 http-api 地址 & 超时时间 (Surge TF)' , '可设置明暗两种主题下的主色调' ] ,
103150 keys : [ '@chavy_boxjs_userCfgs.httpapi' , '@chavy_boxjs_userCfgs.color_dark_primary' , '@chavy_boxjs_userCfgs.color_light_primary' ] ,
104151 settings : [
105- { id : '@chavy_boxjs_userCfgs.httpapis' , name : 'HTTP-API (Surge TF)' , val : '' , type : 'textarea' , placeholder : ',examplekey@127.0.0.1:6166' , autoGrow : true , rows : 2 , desc : '示例: ,examplekey@127.0.0.1:6166! 注意: 以逗号开头, 逗号分隔多个地址, 可加回车' } ,
106- { id : '@chavy_boxjs_userCfgs.httpapi_timeout' , name : 'HTTP-API Timeout (Surge TF)' , val : 20 , type : 'number' , desc : '如果脚本作者指定了超时时间, 会优先使用脚本指定的超时时间.' } ,
152+ {
153+ id : '@chavy_boxjs_userCfgs.httpapis' ,
154+ name : 'HTTP-API (Surge TF)' ,
155+ val : '' ,
156+ type : 'textarea' ,
157+ placeholder : ',examplekey@127.0.0.1:6166' ,
158+ autoGrow : true ,
159+ rows : 2 ,
160+ desc : '示例: ,examplekey@127.0.0.1:6166! 注意: 以逗号开头, 逗号分隔多个地址, 可加回车'
161+ } ,
162+ {
163+ id : '@chavy_boxjs_userCfgs.httpapi_timeout' ,
164+ name : 'HTTP-API Timeout (Surge TF)' ,
165+ val : 20 ,
166+ type : 'number' ,
167+ desc : '如果脚本作者指定了超时时间, 会优先使用脚本指定的超时时间.'
168+ } ,
107169 { id : '@chavy_boxjs_userCfgs.color_light_primary' , name : '明亮色调' , canvas : true , val : '#F7BB0E' , type : 'colorpicker' , desc : '' } ,
108170 { id : '@chavy_boxjs_userCfgs.color_dark_primary' , name : '暗黑色调' , canvas : true , val : '#2196F3' , type : 'colorpicker' , desc : '' }
109171 ] ,
110172 author : '@chavyleung' ,
111173 repo : 'https://github.com/chavyleung/scripts/blob/master/box/switcher/box.switcher.js' ,
112- icons : [ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSetting.mini.png' , 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSetting.png' ]
174+ icons : [
175+ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSetting.mini.png' ,
176+ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSetting.png'
177+ ]
113178 } ,
114179 {
115180 id : 'BoxSwitcher' ,
@@ -119,7 +184,10 @@ function getSystemApps() {
119184 settings : [ { id : 'CFG_BoxSwitcher_isSilent' , name : '静默运行' , val : false , type : 'boolean' , desc : '切换会话时不发出系统通知!' } ] ,
120185 author : '@chavyleung' ,
121186 repo : 'https://github.com/chavyleung/scripts/blob/master/box/switcher/box.switcher.js' ,
122- icons : [ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSwitcher.mini.png' , 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSwitcher.png' ] ,
187+ icons : [
188+ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSwitcher.mini.png' ,
189+ 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxSwitcher.png'
190+ ] ,
123191 script : 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/switcher/box.switcher.js'
124192 }
125193 ]
@@ -290,7 +358,13 @@ async function handleApi() {
290358 const savesuc = $ . setdata ( JSON . stringify ( sessions ) , $ . KEY_sessions )
291359 $ . subt = `保存会话: ${ savesuc ? '成功' : '失败' } (${ session . appName } )`
292360 $ . desc = [ ]
293- $ . desc . push ( `会话名称: ${ session . name } ` , `应用名称: ${ session . appName } ` , `会话编号: ${ session . id } ` , `应用编号: ${ session . appId } ` , `数据: ${ JSON . stringify ( session ) } ` )
361+ $ . desc . push (
362+ `会话名称: ${ session . name } ` ,
363+ `应用名称: ${ session . appName } ` ,
364+ `会话编号: ${ session . id } ` ,
365+ `应用编号: ${ session . appId } ` ,
366+ `数据: ${ JSON . stringify ( session ) } `
367+ )
294368 $ . msg ( $ . name , $ . subt , $ . desc . join ( '\n' ) )
295369 }
296370 // 保存至指定会话
@@ -302,7 +376,13 @@ async function handleApi() {
302376 const savesuc = $ . setdata ( JSON . stringify ( sessions ) , $ . KEY_sessions )
303377 $ . subt = `保存会话: ${ savesuc ? '成功' : '失败' } (${ session . appName } )`
304378 $ . desc = [ ]
305- $ . desc . push ( `会话名称: ${ session . name } ` , `应用名称: ${ session . appName } ` , `会话编号: ${ session . id } ` , `应用编号: ${ session . appId } ` , `数据: ${ JSON . stringify ( session ) } ` )
379+ $ . desc . push (
380+ `会话名称: ${ session . name } ` ,
381+ `应用名称: ${ session . appName } ` ,
382+ `会话编号: ${ session . id } ` ,
383+ `应用编号: ${ session . appId } ` ,
384+ `数据: ${ JSON . stringify ( session ) } `
385+ )
306386 $ . msg ( $ . name , $ . subt , $ . desc . join ( '\n' ) )
307387 }
308388 // 修改指定会话
@@ -315,7 +395,13 @@ async function handleApi() {
315395 const savesuc = $ . setdata ( JSON . stringify ( sessions ) , $ . KEY_sessions )
316396 $ . subt = `保存会话: ${ savesuc ? '成功' : '失败' } (${ session . appName } )`
317397 $ . desc = [ ]
318- $ . desc . push ( `会话名称: ${ session . name } ` , `应用名称: ${ session . appName } ` , `会话编号: ${ session . id } ` , `应用编号: ${ session . appId } ` , `数据: ${ JSON . stringify ( session ) } ` )
398+ $ . desc . push (
399+ `会话名称: ${ session . name } ` ,
400+ `应用名称: ${ session . appName } ` ,
401+ `会话编号: ${ session . id } ` ,
402+ `应用编号: ${ session . appId } ` ,
403+ `数据: ${ JSON . stringify ( session ) } `
404+ )
319405 $ . msg ( $ . name , $ . subt , $ . desc . join ( '\n' ) )
320406 }
321407 // 保存当前会话
@@ -367,7 +453,13 @@ async function handleApi() {
367453 $ . setdata ( JSON . stringify ( curSessions ) , $ . KEY_curSessions )
368454 $ . subt = `应用会话: 成功 (${ session . appName } )`
369455 $ . desc = [ ]
370- $ . desc . push ( `会话名称: ${ session . name } ` , `应用名称: ${ session . appName } ` , `会话编号: ${ session . id } ` , `应用编号: ${ session . appId } ` , `数据: ${ JSON . stringify ( session ) } ` )
456+ $ . desc . push (
457+ `会话名称: ${ session . name } ` ,
458+ `应用名称: ${ session . appName } ` ,
459+ `会话编号: ${ session . id } ` ,
460+ `应用编号: ${ session . appId } ` ,
461+ `数据: ${ JSON . stringify ( session ) } `
462+ )
371463 $ . msg ( $ . name , $ . subt , $ . desc . join ( '\n' ) )
372464 }
373465 }
@@ -380,7 +472,13 @@ async function handleApi() {
380472 const delsuc = $ . setdata ( JSON . stringify ( sessions ) , $ . KEY_sessions ) ? '成功' : '失败'
381473 $ . subt = `删除会话: ${ delsuc ? '成功' : '失败' } (${ session . appName } )`
382474 $ . desc = [ ]
383- $ . desc . push ( `会话名称: ${ session . name } ` , `会话编号: ${ session . id } ` , `应用名称: ${ session . appName } ` , `应用编号: ${ session . appId } ` , `数据: ${ JSON . stringify ( session ) } ` )
475+ $ . desc . push (
476+ `会话名称: ${ session . name } ` ,
477+ `会话编号: ${ session . id } ` ,
478+ `应用名称: ${ session . appName } ` ,
479+ `应用编号: ${ session . appId } ` ,
480+ `数据: ${ JSON . stringify ( session ) } `
481+ )
384482 $ . msg ( $ . name , $ . subt , $ . desc . join ( '\n' ) )
385483 }
386484 }
0 commit comments