forked from chavyleung/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchavy.box.js
1646 lines (1620 loc) · 81.3 KB
/
chavy.box.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const $ = new Env('BoxJs')
$.domain = '8.8.8.8'
$.version = '0.3.6'
$.versionType = 'beta'
$.KEY_sessions = 'chavy_boxjs_sessions'
$.KEY_versions = 'chavy_boxjs_versions'
$.KEY_userCfgs = 'chavy_boxjs_userCfgs'
$.KEY_globalBaks = 'chavy_boxjs_globalBaks'
$.KEY_curSessions = 'chavy_boxjs_cur_sessions'
$.json = $.name
$.html = $.name
!(async () => {
const path = getPath($request.url)
// 处理主页请求 => /home
if (/^\/home/.test(path)) {
await handleHome()
}
// 处理主页请求 => /sub
else if (/^\/sub/.test(path)) {
await handleSub()
}
// 处理 App 请求 => /app
else if (/^\/app/.test(path)) {
const [, appId] = path.split('/app/')
await handleApp(decodeURIComponent(decodeURIComponent(appId)))
}
// 处理 Api 请求 => /api
else if (/^\/api/.test(path)) {
$.isapi = true
await handleApi()
}
// 处理 Api 请求 => /my
else if (/^\/my/.test(path)) {
await handleMy()
}
})()
.catch((e) => {
$.logErr(e)
})
.finally(() => {
if ($.isapi) {
$.done({ body: $.json })
} else {
$.done({ body: $.html })
}
})
/**
* https://dns.google/ => ``
* https://dns.google/api => `/api`
*/
function getPath(url) {
// 如果以`/`结尾, 先去掉最后一个`/`
const fullpath = /\/$/.test(url) ? url.replace(/\/$/, '') : url
return new RegExp($.domain).test(url) ? fullpath.split($.domain)[1] : undefined
}
function getSystemCfgs() {
return {
env: $.isLoon() ? 'Loon' : $.isQuanX() ? 'QuanX' : $.isSurge() ? 'Surge' : 'Node',
version: $.version,
versionType: $.versionType,
envs: [
{ id: 'Surge', icon: 'https://raw.githubusercontent.com/Orz-3/task/master/surge.png' },
{ id: 'QuanX', icon: 'https://raw.githubusercontent.com/Orz-3/task/master/quantumultx.png' },
{ id: 'Loon', icon: 'https://raw.githubusercontent.com/Orz-3/task/master/loon.png' }
],
chavy: {
id: 'Chavy Scripts',
icon: 'https://avatars3.githubusercontent.com/u/29748519',
repo: 'https://github.com/chavyleung/scripts'
},
orz3: {
id: 'Orz-3',
icon: 'https://raw.githubusercontent.com/Orz-3/task/master/Orz-3.png',
repo: 'https://github.com/Orz-3/'
},
boxjs: {
id: 'BoxJs',
show: false,
icon: 'https://raw.githubusercontent.com/Orz-3/task/master/box.png',
repo: 'https://github.com/chavyleung/scripts'
}
}
}
function getSystemApps() {
const sysapps = [
{
id: '10010',
name: '中国联通',
keys: ['chavy_tokenurl_10010', 'chavy_tokenheader_10010', 'chavy_signurl_10010', 'chavy_signheader_10010', 'chavy_loginlotteryurl_10010', 'chavy_loginlotteryheader_10010', 'chavy_findlotteryurl_10010', 'chavy_findlotteryheader_10010'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/10010',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/10010.png', 'https://raw.githubusercontent.com/Orz-3/task/master/10010.png']
},
{
id: '52poje',
name: '吾爱破解',
keys: ['CookieWA'],
author: '@NobyDa',
repo: 'https://github.com/NobyDa/Script/blob/master/52pojie-DailyBonus/52pojie.js',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/52pj.png', 'https://raw.githubusercontent.com/Orz-3/task/master/52pj.png']
},
{
id: 'AcFun',
name: 'AcFun',
keys: ['chavy_cookie_acfun', 'chavy_token_acfun'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/acfun',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/acfun.png', 'https://raw.githubusercontent.com/Orz-3/task/master/acfun.png']
},
{
id: 'ApkTw',
name: 'ApkTw',
keys: ['chavy_cookie_apktw'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/apktw',
url: 'https://apk.tw/',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/apktw.png', 'https://raw.githubusercontent.com/Orz-3/task/master/apktw.png'],
tasks: [{ cron: '3 0 * * *', script: 'apktw.js' }],
rewrites: [{ type: 'request', pattern: '^https://apk.tw/member.php(.*?)action=login', script: 'apktw.cookie.js', body: true }]
},
{
id: 'BAIDU',
name: '百度签到',
keys: ['chavy_cookie_tieba'],
settings: [
{ id: 'CFG_tieba_isOrderBars', name: '按连签排序', val: false, type: 'boolean', desc: '默认按经验排序' },
{ id: 'CFG_tieba_maxShowBars', name: '每页显示数', val: 15, type: 'text', desc: '每页最显示多少个吧信息' },
{ id: 'CFG_tieba_maxSignBars', name: '每次并发', val: 5, type: 'text', desc: '每次并发签到多少个吧' },
{ id: 'CFG_tieba_signWaitTime', name: '并发间隔 (毫秒)', val: 2000, type: 'text', desc: '每次并发间隔时间' }
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/tieba',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/baidu.png', 'https://raw.githubusercontent.com/Orz-3/task/master/baidu.png']
},
{
id: 'iQIYI',
name: '爱奇艺',
keys: ['CookieQY'],
author: '@NobyDa',
repo: 'https://github.com/NobyDa/Script/blob/master/iQIYI-DailyBonus/iQIYI.js',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/iQIYI.png', 'https://raw.githubusercontent.com/Orz-3/task/master/iQIYI.png']
},
{
id: 'JD',
name: '京东',
keys: ['CookieJD', 'CookieJD2'],
author: '@NobyDa',
repo: 'https://github.com/NobyDa/Script/blob/master/JD-DailyBonus/JD_DailyBonus.js',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/jd.png', 'https://raw.githubusercontent.com/Orz-3/task/master/jd.png']
},
{
id: 'JD618',
name: '京东618',
keys: ['chavy_url_jd816', 'chavy_body_jd816', 'chavy_headers_jd816'],
settings: [
{ id: 'CFG_618_radomms_min', name: '最小随机等待 (毫秒)', val: 2000, type: 'text', desc: '在任务默认的等待时间基础上,再增加的随机等待时间!' },
{ id: 'CFG_618_radomms_max', name: '最大随机等待 (毫秒)', val: 5000, type: 'text', desc: '在任务默认的等待时间基础上,再增加的随机等待时间!' },
{ id: 'CFG_618_isSignShop', name: '商店签到', val: true, type: 'boolean', desc: '71 家商店, 如果每天都签不上, 可以关掉了! 默认: true' },
{ id: 'CFG_618_isJoinBrand', name: '品牌会员', val: false, type: 'boolean', desc: '25 个品牌, 会自动加入品牌会员! 默认: true' },
{ id: 'CFG_BOOM_times_JD618', name: '炸弹次数', val: 1, type: 'text', desc: '总共发送多少次炸弹! 默认: 1' },
{ id: 'CFG_BOOM_interval_JD618', name: '炸弹间隔 (毫秒)', val: 100, type: 'text', desc: '每次间隔多少毫秒! 默认: 100' }
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/jd',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/jd.png', 'https://raw.githubusercontent.com/Orz-3/task/master/jd.png']
},
{
id: 'videoqq',
name: '腾讯视频',
keys: ['chavy_cookie_videoqq', 'chavy_auth_url_videoqq', 'chavy_auth_header_videoqq', 'chavy_msign_url_videoqq', 'chavy_msign_header_videoqq'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/videoqq',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/videoqq.png', 'https://raw.githubusercontent.com/Orz-3/task/master/videoqq.png']
},
{
id: 'V2EX',
name: 'V2EX',
keys: ['chavy_cookie_v2ex'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/v2ex',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/v2ex.png', 'https://raw.githubusercontent.com/Orz-3/task/master/v2ex.png']
},
{
id: 'NeteaseMusic',
name: '网易云音乐',
keys: ['chavy_cookie_neteasemusic'],
settings: [
{ id: 'CFG_neteasemusic_retryCnt', name: '重试次数', val: 10, type: 'text', desc: '一直尝试签到直至出现“重复签到”标识!' },
{ id: 'CFG_neteasemusic_retryInterval', name: '重试间隔 (毫秒)', val: 500, type: 'text', desc: '每次重试间隔时间 (毫秒)!' }
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/neteasemusic',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/Netease.png', 'https://raw.githubusercontent.com/Orz-3/task/master/Netease.png']
},
{
id: 'WPS',
name: 'WPS',
keys: ['chavy_signhomeurl_wps', 'chavy_signhomeheader_wps'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/wps',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/wps.png', 'https://raw.githubusercontent.com/Orz-3/task/master/wps.png']
},
{
id: 'NoteYoudao',
name: '有道云笔记',
keys: ['chavy_signurl_noteyoudao', 'chavy_signbody_noteyoudao', 'chavy_signheaders_noteyoudao'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/noteyoudao',
url: 'https://apps.apple.com/cn/app/有道云笔记-扫描王版/id450748070',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/noteyoudao.png', 'https://raw.githubusercontent.com/Orz-3/task/master/noteyoudao.png'],
tasks: [{ cron: '3 0 * * *', script: 'noteyoudao.js' }],
rewrites: [{ type: 'request', pattern: '^https://note.youdao.com/yws/mapi/user?method=checkin', script: 'noteyoudao.cookie.js', body: true }]
},
{
id: 'txnews',
name: '腾讯新闻',
keys: ['sy_signurl_txnews', 'sy_cookie_txnews', 'sy_signurl_txnews2', 'sy_cookie_txnews2'],
author: '@Sunert',
repo: 'https://github.com/Sunert/Scripts/blob/master/Task/txnews.js',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/txnews.png', 'https://raw.githubusercontent.com/Orz-3/task/master/txnews.png']
},
{
id: 'BoxSwitcher',
name: '会话切换',
keys: [],
settings: [{ id: 'CFG_BoxSwitcher_isSilent', name: '静默运行', val: false, type: 'boolean', desc: '切换会话时不发出系统通知!' }],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/blob/master/box/switcher/box.switcher.js',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/box.png', 'https://raw.githubusercontent.com/Orz-3/task/master/box.png']
},
{
id: 'sfexpress',
name: '顺丰速运',
keys: ['chavy_loginurl_sfexpress', 'chavy_loginheader_sfexpress'],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/blob/master/sfexpress',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/sfexpress.png', 'https://raw.githubusercontent.com/Orz-3/task/master/sfexpress.png']
}
]
sysapps.sort((a, b) => a.id.localeCompare(b.id))
wrapapps(sysapps)
return sysapps
}
function getUserCfgs() {
const defcfgs = { favapps: [], appsubs: [], appsubCaches: {} }
const userCfgsStr = $.getdata($.KEY_userCfgs)
return userCfgsStr ? Object.assign(defcfgs, JSON.parse(userCfgsStr)) : defcfgs
}
function getGlobalBaks() {
const globalBaksStr = $.getdata($.KEY_globalBaks)
return globalBaksStr ? JSON.parse(globalBaksStr) : []
}
async function refreshAppSubs() {
const usercfgs = getUserCfgs()
for (let subIdx = 0; subIdx < usercfgs.appsubs.length; subIdx++) {
const sub = usercfgs.appsubs[subIdx]
const suburl = sub.url.replace(/[ ]|[\r\n]/g, '')
await new Promise((resolve) => {
$.get({ url: suburl }, (err, resp, data) => {
try {
const respsub = JSON.parse(data)
if (Array.isArray(respsub.apps)) {
respsub._raw = sub
respsub.updateTime = new Date()
wrapapps(respsub.apps)
usercfgs.appsubCaches[suburl] = respsub
console.log(`更新订阅, 成功! ${suburl}`)
}
} catch (e) {
$.logErr(e, resp)
sub.isErr = true
sub.apps = []
sub._raw = JSON.parse(JSON.stringify(sub))
sub.updateTime = new Date()
usercfgs.appsubCaches[suburl] = sub
console.log(`更新订阅, 失败! ${suburl}`)
} finally {
resolve()
}
})
})
}
$.setdata(JSON.stringify(usercfgs), $.KEY_userCfgs)
console.log(`全部订阅, 完成!`)
}
function getAppSubs() {
const usercfgs = getUserCfgs()
const appsubs = []
for (let subIdx = 0; subIdx < usercfgs.appsubs.length; subIdx++) {
const sub = usercfgs.appsubs[subIdx]
const suburl = sub.url.replace(/[ ]|[\r\n]/g, '')
const cachedsub = usercfgs.appsubCaches[suburl]
if (cachedsub && Array.isArray(cachedsub.apps)) {
cachedsub._raw = sub
cachedsub.apps.forEach((app) => (app.datas = []))
wrapapps(cachedsub.apps)
appsubs.push(cachedsub)
} else {
sub.isErr = true
sub.apps = []
sub._raw = JSON.parse(JSON.stringify(sub))
appsubs.push(sub)
}
}
return appsubs
}
function getUserApps() {
return []
}
function wrapapps(apps) {
apps.forEach((app) => {
// 获取持久化数据
app.datas = Array.isArray(app.datas) ? app.datas : []
app.keys.forEach((key) => {
const valdat = $.getdata(key)
const val = [undefined, null, 'null', ''].includes(valdat) ? null : valdat
app.datas.push({ key, val })
})
Array.isArray(app.settings) &&
app.settings.forEach((setting) => {
const valdat = $.getdata(setting.id)
const val = [undefined, null, 'null', ''].includes(valdat) ? null : valdat
if (setting.type === 'boolean') {
setting.val = val === null ? setting.val : val === 'true'
} else if (setting.type === 'int') {
setting.val = val * 1 || setting.val
} else {
setting.val = val || setting.val
}
if (!Array.isArray(app.icons)) {
app.icons = ['https://raw.githubusercontent.com/Orz-3/mini/master/appstore.png', 'https://raw.githubusercontent.com/Orz-3/task/master/appstore.png']
}
app.author = app.author ? app.author : '@anonymous'
app.repo = app.repo ? app.repo : '作者很神秘, 没有留下任何线索!'
})
// 判断是否收藏应用
const usercfgs = getUserCfgs()
const favapps = usercfgs && usercfgs.favapps
if (favapps) {
app.isFav = favapps.findIndex((appId) => app.id === appId) > -1 ? true : false
}
})
}
function getSessions() {
const sessionstr = $.getdata($.KEY_sessions)
const sessions = sessionstr ? JSON.parse(sessionstr) : []
return Array.isArray(sessions) ? sessions : []
}
async function getVersions() {
let vers = []
await new Promise((resolve) => {
setTimeout(resolve, 1000)
const verurl = 'https://raw.githubusercontent.com/chavyleung/scripts/master/box/release/box.release.json'
$.get({ url: verurl }, (err, resp, data) => {
try {
const _data = JSON.parse(data)
vers = Array.isArray(_data.releases) ? _data.releases : vers
} catch (e) {
$.logErr(e, resp)
} finally {
console.log(`resolve`)
resolve()
}
})
})
return vers
}
function getSystemThemes() {
return [
{ id: '', name: '默认' },
{ id: 'red', name: '红色' },
{ id: 'pink', name: '粉红' },
{ id: 'purple', name: '紫色' },
{ id: 'blue', name: '蓝色' },
{ id: 'light-blue', name: '浅蓝' },
{ id: 'brown', name: '棕色' },
{ id: 'grey', name: '灰色' },
{ id: 'blue-grey', name: '蓝灰' }
]
}
async function handleApi() {
const data = JSON.parse($request.body)
// 保存会话
if (data.cmd === 'saveSession') {
const session = data.val
const sessions = getSessions()
sessions.push(session)
const savesuc = $.setdata(JSON.stringify(sessions), $.KEY_sessions)
$.subt = `保存会话: ${savesuc ? '成功' : '失败'} (${session.appName})`
$.desc = []
$.desc.push(`会话名称: ${session.name}`, `应用名称: ${session.appName}`, `会话编号: ${session.id}`, `应用编号: ${session.appId}`, `数据: ${JSON.stringify(session)}`)
$.msg($.name, $.subt, $.desc.join('\n'))
}
// 保存当前会话
else if (data.cmd === 'saveCurAppSession') {
const app = data.val
let isAllSaveSuc = true
app.datas.forEach((data) => {
const oldval = $.getdata(data.key)
const newval = data.val
const savesuc = $.setdata(`${newval}`, data.key)
isAllSaveSuc = !savesuc ? false : isAllSaveSuc
$.log('', `❕ ${app.name}, 保存设置: ${data.key} ${savesuc ? '成功' : '失败'}!`, `旧值: ${oldval}`, `新值: ${newval}`)
})
$.subt = `保存会话: ${isAllSaveSuc ? '成功' : '失败'} (${app.name})`
$.msg($.name, $.subt, '')
}
// 保存设置
else if (data.cmd === 'saveSettings') {
$.log(`❕ ${$.name}, 保存设置!`)
const settings = data.val
if (Array.isArray(settings)) {
settings.forEach((setting) => {
const oldval = $.getdata(setting.id)
const newval = setting.val
const usesuc = $.setdata(`${newval}`, setting.id)
$.log(`❕ ${$.name}, 保存设置: ${setting.id} ${usesuc ? '成功' : '失败'}!`, `旧值: ${oldval}`, `新值: ${newval}`)
$.setdata(`${newval}`, setting.id)
})
$.subt = `保存设置: 成功! `
$.msg($.name, $.subt, '')
}
}
// 应用会话
else if (data.cmd === 'useSession') {
$.log(`❕ ${$.name}, 应用会话!`)
const curSessionsstr = $.getdata($.KEY_curSessions)
const curSessions = ![undefined, null, 'null', ''].includes(curSessionsstr) ? JSON.parse(curSessionsstr) : {}
const session = data.val
const sessions = getSessions()
const sessionIdx = sessions.findIndex((s) => session.id === s.id)
if (sessions.splice(sessionIdx, 1) !== -1) {
session.datas.forEach((data) => {
const oldval = $.getdata(data.key)
const newval = data.val
const usesuc = $.setdata(`${newval}`, data.key)
$.log(`❕ ${$.name}, 替换数据: ${data.key} ${usesuc ? '成功' : '失败'}!`, `旧值: ${oldval}`, `新值: ${newval}`)
})
curSessions[session.appId] = session.id
$.setdata(JSON.stringify(curSessions), $.KEY_curSessions)
$.subt = `应用会话: 成功 (${session.appName})`
$.desc = []
$.desc.push(`会话名称: ${session.name}`, `应用名称: ${session.appName}`, `会话编号: ${session.id}`, `应用编号: ${session.appId}`, `数据: ${JSON.stringify(session)}`)
$.msg($.name, $.subt, $.desc.join('\n'))
}
}
// 删除会话
else if (data.cmd === 'delSession') {
const session = data.val
const sessions = getSessions()
const sessionIdx = sessions.findIndex((s) => session.id === s.id)
if (sessions.splice(sessionIdx, 1) !== -1) {
const delsuc = $.setdata(JSON.stringify(sessions), $.KEY_sessions) ? '成功' : '失败'
$.subt = `删除会话: ${delsuc ? '成功' : '失败'} (${session.appName})`
$.desc = []
$.desc.push(`会话名称: ${session.name}`, `会话编号: ${session.id}`, `应用名称: ${session.appName}`, `应用编号: ${session.appId}`, `数据: ${JSON.stringify(session)}`)
$.msg($.name, $.subt, $.desc.join('\n'))
}
}
// 保存用户偏好
else if (data.cmd === 'saveUserCfgs') {
const usercfgs = data.val
$.setdata(JSON.stringify(usercfgs), $.KEY_userCfgs)
}
// 添加应用订阅
else if (data.cmd === 'addAppSub') {
const sub = data.val
const usercfgs = getUserCfgs()
usercfgs.appsubs.push(sub)
$.setdata(JSON.stringify(usercfgs), $.KEY_userCfgs)
}
// 删除应用订阅
else if (data.cmd === 'delAppSub') {
const subId = data.val
const usercfgs = getUserCfgs()
const subIdx = usercfgs.appsubs.findIndex((s) => s.id === subId)
if (usercfgs.appsubs.splice(subIdx, 1) !== -1) {
const delsuc = $.setdata(JSON.stringify(usercfgs), $.KEY_userCfgs) ? '成功' : '失败'
$.subt = `删除订阅: ${delsuc ? '成功' : '失败'}`
$.msg($.name, $.subt, '')
}
}
// 全局备份
else if (data.cmd === 'globalBak') {
const baks = getGlobalBaks()
baks.push(data.val)
const baksuc = $.setdata(JSON.stringify(baks), $.KEY_globalBaks)
$.subt = `全局备份: ${baksuc ? '成功' : '失败'}`
$.msg($.name, $.subt, '')
}
// 删除全局备份
else if (data.cmd === 'delGlobalBak') {
const baks = getGlobalBaks()
const bakIdx = baks.findIndex((b) => b.id === data.val)
if (baks.splice(bakIdx, 1) !== -1) {
const delsuc = $.setdata(JSON.stringify(baks), $.KEY_globalBaks) ? '成功' : '失败'
$.subt = `删除备份: ${delsuc ? '成功' : '失败'}`
$.msg($.name, $.subt, '')
}
}
// 还原全局备份
else if (data.cmd === 'revertGlobalBak') {
const baks = getGlobalBaks()
const bakobj = baks.find((b) => b.id === data.val)
if (bakobj && bakobj.bak) {
const { chavy_boxjs_sessions, chavy_boxjs_sysCfgs, chavy_boxjs_userCfgs, chavy_boxjs_sysApps, ...datas } = bakobj.bak
$.setdata(JSON.stringify(chavy_boxjs_sessions), $.KEY_sessions)
$.setdata(JSON.stringify(chavy_boxjs_userCfgs), $.KEY_userCfgs)
Object.keys(datas).forEach((datkey) => $.setdata(datas[datkey] ? datas[datkey] : '', datkey))
$.subt = '还原备份: 成功'
$.msg($.name, $.subt, $.desc)
} else {
$.subt = '还原备份: 失败'
$.desc = `找不到备份: ${data.val}`
$.msg($.name, $.subt, $.desc)
}
}
// 刷新应用订阅
else if (data.cmd === 'refreshAppSubs') {
await refreshAppSubs()
}
}
async function getBoxData() {
return {
sessions: getSessions(),
versions: await getVersions(),
sysapps: getSystemApps(),
userapps: getUserApps(),
appsubs: getAppSubs(),
syscfgs: getSystemCfgs(),
usercfgs: getUserCfgs(),
globalbaks: getGlobalBaks(),
colors: getSystemThemes()
}
}
async function handleHome() {
const box = await getBoxData()
$.html = printHtml(JSON.stringify(box))
if (box.usercfgs.isDebugFormat) {
console.log(printHtml(`'\${data}'`, `'\${curapp}'`, `\${curview}`))
} else if (box.usercfgs.isDebugData) {
console.log($.html)
}
}
async function handleApp(appId) {
const box = await getBoxData()
const apps = []
const cursysapp = box.sysapps.find((app) => app.id === appId)
if (cursysapp) {
apps.push(cursysapp)
}
box.appsubs.filter((sub) => sub.enable !== false).forEach((sub) => apps.push(...sub.apps))
const curapp = apps.find((app) => app.id === appId)
$.html = printHtml(JSON.stringify(box), JSON.stringify(curapp), 'appsession')
if (box.usercfgs.isDebugFormat) {
console.log(printHtml(`'\${data}'`, `'\${curapp}'`, `\${curview}`))
} else if (box.usercfgs.isDebugData) {
console.log($.html)
}
}
async function handleSub() {
const box = await getBoxData()
$.html = printHtml(JSON.stringify(box), null, 'sub')
if (box.usercfgs.isDebugFormat) {
console.log(printHtml(`'\${data}'`, `'\${curapp}'`, `\${curview}`))
} else if (box.usercfgs.isDebugData) {
console.log($.html)
}
}
async function handleMy() {
const box = await getBoxData()
$.html = printHtml(JSON.stringify(box), null, 'my')
if (box.usercfgs.isDebugFormat) {
console.log(printHtml(`'\${data}'`, `'\${curapp}'`, `\${curview}`))
} else if (box.usercfgs.isDebugData) {
console.log($.html)
}
}
function printHtml(data, curapp = null, curview = 'app') {
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>BoxJs</title>
<meta charset="utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="Bookmark" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
<link rel="shortcut icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
<link rel="apple-touch-icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet" />
<style>
[v-cloak]{
display: none
}
</style>
</head>
<body>
<div id="app">
<v-app v-scroll="onScroll" v-cloak>
<v-app-bar :color="ui.appbar.color" app dense>
<v-menu bottom left v-if="['app', 'home', 'log', 'sub'].includes(ui.curview) && box.syscfgs.env !== ''">
<template v-slot:activator="{ on }">
<v-btn icon v-on="on">
<v-avatar size="26">
<img :src="box.syscfgs.envs.find(e=>e.id===box.syscfgs.env).icon" alt="box.syscfgs.env" />
</v-avatar>
</v-btn>
</template>
<v-list dense>
<v-list-item v-for="(env, envIdx) in box.syscfgs.envs" :key="env.id" @click="box.syscfgs.env=env.id">
<v-list-item-avatar size="24"><v-img :src="env.icon"></v-img></v-list-item-avatar>
<v-list-item-title>{{ env.id }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<v-btn icon @click="ui.curview = ui.bfview" v-else><v-icon>mdi-chevron-left</v-icon></v-btn>
<v-autocomplete v-model="ui.autocomplete.curapp" :items="apps" :filter="appfilter" :menu-props="{ closeOnContentClick: true, overflowY: true }" :label="ui.curapp ? ui.curapp.name + ' ' + ui.curapp.author : 'BoxJs - v' + box.syscfgs.version" no-data-text="未实现" dense hide-details solo>
<template v-slot:item="{ item }">
<v-list-item @click="goAppSessionView(item)">
<v-list-item-avatar>
<img :src="item.icons[box.usercfgs.isTransparentIcons ? 0 : 1]">
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ item.name }} ({{ item.id }})</v-list-item-title>
<v-list-item-subtitle>{{ item.repo }}</v-list-item-subtitle>
<v-list-item-subtitle>{{ item.author }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon v-if="item.isFav" @click.stop="onFav(item)"><v-icon color="yellow darken-2">mdi-star</v-icon></v-btn>
<v-btn icon v-else @click.stop="onFav(item)"><v-icon color="grey">mdi-star-outline</v-icon></v-btn>
</v-list-item-action>
</v-list-item>
</template>
</v-autocomplete>
<v-btn icon @click="ui.drawer.show = true">
<v-avatar size="26">
<img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" />
</v-avatar>
</v-btn>
</v-app-bar>
<v-fab-transition>
<v-speed-dial v-show="ui.box.show && !box.usercfgs.isHideBoxIcon" fixed fab bottom direction="top" :left="ui.drawer.show || box.usercfgs.isLeftBoxIcon" :right="!box.usercfgs.isLeftBoxIcon === true" class="mb-12">
<template v-slot:activator>
<v-btn fab>
<v-avatar size="48">
<img :src="box.syscfgs.boxjs.icon" :alt="box.syscfgs.boxjs.repo" />
</v-avatar>
</v-btn>
</template>
<v-btn v-if="!box.usercfgs.isHideHelp" fab small color="grey" @click="ui.versheet.show = true">
<v-icon>mdi-help</v-icon>
</v-btn>
<v-btn fab small color="pink" @click="box.usercfgs.isLeftBoxIcon = !box.usercfgs.isLeftBoxIcon, onUserCfgsChange()">
<v-icon v-if="!box.usercfgs.isLeftBoxIcon">mdi-format-horizontal-align-left</v-icon>
<v-icon v-else>mdi-format-horizontal-align-right</v-icon>
</v-btn>
<v-btn fab small color="indigo" @click="ui.impGlobalBakDialog.show = true">
<v-icon>mdi-database-import</v-icon>
</v-btn>
<v-btn fab small color="green" @click="" v-clipboard:copy="JSON.stringify(boxdat)" v-clipboard:success="onCopy">
<v-icon>mdi-export-variant</v-icon>
</v-btn>
<v-btn fab small color="orange" @click="reload">
<v-icon>mdi-refresh</v-icon>
</v-btn>
</v-speed-dial>
</v-fab-transition>
<v-navigation-drawer v-model="ui.drawer.show" app temporary right>
<v-list dense nav>
<v-list-item two-line dense @click="onLink(box.syscfgs.chavy.repo)">
<v-list-item-avatar>
<img src="https://avatars3.githubusercontent.com/u/29748519?s=460&u=392a19e85465abbcb1791c9b8b32184a16e6795e&v=4" />
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ box.syscfgs.chavy.id }}</v-list-item-title>
<v-list-item-subtitle>{{ box.syscfgs.chavy.repo }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>
<v-list-item>
<v-list-item-content>
<v-switch label="透明图标" v-model="box.usercfgs.isTransparentIcons" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
<v-list-item-action @click="onLink(box.syscfgs.orz3.repo)">
<v-btn fab small text>
<v-avatar size="32"><img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" /></v-avatar>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="隐藏悬浮图标" v-model="box.usercfgs.isHideBoxIcon" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
<v-list-item-action @click="onLink(box.syscfgs.boxjs.repo)">
<v-btn fab small text>
<v-avatar size="32"><img :src="box.syscfgs.boxjs.icon" :alt="box.syscfgs.boxjs.repo" /></v-avatar>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="隐藏我的标题" v-model="box.usercfgs.isHideMyTitle" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
<v-list-item-action>
<v-btn fab small text>
<v-avatar v-if="box.usercfgs.icon" size="32"><img :src="box.usercfgs.icon" :alt="box.syscfgs.boxjs.repo" /></v-avatar>
<v-icon v-else size="32">mdi-face-profile</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="隐藏帮助按钮" v-model="box.usercfgs.isHideHelp" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
<v-list-item-action @click="onLink(box.syscfgs.boxjs.repo)">
<v-btn fab small text>
<v-avatar size="32"><v-icon>mdi-help</v-icon></v-avatar>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="隐藏底部导航" v-model="box.usercfgs.isHideNavi" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="调试模式 (数据)" v-model="box.usercfgs.isDebugData" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-switch label="调试模式 (格式)" v-model="box.usercfgs.isDebugFormat" @change="onUserCfgsChange"></v-switch>
</v-list-item-content>
</v-list-item>
</v-list>
</v-navigation-drawer>
<v-main :class="box.usercfgs.isHideNavi ? 'mb-0' : 'mb-14'">
<v-container fluid v-if="ui.curview === 'app'">
<v-card class="mx-auto" v-if="favapps.length > 0">
<v-list nav dense>
<v-subheader inset>收藏应用 ({{ favapps.length }})</v-subheader>
<v-list-item three-line dense v-for="(app, appIdx) in favapps" :key="app.id" @click="goAppSessionView(app)">
<v-list-item-avatar><v-img :src="app.icons[box.usercfgs.isTransparentIcons ? 0 : 1]"></v-img></v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ app.name }} ({{ app.id }})</v-list-item-title>
<v-list-item-subtitle>{{ app.repo }}</v-list-item-subtitle>
<v-list-item-subtitle color="blue">{{ app.author }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-menu bottom left>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
</template>
<v-list dense>
<v-list-item v-if="appIdx > 0" @click="onMoveFav(appIdx, -1)">
<v-list-item-title>上移</v-list-item-title>
</v-list-item>
<v-list-item v-if="appIdx + 1 < favapps.length" @click="onMoveFav(appIdx, 1)">
<v-list-item-title>下移</v-list-item-title>
</v-list-item>
<v-divider v-if="favapps.length > 1"></v-divider>
<v-list-item @click="onFav(app)">
<v-list-item-title>取消收藏</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-list-item-action>
</v-list-item>
</v-list>
</v-card>
<v-card class="mx-auto mt-4" v-for="(sub, subIdx) in appsubs.filter((sub) => sub.isErr !== true)" :key="sub.id">
<v-list nav dense>
<v-subheader inset>
{{ sub.name ? sub.name : '匿名订阅' }} ({{ sub.apps.length }})
</v-subheader>
<v-list-item three-line dense v-for="(app, appIdx) in sub.apps" :key="app.id" @click="goAppSessionView(app)">
<v-list-item-avatar><v-img :src="app.icons[box.usercfgs.isTransparentIcons ? 0 : 1]"></v-img></v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ app.name }} ({{ app.id }})</v-list-item-title>
<v-list-item-subtitle>{{ app.repo }}</v-list-item-subtitle>
<v-list-item-subtitle color="blue">{{ app.author }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon v-if="app.isFav" @click.stop="onFav(app, appIdx)"><v-icon color="yellow darken-2">mdi-star</v-icon></v-btn>
<v-btn icon v-else @click.stop="onFav(app, appIdx)"><v-icon color="grey">mdi-star-outline</v-icon></v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
</v-card>
<v-card class="mx-auto mt-4">
<v-list nav dense>
<v-subheader inset>内置应用 ({{ box.sysapps.length }})</v-subheader>
<v-list-item three-line dense v-for="(app, appIdx) in box.sysapps" :key="app.id" @click="goAppSessionView(app)">
<v-list-item-avatar><v-img :src="app.icons[box.usercfgs.isTransparentIcons ? 0 : 1]"></v-img></v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ app.name }} ({{ app.id }})</v-list-item-title>
<v-list-item-subtitle>{{ app.repo }}</v-list-item-subtitle>
<v-list-item-subtitle color="blue">{{ app.author }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon v-if="app.isFav" @click.stop="onFav(app, appIdx)"><v-icon color="yellow darken-2">mdi-star</v-icon></v-btn>
<v-btn icon v-else @click.stop="onFav(app, appIdx)"><v-icon color="grey">mdi-star-outline</v-icon></v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
</v-card>
</v-container>
<v-container fluid v-if="ui.curview === 'appsession'">
<v-card class="mx-auto mb-4">
<template v-if="Array.isArray(ui.curapp.settings)">
<v-subheader v-if="Array.isArray(ui.curapp.settings)">
应用设置 ({{ ui.curapp.settings.length }})
</v-subheader>
<v-form class="pl-4 pr-4">
<template v-for="(setting, settingIdx) in ui.curapp.settings">
<v-slider :label="setting.name" v-model="setting.val" :hint="setting.desc" :min="setting.min" :max="setting.max" thumb-label="always" :placeholder="setting.placeholder" v-if="setting.type === 'slider'"></v-slider>
<v-switch :label="setting.name" v-model="setting.val" :hint="setting.desc" :placeholder="setting.placeholder" v-else-if="setting.type === 'boolean'"></v-switch>
<v-textarea :label="setting.name" v-model="setting.val" :hint="setting.desc" :auto-grow="setting.autoGrow" :placeholder="setting.placeholder" v-else-if="setting.type === 'textarea'"></v-textarea>
<v-text-field :label="setting.name" v-model="setting.val" :hint="setting.desc" :placeholder="setting.placeholder" v-else="setting.type === 'text'"></v-text-field>
</template>
</v-form>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn small text color="success" @click="onSaveSettings">保存设置</v-btn>
</v-card-actions>
</template>
</v-card>
<v-card class="mx-auto" v-if="ui.curapp.datas && ui.curapp.datas.length > 0">
<v-subheader>
当前会话 ({{ ui.curapp.datas.length }})
<v-spacer></v-spacer>
<v-menu bottom left>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
</template>
<v-list dense>
<v-list-item @click="" v-clipboard:copy="JSON.stringify(ui.curapp)" v-clipboard:success="onCopy">
<v-list-item-title>复制会话</v-list-item-title>
</v-list-item>
<v-list-item @click="ui.impSessionDialog.show = true">
<v-list-item-title>导入会话</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-subheader>
<v-list-item two-line dense v-for="(data, dataIdx) in ui.curapp.datas" :key="dataIdx">
<v-list-item-content>
<v-list-item-title>{{ data.key }}</v-list-item-title>
<v-list-item-subtitle>{{ data.val ? data.val : '无数据!' }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon @click.stop="onClearCurAppSessionData(ui.curapp, ui.curapp.datas, data)">
<v-icon color="grey darken-1">mdi-close</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn small text color="success" @click="onSaveSession">保存会话</v-btn>
</v-card-actions>
</v-card>
<v-card class="ml-10 mt-4" v-for="(session, sessionIdx) in ui.curappSessions" :key="session.id">
<v-subheader>
#{{ sessionIdx + 1 }} {{ session.name }}
</v-subheader>
<v-list-item two-line dense v-for="(data, dataIdx) in session.datas" :key="dataIdx">
<v-list-item-content>
<v-list-item-title>{{ data.key }}</v-list-item-title>
<v-list-item-subtitle>{{ data.val ? data.val : '无数据!' }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>
<v-card-actions>
<v-btn small text color="grey">{{ session.createTime }}</v-btn>
<v-spacer></v-spacer>
<v-btn small text color="error" @click="onDelSession(session)">删除</v-btn>
<v-btn small text color="success" @click="onUseSession(session)">应用</v-btn>
</v-card-actions>
</v-card>
<v-card class="ma-4" v-if="(!ui.curappSessions || ui.curappSessions.length === 0) && ui.curapp.keys.length > 0">
<v-card-text>当前脚本没有自建会话!</v-card-text>
</v-card>
<v-dialog v-model="ui.impSessionDialog.show" scrollable>
<v-card>
<v-card-title>
导入会话
<v-spacer></v-spacer>
<v-btn text small class="mr-n4" color="red darken-1" @click="ui.impSessionDialog.impval = ''">清空</v-btn>
</v-card-title>
<v-divider></v-divider>
<v-card-text>
<v-textarea clearable auto-grow v-model="ui.impSessionDialog.impval" label="会话数据 (JSON)" hint="请粘贴 JSON 格式的会话数据! 你可以通过 复制会话 获得数据."></v-textarea>
</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<v-btn text small @click="" v-clipboard:copy="ui.impSessionDialog.impval" v-clipboard:success="onCopy">复制</v-btn>
<v-btn text small @click="onImpSessionPaste">粘粘</v-btn>
<v-spacer></v-spacer>
<v-btn text small color="grey darken-1" text @click="ui.impSessionDialog.show = false">取消</v-btn>
<v-btn text small color="success darken-1" text @click="onImpSession">导入</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-container>
<v-container fluid v-if="ui.curview === 'sub'">
<v-card class="mx-auto" v-if="appsubs.length > 0">
<v-list nav dense>
<v-subheader inset>
应用订阅 ({{ appsubs.length }})
<v-spacer></v-spacer>
<v-tooltip v-model="ui.refreshtip.show" bottom>
<template v-slot:activator="{ on }">
<v-btn v-on="on" icon @click="onRefreshAppSubs"><v-icon>mdi-refresh-circle</v-icon></v-btn>
</template>
<span>手动更新订阅</span>
</v-tooltip>
<v-btn icon @click="ui.addAppSubDialog.show = true"><v-icon color="green">mdi-plus-circle</v-icon></v-btn>
</v-subheader>
<v-list-item two-line dense v-for="(sub, subIdx) in appsubs" :key="sub.id" @click="">
<v-list-item-avatar v-if="sub.icon"><v-img :src="sub.icon"></v-img></v-list-item-avatar>
<v-list-item-avatar v-else color="grey"><v-icon dark>mdi-account</v-icon></v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>
{{ sub.name ? sub.name : '匿名订阅' }} ({{ sub.apps.length }})
<v-chip v-if="sub.isErr === true" color="pink" x-small class="ml-4">格式错误</v-chip>
</v-list-item-title>
<v-list-item-subtitle>{{ sub.repo ? sub.repo : sub._raw.url }}</v-list-item-subtitle>
<v-list-item-subtitle color="blue">{{ sub.author ? sub.author : '@anonymous' }}</v-list-item-subtitle>
<v-list-item-subtitle color="blue">更新于: {{ moment(sub.updateTime) }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-menu bottom left>
<template v-slot:activator="{ on }">
<v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
</template>
<v-list dense>
<v-list-item @click="onDelAppSub(sub)">
<v-list-item-title>删除</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-list-item-action>
</v-list-item>
</v-list>
</v-card>
<v-btn class="mx-auto" block v-if="appsubs.length === 0" @click="ui.addAppSubDialog.show = true">添加订阅</v-btn>
<v-dialog v-model="ui.addAppSubDialog.show" scrollable>
<v-card>
<v-card-title>
添加订阅
<v-spacer></v-spacer>
<v-btn text small class="mr-n4" color="red darken-1" @click="ui.addAppSubDialog.url = ''">清空</v-btn>
</v-card-title>
<v-divider></v-divider>
<v-card-text>
<v-textarea clearable auto-grow v-model="ui.addAppSubDialog.url" label="订阅地址 (URL)" hint="请粘贴 URL 格式的订阅地址!"></v-textarea>
</v-card-text>
<v-divider></v-divider>
<v-card-actions>
<v-btn text small @click="" v-clipboard:copy="ui.addAppSubDialog.url" v-clipboard:success="onCopy">复制</v-btn>
<v-btn text small @click="onAddAppSubPaste">粘粘</v-btn>
<v-spacer></v-spacer>
<v-btn text small color="grey darken-1" text @click="ui.addAppSubDialog.show = false">取消</v-btn>
<v-btn text small color="success darken-1" text :disabled="!/^https?:\\/\\/.*?/.test(ui.addAppSubDialog.url)" @click="onAddAppSub">添加</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-container>
<v-container fluid v-if="ui.curview === 'my'">
<v-card class="mx-auto">
<v-card-title class="headline">
{{ box.usercfgs.name ? box.usercfgs.name : '大侠, 留个名字吧!' }}