Skip to content

Commit

Permalink
更新[chavy.box.js]: 可以切换图标主题了, 感谢 @Orz-3
Browse files Browse the repository at this point in the history
  • Loading branch information
chavyleung committed Jun 15, 2020
1 parent e7a8408 commit fc0cbb0
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 51 deletions.
Binary file added BOXJS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 108 additions & 51 deletions chavy.box.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const $ = new Env('chavy.box.js')
$.domain = '8.8.8.8'

$.KEY_sessions = 'chavy_boxjs_sessions'
$.KEY_userCfgs = 'chavy_boxjs_userCfgs'

$.json = $.name
$.html = $.name
Expand Down Expand Up @@ -50,10 +51,20 @@ function getSystemCfgs() {
return {
env: $.isSurge() ? 'Surge' : $.isQuanX ? 'QuanX' : 'Loon',
envs: [
{ id: 'Surge', icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/21/0a/0d/210a0df9-cbe1-b9dc-7549-4c10cd996279/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/492x0w.png' },
{ id: 'QuanX', icon: 'https://is4-ssl.mzstatic.com/image/thumb/Purple123/v4/ae/7c/a2/ae7ca2fb-c4b6-d3a9-885a-935c1ea34cdb/AppIcon-1x_U007emarketing-0-7-0-0-85-220.png/492x0w.png' },
{ id: 'Loon', icon: 'https://is2-ssl.mzstatic.com/image/thumb/Purple123/v4/59/2c/fb/592cfb3b-162e-83dc-4e96-7a2175e1d29f/AppIcon-0-1x_U007emarketing-0-7-0-0-85-220.png/492x0w.png' }
]
{ 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?s=460&u=392a19e85465abbcb1791c9b8b32184a16e6795e&v=4',
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/'
}
}
}

Expand All @@ -65,23 +76,23 @@ function getSystemApps() {
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',
icon: 'https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/f7/03/75/f70375ee-7462-d5fc-4b76-79809e63a325/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-85-220.png/492x0w.png'
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',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/52pj.png'
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',
icon: 'https://is5-ssl.mzstatic.com/image/thumb/Purple123/v4/41/f0/11/41f011f8-1bbc-188f-220f-3db5164a9ae9/AppIcon-1x_U007emarketing-0-7-0-0-85-220.png/492x0w.png'
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/acfun.png', 'https://raw.githubusercontent.com/Orz-3/task/master/acfun.png']
},
{
id: 'ApkTw',
Expand All @@ -90,7 +101,7 @@ function getSystemApps() {
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/apktw',
url: 'https://apk.tw/',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/apktw.png',
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 }]
},
Expand All @@ -106,23 +117,23 @@ function getSystemApps() {
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/tieba',
icon: 'https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/0a/33/50/0a335055-952a-6860-76aa-c657b2627a78/AppIcon-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-85-220.jpeg/434x0w.jpg'
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',
icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/fa/dd/9a/fadd9a15-6b01-e4f7-0e59-920b23e58490/AppIcon-0-0-1x_U007emarketing-0-0-0-5-0-0-85-220.png/492x0w.png'
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',
icon: 'https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/0b/7c/08/0b7c08b3-4c03-1d92-5461-32c176a6fc30/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-85-220.png/460x0w.png'
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/jd.png', 'https://raw.githubusercontent.com/Orz-3/task/master/jd.png']
},
{
id: 'JD618',
Expand All @@ -138,23 +149,23 @@ function getSystemApps() {
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/jd',
icon: 'https://is4-ssl.mzstatic.com/image/thumb/Purple113/v4/0b/7c/08/0b7c08b3-4c03-1d92-5461-32c176a6fc30/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-85-220.png/460x0w.png'
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',
icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/f1/b4/87/f1b4871f-717d-50c6-3151-b087733768ec/AppIcon-0-0-1x_U007emarketing-0-0-0-8-0-85-220.png/492x0w.png'
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',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/v2ex.png'
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/v2ex.png', 'https://raw.githubusercontent.com/Orz-3/task/master/v2ex.png']
},
{
id: 'NeteaseMusic',
Expand All @@ -166,15 +177,15 @@ function getSystemApps() {
],
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/neteasemusic',
icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple113/v4/ef/e3/f4/efe3f4fa-288f-65fc-fc59-eacf6c1cea01/AppIcon-0-0-1x_U007emarketing-0-0-0-6-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/460x0w.png'
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',
icon: 'https://is3-ssl.mzstatic.com/image/thumb/Purple123/v4/a0/15/bc/a015bcec-e853-cdb3-a97b-573c15771265/AppIcon-0-1x_U007emarketing-0-7-0-0-0-0-85-220.png/492x0w.png'
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/wps.png', 'https://raw.githubusercontent.com/Orz-3/task/master/wps.png']
},
{
id: 'NoteYoudao',
Expand All @@ -183,87 +194,94 @@ function getSystemApps() {
author: '@chavyleung',
repo: 'https://github.com/chavyleung/scripts/tree/master/noteyoudao',
url: 'https://apps.apple.com/cn/app/有道云笔记-扫描王版/id450748070',
icon: 'https://is1-ssl.mzstatic.com/image/thumb/Purple113/v4/25/6a/00/256a002d-b5f0-46e1-ef55-841d41f8aafc/AppIcon-0-1x_U007emarketing-0-7-0-0-85-220.png/460x0w.png',
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: 'QTT',
name: '趣头条',
keys: ['senku_signKey_qtt', 'senku_signXTK_qtt', 'senku_readKey_qtt','senku_navCoinKey_qtt'],
keys: ['senku_signKey_qtt', 'senku_signXTK_qtt', 'senku_readKey_qtt', 'senku_navCoinKey_qtt'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/qtt',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/qtt.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/qtt.png', 'https://raw.githubusercontent.com/Orz-3/task/master/qtt.png']
},
{
id: 'qmkg',
name: '全民K歌',
keys: ['senku_signurl_qmkg', 'senku_signheader_qmkg', 'senku_signbody_qmkg'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/qmkg',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/qmkg.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/qmkg.png', 'https://raw.githubusercontent.com/Orz-3/task/master/qmkg.png']
},
{
id: 'bcz',
name: '百词斩',
keys: ['senku_cookie_bcz', 'senku_key_bcz'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/bcz',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/midu.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/midu.png', 'https://raw.githubusercontent.com/Orz-3/task/master/midu.png']
},
{
id: 'zxhc',
name: '智行火车票',
keys: ['senku_signurl_zxhc', 'senku_signheader_zxhc','senku_signbody_zxhc'],
keys: ['senku_signurl_zxhc', 'senku_signheader_zxhc', 'senku_signbody_zxhc'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/zxhc',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/zxhc.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/zxhc.png', 'https://raw.githubusercontent.com/Orz-3/task/master/zxhc.png']
},
{
id: 'fenqile',
name: '分期乐',
keys: ['senku_signurl_fenqile', 'senku_signheader_fenqile','senku_signbody_fenqile','senku_signDailyKey_fenqile','senku_signDailyUrlKey_fenqile'],
keys: ['senku_signurl_fenqile', 'senku_signheader_fenqile', 'senku_signbody_fenqile', 'senku_signDailyKey_fenqile', 'senku_signDailyUrlKey_fenqile'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/fenqile',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/fenqile.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/fenqile.png', 'https://raw.githubusercontent.com/Orz-3/task/master/fenqile.png']
},
{
id: 'fandeng',
name: '樊登读书',
keys: ['senku_signurl_pandeng', 'senku_signheader_pandeng','senku_signbody_pandeng'],
keys: ['senku_signurl_pandeng', 'senku_signheader_pandeng', 'senku_signbody_pandeng'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/fandeng',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/fandeng.png',
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/fandeng.png', 'https://raw.githubusercontent.com/Orz-3/task/master/fandeng.png']
},
{
id: 'dbsj',
name: '豆瓣时间',
keys: ['senku_signurl_dbsj', 'senku_signheader_dbsj','senku_signbody_dbsj'],
keys: ['senku_signurl_dbsj', 'senku_signheader_dbsj', 'senku_signbody_dbsj'],
author: '@GideonSenku',
repo: 'https://github.com/chavyleung/scripts/tree/master/dbsj',
icon: 'https://raw.githubusercontent.com/Orz-3/mini/master/dbsj.png',
},
icons: ['https://raw.githubusercontent.com/Orz-3/mini/master/dbsj.png', 'https://raw.githubusercontent.com/Orz-3/task/master/dbsj.png']
}
]
sysapps.forEach((app) => {
app.datas = Array.isArray(app.datas) ? app.datas : []
app.keys.forEach((key) => {
app.datas.push({ key, val: $.getdata(key) })
})
Array.isArray(app.settings) &&
app.settings.forEach((setting) => {
const val = $.getdata(setting.id)
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
}
sysapps
.sort((a, b) => a.id.localeCompare(b.id))
.forEach((app) => {
app.datas = Array.isArray(app.datas) ? app.datas : []
app.keys.forEach((key) => {
app.datas.push({ key, val: $.getdata(key) })
})
})
Array.isArray(app.settings) &&
app.settings.forEach((setting) => {
const val = $.getdata(setting.id)
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
}
})
})
return sysapps
}

function getUserCfgs() {
const userCfgsStr = $.getdata($.KEY_userCfgs)
return userCfgsStr ? JSON.parse(userCfgsStr) : {}
}

function getUserApps() {
return []
}
Expand Down Expand Up @@ -305,7 +323,7 @@ function handleApi() {
}
}
// 保存当前会话
if (data.cmd === 'saveCurAppSession') {
else if (data.cmd === 'saveCurAppSession') {
const app = data.val
const isExistsApp = getSystemApps().find((_app) => _app.id === app.id)
if (isExistsApp) {
Expand Down Expand Up @@ -369,6 +387,11 @@ function handleApi() {
$.msg($.name, $.subt, $.desc.join('\n'))
}
}
// 保存用户偏好
else if (data.cmd === 'saveUserCfgs') {
const usercfgs = data.val
$.setdata(JSON.stringify(usercfgs), $.KEY_userCfgs)
}
}

function handleApp(appId) {
Expand All @@ -377,6 +400,7 @@ function handleApp(appId) {
sysapps: getSystemApps(),
userapps: getUserApps(),
syscfgs: getSystemCfgs(),
usercfgs: getUserCfgs(),
colors: getSystemThemes()
}
const curapp = appId ? box.sysapps.find((app) => app.id === appId) : null
Expand All @@ -391,6 +415,7 @@ function handleHome() {
sysapps: getSystemApps(),
userapps: getUserApps(),
syscfgs: getSystemCfgs(),
usercfgs: getUserCfgs(),
colors: getSystemThemes()
})
)
Expand All @@ -404,6 +429,7 @@ function printHtml(data, curapp = null) {
<head>
<title>BoxJs</title>
<meta charset="utf-8" />
<link rel="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" />
Expand Down Expand Up @@ -440,16 +466,41 @@ function printHtml(data, curapp = null) {
</v-menu>
<v-btn icon @click="ui.curview = ui.bfview" v-else><v-icon>mdi-chevron-left</v-icon></v-btn>
<v-autocomplete :label="ui.curapp ? ui.curapp.name + ' ' + ui.curapp.author : 'chavy.box.js'" no-data-text="未实现" dense hide-details solo> </v-autocomplete>
<v-app-bar-nav-icon @click="ui.drawer.show = true"></v-app-bar-nav-icon>
<v-btn icon @click="ui.drawer.show = true">
<v-avatar size="24">
<img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" />
</v-avatar>
</v-btn>
</v-app-bar>
<v-navigation-drawer v-model="ui.drawer.show" app temporary right> </v-navigation-drawer>
<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="onIconChange"></v-switch>
</v-list-item-content>
<v-list-item-action @click="onLink(box.syscfgs.orz3.repo)">
<v-avatar size="32"><img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" /></v-avatar>
</v-list-item-action>
</v-list-item>
</v-list>
</v-navigation-drawer>
<v-content>
<v-container fluid v-if="ui.curview === 'app'">
<v-card class="mx-auto" tile>
<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.icon"></v-img></v-list-item-avatar>
<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>
Expand Down Expand Up @@ -644,6 +695,12 @@ function printHtml(data, curapp = null) {
}
},
methods: {
onLink(link) {
window.open(link)
},
onIconChange() {
axios.post('/api', JSON.stringify({ cmd: 'saveUserCfgs', val: this.box.usercfgs }))
},
goAppSessionView(app) {
this.ui.bfview = this.ui.curview
this.ui.curapp = app
Expand Down Expand Up @@ -678,7 +735,7 @@ function printHtml(data, curapp = null) {
navigator.clipboard.readText().then((text) => {
this.ui.impSessionDialog.impval = ''
this.ui.impSessionDialog.impval = text
});
})
},
onImpSession() {
const impjson = this.ui.impSessionDialog.impval
Expand Down

0 comments on commit fc0cbb0

Please sign in to comment.