From 4ee7e8d38c99f9fc5777fac5498c7e466e11b80a Mon Sep 17 00:00:00 2001 From: id77 <9592236+id77@users.noreply.github.com> Date: Thu, 10 Dec 2020 13:45:54 +0800 Subject: [PATCH 001/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=84=9A=E6=9C=AC=E6=8F=90=E5=89=8D=20$done=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bilibili/bilibili.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bilibili/bilibili.js b/bilibili/bilibili.js index fb3854602..349ca9d13 100644 --- a/bilibili/bilibili.js +++ b/bilibili/bilibili.js @@ -37,9 +37,8 @@ function sign() { chavy.msg(title, subTitle, detail) } chavy.log(`${cookieName}, data: ${data}`) + chavy.done() }) - - chavy.done() } function getsigninfo() { let url = { @@ -61,6 +60,7 @@ function getsigninfo() { let result = JSON.parse(data) if (result && result.code == 0) detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}` chavy.msg(title, subTitle, detail) + chavy.done() }) } function init() { From 4d533aa5c6bcce279fc28f5c24f91a719eb60a23 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Sat, 12 Dec 2020 21:05:49 +0800 Subject: [PATCH 002/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[Env]=EF=BC=8Ctime?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Env.js b/Env.js index b23d708ca..d33f3ea67 100644 --- a/Env.js +++ b/Env.js @@ -367,20 +367,22 @@ function Env(name, opts) { * :$.time('yyyyMMddHHmmssS') * y:年 M:月 d:日 q:季 H:时 m:分 s:秒 S:毫秒 * 其中y可选0-4位占位符、S可选0-1位占位符,其余可选0-2位占位符 - * @param {*} fmt 格式化参数 + * @param {string} fmt 格式化参数 + * @param {number} 可选: 根据指定时间戳返回格式化日期 * */ - time(fmt) { + time(fmt, ts = null) { + const date = ts ? new Date(ts) : new Date() let o = { - 'M+': new Date().getMonth() + 1, - 'd+': new Date().getDate(), - 'H+': new Date().getHours(), - 'm+': new Date().getMinutes(), - 's+': new Date().getSeconds(), - 'q+': Math.floor((new Date().getMonth() + 3) / 3), - 'S': new Date().getMilliseconds() + 'M+': date.getMonth() + 1, + 'd+': date.getDate(), + 'H+': date.getHours(), + 'm+': date.getMinutes(), + 's+': date.getSeconds(), + 'q+': Math.floor((date.getMonth() + 3) / 3), + 'S': date.getMilliseconds() } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (new Date().getFullYear() + '').substr(4 - RegExp.$1.length)) + if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) for (let k in o) if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) From bf26846224773d3db6cc44ed90b6c3a83bbfd45c Mon Sep 17 00:00:00 2001 From: zzcyrus Date: Mon, 14 Dec 2020 10:11:17 +0800 Subject: [PATCH 003/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20acfun=20=E7=9A=84?= =?UTF-8?q?=20done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acfun/acfun.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acfun/acfun.js b/acfun/acfun.js index f294ccc4c..f5d55121a 100644 --- a/acfun/acfun.js +++ b/acfun/acfun.js @@ -27,7 +27,6 @@ function sign() { } chavy.log(`${cookieName}, data: ${data}`) }) - chavy.done() } function getinfo(signresult) { @@ -49,6 +48,7 @@ function getinfo(signresult) { detail = `共签: ${result.cumulativeDays}次, 连签: ${result.continuousDays}次, 说明: ${signresult.msg}` chavy.msg(title, subTitle, detail) chavy.log(`${cookieName}, data: ${data}`) + chavy.done() }) } From 64a1465e166596efb50fc4490fab7a9d3b8faba0 Mon Sep 17 00:00:00 2001 From: zzcyrus Date: Tue, 15 Dec 2020 09:30:26 +0800 Subject: [PATCH 004/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20v2ex=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5done=E4=BB=A5=E6=AD=A3=E7=A1=AE=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2ex/quanx/v2ex.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v2ex/quanx/v2ex.js b/v2ex/quanx/v2ex.js index 3f35cb666..7494795e6 100644 --- a/v2ex/quanx/v2ex.js +++ b/v2ex/quanx/v2ex.js @@ -18,6 +18,7 @@ function sign() { let detail = `今天已经签过了` console.log(`${title}, ${subTitle}, ${detail}`) $notify(title, subTitle, detail) + $done() } else { signMission(data.match(/]*\/mission\/daily\/redeem\?once=(\d+)[^>]*>/)[1]) } @@ -45,6 +46,7 @@ function signMission(code) { console.log(`签到失败: ${cookieName}, data: ${data}`) $notify(title, subTitle, detail) } + $done() }) } From c1c0a92bb6f4c5862fc72ddc89d13ef4cff6bd99 Mon Sep 17 00:00:00 2001 From: 2YA <374779789@qq.com> Date: Thu, 24 Dec 2020 17:32:26 +0800 Subject: [PATCH 005/311] Update 10086.fee.cookie.js --- 10086/10086.fee.cookie.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/10086/10086.fee.cookie.js b/10086/10086.fee.cookie.js index 06f278083..13daf286f 100644 --- a/10086/10086.fee.cookie.js +++ b/10086/10086.fee.cookie.js @@ -13,8 +13,8 @@ * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=10086-查话费 * * # Loon - * http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true - * http-response ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true + * http-request ^https:\/\/clientaccess.10086.cn\/biz-orange\/LN\/uamrandcodelogin\/autoLogin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true, tag=中国移动-查话费 + * http-request ^https:\/\/clientaccess.10086.cn\/biz-orange\/BN\/realFeeQuery\/getRealFee script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.cookie.js, requires-body=true, tag=中国移动-查话费 * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js * */ From 96ae2fff188ef785bbb25debbb67a309c96ddaaa Mon Sep 17 00:00:00 2001 From: 2YA <374779789@qq.com> Date: Thu, 24 Dec 2020 17:37:10 +0800 Subject: [PATCH 006/311] Update wanda.cookie.js --- wanda/wanda.cookie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wanda/wanda.cookie.js b/wanda/wanda.cookie.js index e21e189da..3ac7bf7e1 100644 --- a/wanda/wanda.cookie.js +++ b/wanda/wanda.cookie.js @@ -11,7 +11,7 @@ * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.js, tag=wanda-签到 * * # Loon - * http-response ^https:\/\/user-api-prd-mx\.wandafilm\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.cookie.js + * http-request ^https:\/\/user-api-prd-mx\.wandafilm\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.cookie.js, tag=万达电影 * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.js * * # 获取方式:进入签到页面获取,网页端:https://act-m.wandacinemas.com/2005/17621a8caacc4d190dadd/ From fc7b6ee2c65880c2e78fcb5f7193d4d65624127b Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 24 Dec 2020 19:58:51 +0800 Subject: [PATCH 007/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20Vuetify=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=87=B3=20v2.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 67 +++++++++++---------------------- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++ box/release/box.release.tf.json | 12 ++++++ 4 files changed, 46 insertions(+), 47 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 6cab1f0cb..94bfcb590 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -11,7 +11,7 @@ - + @@ -1840,12 +1843,6 @@

v{{ver.versio ) }, created() { - // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 - if (window.location.search) { - const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) - axios.defaults.baseURL = baseURL || '' - this.ui.isCors = true - } // 根据路径跳转视图 const defview = '/' if (!this.isCors) { @@ -1862,6 +1859,18 @@

v{{ver.versio } else { axios.get('/query/boxdata').then((resp) => (this.box = resp.data)) } + // 如果是Quantumult X环境并且配置了HTTP Backend,将axios请求指向到HTTP Backend + if (this.box.syscfgs.env === 'QuanX' && this.box.usercfgs.http_backend) { + axios.defaults.baseURL = this.box.usercfgs.http_backend + this.ui.isCors = true + } + // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 + if (window.location.search) { + const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) + axios.defaults.baseURL = baseURL || '' + this.ui.isCors = true + } + // 获取全局备份 if (this.view === 'bak') { this.loadGlobalBak() @@ -2121,6 +2130,13 @@

v{{ver.versio delete resp.data.usercfgs } Object.assign(this.box, resp.data) + + if (this.curapp.id === 'BoxSetting') { + if (this.box.syscfgs.env === 'QuanX') { + axios.defaults.baseURL = this.box.usercfgs.http_backend || '' + this.ui.isCors = true + } + } }) }, // 保存应用会话 diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index a7cd3bdfd..dd3c8be09 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -302,6 +302,7 @@ function getSystemApps() { keys: [ '@chavy_boxjs_userCfgs.httpapi', '@chavy_boxjs_userCfgs.bgimg', + '@chavy_boxjs_userCfgs.http_backend', '@chavy_boxjs_userCfgs.color_dark_primary', '@chavy_boxjs_userCfgs.color_light_primary' ], @@ -313,7 +314,8 @@ function getSystemApps() { { 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.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 开头的完整路径, 不能是 / 结尾' }, ], scripts: [ { @@ -370,7 +372,13 @@ function getSystemApps() { * 获取用户配置 */ function getUserCfgs() { - const defcfgs = { favapps: [], appsubs: [], isPinedSearchBar: true, httpapi: 'examplekey@127.0.0.1:6166' } + const defcfgs = { + favapps: [], + appsubs: [], + isPinedSearchBar: true, + httpapi: 'examplekey@127.0.0.1:6166', + http_backend: '' + } const usercfgs = Object.assign(defcfgs, $.getjson($.KEY_usercfgs, {})) // 处理异常数据:删除所有为 null 的订阅 diff --git a/chavy.box.js b/chavy.box.js index a7cd3bdfd..8e74dfec9 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -302,12 +302,14 @@ function getSystemApps() { keys: [ '@chavy_boxjs_userCfgs.httpapi', '@chavy_boxjs_userCfgs.bgimg', + '@chavy_boxjs_userCfgs.http_backend', '@chavy_boxjs_userCfgs.color_dark_primary', '@chavy_boxjs_userCfgs.color_light_primary' ], 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: '' }, @@ -370,7 +372,13 @@ function getSystemApps() { * 获取用户配置 */ function getUserCfgs() { - const defcfgs = { favapps: [], appsubs: [], isPinedSearchBar: true, httpapi: 'examplekey@127.0.0.1:6166' } + const defcfgs = { + favapps: [], + appsubs: [], + isPinedSearchBar: true, + httpapi: 'examplekey@127.0.0.1:6166', + http_backend: '' + } const usercfgs = Object.assign(defcfgs, $.getjson($.KEY_usercfgs, {})) // 处理异常数据:删除所有为 null 的订阅 From 9e8c14836700c1d9bf2b816e0e4c9547becea45b Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 25 Mar 2021 16:48:03 +0800 Subject: [PATCH 048/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=89=88=E6=9C=AC=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 153 ++++++++++++++++++++++++++++---- box/release/box.release.tf.json | 86 ++++++++++++++++-- chavy.box.js | 6 +- 4 files changed, 220 insertions(+), 27 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index dd3c8be09..b672606c3 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.77' +$.version = '0.7.78' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 8d1e0babe..bb947dc9b 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,31 @@ { "releases": [ + { + "version": "0.7.78", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 增加版本说明", + "notes": [ + { + "name": "新增", + "descs": [ + "偏好设置增加 HTTP Backend (Quantumult X)", + "说明: ", + "发现: Quantumult X 通过重写的方式访问 BoxJs 可能会导致无法删除备份的问题, 但通过 HTTP Backend 方式访问则正常。", + "建议: 改用 HTTP Backend 或 重写与 HTTP Backend 结合的方式访问 BoxJs", + "姿势: 见 使用文档 (悬浮按钮 > ?)" + ] + }, + { + "name": "优化", + "descs": ["增加底部空间避免悬浮按钮遮挡空间"] + }, + { + "name": "感谢", + "descs": ["@chouchoui PR"] + } + ] + }, { "version": "0.7.77", "tags": ["beta"], @@ -24,7 +50,25 @@ }, { "name": "说明", - "descs": ["抹掉:所有缓存", "抹掉订阅及页面缓存,会导致所有订阅显示格式错误,双击底栏'订阅'菜单或更新订阅即可恢复", "", "抹掉:收藏应用", "抹掉所有收藏的应用,排序出现问题时可尝试抹掉", "", "抹掉:用户偏好", "抹掉头像、设置、收藏等个人相关的数据, 注意:不含会话、备份、缓存", "", "抹掉:所有会话", "抹掉所有应用下的会话, 注意:不会抹掉当前会话", "", "抹掉:所有备份", "抹掉所有全局备份, 注意:抹掉前可先把备份复制到其他文本类应用内", "", "抹掉:BoxJs", "抹掉所有由 BoxJs 管理的数据, 如:备份、会话、偏好、缓存等 (不包含当前会话)"] + "descs": [ + "抹掉:所有缓存", + "抹掉订阅及页面缓存,会导致所有订阅显示格式错误,双击底栏'订阅'菜单或更新订阅即可恢复", + "", + "抹掉:收藏应用", + "抹掉所有收藏的应用,排序出现问题时可尝试抹掉", + "", + "抹掉:用户偏好", + "抹掉头像、设置、收藏等个人相关的数据, 注意:不含会话、备份、缓存", + "", + "抹掉:所有会话", + "抹掉所有应用下的会话, 注意:不会抹掉当前会话", + "", + "抹掉:所有备份", + "抹掉所有全局备份, 注意:抹掉前可先把备份复制到其他文本类应用内", + "", + "抹掉:BoxJs", + "抹掉所有由 BoxJs 管理的数据, 如:备份、会话、偏好、缓存等 (不包含当前会话)" + ] } ] }, @@ -104,7 +148,14 @@ "notes": [ { "name": "说明", - "descs": ["由于通过 gitee 访问部分仓库资源时出现 `根据相关法律政策,该内容无法显示`", "虽然我手动同步 github 代码后已经可以正常访问", "但为避免以后出现不可预知的情况:", "我们把全部 gitee 链接替换为 github raw 及 jsdelivr", "----", "大家只需正常更新订阅并重启代理即可"] + "descs": [ + "由于通过 gitee 访问部分仓库资源时出现 `根据相关法律政策,该内容无法显示`", + "虽然我手动同步 github 代码后已经可以正常访问", + "但为避免以后出现不可预知的情况:", + "我们把全部 gitee 链接替换为 github raw 及 jsdelivr", + "----", + "大家只需正常更新订阅并重启代理即可" + ] }, { "name": "感谢", @@ -344,7 +395,10 @@ }, { "name": "说明", - "descs": ["背景图片清单中设置:无{换行} 跟随系统,跟随系统{换行} light,图片地址{换行} dark,图片地址{换行}", "如果不设置`跟随系统,跟随系统`,则默认跟随系统为无背景"] + "descs": [ + "背景图片清单中设置:无{换行} 跟随系统,跟随系统{换行} light,图片地址{换行} dark,图片地址{换行}", + "如果不设置`跟随系统,跟随系统`,则默认跟随系统为无背景" + ] } ] }, @@ -540,7 +594,17 @@ }, { "name": "壁纸", - "descs": ["无背景,", "随机,https://uploadbeta.com/api/pictures/random", "推女郎,https://uploadbeta.com/api/pictures/random/?key=推女郎", "性感,https://uploadbeta.com/api/pictures/random/?key=性感", "车模,https://uploadbeta.com/api/pictures/random/?key=车模", "美腿,https://uploadbeta.com/api/pictures/random/?key=美腿", "美女,https://uploadbeta.com/api/pictures/random/?key=美女", "手机妹子,http://api.btstu.cn/sjbz/zsy.php", "手机美女,http://api.btstu.cn/sjbz/?m_lx=suiji"] + "descs": [ + "无背景,", + "随机,https://uploadbeta.com/api/pictures/random", + "推女郎,https://uploadbeta.com/api/pictures/random/?key=推女郎", + "性感,https://uploadbeta.com/api/pictures/random/?key=性感", + "车模,https://uploadbeta.com/api/pictures/random/?key=车模", + "美腿,https://uploadbeta.com/api/pictures/random/?key=美腿", + "美女,https://uploadbeta.com/api/pictures/random/?key=美女", + "手机妹子,http://api.btstu.cn/sjbz/zsy.php", + "手机美女,http://api.btstu.cn/sjbz/?m_lx=suiji" + ] } ] }, @@ -756,7 +820,12 @@ }, { "name": "说明", - "descs": ["除了本机运行外", "可以使用 PC 连上 QuanX 的 HTTP Backend", "实现在 PC 上写代码然后发送到 QuanX 执行", "Surge、Loon 同理"] + "descs": [ + "除了本机运行外", + "可以使用 PC 连上 QuanX 的 HTTP Backend", + "实现在 PC 上写代码然后发送到 QuanX 执行", + "Surge、Loon 同理" + ] } ] }, @@ -837,7 +906,12 @@ }, { "name": "操作", - "descs": ["可以修复全局备份的名字", "点击'应用'回到顶部,再次单击折叠面板", "点击'订阅'回到顶部,再次单击刷新订阅", "点击具体订阅可刷新"] + "descs": [ + "可以修复全局备份的名字", + "点击'应用'回到顶部,再次单击折叠面板", + "点击'订阅'回到顶部,再次单击刷新订阅", + "点击具体订阅可刷新" + ] } ] }, @@ -896,7 +970,9 @@ }, { "name": "示例", - "descs": ["https://gist.githubusercontent.com/chavyleung/9d53fc4809eb41dca5f5923790ec5554/raw/09742d3473420d8e0bd7b02a910849f65af879fa/chavy.app.sub.simple.json"] + "descs": [ + "https://gist.githubusercontent.com/chavyleung/9d53fc4809eb41dca5f5923790ec5554/raw/09742d3473420d8e0bd7b02a910849f65af879fa/chavy.app.sub.simple.json" + ] }, { "name": "注意", @@ -951,11 +1027,19 @@ }, { "name": "新的重写订阅", - "descs": ["Surge: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.surge.sgmodule", "QuanX: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.quanx.conf", "Loon: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.loon.conf"] + "descs": [ + "Surge: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.surge.sgmodule", + "QuanX: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.quanx.conf", + "Loon: https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.loon.conf" + ] }, { "name": "注意", - "descs": ["新的重写订阅只有 boxjs.com", "旧的重写订阅仍然保留 8888 1111 和新增的 boxjs.com", "可以直接访问 http://boxjs.com 不加/home"] + "descs": [ + "新的重写订阅只有 boxjs.com", + "旧的重写订阅仍然保留 8888 1111 和新增的 boxjs.com", + "可以直接访问 http://boxjs.com 不加/home" + ] } ] }, @@ -968,7 +1052,13 @@ "notes": [ { "name": "优化", - "descs": ["双击底栏'应用'可以收缩面板并回到顶部", "双击底栏'订阅'可以刷新订阅并回到顶部", "双击'BoxJs'按钮可以刷新页面", "保存应用设置、清存会话数据能马上生效 (不用刷新页面)", "可以隐藏刷新按钮"] + "descs": [ + "双击底栏'应用'可以收缩面板并回到顶部", + "双击底栏'订阅'可以刷新订阅并回到顶部", + "双击'BoxJs'按钮可以刷新页面", + "保存应用设置、清存会话数据能马上生效 (不用刷新页面)", + "可以隐藏刷新按钮" + ] }, { "name": "主题", @@ -976,7 +1066,12 @@ }, { "name": "重写", - "descs": ["BoxJs 的重写已经去除代码级依赖", "意味着仅通过修改正则和主机名即可替换 BoxJs 的访问地址", "同时征集一个比较理想的国内域名作为 BoxJs 的免翻墙访问地址", "iOS14 Surge TF 下提示私密连接的问题, 可以找一个 http 的域名来试试"] + "descs": [ + "BoxJs 的重写已经去除代码级依赖", + "意味着仅通过修改正则和主机名即可替换 BoxJs 的访问地址", + "同时征集一个比较理想的国内域名作为 BoxJs 的免翻墙访问地址", + "iOS14 Surge TF 下提示私密连接的问题, 可以找一个 http 的域名来试试" + ] } ] }, @@ -1044,7 +1139,11 @@ }, { "name": "新增", - "descs": ["可以显示当前切换至哪个会话", "应用可以设定多个运行脚本 scripts: {name: '', script: ''}", "示例: https://gist.githubusercontent.com/chavyleung/9d53fc4809eb41dca5f5923790ec5554/raw/4d8b140ba149c33aa1fc622e93c4035ae74a73bb/chavy.app.sub.simple.json"] + "descs": [ + "可以显示当前切换至哪个会话", + "应用可以设定多个运行脚本 scripts: {name: '', script: ''}", + "示例: https://gist.githubusercontent.com/chavyleung/9d53fc4809eb41dca5f5923790ec5554/raw/4d8b140ba149c33aa1fc622e93c4035ae74a73bb/chavy.app.sub.simple.json" + ] } ] }, @@ -1061,7 +1160,10 @@ }, { "name": "调整", - "descs": ["迁移 吾爱破解、爱奇艺 至原作者订阅: @NobyDa (野比)", "https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json"] + "descs": [ + "迁移 吾爱破解、爱奇艺 至原作者订阅: @NobyDa (野比)", + "https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json" + ] } ] }, @@ -1091,7 +1193,11 @@ }, { "name": "说明", - "descs": ["手动运行脚本采用 eval() 方案", "Surge 在配置了 http-api 参数下会使用 http-api 方案运行脚本", "因为手法有点特殊, 不保证所有脚本都能良好"] + "descs": [ + "手动运行脚本采用 eval() 方案", + "Surge 在配置了 http-api 参数下会使用 http-api 方案运行脚本", + "因为手法有点特殊, 不保证所有脚本都能良好" + ] }, { "name": "感谢", @@ -1163,7 +1269,13 @@ }, { "name": "注意", - "descs": ["目前仅支持 Surge iOS TF & Surge mac 4.x", "需要在 Surge配置文件中指定 http-api", "然后在 BoxJs 侧栏中设置 http-api 路径", "目前内置应用和 chavy.boxjs.json 内的应用都可以手动运行, 其他订阅需订阅作者更新订阅", "资料: https://community.nssurge.com/d/327-http-api"] + "descs": [ + "目前仅支持 Surge iOS TF & Surge mac 4.x", + "需要在 Surge配置文件中指定 http-api", + "然后在 BoxJs 侧栏中设置 http-api 路径", + "目前内置应用和 chavy.boxjs.json 内的应用都可以手动运行, 其他订阅需订阅作者更新订阅", + "资料: https://community.nssurge.com/d/327-http-api" + ] } ] }, @@ -1262,7 +1374,9 @@ }, { "name": "调整", - "descs": ["迁移内置应用至订阅: https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.json (需要手动更新订阅)"] + "descs": [ + "迁移内置应用至订阅: https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.json (需要手动更新订阅)" + ] } ] }, @@ -1641,7 +1755,12 @@ "notes": [ { "name": "优化", - "descs": ["刷新窗口增加 3 秒倒数自动刷新", "添加订阅能马上刷新订阅", "刷新窗口弹出时会顺便发起更新应用订阅", "可以隐藏手动更新订阅的提示"] + "descs": [ + "刷新窗口增加 3 秒倒数自动刷新", + "添加订阅能马上刷新订阅", + "刷新窗口弹出时会顺便发起更新应用订阅", + "可以隐藏手动更新订阅的提示" + ] } ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index e7dd28ba3..abc4b26fc 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,31 @@ { "releases": [ + { + "version": "0.7.78", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 增加版本说明", + "notes": [ + { + "name": "新增", + "descs": [ + "偏好设置增加 HTTP Backend (Quantumult X)", + "说明: ", + "发现: Quantumult X 通过重写的方式访问 BoxJs 可能会导致无法删除备份的问题, 但通过 HTTP Backend 方式访问则正常。", + "建议: 改用 HTTP Backend 或 重写与 HTTP Backend 结合的方式访问 BoxJs", + "姿势: 见 使用文档 (悬浮按钮 > ?)" + ] + }, + { + "name": "优化", + "descs": ["增加底部空间避免悬浮按钮遮挡空间"] + }, + { + "name": "感谢", + "descs": ["@chouchoui PR"] + } + ] + }, { "version": "0.7.77", "tags": ["beta"], @@ -24,7 +50,25 @@ }, { "name": "说明", - "descs": ["抹掉:所有缓存", "抹掉订阅及页面缓存,会导致所有订阅显示格式错误,双击底栏'订阅'菜单或更新订阅即可恢复", "", "抹掉:收藏应用", "抹掉所有收藏的应用,排序出现问题时可尝试抹掉", "", "抹掉:用户偏好", "抹掉头像、设置、收藏等个人相关的数据, 注意:不含会话、备份、缓存", "", "抹掉:所有会话", "抹掉所有应用下的会话, 注意:不会抹掉当前会话", "", "抹掉:所有备份", "抹掉所有全局备份, 注意:抹掉前可先把备份复制到其他文本类应用内", "", "抹掉:BoxJs", "抹掉所有由 BoxJs 管理的数据, 如:备份、会话、偏好、缓存等 (不包含当前会话)"] + "descs": [ + "抹掉:所有缓存", + "抹掉订阅及页面缓存,会导致所有订阅显示格式错误,双击底栏'订阅'菜单或更新订阅即可恢复", + "", + "抹掉:收藏应用", + "抹掉所有收藏的应用,排序出现问题时可尝试抹掉", + "", + "抹掉:用户偏好", + "抹掉头像、设置、收藏等个人相关的数据, 注意:不含会话、备份、缓存", + "", + "抹掉:所有会话", + "抹掉所有应用下的会话, 注意:不会抹掉当前会话", + "", + "抹掉:所有备份", + "抹掉所有全局备份, 注意:抹掉前可先把备份复制到其他文本类应用内", + "", + "抹掉:BoxJs", + "抹掉所有由 BoxJs 管理的数据, 如:备份、会话、偏好、缓存等 (不包含当前会话)" + ] } ] }, @@ -104,7 +148,14 @@ "notes": [ { "name": "说明", - "descs": ["由于通过 gitee 访问部分仓库资源时出现 `根据相关法律政策,该内容无法显示`", "虽然我手动同步 github 代码后已经可以正常访问", "但为避免以后出现不可预知的情况:", "我们把全部 gitee 链接替换为 github raw 及 jsdelivr", "----", "大家只需正常更新订阅并重启代理即可"] + "descs": [ + "由于通过 gitee 访问部分仓库资源时出现 `根据相关法律政策,该内容无法显示`", + "虽然我手动同步 github 代码后已经可以正常访问", + "但为避免以后出现不可预知的情况:", + "我们把全部 gitee 链接替换为 github raw 及 jsdelivr", + "----", + "大家只需正常更新订阅并重启代理即可" + ] }, { "name": "感谢", @@ -344,7 +395,10 @@ }, { "name": "说明", - "descs": ["背景图片清单中设置:无{换行} 跟随系统,跟随系统{换行} light,图片地址{换行} dark,图片地址{换行}", "如果不设置`跟随系统,跟随系统`,则默认跟随系统为无背景"] + "descs": [ + "背景图片清单中设置:无{换行} 跟随系统,跟随系统{换行} light,图片地址{换行} dark,图片地址{换行}", + "如果不设置`跟随系统,跟随系统`,则默认跟随系统为无背景" + ] } ] }, @@ -540,7 +594,17 @@ }, { "name": "壁纸", - "descs": ["无背景,", "随机,https://uploadbeta.com/api/pictures/random", "推女郎,https://uploadbeta.com/api/pictures/random/?key=推女郎", "性感,https://uploadbeta.com/api/pictures/random/?key=性感", "车模,https://uploadbeta.com/api/pictures/random/?key=车模", "美腿,https://uploadbeta.com/api/pictures/random/?key=美腿", "美女,https://uploadbeta.com/api/pictures/random/?key=美女", "手机妹子,http://api.btstu.cn/sjbz/zsy.php", "手机美女,http://api.btstu.cn/sjbz/?m_lx=suiji"] + "descs": [ + "无背景,", + "随机,https://uploadbeta.com/api/pictures/random", + "推女郎,https://uploadbeta.com/api/pictures/random/?key=推女郎", + "性感,https://uploadbeta.com/api/pictures/random/?key=性感", + "车模,https://uploadbeta.com/api/pictures/random/?key=车模", + "美腿,https://uploadbeta.com/api/pictures/random/?key=美腿", + "美女,https://uploadbeta.com/api/pictures/random/?key=美女", + "手机妹子,http://api.btstu.cn/sjbz/zsy.php", + "手机美女,http://api.btstu.cn/sjbz/?m_lx=suiji" + ] } ] }, @@ -756,7 +820,12 @@ }, { "name": "说明", - "descs": ["除了本机运行外", "可以使用 PC 连上 QuanX 的 HTTP Backend", "实现在 PC 上写代码然后发送到 QuanX 执行", "Surge、Loon 同理"] + "descs": [ + "除了本机运行外", + "可以使用 PC 连上 QuanX 的 HTTP Backend", + "实现在 PC 上写代码然后发送到 QuanX 执行", + "Surge、Loon 同理" + ] } ] }, @@ -837,7 +906,12 @@ }, { "name": "操作", - "descs": ["可以修复全局备份的名字", "点击'应用'回到顶部,再次单击折叠面板", "点击'订阅'回到顶部,再次单击刷新订阅", "点击具体订阅可刷新"] + "descs": [ + "可以修复全局备份的名字", + "点击'应用'回到顶部,再次单击折叠面板", + "点击'订阅'回到顶部,再次单击刷新订阅", + "点击具体订阅可刷新" + ] } ] } diff --git a/chavy.box.js b/chavy.box.js index 8e74dfec9..b672606c3 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.77' +$.version = '0.7.78' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -309,13 +309,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.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 开头的完整路径, 不能是 / 结尾' }, ], scripts: [ { From 14917413ebce61cd52814458dc671b14d8eb2719 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Sat, 27 Mar 2021 11:20:12 +0800 Subject: [PATCH 049/311] =?UTF-8?q?feat:=20BoxJS=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 18 +++++++++++++++--- box/release/box.release.json | 12 ++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 901218549..833794184 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -12,6 +12,7 @@ + @@ -521,7 +525,7 @@ > -
+
@@ -1609,7 +1613,7 @@

v{{ver.versio return this.box.sessions }, // 获取`收藏`应用 - favApps(){ + favApps() { const favapps = [] const favAppIds = this.box.usercfgs.favapps || [] if (favAppIds) { diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 1e5469e26..45a397176 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.80' +$.version = '0.7.81' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 54aff3270..3e03ed983 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.81", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "更新[BoxJs]: 修复拖拽图标的时候出现文本选择光标问题", + "notes": [ + { + "name": "修复", + "descs": ["拖拽图标的时候出现文本选择光标问题"] + } + ] + }, { "version": "0.7.80", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 8384287af..06b57db31 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.81", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "更新[BoxJs]: 修复拖拽图标的时候出现文本选择光标问题", + "notes": [ + { + "name": "修复", + "descs": ["拖拽图标的时候出现文本选择光标问题"] + } + ] + }, { "version": "0.7.80", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 1e5469e26..45a397176 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.80' +$.version = '0.7.81' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 4b0b07a8fbc5815ecf02d8885d378354961909e6 Mon Sep 17 00:00:00 2001 From: chouchoui Date: Sun, 28 Mar 2021 00:36:37 +0800 Subject: [PATCH 056/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20HTTP=20Bac?= =?UTF-8?q?kend=E7=8E=AF=E5=A2=83=E4=B8=8B=E4=BD=BF=E7=94=A8=E9=BB=98?= =?UTF-8?q?=E8=AE=A4API=E8=AF=B7=E6=B1=82=E8=B7=AF=E5=BE=84=EF=BC=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BA=86HTTP=20Backend=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E4=BF=AE=E5=A4=8DPC=E8=BF=9C=E7=A8=8B=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=EF=BC=89=EF=BC=9B=E6=A0=BC=E5=BC=8F=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84HTTP=20Backend=E4=B8=8D=E4=BC=9A=E7=94=9F?= =?UTF-8?q?=E6=95=88=EF=BC=88=E5=BD=93=E5=89=8D=E5=88=A4=E5=AE=9A=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=98=AFhttp:=E5=BC=80=E5=A4=B4=EF=BC=8C9999=E7=BB=93?= =?UTF-8?q?=E5=B0=BE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index a125876ba..4a3bb6a82 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1847,6 +1847,12 @@

v{{ver.versio ) }, created() { + // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 + if (window.location.search) { + const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) + axios.defaults.baseURL = baseURL || '' + this.ui.isCors = true + } // 根据路径跳转视图 const defview = '/' if (!this.isCors) { @@ -1860,21 +1866,11 @@

v{{ver.versio // 如果后端没有渲染数据, 则发出请求获取数据 if (this.boxServerData) { this.box = this.boxServerData + this.setHttpBackend() } else { axios.get('/query/boxdata').then((resp) => (this.box = resp.data)) + this.setHttpBackend() } - // 如果是Quantumult X环境并且配置了HTTP Backend,将axios请求指向到HTTP Backend - if (this.box.syscfgs.env === 'QuanX' && this.box.usercfgs.http_backend) { - axios.defaults.baseURL = this.box.usercfgs.http_backend - this.ui.isCors = true - } - // 如果 url 参数中指定的 baseURL, 则后续的请求都请求到指定的域 - if (window.location.search) { - const [, baseURL] = /baseURL=(.*?)(&|$)/.exec(window.location.search) - axios.defaults.baseURL = baseURL || '' - this.ui.isCors = true - } - // 获取全局备份 if (this.view === 'bak') { this.loadGlobalBak() @@ -2151,10 +2147,7 @@

v{{ver.versio Object.assign(this.box, resp.data) if (this.curapp.id === 'BoxSetting') { - if (this.box.syscfgs.env === 'QuanX') { - axios.defaults.baseURL = this.box.usercfgs.http_backend || '' - this.ui.isCors = true - } + this.setHttpBackend() } }) }, @@ -2395,6 +2388,24 @@

v{{ver.versio _v2 = v2.split('.'), _r = _v1[0] - _v2[0] return _r == 0 && v1 != v2 ? this.compareVersion(_v1.splice(1).join('.'), _v2.splice(1).join('.')) : _r + }, + // 设置HTTP Backend + setHttpBackend() { + // 目前HTTP Backend不能修改端口号 + var regex = /^http:\/\/(.*):9999$/ + if (this.box.syscfgs.env === 'QuanX') { + if (regex.test(window.location.origin)) { + axios.defaults.baseURL = '' + return + } + // 如果是Quantumult X环境并且配置了正确格式的HTTP Backend,将axios请求指向到HTTP Backend + if (this.box.usercfgs.http_backend && regex.test(this.box.usercfgs.http_backend)) { + axios.defaults.baseURL = this.box.usercfgs.http_backend + this.ui.isCors = true + } else { + axios.defaults.baseURL = '' + } + } } } }) From ced95c8a87c3c0fdfad105bfabf9e5da4853fffb Mon Sep 17 00:00:00 2001 From: chouchoui Date: Sun, 28 Mar 2021 00:48:00 +0800 Subject: [PATCH 057/311] fix promise --- box/chavy.boxjs.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 4a3bb6a82..6addb3e41 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1868,8 +1868,10 @@

v{{ver.versio this.box = this.boxServerData this.setHttpBackend() } else { - axios.get('/query/boxdata').then((resp) => (this.box = resp.data)) - this.setHttpBackend() + axios.get('/query/boxdata').then((resp) => { + this.box = resp.data + this.setHttpBackend() + }) } // 获取全局备份 if (this.view === 'bak') { From f7510e3144c7b9d80f7a7911587f13db817c26b4 Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 28 Mar 2021 03:02:41 +0800 Subject: [PATCH 058/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=89=88=E6=9C=AC=200.7.82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ chavy.box.js | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 45a397176..7aed06ef8 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.81' +$.version = '0.7.82' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 3e03ed983..cbe0a5563 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.82", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效", + "notes": [ + { + "name": "优化", + "descs": ["格式不正确的HTTP Backend不会生效"] + } + ] + }, { "version": "0.7.81", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 06b57db31..84d4629f1 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.82", + "tags": ["beta"], + "author": "@chouchoui", + "msg": "更新[BoxJs]: 格式不正确的HTTP Backend不会生效", + "notes": [ + { + "name": "优化", + "descs": ["格式不正确的HTTP Backend不会生效"] + } + ] + }, { "version": "0.7.81", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 45a397176..7aed06ef8 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.81' +$.version = '0.7.82' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 04fd15b7207c590a440885a06a3f9f26c5e1b64d Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 28 Mar 2021 12:27:38 +0800 Subject: [PATCH 059/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=9B=BE=E6=A0=87=E6=8B=96=E6=8B=BD=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 1 + box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ chavy.box.js | 2 +- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 6addb3e41..4e58980d2 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1884,6 +1884,7 @@

v{{ver.versio const el = document.getElementById('appList') const _this = this const sortable = Sortable.create(el, { + animation: 600, delay: 200, onEnd(evt) { const favApps = _this.box.usercfgs.favapps diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 7aed06ef8..a0ead3546 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.82' +$.version = '0.7.83' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index cbe0a5563..212dd5367 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.83", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "更新[BoxJs]: 增加图标拖拽动画", + "notes": [ + { + "name": "优化", + "descs": ["增加图标拖拽动画"] + } + ] + }, { "version": "0.7.82", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 84d4629f1..aa09fa794 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.7.83", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "更新[BoxJs]: 增加图标拖拽动画", + "notes": [ + { + "name": "优化", + "descs": ["增加图标拖拽动画"] + } + ] + }, { "version": "0.7.82", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 7aed06ef8..a0ead3546 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.82' +$.version = '0.7.83' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From a04e1569766968f88283d40065f0bf6c99e871eb Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 29 Mar 2021 23:00:21 +0800 Subject: [PATCH 060/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E5=80=BC=E5=BE=97=E4=B9=B0]:=20=E6=81=A2=E5=A4=8D=20APP=20?= =?UTF-8?q?=E7=AB=AF=E7=AD=BE=E5=88=B0=EF=BC=8C=E6=84=9F=E8=B0=A2=20@wangf?= =?UTF-8?q?ei021325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smzdm/smzdm.js | 116 ++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 74 deletions(-) diff --git a/smzdm/smzdm.js b/smzdm/smzdm.js index 4701c22bf..b6012380a 100644 --- a/smzdm/smzdm.js +++ b/smzdm/smzdm.js @@ -1,11 +1,21 @@ +// prettier-ignore +!function (t, r) { "object" == typeof exports ? module.exports = exports = r() : "function" == typeof define && define.amd ? define([], r) : t.CryptoJS = r() }(this, function () { + var t = t || function (t, r) { var e = Object.create || function () { function t() { } return function (r) { var e; return t.prototype = r, e = new t, t.prototype = null, e } }(), i = {}, n = i.lib = {}, o = n.Base = function () { return { extend: function (t) { var r = e(this); return t && r.mixIn(t), r.hasOwnProperty("init") && this.init !== r.init || (r.init = function () { r.$super.init.apply(this, arguments) }), r.init.prototype = r, r.$super = this, r }, create: function () { var t = this.extend(); return t.init.apply(t, arguments), t }, init: function () { }, mixIn: function (t) { for (var r in t) t.hasOwnProperty(r) && (this[r] = t[r]); t.hasOwnProperty("toString") && (this.toString = t.toString) }, clone: function () { return this.init.prototype.extend(this) } } }(), s = n.WordArray = o.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 4 * t.length }, toString: function (t) { return (t || c).stringify(this) }, concat: function (t) { var r = this.words, e = t.words, i = this.sigBytes, n = t.sigBytes; if (this.clamp(), i % 4) for (var o = 0; o < n; o++) { var s = e[o >>> 2] >>> 24 - o % 4 * 8 & 255; r[i + o >>> 2] |= s << 24 - (i + o) % 4 * 8 } else for (var o = 0; o < n; o += 4)r[i + o >>> 2] = e[o >>> 2]; return this.sigBytes += n, this }, clamp: function () { var r = this.words, e = this.sigBytes; r[e >>> 2] &= 4294967295 << 32 - e % 4 * 8, r.length = t.ceil(e / 4) }, clone: function () { var t = o.clone.call(this); return t.words = this.words.slice(0), t }, random: function (r) { for (var e, i = [], n = function (r) { var r = r, e = 987654321, i = 4294967295; return function () { e = 36969 * (65535 & e) + (e >> 16) & i, r = 18e3 * (65535 & r) + (r >> 16) & i; var n = (e << 16) + r & i; return n /= 4294967296, n += .5, n * (t.random() > .5 ? 1 : -1) } }, o = 0; o < r; o += 4) { var a = n(4294967296 * (e || t.random())); e = 987654071 * a(), i.push(4294967296 * a() | 0) } return new s.init(i, r) } }), a = i.enc = {}, c = a.Hex = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push((o >>> 4).toString(16)), i.push((15 & o).toString(16)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i += 2)e[i >>> 3] |= parseInt(t.substr(i, 2), 16) << 24 - i % 8 * 4; return new s.init(e, r / 2) } }, h = a.Latin1 = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 2] |= (255 & t.charCodeAt(i)) << 24 - i % 4 * 8; return new s.init(e, r) } }, l = a.Utf8 = { stringify: function (t) { try { return decodeURIComponent(escape(h.stringify(t))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, parse: function (t) { return h.parse(unescape(encodeURIComponent(t))) } }, f = n.BufferedBlockAlgorithm = o.extend({ reset: function () { this._data = new s.init, this._nDataBytes = 0 }, _append: function (t) { "string" == typeof t && (t = l.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes }, _process: function (r) { var e = this._data, i = e.words, n = e.sigBytes, o = this.blockSize, a = 4 * o, c = n / a; c = r ? t.ceil(c) : t.max((0 | c) - this._minBufferSize, 0); var h = c * o, l = t.min(4 * h, n); if (h) { for (var f = 0; f < h; f += o)this._doProcessBlock(i, f); var u = i.splice(0, h); e.sigBytes -= l } return new s.init(u, l) }, clone: function () { var t = o.clone.call(this); return t._data = this._data.clone(), t }, _minBufferSize: 0 }), u = (n.Hasher = f.extend({ cfg: o.extend(), init: function (t) { this.cfg = this.cfg.extend(t), this.reset() }, reset: function () { f.reset.call(this), this._doReset() }, update: function (t) { return this._append(t), this._process(), this }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, blockSize: 16, _createHelper: function (t) { return function (r, e) { return new t.init(e).finalize(r) } }, _createHmacHelper: function (t) { return function (r, e) { return new u.HMAC.init(t, e).finalize(r) } } }), i.algo = {}); return i }(Math); return function () { function r(t, r, e) { for (var i = [], o = 0, s = 0; s < r; s++)if (s % 4) { var a = e[t.charCodeAt(s - 1)] << s % 4 * 2, c = e[t.charCodeAt(s)] >>> 6 - s % 4 * 2; i[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ } return n.create(i, o) } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Base64 = { stringify: function (t) { var r = t.words, e = t.sigBytes, i = this._map; t.clamp(); for (var n = [], o = 0; o < e; o += 3)for (var s = r[o >>> 2] >>> 24 - o % 4 * 8 & 255, a = r[o + 1 >>> 2] >>> 24 - (o + 1) % 4 * 8 & 255, c = r[o + 2 >>> 2] >>> 24 - (o + 2) % 4 * 8 & 255, h = s << 16 | a << 8 | c, l = 0; l < 4 && o + .75 * l < e; l++)n.push(i.charAt(h >>> 6 * (3 - l) & 63)); var f = i.charAt(64); if (f) for (; n.length % 4;)n.push(f); return n.join("") }, parse: function (t) { var e = t.length, i = this._map, n = this._reverseMap; if (!n) { n = this._reverseMap = []; for (var o = 0; o < i.length; o++)n[i.charCodeAt(o)] = o } var s = i.charAt(64); if (s) { var a = t.indexOf(s); a !== -1 && (e = a) } return r(t, e, n) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } }(), function (r) { function e(t, r, e, i, n, o, s) { var a = t + (r & e | ~r & i) + n + s; return (a << o | a >>> 32 - o) + r } function i(t, r, e, i, n, o, s) { var a = t + (r & i | e & ~i) + n + s; return (a << o | a >>> 32 - o) + r } function n(t, r, e, i, n, o, s) { var a = t + (r ^ e ^ i) + n + s; return (a << o | a >>> 32 - o) + r } function o(t, r, e, i, n, o, s) { var a = t + (e ^ (r | ~i)) + n + s; return (a << o | a >>> 32 - o) + r } var s = t, a = s.lib, c = a.WordArray, h = a.Hasher, l = s.algo, f = []; !function () { for (var t = 0; t < 64; t++)f[t] = 4294967296 * r.abs(r.sin(t + 1)) | 0 }(); var u = l.MD5 = h.extend({ _doReset: function () { this._hash = new c.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (t, r) { for (var s = 0; s < 16; s++) { var a = r + s, c = t[a]; t[a] = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8) } var h = this._hash.words, l = t[r + 0], u = t[r + 1], d = t[r + 2], v = t[r + 3], p = t[r + 4], _ = t[r + 5], y = t[r + 6], g = t[r + 7], B = t[r + 8], w = t[r + 9], k = t[r + 10], S = t[r + 11], m = t[r + 12], x = t[r + 13], b = t[r + 14], H = t[r + 15], z = h[0], A = h[1], C = h[2], D = h[3]; z = e(z, A, C, D, l, 7, f[0]), D = e(D, z, A, C, u, 12, f[1]), C = e(C, D, z, A, d, 17, f[2]), A = e(A, C, D, z, v, 22, f[3]), z = e(z, A, C, D, p, 7, f[4]), D = e(D, z, A, C, _, 12, f[5]), C = e(C, D, z, A, y, 17, f[6]), A = e(A, C, D, z, g, 22, f[7]), z = e(z, A, C, D, B, 7, f[8]), D = e(D, z, A, C, w, 12, f[9]), C = e(C, D, z, A, k, 17, f[10]), A = e(A, C, D, z, S, 22, f[11]), z = e(z, A, C, D, m, 7, f[12]), D = e(D, z, A, C, x, 12, f[13]), C = e(C, D, z, A, b, 17, f[14]), A = e(A, C, D, z, H, 22, f[15]), z = i(z, A, C, D, u, 5, f[16]), D = i(D, z, A, C, y, 9, f[17]), C = i(C, D, z, A, S, 14, f[18]), A = i(A, C, D, z, l, 20, f[19]), z = i(z, A, C, D, _, 5, f[20]), D = i(D, z, A, C, k, 9, f[21]), C = i(C, D, z, A, H, 14, f[22]), A = i(A, C, D, z, p, 20, f[23]), z = i(z, A, C, D, w, 5, f[24]), D = i(D, z, A, C, b, 9, f[25]), C = i(C, D, z, A, v, 14, f[26]), A = i(A, C, D, z, B, 20, f[27]), z = i(z, A, C, D, x, 5, f[28]), D = i(D, z, A, C, d, 9, f[29]), C = i(C, D, z, A, g, 14, f[30]), A = i(A, C, D, z, m, 20, f[31]), z = n(z, A, C, D, _, 4, f[32]), D = n(D, z, A, C, B, 11, f[33]), C = n(C, D, z, A, S, 16, f[34]), A = n(A, C, D, z, b, 23, f[35]), z = n(z, A, C, D, u, 4, f[36]), D = n(D, z, A, C, p, 11, f[37]), C = n(C, D, z, A, g, 16, f[38]), A = n(A, C, D, z, k, 23, f[39]), z = n(z, A, C, D, x, 4, f[40]), D = n(D, z, A, C, l, 11, f[41]), C = n(C, D, z, A, v, 16, f[42]), A = n(A, C, D, z, y, 23, f[43]), z = n(z, A, C, D, w, 4, f[44]), D = n(D, z, A, C, m, 11, f[45]), C = n(C, D, z, A, H, 16, f[46]), A = n(A, C, D, z, d, 23, f[47]), z = o(z, A, C, D, l, 6, f[48]), D = o(D, z, A, C, g, 10, f[49]), C = o(C, D, z, A, b, 15, f[50]), A = o(A, C, D, z, _, 21, f[51]), z = o(z, A, C, D, m, 6, f[52]), D = o(D, z, A, C, v, 10, f[53]), C = o(C, D, z, A, k, 15, f[54]), A = o(A, C, D, z, u, 21, f[55]), z = o(z, A, C, D, B, 6, f[56]), D = o(D, z, A, C, H, 10, f[57]), C = o(C, D, z, A, y, 15, f[58]), A = o(A, C, D, z, x, 21, f[59]), z = o(z, A, C, D, p, 6, f[60]), D = o(D, z, A, C, S, 10, f[61]), C = o(C, D, z, A, d, 15, f[62]), A = o(A, C, D, z, w, 21, f[63]), h[0] = h[0] + z | 0, h[1] = h[1] + A | 0, h[2] = h[2] + C | 0, h[3] = h[3] + D | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; e[n >>> 5] |= 128 << 24 - n % 32; var o = r.floor(i / 4294967296), s = i; e[(n + 64 >>> 9 << 4) + 15] = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), e[(n + 64 >>> 9 << 4) + 14] = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8), t.sigBytes = 4 * (e.length + 1), this._process(); for (var a = this._hash, c = a.words, h = 0; h < 4; h++) { var l = c[h]; c[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } return a }, clone: function () { var t = h.clone.call(this); return t._hash = this._hash.clone(), t } }); s.MD5 = h._createHelper(u), s.HmacMD5 = h._createHmacHelper(u) }(Math), function () { var r = t, e = r.lib, i = e.WordArray, n = e.Hasher, o = r.algo, s = [], a = o.SHA1 = n.extend({ _doReset: function () { this._hash = new i.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], a = e[3], c = e[4], h = 0; h < 80; h++) { if (h < 16) s[h] = 0 | t[r + h]; else { var l = s[h - 3] ^ s[h - 8] ^ s[h - 14] ^ s[h - 16]; s[h] = l << 1 | l >>> 31 } var f = (i << 5 | i >>> 27) + c + s[h]; f += h < 20 ? (n & o | ~n & a) + 1518500249 : h < 40 ? (n ^ o ^ a) + 1859775393 : h < 60 ? (n & o | n & a | o & a) - 1894007588 : (n ^ o ^ a) - 899497514, c = a, a = o, o = n << 30 | n >>> 2, n = i, i = f } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + a | 0, e[4] = e[4] + c | 0 }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; return r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = Math.floor(e / 4294967296), r[(i + 64 >>> 9 << 4) + 15] = e, t.sigBytes = 4 * r.length, this._process(), this._hash }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t } }); r.SHA1 = n._createHelper(a), r.HmacSHA1 = n._createHmacHelper(a) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.algo, a = [], c = []; !function () { function t(t) { for (var e = r.sqrt(t), i = 2; i <= e; i++)if (!(t % i)) return !1; return !0 } function e(t) { return 4294967296 * (t - (0 | t)) | 0 } for (var i = 2, n = 0; n < 64;)t(i) && (n < 8 && (a[n] = e(r.pow(i, .5))), c[n] = e(r.pow(i, 1 / 3)), n++), i++ }(); var h = [], l = s.SHA256 = o.extend({ _doReset: function () { this._hash = new n.init(a.slice(0)) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], l = e[5], f = e[6], u = e[7], d = 0; d < 64; d++) { if (d < 16) h[d] = 0 | t[r + d]; else { var v = h[d - 15], p = (v << 25 | v >>> 7) ^ (v << 14 | v >>> 18) ^ v >>> 3, _ = h[d - 2], y = (_ << 15 | _ >>> 17) ^ (_ << 13 | _ >>> 19) ^ _ >>> 10; h[d] = p + h[d - 7] + y + h[d - 16] } var g = a & l ^ ~a & f, B = i & n ^ i & o ^ n & o, w = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), k = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), S = u + k + g + c[d] + h[d], m = w + B; u = f, f = l, l = a, a = s + S | 0, s = o, o = n, n = i, i = S + m | 0 } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + s | 0, e[4] = e[4] + a | 0, e[5] = e[5] + l | 0, e[6] = e[6] + f | 0, e[7] = e[7] + u | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; return e[n >>> 5] |= 128 << 24 - n % 32, e[(n + 64 >>> 9 << 4) + 14] = r.floor(i / 4294967296), e[(n + 64 >>> 9 << 4) + 15] = i, t.sigBytes = 4 * e.length, this._process(), this._hash }, clone: function () { var t = o.clone.call(this); return t._hash = this._hash.clone(), t } }); e.SHA256 = o._createHelper(l), e.HmacSHA256 = o._createHmacHelper(l) }(Math), function () { function r(t) { return t << 8 & 4278255360 | t >>> 8 & 16711935 } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Utf16 = o.Utf16BE = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n += 2) { var o = r[n >>> 2] >>> 16 - n % 4 * 8 & 65535; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 1] |= t.charCodeAt(i) << 16 - i % 2 * 16; return n.create(e, 2 * r) } }; o.Utf16LE = { stringify: function (t) { for (var e = t.words, i = t.sigBytes, n = [], o = 0; o < i; o += 2) { var s = r(e[o >>> 2] >>> 16 - o % 4 * 8 & 65535); n.push(String.fromCharCode(s)) } return n.join("") }, parse: function (t) { for (var e = t.length, i = [], o = 0; o < e; o++)i[o >>> 1] |= r(t.charCodeAt(o) << 16 - o % 2 * 16); return n.create(i, 2 * e) } } }(), function () { if ("function" == typeof ArrayBuffer) { var r = t, e = r.lib, i = e.WordArray, n = i.init, o = i.init = function (t) { if (t instanceof ArrayBuffer && (t = new Uint8Array(t)), (t instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array) && (t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength)), t instanceof Uint8Array) { for (var r = t.byteLength, e = [], i = 0; i < r; i++)e[i >>> 2] |= t[i] << 24 - i % 4 * 8; n.call(this, e, r) } else n.apply(this, arguments) }; o.prototype = i } }(), function (r) { function e(t, r, e) { return t ^ r ^ e } function i(t, r, e) { return t & r | ~t & e } function n(t, r, e) { return (t | ~r) ^ e } function o(t, r, e) { return t & e | r & ~e } function s(t, r, e) { return t ^ (r | ~e) } function a(t, r) { return t << r | t >>> 32 - r } var c = t, h = c.lib, l = h.WordArray, f = h.Hasher, u = c.algo, d = l.create([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]), v = l.create([5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]), p = l.create([11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]), _ = l.create([8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]), y = l.create([0, 1518500249, 1859775393, 2400959708, 2840853838]), g = l.create([1352829926, 1548603684, 1836072691, 2053994217, 0]), B = u.RIPEMD160 = f.extend({ _doReset: function () { this._hash = l.create([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var c = 0; c < 16; c++) { var h = r + c, l = t[h]; t[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } var f, u, B, w, k, S, m, x, b, H, z = this._hash.words, A = y.words, C = g.words, D = d.words, R = v.words, E = p.words, M = _.words; S = f = z[0], m = u = z[1], x = B = z[2], b = w = z[3], H = k = z[4]; for (var F, c = 0; c < 80; c += 1)F = f + t[r + D[c]] | 0, F += c < 16 ? e(u, B, w) + A[0] : c < 32 ? i(u, B, w) + A[1] : c < 48 ? n(u, B, w) + A[2] : c < 64 ? o(u, B, w) + A[3] : s(u, B, w) + A[4], F |= 0, F = a(F, E[c]), F = F + k | 0, f = k, k = w, w = a(B, 10), B = u, u = F, F = S + t[r + R[c]] | 0, F += c < 16 ? s(m, x, b) + C[0] : c < 32 ? o(m, x, b) + C[1] : c < 48 ? n(m, x, b) + C[2] : c < 64 ? i(m, x, b) + C[3] : e(m, x, b) + C[4], F |= 0, F = a(F, M[c]), F = F + H | 0, S = H, H = b, b = a(x, 10), x = m, m = F; F = z[1] + B + b | 0, z[1] = z[2] + w + H | 0, z[2] = z[3] + k + S | 0, z[3] = z[4] + f + m | 0, z[4] = z[0] + u + x | 0, z[0] = F }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = 16711935 & (e << 8 | e >>> 24) | 4278255360 & (e << 24 | e >>> 8), t.sigBytes = 4 * (r.length + 1), this._process(); for (var n = this._hash, o = n.words, s = 0; s < 5; s++) { var a = o[s]; o[s] = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8) } return n }, clone: function () { var t = f.clone.call(this); return t._hash = this._hash.clone(), t } }); c.RIPEMD160 = f._createHelper(B), c.HmacRIPEMD160 = f._createHmacHelper(B) }(Math), function () { var r = t, e = r.lib, i = e.Base, n = r.enc, o = n.Utf8, s = r.algo; s.HMAC = i.extend({ init: function (t, r) { t = this._hasher = new t.init, "string" == typeof r && (r = o.parse(r)); var e = t.blockSize, i = 4 * e; r.sigBytes > i && (r = t.finalize(r)), r.clamp(); for (var n = this._oKey = r.clone(), s = this._iKey = r.clone(), a = n.words, c = s.words, h = 0; h < e; h++)a[h] ^= 1549556828, c[h] ^= 909522486; n.sigBytes = s.sigBytes = i, this.reset() }, reset: function () { var t = this._hasher; t.reset(), t.update(this._iKey) }, update: function (t) { return this._hasher.update(t), this }, finalize: function (t) { var r = this._hasher, e = r.finalize(t); r.reset(); var i = r.finalize(this._oKey.clone().concat(e)); return i } }) }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.SHA1, a = o.HMAC, c = o.PBKDF2 = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = a.create(e.hasher, t), o = n.create(), s = n.create([1]), c = o.words, h = s.words, l = e.keySize, f = e.iterations; c.length < l;) { var u = i.update(r).finalize(s); i.reset(); for (var d = u.words, v = d.length, p = u, _ = 1; _ < f; _++) { p = i.finalize(p), i.reset(); for (var y = p.words, g = 0; g < v; g++)d[g] ^= y[g] } o.concat(u), h[0]++ } return o.sigBytes = 4 * l, o } }); r.PBKDF2 = function (t, r, e) { return c.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.MD5, a = o.EvpKDF = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = e.hasher.create(), o = n.create(), s = o.words, a = e.keySize, c = e.iterations; s.length < a;) { h && i.update(h); var h = i.update(t).finalize(r); i.reset(); for (var l = 1; l < c; l++)h = i.finalize(h), i.reset(); o.concat(h) } return o.sigBytes = 4 * a, o } }); r.EvpKDF = function (t, r, e) { return a.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.WordArray, n = r.algo, o = n.SHA256, s = n.SHA224 = o.extend({ _doReset: function () { this._hash = new i.init([3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]) }, _doFinalize: function () { var t = o._doFinalize.call(this); return t.sigBytes -= 4, t } }); r.SHA224 = o._createHelper(s), r.HmacSHA224 = o._createHmacHelper(s) }(), function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = e.x64 = {}; s.Word = n.extend({ init: function (t, r) { this.high = t, this.low = r } }), s.WordArray = n.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 8 * t.length }, toX32: function () { for (var t = this.words, r = t.length, e = [], i = 0; i < r; i++) { var n = t[i]; e.push(n.high), e.push(n.low) } return o.create(e, this.sigBytes) }, clone: function () { for (var t = n.clone.call(this), r = t.words = this.words.slice(0), e = r.length, i = 0; i < e; i++)r[i] = r[i].clone(); return t } }) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.x64, a = s.Word, c = e.algo, h = [], l = [], f = []; !function () { for (var t = 1, r = 0, e = 0; e < 24; e++) { h[t + 5 * r] = (e + 1) * (e + 2) / 2 % 64; var i = r % 5, n = (2 * t + 3 * r) % 5; t = i, r = n } for (var t = 0; t < 5; t++)for (var r = 0; r < 5; r++)l[t + 5 * r] = r + (2 * t + 3 * r) % 5 * 5; for (var o = 1, s = 0; s < 24; s++) { for (var c = 0, u = 0, d = 0; d < 7; d++) { if (1 & o) { var v = (1 << d) - 1; v < 32 ? u ^= 1 << v : c ^= 1 << v - 32 } 128 & o ? o = o << 1 ^ 113 : o <<= 1 } f[s] = a.create(c, u) } }(); var u = []; !function () { for (var t = 0; t < 25; t++)u[t] = a.create() }(); var d = c.SHA3 = o.extend({ cfg: o.cfg.extend({ outputLength: 512 }), _doReset: function () { for (var t = this._state = [], r = 0; r < 25; r++)t[r] = new a.init; this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32 }, _doProcessBlock: function (t, r) { for (var e = this._state, i = this.blockSize / 2, n = 0; n < i; n++) { var o = t[r + 2 * n], s = t[r + 2 * n + 1]; o = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), s = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8); var a = e[n]; a.high ^= s, a.low ^= o } for (var c = 0; c < 24; c++) { for (var d = 0; d < 5; d++) { for (var v = 0, p = 0, _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; v ^= a.high, p ^= a.low } var y = u[d]; y.high = v, y.low = p } for (var d = 0; d < 5; d++)for (var g = u[(d + 4) % 5], B = u[(d + 1) % 5], w = B.high, k = B.low, v = g.high ^ (w << 1 | k >>> 31), p = g.low ^ (k << 1 | w >>> 31), _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; a.high ^= v, a.low ^= p } for (var S = 1; S < 25; S++) { var a = e[S], m = a.high, x = a.low, b = h[S]; if (b < 32) var v = m << b | x >>> 32 - b, p = x << b | m >>> 32 - b; else var v = x << b - 32 | m >>> 64 - b, p = m << b - 32 | x >>> 64 - b; var H = u[l[S]]; H.high = v, H.low = p } var z = u[0], A = e[0]; z.high = A.high, z.low = A.low; for (var d = 0; d < 5; d++)for (var _ = 0; _ < 5; _++) { var S = d + 5 * _, a = e[S], C = u[S], D = u[(d + 1) % 5 + 5 * _], R = u[(d + 2) % 5 + 5 * _]; a.high = C.high ^ ~D.high & R.high, a.low = C.low ^ ~D.low & R.low } var a = e[0], E = f[c]; a.high ^= E.high, a.low ^= E.low } }, _doFinalize: function () { var t = this._data, e = t.words, i = (8 * this._nDataBytes, 8 * t.sigBytes), o = 32 * this.blockSize; e[i >>> 5] |= 1 << 24 - i % 32, e[(r.ceil((i + 1) / o) * o >>> 5) - 1] |= 128, t.sigBytes = 4 * e.length, this._process(); for (var s = this._state, a = this.cfg.outputLength / 8, c = a / 8, h = [], l = 0; l < c; l++) { var f = s[l], u = f.high, d = f.low; u = 16711935 & (u << 8 | u >>> 24) | 4278255360 & (u << 24 | u >>> 8), d = 16711935 & (d << 8 | d >>> 24) | 4278255360 & (d << 24 | d >>> 8), h.push(d), h.push(u) } return new n.init(h, a) }, clone: function () { for (var t = o.clone.call(this), r = t._state = this._state.slice(0), e = 0; e < 25; e++)r[e] = r[e].clone(); return t } }); e.SHA3 = o._createHelper(d), e.HmacSHA3 = o._createHmacHelper(d) }(Math), function () { function r() { return s.create.apply(s, arguments) } var e = t, i = e.lib, n = i.Hasher, o = e.x64, s = o.Word, a = o.WordArray, c = e.algo, h = [r(1116352408, 3609767458), r(1899447441, 602891725), r(3049323471, 3964484399), r(3921009573, 2173295548), r(961987163, 4081628472), r(1508970993, 3053834265), r(2453635748, 2937671579), r(2870763221, 3664609560), r(3624381080, 2734883394), r(310598401, 1164996542), r(607225278, 1323610764), r(1426881987, 3590304994), r(1925078388, 4068182383), r(2162078206, 991336113), r(2614888103, 633803317), r(3248222580, 3479774868), r(3835390401, 2666613458), r(4022224774, 944711139), r(264347078, 2341262773), r(604807628, 2007800933), r(770255983, 1495990901), r(1249150122, 1856431235), r(1555081692, 3175218132), r(1996064986, 2198950837), r(2554220882, 3999719339), r(2821834349, 766784016), r(2952996808, 2566594879), r(3210313671, 3203337956), r(3336571891, 1034457026), r(3584528711, 2466948901), r(113926993, 3758326383), r(338241895, 168717936), r(666307205, 1188179964), r(773529912, 1546045734), r(1294757372, 1522805485), r(1396182291, 2643833823), r(1695183700, 2343527390), r(1986661051, 1014477480), r(2177026350, 1206759142), r(2456956037, 344077627), r(2730485921, 1290863460), r(2820302411, 3158454273), r(3259730800, 3505952657), r(3345764771, 106217008), r(3516065817, 3606008344), r(3600352804, 1432725776), r(4094571909, 1467031594), r(275423344, 851169720), r(430227734, 3100823752), r(506948616, 1363258195), r(659060556, 3750685593), r(883997877, 3785050280), r(958139571, 3318307427), r(1322822218, 3812723403), r(1537002063, 2003034995), r(1747873779, 3602036899), r(1955562222, 1575990012), r(2024104815, 1125592928), r(2227730452, 2716904306), r(2361852424, 442776044), r(2428436474, 593698344), r(2756734187, 3733110249), r(3204031479, 2999351573), r(3329325298, 3815920427), r(3391569614, 3928383900), r(3515267271, 566280711), r(3940187606, 3454069534), r(4118630271, 4000239992), r(116418474, 1914138554), r(174292421, 2731055270), r(289380356, 3203993006), r(460393269, 320620315), r(685471733, 587496836), r(852142971, 1086792851), r(1017036298, 365543100), r(1126000580, 2618297676), r(1288033470, 3409855158), r(1501505948, 4234509866), r(1607167915, 987167468), r(1816402316, 1246189591)], l = []; !function () { for (var t = 0; t < 80; t++)l[t] = r() }(); var f = c.SHA512 = n.extend({ _doReset: function () { this._hash = new a.init([new s.init(1779033703, 4089235720), new s.init(3144134277, 2227873595), new s.init(1013904242, 4271175723), new s.init(2773480762, 1595750129), new s.init(1359893119, 2917565137), new s.init(2600822924, 725511199), new s.init(528734635, 4215389547), new s.init(1541459225, 327033209)]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], c = e[5], f = e[6], u = e[7], d = i.high, v = i.low, p = n.high, _ = n.low, y = o.high, g = o.low, B = s.high, w = s.low, k = a.high, S = a.low, m = c.high, x = c.low, b = f.high, H = f.low, z = u.high, A = u.low, C = d, D = v, R = p, E = _, M = y, F = g, P = B, W = w, O = k, U = S, I = m, K = x, X = b, L = H, j = z, N = A, T = 0; T < 80; T++) { var Z = l[T]; if (T < 16) var q = Z.high = 0 | t[r + 2 * T], G = Z.low = 0 | t[r + 2 * T + 1]; else { var J = l[T - 15], $ = J.high, Q = J.low, V = ($ >>> 1 | Q << 31) ^ ($ >>> 8 | Q << 24) ^ $ >>> 7, Y = (Q >>> 1 | $ << 31) ^ (Q >>> 8 | $ << 24) ^ (Q >>> 7 | $ << 25), tt = l[T - 2], rt = tt.high, et = tt.low, it = (rt >>> 19 | et << 13) ^ (rt << 3 | et >>> 29) ^ rt >>> 6, nt = (et >>> 19 | rt << 13) ^ (et << 3 | rt >>> 29) ^ (et >>> 6 | rt << 26), ot = l[T - 7], st = ot.high, at = ot.low, ct = l[T - 16], ht = ct.high, lt = ct.low, G = Y + at, q = V + st + (G >>> 0 < Y >>> 0 ? 1 : 0), G = G + nt, q = q + it + (G >>> 0 < nt >>> 0 ? 1 : 0), G = G + lt, q = q + ht + (G >>> 0 < lt >>> 0 ? 1 : 0); Z.high = q, Z.low = G } var ft = O & I ^ ~O & X, ut = U & K ^ ~U & L, dt = C & R ^ C & M ^ R & M, vt = D & E ^ D & F ^ E & F, pt = (C >>> 28 | D << 4) ^ (C << 30 | D >>> 2) ^ (C << 25 | D >>> 7), _t = (D >>> 28 | C << 4) ^ (D << 30 | C >>> 2) ^ (D << 25 | C >>> 7), yt = (O >>> 14 | U << 18) ^ (O >>> 18 | U << 14) ^ (O << 23 | U >>> 9), gt = (U >>> 14 | O << 18) ^ (U >>> 18 | O << 14) ^ (U << 23 | O >>> 9), Bt = h[T], wt = Bt.high, kt = Bt.low, St = N + gt, mt = j + yt + (St >>> 0 < N >>> 0 ? 1 : 0), St = St + ut, mt = mt + ft + (St >>> 0 < ut >>> 0 ? 1 : 0), St = St + kt, mt = mt + wt + (St >>> 0 < kt >>> 0 ? 1 : 0), St = St + G, mt = mt + q + (St >>> 0 < G >>> 0 ? 1 : 0), xt = _t + vt, bt = pt + dt + (xt >>> 0 < _t >>> 0 ? 1 : 0); j = X, N = L, X = I, L = K, I = O, K = U, U = W + St | 0, O = P + mt + (U >>> 0 < W >>> 0 ? 1 : 0) | 0, P = M, W = F, M = R, F = E, R = C, E = D, D = St + xt | 0, C = mt + bt + (D >>> 0 < St >>> 0 ? 1 : 0) | 0 } v = i.low = v + D, i.high = d + C + (v >>> 0 < D >>> 0 ? 1 : 0), _ = n.low = _ + E, n.high = p + R + (_ >>> 0 < E >>> 0 ? 1 : 0), g = o.low = g + F, o.high = y + M + (g >>> 0 < F >>> 0 ? 1 : 0), w = s.low = w + W, s.high = B + P + (w >>> 0 < W >>> 0 ? 1 : 0), S = a.low = S + U, a.high = k + O + (S >>> 0 < U >>> 0 ? 1 : 0), x = c.low = x + K, c.high = m + I + (x >>> 0 < K >>> 0 ? 1 : 0), H = f.low = H + L, f.high = b + X + (H >>> 0 < L >>> 0 ? 1 : 0), A = u.low = A + N, u.high = z + j + (A >>> 0 < N >>> 0 ? 1 : 0) }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 128 >>> 10 << 5) + 30] = Math.floor(e / 4294967296), r[(i + 128 >>> 10 << 5) + 31] = e, t.sigBytes = 4 * r.length, this._process(); var n = this._hash.toX32(); return n }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t }, blockSize: 32 }); e.SHA512 = n._createHelper(f), e.HmacSHA512 = n._createHmacHelper(f) }(), function () { var r = t, e = r.x64, i = e.Word, n = e.WordArray, o = r.algo, s = o.SHA512, a = o.SHA384 = s.extend({ _doReset: function () { this._hash = new n.init([new i.init(3418070365, 3238371032), new i.init(1654270250, 914150663), new i.init(2438529370, 812702999), new i.init(355462360, 4144912697), new i.init(1731405415, 4290775857), new i.init(2394180231, 1750603025), new i.init(3675008525, 1694076839), new i.init(1203062813, 3204075428)]) }, _doFinalize: function () { var t = s._doFinalize.call(this); return t.sigBytes -= 16, t } }); r.SHA384 = s._createHelper(a), r.HmacSHA384 = s._createHmacHelper(a) }(), t.lib.Cipher || function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = i.BufferedBlockAlgorithm, a = e.enc, c = (a.Utf8, a.Base64), h = e.algo, l = h.EvpKDF, f = i.Cipher = s.extend({ cfg: n.extend(), createEncryptor: function (t, r) { return this.create(this._ENC_XFORM_MODE, t, r) }, createDecryptor: function (t, r) { return this.create(this._DEC_XFORM_MODE, t, r) }, init: function (t, r, e) { this.cfg = this.cfg.extend(e), this._xformMode = t, this._key = r, this.reset() }, reset: function () { s.reset.call(this), this._doReset() }, process: function (t) { return this._append(t), this._process() }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, keySize: 4, ivSize: 4, _ENC_XFORM_MODE: 1, _DEC_XFORM_MODE: 2, _createHelper: function () { function t(t) { return "string" == typeof t ? m : w } return function (r) { return { encrypt: function (e, i, n) { return t(i).encrypt(r, e, i, n) }, decrypt: function (e, i, n) { return t(i).decrypt(r, e, i, n) } } } }() }), u = (i.StreamCipher = f.extend({ _doFinalize: function () { var t = this._process(!0); return t }, blockSize: 1 }), e.mode = {}), d = i.BlockCipherMode = n.extend({ createEncryptor: function (t, r) { return this.Encryptor.create(t, r) }, createDecryptor: function (t, r) { return this.Decryptor.create(t, r) }, init: function (t, r) { this._cipher = t, this._iv = r } }), v = u.CBC = function () { function t(t, e, i) { var n = this._iv; if (n) { var o = n; this._iv = r } else var o = this._prevBlock; for (var s = 0; s < i; s++)t[e + s] ^= o[s] } var e = d.extend(); return e.Encryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize; t.call(this, r, e, n), i.encryptBlock(r, e), this._prevBlock = r.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize, o = r.slice(e, e + n); i.decryptBlock(r, e), t.call(this, r, e, n), this._prevBlock = o } }), e }(), p = e.pad = {}, _ = p.Pkcs7 = { pad: function (t, r) { for (var e = 4 * r, i = e - t.sigBytes % e, n = i << 24 | i << 16 | i << 8 | i, s = [], a = 0; a < i; a += 4)s.push(n); var c = o.create(s, i); t.concat(c) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, y = (i.BlockCipher = f.extend({ cfg: f.cfg.extend({ mode: v, padding: _ }), reset: function () { f.reset.call(this); var t = this.cfg, r = t.iv, e = t.mode; if (this._xformMode == this._ENC_XFORM_MODE) var i = e.createEncryptor; else { var i = e.createDecryptor; this._minBufferSize = 1 } this._mode && this._mode.__creator == i ? this._mode.init(this, r && r.words) : (this._mode = i.call(e, this, r && r.words), this._mode.__creator = i) }, _doProcessBlock: function (t, r) { this._mode.processBlock(t, r) }, _doFinalize: function () { var t = this.cfg.padding; if (this._xformMode == this._ENC_XFORM_MODE) { t.pad(this._data, this.blockSize); var r = this._process(!0) } else { var r = this._process(!0); t.unpad(r) } return r }, blockSize: 4 }), i.CipherParams = n.extend({ init: function (t) { this.mixIn(t) }, toString: function (t) { return (t || this.formatter).stringify(this) } })), g = e.format = {}, B = g.OpenSSL = { stringify: function (t) { var r = t.ciphertext, e = t.salt; if (e) var i = o.create([1398893684, 1701076831]).concat(e).concat(r); else var i = r; return i.toString(c) }, parse: function (t) { var r = c.parse(t), e = r.words; if (1398893684 == e[0] && 1701076831 == e[1]) { var i = o.create(e.slice(2, 4)); e.splice(0, 4), r.sigBytes -= 16 } return y.create({ ciphertext: r, salt: i }) } }, w = i.SerializableCipher = n.extend({ cfg: n.extend({ format: B }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = t.createEncryptor(e, i), o = n.finalize(r), s = n.cfg; return y.create({ ciphertext: o, key: e, iv: s.iv, algorithm: t, mode: s.mode, padding: s.padding, blockSize: t.blockSize, formatter: i.format }) }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = t.createDecryptor(e, i).finalize(r.ciphertext); return n }, _parse: function (t, r) { return "string" == typeof t ? r.parse(t, this) : t } }), k = e.kdf = {}, S = k.OpenSSL = { execute: function (t, r, e, i) { i || (i = o.random(8)); var n = l.create({ keySize: r + e }).compute(t, i), s = o.create(n.words.slice(r), 4 * e); return n.sigBytes = 4 * r, y.create({ key: n, iv: s, salt: i }) } }, m = i.PasswordBasedCipher = w.extend({ cfg: w.cfg.extend({ kdf: S }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = i.kdf.execute(e, t.keySize, t.ivSize); i.iv = n.iv; var o = w.encrypt.call(this, t, r, n.key, i); return o.mixIn(n), o }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = i.kdf.execute(e, t.keySize, t.ivSize, r.salt); i.iv = n.iv; var o = w.decrypt.call(this, t, r, n.key, i); return o } }) }(), t.mode.CFB = function () { function r(t, r, e, i) { var n = this._iv; if (n) { var o = n.slice(0); this._iv = void 0 } else var o = this._prevBlock; i.encryptBlock(o, 0); for (var s = 0; s < e; s++)t[r + s] ^= o[s] } var e = t.lib.BlockCipherMode.extend(); return e.Encryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize; r.call(this, t, e, n, i), this._prevBlock = t.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize, o = t.slice(e, e + n); r.call(this, t, e, n, i), this._prevBlock = o } }), e }(), t.mode.ECB = function () { var r = t.lib.BlockCipherMode.extend(); return r.Encryptor = r.extend({ processBlock: function (t, r) { this._cipher.encryptBlock(t, r) } }), r.Decryptor = r.extend({ processBlock: function (t, r) { this._cipher.decryptBlock(t, r) } }), r }(), t.pad.AnsiX923 = { pad: function (t, r) { var e = t.sigBytes, i = 4 * r, n = i - e % i, o = e + n - 1; t.clamp(), t.words[o >>> 2] |= n << 24 - o % 4 * 8, t.sigBytes += n }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso10126 = { pad: function (r, e) { var i = 4 * e, n = i - r.sigBytes % i; r.concat(t.lib.WordArray.random(n - 1)).concat(t.lib.WordArray.create([n << 24], 1)) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso97971 = { pad: function (r, e) { r.concat(t.lib.WordArray.create([2147483648], 1)), t.pad.ZeroPadding.pad(r, e) }, unpad: function (r) { t.pad.ZeroPadding.unpad(r), r.sigBytes-- } }, t.mode.OFB = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._keystream; n && (o = this._keystream = n.slice(0), this._iv = void 0), e.encryptBlock(o, 0); for (var s = 0; s < i; s++)t[r + s] ^= o[s] } }); return r.Decryptor = e, r }(), t.pad.NoPadding = { pad: function () { }, unpad: function () { } }, function (r) { var e = t, i = e.lib, n = i.CipherParams, o = e.enc, s = o.Hex, a = e.format; a.Hex = { stringify: function (t) { return t.ciphertext.toString(s) }, parse: function (t) { var r = s.parse(t); return n.create({ ciphertext: r }) } } }(), function () { var r = t, e = r.lib, i = e.BlockCipher, n = r.algo, o = [], s = [], a = [], c = [], h = [], l = [], f = [], u = [], d = [], v = []; !function () { for (var t = [], r = 0; r < 256; r++)r < 128 ? t[r] = r << 1 : t[r] = r << 1 ^ 283; for (var e = 0, i = 0, r = 0; r < 256; r++) { var n = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4; n = n >>> 8 ^ 255 & n ^ 99, o[e] = n, s[n] = e; var p = t[e], _ = t[p], y = t[_], g = 257 * t[n] ^ 16843008 * n; a[e] = g << 24 | g >>> 8, c[e] = g << 16 | g >>> 16, h[e] = g << 8 | g >>> 24, l[e] = g; var g = 16843009 * y ^ 65537 * _ ^ 257 * p ^ 16843008 * e; f[n] = g << 24 | g >>> 8, u[n] = g << 16 | g >>> 16, d[n] = g << 8 | g >>> 24, v[n] = g, e ? (e = p ^ t[t[t[y ^ p]]], i ^= t[t[i]]) : e = i = 1 } }(); var p = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], _ = n.AES = i.extend({ _doReset: function () { if (!this._nRounds || this._keyPriorReset !== this._key) { for (var t = this._keyPriorReset = this._key, r = t.words, e = t.sigBytes / 4, i = this._nRounds = e + 6, n = 4 * (i + 1), s = this._keySchedule = [], a = 0; a < n; a++)if (a < e) s[a] = r[a]; else { var c = s[a - 1]; a % e ? e > 6 && a % e == 4 && (c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c]) : (c = c << 8 | c >>> 24, c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c], c ^= p[a / e | 0] << 24), s[a] = s[a - e] ^ c } for (var h = this._invKeySchedule = [], l = 0; l < n; l++) { var a = n - l; if (l % 4) var c = s[a]; else var c = s[a - 4]; l < 4 || a <= 4 ? h[l] = c : h[l] = f[o[c >>> 24]] ^ u[o[c >>> 16 & 255]] ^ d[o[c >>> 8 & 255]] ^ v[o[255 & c]] } } }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._keySchedule, a, c, h, l, o) }, decryptBlock: function (t, r) { var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e, this._doCryptBlock(t, r, this._invKeySchedule, f, u, d, v, s); var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e }, _doCryptBlock: function (t, r, e, i, n, o, s, a) { for (var c = this._nRounds, h = t[r] ^ e[0], l = t[r + 1] ^ e[1], f = t[r + 2] ^ e[2], u = t[r + 3] ^ e[3], d = 4, v = 1; v < c; v++) { var p = i[h >>> 24] ^ n[l >>> 16 & 255] ^ o[f >>> 8 & 255] ^ s[255 & u] ^ e[d++], _ = i[l >>> 24] ^ n[f >>> 16 & 255] ^ o[u >>> 8 & 255] ^ s[255 & h] ^ e[d++], y = i[f >>> 24] ^ n[u >>> 16 & 255] ^ o[h >>> 8 & 255] ^ s[255 & l] ^ e[d++], g = i[u >>> 24] ^ n[h >>> 16 & 255] ^ o[l >>> 8 & 255] ^ s[255 & f] ^ e[d++]; h = p, l = _, f = y, u = g } var p = (a[h >>> 24] << 24 | a[l >>> 16 & 255] << 16 | a[f >>> 8 & 255] << 8 | a[255 & u]) ^ e[d++], _ = (a[l >>> 24] << 24 | a[f >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & h]) ^ e[d++], y = (a[f >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[h >>> 8 & 255] << 8 | a[255 & l]) ^ e[d++], g = (a[u >>> 24] << 24 | a[h >>> 16 & 255] << 16 | a[l >>> 8 & 255] << 8 | a[255 & f]) ^ e[d++]; t[r] = p, t[r + 1] = _, t[r + 2] = y, t[r + 3] = g }, keySize: 8 }); r.AES = i._createHelper(_) }(), function () { + function r(t, r) { var e = (this._lBlock >>> t ^ this._rBlock) & r; this._rBlock ^= e, this._lBlock ^= e << t } function e(t, r) { + var e = (this._rBlock >>> t ^ this._lBlock) & r; this._lBlock ^= e, this._rBlock ^= e << t; + } var i = t, n = i.lib, o = n.WordArray, s = n.BlockCipher, a = i.algo, c = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4], h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32], l = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28], f = [{ 0: 8421888, 268435456: 32768, 536870912: 8421378, 805306368: 2, 1073741824: 512, 1342177280: 8421890, 1610612736: 8389122, 1879048192: 8388608, 2147483648: 514, 2415919104: 8389120, 2684354560: 33280, 2952790016: 8421376, 3221225472: 32770, 3489660928: 8388610, 3758096384: 0, 4026531840: 33282, 134217728: 0, 402653184: 8421890, 671088640: 33282, 939524096: 32768, 1207959552: 8421888, 1476395008: 512, 1744830464: 8421378, 2013265920: 2, 2281701376: 8389120, 2550136832: 33280, 2818572288: 8421376, 3087007744: 8389122, 3355443200: 8388610, 3623878656: 32770, 3892314112: 514, 4160749568: 8388608, 1: 32768, 268435457: 2, 536870913: 8421888, 805306369: 8388608, 1073741825: 8421378, 1342177281: 33280, 1610612737: 512, 1879048193: 8389122, 2147483649: 8421890, 2415919105: 8421376, 2684354561: 8388610, 2952790017: 33282, 3221225473: 514, 3489660929: 8389120, 3758096385: 32770, 4026531841: 0, 134217729: 8421890, 402653185: 8421376, 671088641: 8388608, 939524097: 512, 1207959553: 32768, 1476395009: 8388610, 1744830465: 2, 2013265921: 33282, 2281701377: 32770, 2550136833: 8389122, 2818572289: 514, 3087007745: 8421888, 3355443201: 8389120, 3623878657: 0, 3892314113: 33280, 4160749569: 8421378 }, { 0: 1074282512, 16777216: 16384, 33554432: 524288, 50331648: 1074266128, 67108864: 1073741840, 83886080: 1074282496, 100663296: 1073758208, 117440512: 16, 134217728: 540672, 150994944: 1073758224, 167772160: 1073741824, 184549376: 540688, 201326592: 524304, 218103808: 0, 234881024: 16400, 251658240: 1074266112, 8388608: 1073758208, 25165824: 540688, 41943040: 16, 58720256: 1073758224, 75497472: 1074282512, 92274688: 1073741824, 109051904: 524288, 125829120: 1074266128, 142606336: 524304, 159383552: 0, 176160768: 16384, 192937984: 1074266112, 209715200: 1073741840, 226492416: 540672, 243269632: 1074282496, 260046848: 16400, 268435456: 0, 285212672: 1074266128, 301989888: 1073758224, 318767104: 1074282496, 335544320: 1074266112, 352321536: 16, 369098752: 540688, 385875968: 16384, 402653184: 16400, 419430400: 524288, 436207616: 524304, 452984832: 1073741840, 469762048: 540672, 486539264: 1073758208, 503316480: 1073741824, 520093696: 1074282512, 276824064: 540688, 293601280: 524288, 310378496: 1074266112, 327155712: 16384, 343932928: 1073758208, 360710144: 1074282512, 377487360: 16, 394264576: 1073741824, 411041792: 1074282496, 427819008: 1073741840, 444596224: 1073758224, 461373440: 524304, 478150656: 0, 494927872: 16400, 511705088: 1074266128, 528482304: 540672 }, { 0: 260, 1048576: 0, 2097152: 67109120, 3145728: 65796, 4194304: 65540, 5242880: 67108868, 6291456: 67174660, 7340032: 67174400, 8388608: 67108864, 9437184: 67174656, 10485760: 65792, 11534336: 67174404, 12582912: 67109124, 13631488: 65536, 14680064: 4, 15728640: 256, 524288: 67174656, 1572864: 67174404, 2621440: 0, 3670016: 67109120, 4718592: 67108868, 5767168: 65536, 6815744: 65540, 7864320: 260, 8912896: 4, 9961472: 256, 11010048: 67174400, 12058624: 65796, 13107200: 65792, 14155776: 67109124, 15204352: 67174660, 16252928: 67108864, 16777216: 67174656, 17825792: 65540, 18874368: 65536, 19922944: 67109120, 20971520: 256, 22020096: 67174660, 23068672: 67108868, 24117248: 0, 25165824: 67109124, 26214400: 67108864, 27262976: 4, 28311552: 65792, 29360128: 67174400, 30408704: 260, 31457280: 65796, 32505856: 67174404, 17301504: 67108864, 18350080: 260, 19398656: 67174656, 20447232: 0, 21495808: 65540, 22544384: 67109120, 23592960: 256, 24641536: 67174404, 25690112: 65536, 26738688: 67174660, 27787264: 65796, 28835840: 67108868, 29884416: 67109124, 30932992: 67174400, 31981568: 4, 33030144: 65792 }, { 0: 2151682048, 65536: 2147487808, 131072: 4198464, 196608: 2151677952, 262144: 0, 327680: 4198400, 393216: 2147483712, 458752: 4194368, 524288: 2147483648, 589824: 4194304, 655360: 64, 720896: 2147487744, 786432: 2151678016, 851968: 4160, 917504: 4096, 983040: 2151682112, 32768: 2147487808, 98304: 64, 163840: 2151678016, 229376: 2147487744, 294912: 4198400, 360448: 2151682112, 425984: 0, 491520: 2151677952, 557056: 4096, 622592: 2151682048, 688128: 4194304, 753664: 4160, 819200: 2147483648, 884736: 4194368, 950272: 4198464, 1015808: 2147483712, 1048576: 4194368, 1114112: 4198400, 1179648: 2147483712, 1245184: 0, 1310720: 4160, 1376256: 2151678016, 1441792: 2151682048, 1507328: 2147487808, 1572864: 2151682112, 1638400: 2147483648, 1703936: 2151677952, 1769472: 4198464, 1835008: 2147487744, 1900544: 4194304, 1966080: 64, 2031616: 4096, 1081344: 2151677952, 1146880: 2151682112, 1212416: 0, 1277952: 4198400, 1343488: 4194368, 1409024: 2147483648, 1474560: 2147487808, 1540096: 64, 1605632: 2147483712, 1671168: 4096, 1736704: 2147487744, 1802240: 2151678016, 1867776: 4160, 1933312: 2151682048, 1998848: 4194304, 2064384: 4198464 }, { 0: 128, 4096: 17039360, 8192: 262144, 12288: 536870912, 16384: 537133184, 20480: 16777344, 24576: 553648256, 28672: 262272, 32768: 16777216, 36864: 537133056, 40960: 536871040, 45056: 553910400, 49152: 553910272, 53248: 0, 57344: 17039488, 61440: 553648128, 2048: 17039488, 6144: 553648256, 10240: 128, 14336: 17039360, 18432: 262144, 22528: 537133184, 26624: 553910272, 30720: 536870912, 34816: 537133056, 38912: 0, 43008: 553910400, 47104: 16777344, 51200: 536871040, 55296: 553648128, 59392: 16777216, 63488: 262272, 65536: 262144, 69632: 128, 73728: 536870912, 77824: 553648256, 81920: 16777344, 86016: 553910272, 90112: 537133184, 94208: 16777216, 98304: 553910400, 102400: 553648128, 106496: 17039360, 110592: 537133056, 114688: 262272, 118784: 536871040, 122880: 0, 126976: 17039488, 67584: 553648256, 71680: 16777216, 75776: 17039360, 79872: 537133184, 83968: 536870912, 88064: 17039488, 92160: 128, 96256: 553910272, 100352: 262272, 104448: 553910400, 108544: 0, 112640: 553648128, 116736: 16777344, 120832: 262144, 124928: 537133056, 129024: 536871040 }, { 0: 268435464, 256: 8192, 512: 270532608, 768: 270540808, 1024: 268443648, 1280: 2097152, 1536: 2097160, 1792: 268435456, 2048: 0, 2304: 268443656, 2560: 2105344, 2816: 8, 3072: 270532616, 3328: 2105352, 3584: 8200, 3840: 270540800, 128: 270532608, 384: 270540808, 640: 8, 896: 2097152, 1152: 2105352, 1408: 268435464, 1664: 268443648, 1920: 8200, 2176: 2097160, 2432: 8192, 2688: 268443656, 2944: 270532616, 3200: 0, 3456: 270540800, 3712: 2105344, 3968: 268435456, 4096: 268443648, 4352: 270532616, 4608: 270540808, 4864: 8200, 5120: 2097152, 5376: 268435456, 5632: 268435464, 5888: 2105344, 6144: 2105352, 6400: 0, 6656: 8, 6912: 270532608, 7168: 8192, 7424: 268443656, 7680: 270540800, 7936: 2097160, 4224: 8, 4480: 2105344, 4736: 2097152, 4992: 268435464, 5248: 268443648, 5504: 8200, 5760: 270540808, 6016: 270532608, 6272: 270540800, 6528: 270532616, 6784: 8192, 7040: 2105352, 7296: 2097160, 7552: 0, 7808: 268435456, 8064: 268443656 }, { 0: 1048576, 16: 33555457, 32: 1024, 48: 1049601, 64: 34604033, 80: 0, 96: 1, 112: 34603009, 128: 33555456, 144: 1048577, 160: 33554433, 176: 34604032, 192: 34603008, 208: 1025, 224: 1049600, 240: 33554432, 8: 34603009, 24: 0, 40: 33555457, 56: 34604032, 72: 1048576, 88: 33554433, 104: 33554432, 120: 1025, 136: 1049601, 152: 33555456, 168: 34603008, 184: 1048577, 200: 1024, 216: 34604033, 232: 1, 248: 1049600, 256: 33554432, 272: 1048576, 288: 33555457, 304: 34603009, 320: 1048577, 336: 33555456, 352: 34604032, 368: 1049601, 384: 1025, 400: 34604033, 416: 1049600, 432: 1, 448: 0, 464: 34603008, 480: 33554433, 496: 1024, 264: 1049600, 280: 33555457, 296: 34603009, 312: 1, 328: 33554432, 344: 1048576, 360: 1025, 376: 34604032, 392: 33554433, 408: 34603008, 424: 0, 440: 34604033, 456: 1049601, 472: 1024, 488: 33555456, 504: 1048577 }, { 0: 134219808, 1: 131072, 2: 134217728, 3: 32, 4: 131104, 5: 134350880, 6: 134350848, 7: 2048, 8: 134348800, 9: 134219776, 10: 133120, 11: 134348832, 12: 2080, 13: 0, 14: 134217760, 15: 133152, 2147483648: 2048, 2147483649: 134350880, 2147483650: 134219808, 2147483651: 134217728, 2147483652: 134348800, 2147483653: 133120, 2147483654: 133152, 2147483655: 32, 2147483656: 134217760, 2147483657: 2080, 2147483658: 131104, 2147483659: 134350848, 2147483660: 0, 2147483661: 134348832, 2147483662: 134219776, 2147483663: 131072, 16: 133152, 17: 134350848, 18: 32, 19: 2048, 20: 134219776, 21: 134217760, 22: 134348832, 23: 131072, 24: 0, 25: 131104, 26: 134348800, 27: 134219808, 28: 134350880, 29: 133120, 30: 2080, 31: 134217728, 2147483664: 131072, 2147483665: 2048, 2147483666: 134348832, 2147483667: 133152, 2147483668: 32, 2147483669: 134348800, 2147483670: 134217728, 2147483671: 134219808, 2147483672: 134350880, 2147483673: 134217760, 2147483674: 134219776, 2147483675: 0, 2147483676: 133120, 2147483677: 2080, 2147483678: 131104, 2147483679: 134350848 }], u = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679], d = a.DES = s.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = [], i = 0; i < 56; i++) { var n = c[i] - 1; e[i] = r[n >>> 5] >>> 31 - n % 32 & 1 } for (var o = this._subKeys = [], s = 0; s < 16; s++) { for (var a = o[s] = [], f = l[s], i = 0; i < 24; i++)a[i / 6 | 0] |= e[(h[i] - 1 + f) % 28] << 31 - i % 6, a[4 + (i / 6 | 0)] |= e[28 + (h[i + 24] - 1 + f) % 28] << 31 - i % 6; a[0] = a[0] << 1 | a[0] >>> 31; for (var i = 1; i < 7; i++)a[i] = a[i] >>> 4 * (i - 1) + 3; a[7] = a[7] << 5 | a[7] >>> 27 } for (var u = this._invSubKeys = [], i = 0; i < 16; i++)u[i] = o[15 - i] }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._subKeys) }, decryptBlock: function (t, r) { this._doCryptBlock(t, r, this._invSubKeys) }, _doCryptBlock: function (t, i, n) { this._lBlock = t[i], this._rBlock = t[i + 1], r.call(this, 4, 252645135), r.call(this, 16, 65535), e.call(this, 2, 858993459), e.call(this, 8, 16711935), r.call(this, 1, 1431655765); for (var o = 0; o < 16; o++) { for (var s = n[o], a = this._lBlock, c = this._rBlock, h = 0, l = 0; l < 8; l++)h |= f[l][((c ^ s[l]) & u[l]) >>> 0]; this._lBlock = c, this._rBlock = a ^ h } var d = this._lBlock; this._lBlock = this._rBlock, this._rBlock = d, r.call(this, 1, 1431655765), e.call(this, 8, 16711935), e.call(this, 2, 858993459), r.call(this, 16, 65535), r.call(this, 4, 252645135), t[i] = this._lBlock, t[i + 1] = this._rBlock }, keySize: 2, ivSize: 2, blockSize: 2 }); i.DES = s._createHelper(d); var v = a.TripleDES = s.extend({ _doReset: function () { var t = this._key, r = t.words; this._des1 = d.createEncryptor(o.create(r.slice(0, 2))), this._des2 = d.createEncryptor(o.create(r.slice(2, 4))), this._des3 = d.createEncryptor(o.create(r.slice(4, 6))) }, encryptBlock: function (t, r) { this._des1.encryptBlock(t, r), this._des2.decryptBlock(t, r), this._des3.encryptBlock(t, r) }, decryptBlock: function (t, r) { this._des3.decryptBlock(t, r), this._des2.encryptBlock(t, r), this._des1.decryptBlock(t, r) }, keySize: 6, ivSize: 2, blockSize: 2 }); i.TripleDES = s._createHelper(v) + }(), function () { function r() { for (var t = this._S, r = this._i, e = this._j, i = 0, n = 0; n < 4; n++) { r = (r + 1) % 256, e = (e + t[r]) % 256; var o = t[r]; t[r] = t[e], t[e] = o, i |= t[(t[r] + t[e]) % 256] << 24 - 8 * n } return this._i = r, this._j = e, i } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = o.RC4 = n.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = t.sigBytes, i = this._S = [], n = 0; n < 256; n++)i[n] = n; for (var n = 0, o = 0; n < 256; n++) { var s = n % e, a = r[s >>> 2] >>> 24 - s % 4 * 8 & 255; o = (o + i[n] + a) % 256; var c = i[n]; i[n] = i[o], i[o] = c } this._i = this._j = 0 }, _doProcessBlock: function (t, e) { t[e] ^= r.call(this) }, keySize: 8, ivSize: 0 }); e.RC4 = n._createHelper(s); var a = o.RC4Drop = s.extend({ cfg: s.cfg.extend({ drop: 192 }), _doReset: function () { s._doReset.call(this); for (var t = this.cfg.drop; t > 0; t--)r.call(this) } }); e.RC4Drop = n._createHelper(a) }(), t.mode.CTRGladman = function () { function r(t) { if (255 === (t >> 24 & 255)) { var r = t >> 16 & 255, e = t >> 8 & 255, i = 255 & t; 255 === r ? (r = 0, 255 === e ? (e = 0, 255 === i ? i = 0 : ++i) : ++e) : ++r, t = 0, t += r << 16, t += e << 8, t += i } else t += 1 << 24; return t } function e(t) { return 0 === (t[0] = r(t[0])) && (t[1] = r(t[1])), t } var i = t.lib.BlockCipherMode.extend(), n = i.Encryptor = i.extend({ processBlock: function (t, r) { var i = this._cipher, n = i.blockSize, o = this._iv, s = this._counter; o && (s = this._counter = o.slice(0), this._iv = void 0), e(s); var a = s.slice(0); i.encryptBlock(a, 0); for (var c = 0; c < n; c++)t[r + c] ^= a[c] } }); return i.Decryptor = n, i }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.Rabbit = n.extend({ _doReset: function () { for (var t = this._key.words, e = this.cfg.iv, i = 0; i < 4; i++)t[i] = 16711935 & (t[i] << 8 | t[i] >>> 24) | 4278255360 & (t[i] << 24 | t[i] >>> 8); var n = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], o = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var i = 0; i < 4; i++)r.call(this); for (var i = 0; i < 8; i++)o[i] ^= n[i + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; o[0] ^= h, o[1] ^= f, o[2] ^= l, o[3] ^= u, o[4] ^= h, o[5] ^= f, o[6] ^= l, o[7] ^= u; for (var i = 0; i < 4; i++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.Rabbit = n._createHelper(h) }(), t.mode.CTR = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._counter; n && (o = this._counter = n.slice(0), this._iv = void 0); var s = o.slice(0); e.encryptBlock(s, 0), o[i - 1] = o[i - 1] + 1 | 0; for (var a = 0; a < i; a++)t[r + a] ^= s[a] } }); return r.Decryptor = e, r }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.RabbitLegacy = n.extend({ _doReset: function () { var t = this._key.words, e = this.cfg.iv, i = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], n = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var o = 0; o < 4; o++)r.call(this); for (var o = 0; o < 8; o++)n[o] ^= i[o + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; n[0] ^= h, n[1] ^= f, n[2] ^= l, n[3] ^= u, n[4] ^= h, n[5] ^= f, n[6] ^= l, n[7] ^= u; for (var o = 0; o < 4; o++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.RabbitLegacy = n._createHelper(h) }(), t.pad.ZeroPadding = { pad: function (t, r) { var e = 4 * r; t.clamp(), t.sigBytes += e - (t.sigBytes % e || e) }, unpad: function (t) { for (var r = t.words, e = t.sigBytes - 1; !(r[e >>> 2] >>> 24 - e % 4 * 8 & 255);)e--; t.sigBytes = e + 1 } }, t +}); + const $ = new Env('什么值得买') $.VAL_cookies = $.getdata('chavy_cookie_smzdm') -$.VAl_accounts = $.getdata('chavy_accounts_smzdm') -$.CFG_tokens = 'chavy_tokens_smzdm' !(async () => { - // await signapp() + $.CryptoJS = $.isNode() ? require('crypto-js') : CryptoJS + await signweb() + await $.wait(4000) + await signapp() await showmsg() })() .catch((e) => $.logErr(e)) @@ -21,7 +31,6 @@ function signweb() { try { $.web = JSON.parse(data) } catch (e) { - $.token = null $.logErr(e, resp) } finally { resove() @@ -30,34 +39,20 @@ function signweb() { }) } -async function signapp() { - const accounts = getAccounts() - for (let accIdx = 0; accIdx < accounts.length; accIdx++) { - const account = accounts[accIdx] - await loginapp(account) - await $.wait(account.isCached ? 0 : 3000) - await signinapp(account) - await $.wait(3000) - } - $.accounts = accounts -} - -function loginapp(account) { - const tokens = getTokens() - if (tokens[account.acc]) { - account.isCached = true - account.token = tokens[account.acc] - return - } +function signapp() { + const body = getBody() return new Promise((resove) => { - const url = { url: 'https://api.smzdm.com/v1/user/login', headers: {} } - url.body = `user_login=${account.acc}&user_pass=${account.pwd}&f=win` + const url = { + url: 'https://user-api.smzdm.com/checkin', + body, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': $.VAL_cookies + } + } $.post(url, (err, resp, data) => { try { - account.token = $.lodash_get(JSON.parse(data), 'data.token') - const tokens = getTokens() - tokens[account.acc] = account.token - $.setdata(JSON.stringify(tokens), $.CFG_tokens) + $.app = JSON.parse(data) } catch (e) { $.logErr(e, resp) } finally { @@ -67,65 +62,38 @@ function loginapp(account) { }) } -function signinapp(account) { - return new Promise((resove) => { - const url = { url: 'https://api.smzdm.com/v1/user/checkin', headers: {} } - url.body = `f=win&token=${account.token}` - $.post(url, (err, resp, data) => { - try { - const _data = JSON.parse(data) - const errCode = _data.error_code - if (errCode === '0' && _data.data.checkin_status === '0') account.issuc = true - else if (errCode === '0' && _data.data.checkin_status === '1') account.isrepeat = true - else account.msg = _data.error_msg - } catch (e) { - $.logErr(e, resp) - } finally { - resove() - } - }) - }) +function getToken() { + const [, token] = $.VAL_cookies.match(/sess=(.*?);/) + return token } -function getAccounts() { - const accounts = [] - $.VAl_accounts && - $.VAl_accounts.split('\n').forEach((account) => { - let [acc, pwd] = account.split(',') - acc = acc ? acc.trim() : acc - pwd = pwd ? pwd.trim() : pwd - if (acc && pwd) { - accounts.push({ acc, pwd }) - } - }) - return accounts +function getAppSign() { + const t = new Date().getTime() + const sign = 'f=android&sk=1&time=' + t + '&token=' + getToken() + '&v=10.0&weixin=0&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC' + return $.CryptoJS.MD5(sign).toString().toUpperCase() } -function getTokens() { - const tokendat = $.getdata($.CFG_tokens) - return [undefined, null, 'null', 'undefined', ''].includes(tokendat) ? {} : JSON.parse(tokendat) +function getBody() { + const t = new Date().getTime() + const token = getToken() + const sign = getAppSign() + return 'touchstone_event=&v=10.0&sign=' + sign + '&weixin=0&time=' + t + '&sk=1&token=' + token + '&f=android&captcha=' } function showmsg() { return new Promise((resolve) => { $.subt = '' $.desc = [] + console.log($.web) + console.log($.app) $.subt = $.web.error_code === 0 ? 'PC: 成功' : $.web.error_code === 99 ? 'PC: 未登录' : 'PC: 失败' if ($.web.error_code === 0 && $.web.data) { $.desc.push(`累计: ${$.web.data.checkin_num}次, 经验: ${$.web.data.exp}, 金币: ${$.web.data.gold}, 积分: ${$.web.data.point}`) } - // if (Array.isArray($.accounts) && $.accounts.length > 0) { - // $.desc.push('点击查看详情', '') - // let signedCnt = 0 - // for (let accIdx = 0; accIdx < $.accounts.length; accIdx++) { - // const account = $.accounts[accIdx] - // signedCnt += account.issuc || account.isrepeat ? 1 : 0 - // $.desc.push(`${account.acc}: ${account.issuc ? '成功' : account.isrepeat ? '重复' : `失败. ${account.msg}`}`) - // } - // $.subt += `, APP: ${signedCnt}/${$.accounts.length}` - // } else { - // $.subt += ', APP: 在BoxJs设置签到账号' - // } + if ($.app) { + $.subt += $.app.error_code === '0' ? ', APP: 成功' : ', APP: 失败' + $.desc.push($.app.error_msg) + } $.msg($.name, $.subt, $.desc.join('\n')) resolve() }) From 9d5dc2436620b3a07155445a244c509273a08137 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 29 Mar 2021 23:01:25 +0800 Subject: [PATCH 061/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E5=80=BC=E5=BE=97=E4=B9=B0]:=20=E6=81=A2=E5=A4=8D=20APP=20?= =?UTF-8?q?=E7=AB=AF=E7=AD=BE=E5=88=B0=EF=BC=8C=E6=84=9F=E8=B0=A2=20@wangf?= =?UTF-8?q?ei021325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smzdm/quanx/smzdm.js | 116 ++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 74 deletions(-) diff --git a/smzdm/quanx/smzdm.js b/smzdm/quanx/smzdm.js index d242e79e7..b6012380a 100644 --- a/smzdm/quanx/smzdm.js +++ b/smzdm/quanx/smzdm.js @@ -1,11 +1,21 @@ +// prettier-ignore +!function (t, r) { "object" == typeof exports ? module.exports = exports = r() : "function" == typeof define && define.amd ? define([], r) : t.CryptoJS = r() }(this, function () { + var t = t || function (t, r) { var e = Object.create || function () { function t() { } return function (r) { var e; return t.prototype = r, e = new t, t.prototype = null, e } }(), i = {}, n = i.lib = {}, o = n.Base = function () { return { extend: function (t) { var r = e(this); return t && r.mixIn(t), r.hasOwnProperty("init") && this.init !== r.init || (r.init = function () { r.$super.init.apply(this, arguments) }), r.init.prototype = r, r.$super = this, r }, create: function () { var t = this.extend(); return t.init.apply(t, arguments), t }, init: function () { }, mixIn: function (t) { for (var r in t) t.hasOwnProperty(r) && (this[r] = t[r]); t.hasOwnProperty("toString") && (this.toString = t.toString) }, clone: function () { return this.init.prototype.extend(this) } } }(), s = n.WordArray = o.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 4 * t.length }, toString: function (t) { return (t || c).stringify(this) }, concat: function (t) { var r = this.words, e = t.words, i = this.sigBytes, n = t.sigBytes; if (this.clamp(), i % 4) for (var o = 0; o < n; o++) { var s = e[o >>> 2] >>> 24 - o % 4 * 8 & 255; r[i + o >>> 2] |= s << 24 - (i + o) % 4 * 8 } else for (var o = 0; o < n; o += 4)r[i + o >>> 2] = e[o >>> 2]; return this.sigBytes += n, this }, clamp: function () { var r = this.words, e = this.sigBytes; r[e >>> 2] &= 4294967295 << 32 - e % 4 * 8, r.length = t.ceil(e / 4) }, clone: function () { var t = o.clone.call(this); return t.words = this.words.slice(0), t }, random: function (r) { for (var e, i = [], n = function (r) { var r = r, e = 987654321, i = 4294967295; return function () { e = 36969 * (65535 & e) + (e >> 16) & i, r = 18e3 * (65535 & r) + (r >> 16) & i; var n = (e << 16) + r & i; return n /= 4294967296, n += .5, n * (t.random() > .5 ? 1 : -1) } }, o = 0; o < r; o += 4) { var a = n(4294967296 * (e || t.random())); e = 987654071 * a(), i.push(4294967296 * a() | 0) } return new s.init(i, r) } }), a = i.enc = {}, c = a.Hex = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push((o >>> 4).toString(16)), i.push((15 & o).toString(16)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i += 2)e[i >>> 3] |= parseInt(t.substr(i, 2), 16) << 24 - i % 8 * 4; return new s.init(e, r / 2) } }, h = a.Latin1 = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 2] |= (255 & t.charCodeAt(i)) << 24 - i % 4 * 8; return new s.init(e, r) } }, l = a.Utf8 = { stringify: function (t) { try { return decodeURIComponent(escape(h.stringify(t))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, parse: function (t) { return h.parse(unescape(encodeURIComponent(t))) } }, f = n.BufferedBlockAlgorithm = o.extend({ reset: function () { this._data = new s.init, this._nDataBytes = 0 }, _append: function (t) { "string" == typeof t && (t = l.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes }, _process: function (r) { var e = this._data, i = e.words, n = e.sigBytes, o = this.blockSize, a = 4 * o, c = n / a; c = r ? t.ceil(c) : t.max((0 | c) - this._minBufferSize, 0); var h = c * o, l = t.min(4 * h, n); if (h) { for (var f = 0; f < h; f += o)this._doProcessBlock(i, f); var u = i.splice(0, h); e.sigBytes -= l } return new s.init(u, l) }, clone: function () { var t = o.clone.call(this); return t._data = this._data.clone(), t }, _minBufferSize: 0 }), u = (n.Hasher = f.extend({ cfg: o.extend(), init: function (t) { this.cfg = this.cfg.extend(t), this.reset() }, reset: function () { f.reset.call(this), this._doReset() }, update: function (t) { return this._append(t), this._process(), this }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, blockSize: 16, _createHelper: function (t) { return function (r, e) { return new t.init(e).finalize(r) } }, _createHmacHelper: function (t) { return function (r, e) { return new u.HMAC.init(t, e).finalize(r) } } }), i.algo = {}); return i }(Math); return function () { function r(t, r, e) { for (var i = [], o = 0, s = 0; s < r; s++)if (s % 4) { var a = e[t.charCodeAt(s - 1)] << s % 4 * 2, c = e[t.charCodeAt(s)] >>> 6 - s % 4 * 2; i[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ } return n.create(i, o) } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Base64 = { stringify: function (t) { var r = t.words, e = t.sigBytes, i = this._map; t.clamp(); for (var n = [], o = 0; o < e; o += 3)for (var s = r[o >>> 2] >>> 24 - o % 4 * 8 & 255, a = r[o + 1 >>> 2] >>> 24 - (o + 1) % 4 * 8 & 255, c = r[o + 2 >>> 2] >>> 24 - (o + 2) % 4 * 8 & 255, h = s << 16 | a << 8 | c, l = 0; l < 4 && o + .75 * l < e; l++)n.push(i.charAt(h >>> 6 * (3 - l) & 63)); var f = i.charAt(64); if (f) for (; n.length % 4;)n.push(f); return n.join("") }, parse: function (t) { var e = t.length, i = this._map, n = this._reverseMap; if (!n) { n = this._reverseMap = []; for (var o = 0; o < i.length; o++)n[i.charCodeAt(o)] = o } var s = i.charAt(64); if (s) { var a = t.indexOf(s); a !== -1 && (e = a) } return r(t, e, n) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } }(), function (r) { function e(t, r, e, i, n, o, s) { var a = t + (r & e | ~r & i) + n + s; return (a << o | a >>> 32 - o) + r } function i(t, r, e, i, n, o, s) { var a = t + (r & i | e & ~i) + n + s; return (a << o | a >>> 32 - o) + r } function n(t, r, e, i, n, o, s) { var a = t + (r ^ e ^ i) + n + s; return (a << o | a >>> 32 - o) + r } function o(t, r, e, i, n, o, s) { var a = t + (e ^ (r | ~i)) + n + s; return (a << o | a >>> 32 - o) + r } var s = t, a = s.lib, c = a.WordArray, h = a.Hasher, l = s.algo, f = []; !function () { for (var t = 0; t < 64; t++)f[t] = 4294967296 * r.abs(r.sin(t + 1)) | 0 }(); var u = l.MD5 = h.extend({ _doReset: function () { this._hash = new c.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (t, r) { for (var s = 0; s < 16; s++) { var a = r + s, c = t[a]; t[a] = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8) } var h = this._hash.words, l = t[r + 0], u = t[r + 1], d = t[r + 2], v = t[r + 3], p = t[r + 4], _ = t[r + 5], y = t[r + 6], g = t[r + 7], B = t[r + 8], w = t[r + 9], k = t[r + 10], S = t[r + 11], m = t[r + 12], x = t[r + 13], b = t[r + 14], H = t[r + 15], z = h[0], A = h[1], C = h[2], D = h[3]; z = e(z, A, C, D, l, 7, f[0]), D = e(D, z, A, C, u, 12, f[1]), C = e(C, D, z, A, d, 17, f[2]), A = e(A, C, D, z, v, 22, f[3]), z = e(z, A, C, D, p, 7, f[4]), D = e(D, z, A, C, _, 12, f[5]), C = e(C, D, z, A, y, 17, f[6]), A = e(A, C, D, z, g, 22, f[7]), z = e(z, A, C, D, B, 7, f[8]), D = e(D, z, A, C, w, 12, f[9]), C = e(C, D, z, A, k, 17, f[10]), A = e(A, C, D, z, S, 22, f[11]), z = e(z, A, C, D, m, 7, f[12]), D = e(D, z, A, C, x, 12, f[13]), C = e(C, D, z, A, b, 17, f[14]), A = e(A, C, D, z, H, 22, f[15]), z = i(z, A, C, D, u, 5, f[16]), D = i(D, z, A, C, y, 9, f[17]), C = i(C, D, z, A, S, 14, f[18]), A = i(A, C, D, z, l, 20, f[19]), z = i(z, A, C, D, _, 5, f[20]), D = i(D, z, A, C, k, 9, f[21]), C = i(C, D, z, A, H, 14, f[22]), A = i(A, C, D, z, p, 20, f[23]), z = i(z, A, C, D, w, 5, f[24]), D = i(D, z, A, C, b, 9, f[25]), C = i(C, D, z, A, v, 14, f[26]), A = i(A, C, D, z, B, 20, f[27]), z = i(z, A, C, D, x, 5, f[28]), D = i(D, z, A, C, d, 9, f[29]), C = i(C, D, z, A, g, 14, f[30]), A = i(A, C, D, z, m, 20, f[31]), z = n(z, A, C, D, _, 4, f[32]), D = n(D, z, A, C, B, 11, f[33]), C = n(C, D, z, A, S, 16, f[34]), A = n(A, C, D, z, b, 23, f[35]), z = n(z, A, C, D, u, 4, f[36]), D = n(D, z, A, C, p, 11, f[37]), C = n(C, D, z, A, g, 16, f[38]), A = n(A, C, D, z, k, 23, f[39]), z = n(z, A, C, D, x, 4, f[40]), D = n(D, z, A, C, l, 11, f[41]), C = n(C, D, z, A, v, 16, f[42]), A = n(A, C, D, z, y, 23, f[43]), z = n(z, A, C, D, w, 4, f[44]), D = n(D, z, A, C, m, 11, f[45]), C = n(C, D, z, A, H, 16, f[46]), A = n(A, C, D, z, d, 23, f[47]), z = o(z, A, C, D, l, 6, f[48]), D = o(D, z, A, C, g, 10, f[49]), C = o(C, D, z, A, b, 15, f[50]), A = o(A, C, D, z, _, 21, f[51]), z = o(z, A, C, D, m, 6, f[52]), D = o(D, z, A, C, v, 10, f[53]), C = o(C, D, z, A, k, 15, f[54]), A = o(A, C, D, z, u, 21, f[55]), z = o(z, A, C, D, B, 6, f[56]), D = o(D, z, A, C, H, 10, f[57]), C = o(C, D, z, A, y, 15, f[58]), A = o(A, C, D, z, x, 21, f[59]), z = o(z, A, C, D, p, 6, f[60]), D = o(D, z, A, C, S, 10, f[61]), C = o(C, D, z, A, d, 15, f[62]), A = o(A, C, D, z, w, 21, f[63]), h[0] = h[0] + z | 0, h[1] = h[1] + A | 0, h[2] = h[2] + C | 0, h[3] = h[3] + D | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; e[n >>> 5] |= 128 << 24 - n % 32; var o = r.floor(i / 4294967296), s = i; e[(n + 64 >>> 9 << 4) + 15] = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), e[(n + 64 >>> 9 << 4) + 14] = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8), t.sigBytes = 4 * (e.length + 1), this._process(); for (var a = this._hash, c = a.words, h = 0; h < 4; h++) { var l = c[h]; c[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } return a }, clone: function () { var t = h.clone.call(this); return t._hash = this._hash.clone(), t } }); s.MD5 = h._createHelper(u), s.HmacMD5 = h._createHmacHelper(u) }(Math), function () { var r = t, e = r.lib, i = e.WordArray, n = e.Hasher, o = r.algo, s = [], a = o.SHA1 = n.extend({ _doReset: function () { this._hash = new i.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], a = e[3], c = e[4], h = 0; h < 80; h++) { if (h < 16) s[h] = 0 | t[r + h]; else { var l = s[h - 3] ^ s[h - 8] ^ s[h - 14] ^ s[h - 16]; s[h] = l << 1 | l >>> 31 } var f = (i << 5 | i >>> 27) + c + s[h]; f += h < 20 ? (n & o | ~n & a) + 1518500249 : h < 40 ? (n ^ o ^ a) + 1859775393 : h < 60 ? (n & o | n & a | o & a) - 1894007588 : (n ^ o ^ a) - 899497514, c = a, a = o, o = n << 30 | n >>> 2, n = i, i = f } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + a | 0, e[4] = e[4] + c | 0 }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; return r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = Math.floor(e / 4294967296), r[(i + 64 >>> 9 << 4) + 15] = e, t.sigBytes = 4 * r.length, this._process(), this._hash }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t } }); r.SHA1 = n._createHelper(a), r.HmacSHA1 = n._createHmacHelper(a) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.algo, a = [], c = []; !function () { function t(t) { for (var e = r.sqrt(t), i = 2; i <= e; i++)if (!(t % i)) return !1; return !0 } function e(t) { return 4294967296 * (t - (0 | t)) | 0 } for (var i = 2, n = 0; n < 64;)t(i) && (n < 8 && (a[n] = e(r.pow(i, .5))), c[n] = e(r.pow(i, 1 / 3)), n++), i++ }(); var h = [], l = s.SHA256 = o.extend({ _doReset: function () { this._hash = new n.init(a.slice(0)) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], l = e[5], f = e[6], u = e[7], d = 0; d < 64; d++) { if (d < 16) h[d] = 0 | t[r + d]; else { var v = h[d - 15], p = (v << 25 | v >>> 7) ^ (v << 14 | v >>> 18) ^ v >>> 3, _ = h[d - 2], y = (_ << 15 | _ >>> 17) ^ (_ << 13 | _ >>> 19) ^ _ >>> 10; h[d] = p + h[d - 7] + y + h[d - 16] } var g = a & l ^ ~a & f, B = i & n ^ i & o ^ n & o, w = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), k = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), S = u + k + g + c[d] + h[d], m = w + B; u = f, f = l, l = a, a = s + S | 0, s = o, o = n, n = i, i = S + m | 0 } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + s | 0, e[4] = e[4] + a | 0, e[5] = e[5] + l | 0, e[6] = e[6] + f | 0, e[7] = e[7] + u | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; return e[n >>> 5] |= 128 << 24 - n % 32, e[(n + 64 >>> 9 << 4) + 14] = r.floor(i / 4294967296), e[(n + 64 >>> 9 << 4) + 15] = i, t.sigBytes = 4 * e.length, this._process(), this._hash }, clone: function () { var t = o.clone.call(this); return t._hash = this._hash.clone(), t } }); e.SHA256 = o._createHelper(l), e.HmacSHA256 = o._createHmacHelper(l) }(Math), function () { function r(t) { return t << 8 & 4278255360 | t >>> 8 & 16711935 } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Utf16 = o.Utf16BE = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n += 2) { var o = r[n >>> 2] >>> 16 - n % 4 * 8 & 65535; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 1] |= t.charCodeAt(i) << 16 - i % 2 * 16; return n.create(e, 2 * r) } }; o.Utf16LE = { stringify: function (t) { for (var e = t.words, i = t.sigBytes, n = [], o = 0; o < i; o += 2) { var s = r(e[o >>> 2] >>> 16 - o % 4 * 8 & 65535); n.push(String.fromCharCode(s)) } return n.join("") }, parse: function (t) { for (var e = t.length, i = [], o = 0; o < e; o++)i[o >>> 1] |= r(t.charCodeAt(o) << 16 - o % 2 * 16); return n.create(i, 2 * e) } } }(), function () { if ("function" == typeof ArrayBuffer) { var r = t, e = r.lib, i = e.WordArray, n = i.init, o = i.init = function (t) { if (t instanceof ArrayBuffer && (t = new Uint8Array(t)), (t instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array) && (t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength)), t instanceof Uint8Array) { for (var r = t.byteLength, e = [], i = 0; i < r; i++)e[i >>> 2] |= t[i] << 24 - i % 4 * 8; n.call(this, e, r) } else n.apply(this, arguments) }; o.prototype = i } }(), function (r) { function e(t, r, e) { return t ^ r ^ e } function i(t, r, e) { return t & r | ~t & e } function n(t, r, e) { return (t | ~r) ^ e } function o(t, r, e) { return t & e | r & ~e } function s(t, r, e) { return t ^ (r | ~e) } function a(t, r) { return t << r | t >>> 32 - r } var c = t, h = c.lib, l = h.WordArray, f = h.Hasher, u = c.algo, d = l.create([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]), v = l.create([5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]), p = l.create([11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]), _ = l.create([8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]), y = l.create([0, 1518500249, 1859775393, 2400959708, 2840853838]), g = l.create([1352829926, 1548603684, 1836072691, 2053994217, 0]), B = u.RIPEMD160 = f.extend({ _doReset: function () { this._hash = l.create([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var c = 0; c < 16; c++) { var h = r + c, l = t[h]; t[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } var f, u, B, w, k, S, m, x, b, H, z = this._hash.words, A = y.words, C = g.words, D = d.words, R = v.words, E = p.words, M = _.words; S = f = z[0], m = u = z[1], x = B = z[2], b = w = z[3], H = k = z[4]; for (var F, c = 0; c < 80; c += 1)F = f + t[r + D[c]] | 0, F += c < 16 ? e(u, B, w) + A[0] : c < 32 ? i(u, B, w) + A[1] : c < 48 ? n(u, B, w) + A[2] : c < 64 ? o(u, B, w) + A[3] : s(u, B, w) + A[4], F |= 0, F = a(F, E[c]), F = F + k | 0, f = k, k = w, w = a(B, 10), B = u, u = F, F = S + t[r + R[c]] | 0, F += c < 16 ? s(m, x, b) + C[0] : c < 32 ? o(m, x, b) + C[1] : c < 48 ? n(m, x, b) + C[2] : c < 64 ? i(m, x, b) + C[3] : e(m, x, b) + C[4], F |= 0, F = a(F, M[c]), F = F + H | 0, S = H, H = b, b = a(x, 10), x = m, m = F; F = z[1] + B + b | 0, z[1] = z[2] + w + H | 0, z[2] = z[3] + k + S | 0, z[3] = z[4] + f + m | 0, z[4] = z[0] + u + x | 0, z[0] = F }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = 16711935 & (e << 8 | e >>> 24) | 4278255360 & (e << 24 | e >>> 8), t.sigBytes = 4 * (r.length + 1), this._process(); for (var n = this._hash, o = n.words, s = 0; s < 5; s++) { var a = o[s]; o[s] = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8) } return n }, clone: function () { var t = f.clone.call(this); return t._hash = this._hash.clone(), t } }); c.RIPEMD160 = f._createHelper(B), c.HmacRIPEMD160 = f._createHmacHelper(B) }(Math), function () { var r = t, e = r.lib, i = e.Base, n = r.enc, o = n.Utf8, s = r.algo; s.HMAC = i.extend({ init: function (t, r) { t = this._hasher = new t.init, "string" == typeof r && (r = o.parse(r)); var e = t.blockSize, i = 4 * e; r.sigBytes > i && (r = t.finalize(r)), r.clamp(); for (var n = this._oKey = r.clone(), s = this._iKey = r.clone(), a = n.words, c = s.words, h = 0; h < e; h++)a[h] ^= 1549556828, c[h] ^= 909522486; n.sigBytes = s.sigBytes = i, this.reset() }, reset: function () { var t = this._hasher; t.reset(), t.update(this._iKey) }, update: function (t) { return this._hasher.update(t), this }, finalize: function (t) { var r = this._hasher, e = r.finalize(t); r.reset(); var i = r.finalize(this._oKey.clone().concat(e)); return i } }) }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.SHA1, a = o.HMAC, c = o.PBKDF2 = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = a.create(e.hasher, t), o = n.create(), s = n.create([1]), c = o.words, h = s.words, l = e.keySize, f = e.iterations; c.length < l;) { var u = i.update(r).finalize(s); i.reset(); for (var d = u.words, v = d.length, p = u, _ = 1; _ < f; _++) { p = i.finalize(p), i.reset(); for (var y = p.words, g = 0; g < v; g++)d[g] ^= y[g] } o.concat(u), h[0]++ } return o.sigBytes = 4 * l, o } }); r.PBKDF2 = function (t, r, e) { return c.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.MD5, a = o.EvpKDF = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = e.hasher.create(), o = n.create(), s = o.words, a = e.keySize, c = e.iterations; s.length < a;) { h && i.update(h); var h = i.update(t).finalize(r); i.reset(); for (var l = 1; l < c; l++)h = i.finalize(h), i.reset(); o.concat(h) } return o.sigBytes = 4 * a, o } }); r.EvpKDF = function (t, r, e) { return a.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.WordArray, n = r.algo, o = n.SHA256, s = n.SHA224 = o.extend({ _doReset: function () { this._hash = new i.init([3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]) }, _doFinalize: function () { var t = o._doFinalize.call(this); return t.sigBytes -= 4, t } }); r.SHA224 = o._createHelper(s), r.HmacSHA224 = o._createHmacHelper(s) }(), function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = e.x64 = {}; s.Word = n.extend({ init: function (t, r) { this.high = t, this.low = r } }), s.WordArray = n.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 8 * t.length }, toX32: function () { for (var t = this.words, r = t.length, e = [], i = 0; i < r; i++) { var n = t[i]; e.push(n.high), e.push(n.low) } return o.create(e, this.sigBytes) }, clone: function () { for (var t = n.clone.call(this), r = t.words = this.words.slice(0), e = r.length, i = 0; i < e; i++)r[i] = r[i].clone(); return t } }) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.x64, a = s.Word, c = e.algo, h = [], l = [], f = []; !function () { for (var t = 1, r = 0, e = 0; e < 24; e++) { h[t + 5 * r] = (e + 1) * (e + 2) / 2 % 64; var i = r % 5, n = (2 * t + 3 * r) % 5; t = i, r = n } for (var t = 0; t < 5; t++)for (var r = 0; r < 5; r++)l[t + 5 * r] = r + (2 * t + 3 * r) % 5 * 5; for (var o = 1, s = 0; s < 24; s++) { for (var c = 0, u = 0, d = 0; d < 7; d++) { if (1 & o) { var v = (1 << d) - 1; v < 32 ? u ^= 1 << v : c ^= 1 << v - 32 } 128 & o ? o = o << 1 ^ 113 : o <<= 1 } f[s] = a.create(c, u) } }(); var u = []; !function () { for (var t = 0; t < 25; t++)u[t] = a.create() }(); var d = c.SHA3 = o.extend({ cfg: o.cfg.extend({ outputLength: 512 }), _doReset: function () { for (var t = this._state = [], r = 0; r < 25; r++)t[r] = new a.init; this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32 }, _doProcessBlock: function (t, r) { for (var e = this._state, i = this.blockSize / 2, n = 0; n < i; n++) { var o = t[r + 2 * n], s = t[r + 2 * n + 1]; o = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), s = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8); var a = e[n]; a.high ^= s, a.low ^= o } for (var c = 0; c < 24; c++) { for (var d = 0; d < 5; d++) { for (var v = 0, p = 0, _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; v ^= a.high, p ^= a.low } var y = u[d]; y.high = v, y.low = p } for (var d = 0; d < 5; d++)for (var g = u[(d + 4) % 5], B = u[(d + 1) % 5], w = B.high, k = B.low, v = g.high ^ (w << 1 | k >>> 31), p = g.low ^ (k << 1 | w >>> 31), _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; a.high ^= v, a.low ^= p } for (var S = 1; S < 25; S++) { var a = e[S], m = a.high, x = a.low, b = h[S]; if (b < 32) var v = m << b | x >>> 32 - b, p = x << b | m >>> 32 - b; else var v = x << b - 32 | m >>> 64 - b, p = m << b - 32 | x >>> 64 - b; var H = u[l[S]]; H.high = v, H.low = p } var z = u[0], A = e[0]; z.high = A.high, z.low = A.low; for (var d = 0; d < 5; d++)for (var _ = 0; _ < 5; _++) { var S = d + 5 * _, a = e[S], C = u[S], D = u[(d + 1) % 5 + 5 * _], R = u[(d + 2) % 5 + 5 * _]; a.high = C.high ^ ~D.high & R.high, a.low = C.low ^ ~D.low & R.low } var a = e[0], E = f[c]; a.high ^= E.high, a.low ^= E.low } }, _doFinalize: function () { var t = this._data, e = t.words, i = (8 * this._nDataBytes, 8 * t.sigBytes), o = 32 * this.blockSize; e[i >>> 5] |= 1 << 24 - i % 32, e[(r.ceil((i + 1) / o) * o >>> 5) - 1] |= 128, t.sigBytes = 4 * e.length, this._process(); for (var s = this._state, a = this.cfg.outputLength / 8, c = a / 8, h = [], l = 0; l < c; l++) { var f = s[l], u = f.high, d = f.low; u = 16711935 & (u << 8 | u >>> 24) | 4278255360 & (u << 24 | u >>> 8), d = 16711935 & (d << 8 | d >>> 24) | 4278255360 & (d << 24 | d >>> 8), h.push(d), h.push(u) } return new n.init(h, a) }, clone: function () { for (var t = o.clone.call(this), r = t._state = this._state.slice(0), e = 0; e < 25; e++)r[e] = r[e].clone(); return t } }); e.SHA3 = o._createHelper(d), e.HmacSHA3 = o._createHmacHelper(d) }(Math), function () { function r() { return s.create.apply(s, arguments) } var e = t, i = e.lib, n = i.Hasher, o = e.x64, s = o.Word, a = o.WordArray, c = e.algo, h = [r(1116352408, 3609767458), r(1899447441, 602891725), r(3049323471, 3964484399), r(3921009573, 2173295548), r(961987163, 4081628472), r(1508970993, 3053834265), r(2453635748, 2937671579), r(2870763221, 3664609560), r(3624381080, 2734883394), r(310598401, 1164996542), r(607225278, 1323610764), r(1426881987, 3590304994), r(1925078388, 4068182383), r(2162078206, 991336113), r(2614888103, 633803317), r(3248222580, 3479774868), r(3835390401, 2666613458), r(4022224774, 944711139), r(264347078, 2341262773), r(604807628, 2007800933), r(770255983, 1495990901), r(1249150122, 1856431235), r(1555081692, 3175218132), r(1996064986, 2198950837), r(2554220882, 3999719339), r(2821834349, 766784016), r(2952996808, 2566594879), r(3210313671, 3203337956), r(3336571891, 1034457026), r(3584528711, 2466948901), r(113926993, 3758326383), r(338241895, 168717936), r(666307205, 1188179964), r(773529912, 1546045734), r(1294757372, 1522805485), r(1396182291, 2643833823), r(1695183700, 2343527390), r(1986661051, 1014477480), r(2177026350, 1206759142), r(2456956037, 344077627), r(2730485921, 1290863460), r(2820302411, 3158454273), r(3259730800, 3505952657), r(3345764771, 106217008), r(3516065817, 3606008344), r(3600352804, 1432725776), r(4094571909, 1467031594), r(275423344, 851169720), r(430227734, 3100823752), r(506948616, 1363258195), r(659060556, 3750685593), r(883997877, 3785050280), r(958139571, 3318307427), r(1322822218, 3812723403), r(1537002063, 2003034995), r(1747873779, 3602036899), r(1955562222, 1575990012), r(2024104815, 1125592928), r(2227730452, 2716904306), r(2361852424, 442776044), r(2428436474, 593698344), r(2756734187, 3733110249), r(3204031479, 2999351573), r(3329325298, 3815920427), r(3391569614, 3928383900), r(3515267271, 566280711), r(3940187606, 3454069534), r(4118630271, 4000239992), r(116418474, 1914138554), r(174292421, 2731055270), r(289380356, 3203993006), r(460393269, 320620315), r(685471733, 587496836), r(852142971, 1086792851), r(1017036298, 365543100), r(1126000580, 2618297676), r(1288033470, 3409855158), r(1501505948, 4234509866), r(1607167915, 987167468), r(1816402316, 1246189591)], l = []; !function () { for (var t = 0; t < 80; t++)l[t] = r() }(); var f = c.SHA512 = n.extend({ _doReset: function () { this._hash = new a.init([new s.init(1779033703, 4089235720), new s.init(3144134277, 2227873595), new s.init(1013904242, 4271175723), new s.init(2773480762, 1595750129), new s.init(1359893119, 2917565137), new s.init(2600822924, 725511199), new s.init(528734635, 4215389547), new s.init(1541459225, 327033209)]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], c = e[5], f = e[6], u = e[7], d = i.high, v = i.low, p = n.high, _ = n.low, y = o.high, g = o.low, B = s.high, w = s.low, k = a.high, S = a.low, m = c.high, x = c.low, b = f.high, H = f.low, z = u.high, A = u.low, C = d, D = v, R = p, E = _, M = y, F = g, P = B, W = w, O = k, U = S, I = m, K = x, X = b, L = H, j = z, N = A, T = 0; T < 80; T++) { var Z = l[T]; if (T < 16) var q = Z.high = 0 | t[r + 2 * T], G = Z.low = 0 | t[r + 2 * T + 1]; else { var J = l[T - 15], $ = J.high, Q = J.low, V = ($ >>> 1 | Q << 31) ^ ($ >>> 8 | Q << 24) ^ $ >>> 7, Y = (Q >>> 1 | $ << 31) ^ (Q >>> 8 | $ << 24) ^ (Q >>> 7 | $ << 25), tt = l[T - 2], rt = tt.high, et = tt.low, it = (rt >>> 19 | et << 13) ^ (rt << 3 | et >>> 29) ^ rt >>> 6, nt = (et >>> 19 | rt << 13) ^ (et << 3 | rt >>> 29) ^ (et >>> 6 | rt << 26), ot = l[T - 7], st = ot.high, at = ot.low, ct = l[T - 16], ht = ct.high, lt = ct.low, G = Y + at, q = V + st + (G >>> 0 < Y >>> 0 ? 1 : 0), G = G + nt, q = q + it + (G >>> 0 < nt >>> 0 ? 1 : 0), G = G + lt, q = q + ht + (G >>> 0 < lt >>> 0 ? 1 : 0); Z.high = q, Z.low = G } var ft = O & I ^ ~O & X, ut = U & K ^ ~U & L, dt = C & R ^ C & M ^ R & M, vt = D & E ^ D & F ^ E & F, pt = (C >>> 28 | D << 4) ^ (C << 30 | D >>> 2) ^ (C << 25 | D >>> 7), _t = (D >>> 28 | C << 4) ^ (D << 30 | C >>> 2) ^ (D << 25 | C >>> 7), yt = (O >>> 14 | U << 18) ^ (O >>> 18 | U << 14) ^ (O << 23 | U >>> 9), gt = (U >>> 14 | O << 18) ^ (U >>> 18 | O << 14) ^ (U << 23 | O >>> 9), Bt = h[T], wt = Bt.high, kt = Bt.low, St = N + gt, mt = j + yt + (St >>> 0 < N >>> 0 ? 1 : 0), St = St + ut, mt = mt + ft + (St >>> 0 < ut >>> 0 ? 1 : 0), St = St + kt, mt = mt + wt + (St >>> 0 < kt >>> 0 ? 1 : 0), St = St + G, mt = mt + q + (St >>> 0 < G >>> 0 ? 1 : 0), xt = _t + vt, bt = pt + dt + (xt >>> 0 < _t >>> 0 ? 1 : 0); j = X, N = L, X = I, L = K, I = O, K = U, U = W + St | 0, O = P + mt + (U >>> 0 < W >>> 0 ? 1 : 0) | 0, P = M, W = F, M = R, F = E, R = C, E = D, D = St + xt | 0, C = mt + bt + (D >>> 0 < St >>> 0 ? 1 : 0) | 0 } v = i.low = v + D, i.high = d + C + (v >>> 0 < D >>> 0 ? 1 : 0), _ = n.low = _ + E, n.high = p + R + (_ >>> 0 < E >>> 0 ? 1 : 0), g = o.low = g + F, o.high = y + M + (g >>> 0 < F >>> 0 ? 1 : 0), w = s.low = w + W, s.high = B + P + (w >>> 0 < W >>> 0 ? 1 : 0), S = a.low = S + U, a.high = k + O + (S >>> 0 < U >>> 0 ? 1 : 0), x = c.low = x + K, c.high = m + I + (x >>> 0 < K >>> 0 ? 1 : 0), H = f.low = H + L, f.high = b + X + (H >>> 0 < L >>> 0 ? 1 : 0), A = u.low = A + N, u.high = z + j + (A >>> 0 < N >>> 0 ? 1 : 0) }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 128 >>> 10 << 5) + 30] = Math.floor(e / 4294967296), r[(i + 128 >>> 10 << 5) + 31] = e, t.sigBytes = 4 * r.length, this._process(); var n = this._hash.toX32(); return n }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t }, blockSize: 32 }); e.SHA512 = n._createHelper(f), e.HmacSHA512 = n._createHmacHelper(f) }(), function () { var r = t, e = r.x64, i = e.Word, n = e.WordArray, o = r.algo, s = o.SHA512, a = o.SHA384 = s.extend({ _doReset: function () { this._hash = new n.init([new i.init(3418070365, 3238371032), new i.init(1654270250, 914150663), new i.init(2438529370, 812702999), new i.init(355462360, 4144912697), new i.init(1731405415, 4290775857), new i.init(2394180231, 1750603025), new i.init(3675008525, 1694076839), new i.init(1203062813, 3204075428)]) }, _doFinalize: function () { var t = s._doFinalize.call(this); return t.sigBytes -= 16, t } }); r.SHA384 = s._createHelper(a), r.HmacSHA384 = s._createHmacHelper(a) }(), t.lib.Cipher || function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = i.BufferedBlockAlgorithm, a = e.enc, c = (a.Utf8, a.Base64), h = e.algo, l = h.EvpKDF, f = i.Cipher = s.extend({ cfg: n.extend(), createEncryptor: function (t, r) { return this.create(this._ENC_XFORM_MODE, t, r) }, createDecryptor: function (t, r) { return this.create(this._DEC_XFORM_MODE, t, r) }, init: function (t, r, e) { this.cfg = this.cfg.extend(e), this._xformMode = t, this._key = r, this.reset() }, reset: function () { s.reset.call(this), this._doReset() }, process: function (t) { return this._append(t), this._process() }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, keySize: 4, ivSize: 4, _ENC_XFORM_MODE: 1, _DEC_XFORM_MODE: 2, _createHelper: function () { function t(t) { return "string" == typeof t ? m : w } return function (r) { return { encrypt: function (e, i, n) { return t(i).encrypt(r, e, i, n) }, decrypt: function (e, i, n) { return t(i).decrypt(r, e, i, n) } } } }() }), u = (i.StreamCipher = f.extend({ _doFinalize: function () { var t = this._process(!0); return t }, blockSize: 1 }), e.mode = {}), d = i.BlockCipherMode = n.extend({ createEncryptor: function (t, r) { return this.Encryptor.create(t, r) }, createDecryptor: function (t, r) { return this.Decryptor.create(t, r) }, init: function (t, r) { this._cipher = t, this._iv = r } }), v = u.CBC = function () { function t(t, e, i) { var n = this._iv; if (n) { var o = n; this._iv = r } else var o = this._prevBlock; for (var s = 0; s < i; s++)t[e + s] ^= o[s] } var e = d.extend(); return e.Encryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize; t.call(this, r, e, n), i.encryptBlock(r, e), this._prevBlock = r.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize, o = r.slice(e, e + n); i.decryptBlock(r, e), t.call(this, r, e, n), this._prevBlock = o } }), e }(), p = e.pad = {}, _ = p.Pkcs7 = { pad: function (t, r) { for (var e = 4 * r, i = e - t.sigBytes % e, n = i << 24 | i << 16 | i << 8 | i, s = [], a = 0; a < i; a += 4)s.push(n); var c = o.create(s, i); t.concat(c) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, y = (i.BlockCipher = f.extend({ cfg: f.cfg.extend({ mode: v, padding: _ }), reset: function () { f.reset.call(this); var t = this.cfg, r = t.iv, e = t.mode; if (this._xformMode == this._ENC_XFORM_MODE) var i = e.createEncryptor; else { var i = e.createDecryptor; this._minBufferSize = 1 } this._mode && this._mode.__creator == i ? this._mode.init(this, r && r.words) : (this._mode = i.call(e, this, r && r.words), this._mode.__creator = i) }, _doProcessBlock: function (t, r) { this._mode.processBlock(t, r) }, _doFinalize: function () { var t = this.cfg.padding; if (this._xformMode == this._ENC_XFORM_MODE) { t.pad(this._data, this.blockSize); var r = this._process(!0) } else { var r = this._process(!0); t.unpad(r) } return r }, blockSize: 4 }), i.CipherParams = n.extend({ init: function (t) { this.mixIn(t) }, toString: function (t) { return (t || this.formatter).stringify(this) } })), g = e.format = {}, B = g.OpenSSL = { stringify: function (t) { var r = t.ciphertext, e = t.salt; if (e) var i = o.create([1398893684, 1701076831]).concat(e).concat(r); else var i = r; return i.toString(c) }, parse: function (t) { var r = c.parse(t), e = r.words; if (1398893684 == e[0] && 1701076831 == e[1]) { var i = o.create(e.slice(2, 4)); e.splice(0, 4), r.sigBytes -= 16 } return y.create({ ciphertext: r, salt: i }) } }, w = i.SerializableCipher = n.extend({ cfg: n.extend({ format: B }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = t.createEncryptor(e, i), o = n.finalize(r), s = n.cfg; return y.create({ ciphertext: o, key: e, iv: s.iv, algorithm: t, mode: s.mode, padding: s.padding, blockSize: t.blockSize, formatter: i.format }) }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = t.createDecryptor(e, i).finalize(r.ciphertext); return n }, _parse: function (t, r) { return "string" == typeof t ? r.parse(t, this) : t } }), k = e.kdf = {}, S = k.OpenSSL = { execute: function (t, r, e, i) { i || (i = o.random(8)); var n = l.create({ keySize: r + e }).compute(t, i), s = o.create(n.words.slice(r), 4 * e); return n.sigBytes = 4 * r, y.create({ key: n, iv: s, salt: i }) } }, m = i.PasswordBasedCipher = w.extend({ cfg: w.cfg.extend({ kdf: S }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = i.kdf.execute(e, t.keySize, t.ivSize); i.iv = n.iv; var o = w.encrypt.call(this, t, r, n.key, i); return o.mixIn(n), o }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = i.kdf.execute(e, t.keySize, t.ivSize, r.salt); i.iv = n.iv; var o = w.decrypt.call(this, t, r, n.key, i); return o } }) }(), t.mode.CFB = function () { function r(t, r, e, i) { var n = this._iv; if (n) { var o = n.slice(0); this._iv = void 0 } else var o = this._prevBlock; i.encryptBlock(o, 0); for (var s = 0; s < e; s++)t[r + s] ^= o[s] } var e = t.lib.BlockCipherMode.extend(); return e.Encryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize; r.call(this, t, e, n, i), this._prevBlock = t.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize, o = t.slice(e, e + n); r.call(this, t, e, n, i), this._prevBlock = o } }), e }(), t.mode.ECB = function () { var r = t.lib.BlockCipherMode.extend(); return r.Encryptor = r.extend({ processBlock: function (t, r) { this._cipher.encryptBlock(t, r) } }), r.Decryptor = r.extend({ processBlock: function (t, r) { this._cipher.decryptBlock(t, r) } }), r }(), t.pad.AnsiX923 = { pad: function (t, r) { var e = t.sigBytes, i = 4 * r, n = i - e % i, o = e + n - 1; t.clamp(), t.words[o >>> 2] |= n << 24 - o % 4 * 8, t.sigBytes += n }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso10126 = { pad: function (r, e) { var i = 4 * e, n = i - r.sigBytes % i; r.concat(t.lib.WordArray.random(n - 1)).concat(t.lib.WordArray.create([n << 24], 1)) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso97971 = { pad: function (r, e) { r.concat(t.lib.WordArray.create([2147483648], 1)), t.pad.ZeroPadding.pad(r, e) }, unpad: function (r) { t.pad.ZeroPadding.unpad(r), r.sigBytes-- } }, t.mode.OFB = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._keystream; n && (o = this._keystream = n.slice(0), this._iv = void 0), e.encryptBlock(o, 0); for (var s = 0; s < i; s++)t[r + s] ^= o[s] } }); return r.Decryptor = e, r }(), t.pad.NoPadding = { pad: function () { }, unpad: function () { } }, function (r) { var e = t, i = e.lib, n = i.CipherParams, o = e.enc, s = o.Hex, a = e.format; a.Hex = { stringify: function (t) { return t.ciphertext.toString(s) }, parse: function (t) { var r = s.parse(t); return n.create({ ciphertext: r }) } } }(), function () { var r = t, e = r.lib, i = e.BlockCipher, n = r.algo, o = [], s = [], a = [], c = [], h = [], l = [], f = [], u = [], d = [], v = []; !function () { for (var t = [], r = 0; r < 256; r++)r < 128 ? t[r] = r << 1 : t[r] = r << 1 ^ 283; for (var e = 0, i = 0, r = 0; r < 256; r++) { var n = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4; n = n >>> 8 ^ 255 & n ^ 99, o[e] = n, s[n] = e; var p = t[e], _ = t[p], y = t[_], g = 257 * t[n] ^ 16843008 * n; a[e] = g << 24 | g >>> 8, c[e] = g << 16 | g >>> 16, h[e] = g << 8 | g >>> 24, l[e] = g; var g = 16843009 * y ^ 65537 * _ ^ 257 * p ^ 16843008 * e; f[n] = g << 24 | g >>> 8, u[n] = g << 16 | g >>> 16, d[n] = g << 8 | g >>> 24, v[n] = g, e ? (e = p ^ t[t[t[y ^ p]]], i ^= t[t[i]]) : e = i = 1 } }(); var p = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], _ = n.AES = i.extend({ _doReset: function () { if (!this._nRounds || this._keyPriorReset !== this._key) { for (var t = this._keyPriorReset = this._key, r = t.words, e = t.sigBytes / 4, i = this._nRounds = e + 6, n = 4 * (i + 1), s = this._keySchedule = [], a = 0; a < n; a++)if (a < e) s[a] = r[a]; else { var c = s[a - 1]; a % e ? e > 6 && a % e == 4 && (c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c]) : (c = c << 8 | c >>> 24, c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c], c ^= p[a / e | 0] << 24), s[a] = s[a - e] ^ c } for (var h = this._invKeySchedule = [], l = 0; l < n; l++) { var a = n - l; if (l % 4) var c = s[a]; else var c = s[a - 4]; l < 4 || a <= 4 ? h[l] = c : h[l] = f[o[c >>> 24]] ^ u[o[c >>> 16 & 255]] ^ d[o[c >>> 8 & 255]] ^ v[o[255 & c]] } } }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._keySchedule, a, c, h, l, o) }, decryptBlock: function (t, r) { var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e, this._doCryptBlock(t, r, this._invKeySchedule, f, u, d, v, s); var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e }, _doCryptBlock: function (t, r, e, i, n, o, s, a) { for (var c = this._nRounds, h = t[r] ^ e[0], l = t[r + 1] ^ e[1], f = t[r + 2] ^ e[2], u = t[r + 3] ^ e[3], d = 4, v = 1; v < c; v++) { var p = i[h >>> 24] ^ n[l >>> 16 & 255] ^ o[f >>> 8 & 255] ^ s[255 & u] ^ e[d++], _ = i[l >>> 24] ^ n[f >>> 16 & 255] ^ o[u >>> 8 & 255] ^ s[255 & h] ^ e[d++], y = i[f >>> 24] ^ n[u >>> 16 & 255] ^ o[h >>> 8 & 255] ^ s[255 & l] ^ e[d++], g = i[u >>> 24] ^ n[h >>> 16 & 255] ^ o[l >>> 8 & 255] ^ s[255 & f] ^ e[d++]; h = p, l = _, f = y, u = g } var p = (a[h >>> 24] << 24 | a[l >>> 16 & 255] << 16 | a[f >>> 8 & 255] << 8 | a[255 & u]) ^ e[d++], _ = (a[l >>> 24] << 24 | a[f >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & h]) ^ e[d++], y = (a[f >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[h >>> 8 & 255] << 8 | a[255 & l]) ^ e[d++], g = (a[u >>> 24] << 24 | a[h >>> 16 & 255] << 16 | a[l >>> 8 & 255] << 8 | a[255 & f]) ^ e[d++]; t[r] = p, t[r + 1] = _, t[r + 2] = y, t[r + 3] = g }, keySize: 8 }); r.AES = i._createHelper(_) }(), function () { + function r(t, r) { var e = (this._lBlock >>> t ^ this._rBlock) & r; this._rBlock ^= e, this._lBlock ^= e << t } function e(t, r) { + var e = (this._rBlock >>> t ^ this._lBlock) & r; this._lBlock ^= e, this._rBlock ^= e << t; + } var i = t, n = i.lib, o = n.WordArray, s = n.BlockCipher, a = i.algo, c = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4], h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32], l = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28], f = [{ 0: 8421888, 268435456: 32768, 536870912: 8421378, 805306368: 2, 1073741824: 512, 1342177280: 8421890, 1610612736: 8389122, 1879048192: 8388608, 2147483648: 514, 2415919104: 8389120, 2684354560: 33280, 2952790016: 8421376, 3221225472: 32770, 3489660928: 8388610, 3758096384: 0, 4026531840: 33282, 134217728: 0, 402653184: 8421890, 671088640: 33282, 939524096: 32768, 1207959552: 8421888, 1476395008: 512, 1744830464: 8421378, 2013265920: 2, 2281701376: 8389120, 2550136832: 33280, 2818572288: 8421376, 3087007744: 8389122, 3355443200: 8388610, 3623878656: 32770, 3892314112: 514, 4160749568: 8388608, 1: 32768, 268435457: 2, 536870913: 8421888, 805306369: 8388608, 1073741825: 8421378, 1342177281: 33280, 1610612737: 512, 1879048193: 8389122, 2147483649: 8421890, 2415919105: 8421376, 2684354561: 8388610, 2952790017: 33282, 3221225473: 514, 3489660929: 8389120, 3758096385: 32770, 4026531841: 0, 134217729: 8421890, 402653185: 8421376, 671088641: 8388608, 939524097: 512, 1207959553: 32768, 1476395009: 8388610, 1744830465: 2, 2013265921: 33282, 2281701377: 32770, 2550136833: 8389122, 2818572289: 514, 3087007745: 8421888, 3355443201: 8389120, 3623878657: 0, 3892314113: 33280, 4160749569: 8421378 }, { 0: 1074282512, 16777216: 16384, 33554432: 524288, 50331648: 1074266128, 67108864: 1073741840, 83886080: 1074282496, 100663296: 1073758208, 117440512: 16, 134217728: 540672, 150994944: 1073758224, 167772160: 1073741824, 184549376: 540688, 201326592: 524304, 218103808: 0, 234881024: 16400, 251658240: 1074266112, 8388608: 1073758208, 25165824: 540688, 41943040: 16, 58720256: 1073758224, 75497472: 1074282512, 92274688: 1073741824, 109051904: 524288, 125829120: 1074266128, 142606336: 524304, 159383552: 0, 176160768: 16384, 192937984: 1074266112, 209715200: 1073741840, 226492416: 540672, 243269632: 1074282496, 260046848: 16400, 268435456: 0, 285212672: 1074266128, 301989888: 1073758224, 318767104: 1074282496, 335544320: 1074266112, 352321536: 16, 369098752: 540688, 385875968: 16384, 402653184: 16400, 419430400: 524288, 436207616: 524304, 452984832: 1073741840, 469762048: 540672, 486539264: 1073758208, 503316480: 1073741824, 520093696: 1074282512, 276824064: 540688, 293601280: 524288, 310378496: 1074266112, 327155712: 16384, 343932928: 1073758208, 360710144: 1074282512, 377487360: 16, 394264576: 1073741824, 411041792: 1074282496, 427819008: 1073741840, 444596224: 1073758224, 461373440: 524304, 478150656: 0, 494927872: 16400, 511705088: 1074266128, 528482304: 540672 }, { 0: 260, 1048576: 0, 2097152: 67109120, 3145728: 65796, 4194304: 65540, 5242880: 67108868, 6291456: 67174660, 7340032: 67174400, 8388608: 67108864, 9437184: 67174656, 10485760: 65792, 11534336: 67174404, 12582912: 67109124, 13631488: 65536, 14680064: 4, 15728640: 256, 524288: 67174656, 1572864: 67174404, 2621440: 0, 3670016: 67109120, 4718592: 67108868, 5767168: 65536, 6815744: 65540, 7864320: 260, 8912896: 4, 9961472: 256, 11010048: 67174400, 12058624: 65796, 13107200: 65792, 14155776: 67109124, 15204352: 67174660, 16252928: 67108864, 16777216: 67174656, 17825792: 65540, 18874368: 65536, 19922944: 67109120, 20971520: 256, 22020096: 67174660, 23068672: 67108868, 24117248: 0, 25165824: 67109124, 26214400: 67108864, 27262976: 4, 28311552: 65792, 29360128: 67174400, 30408704: 260, 31457280: 65796, 32505856: 67174404, 17301504: 67108864, 18350080: 260, 19398656: 67174656, 20447232: 0, 21495808: 65540, 22544384: 67109120, 23592960: 256, 24641536: 67174404, 25690112: 65536, 26738688: 67174660, 27787264: 65796, 28835840: 67108868, 29884416: 67109124, 30932992: 67174400, 31981568: 4, 33030144: 65792 }, { 0: 2151682048, 65536: 2147487808, 131072: 4198464, 196608: 2151677952, 262144: 0, 327680: 4198400, 393216: 2147483712, 458752: 4194368, 524288: 2147483648, 589824: 4194304, 655360: 64, 720896: 2147487744, 786432: 2151678016, 851968: 4160, 917504: 4096, 983040: 2151682112, 32768: 2147487808, 98304: 64, 163840: 2151678016, 229376: 2147487744, 294912: 4198400, 360448: 2151682112, 425984: 0, 491520: 2151677952, 557056: 4096, 622592: 2151682048, 688128: 4194304, 753664: 4160, 819200: 2147483648, 884736: 4194368, 950272: 4198464, 1015808: 2147483712, 1048576: 4194368, 1114112: 4198400, 1179648: 2147483712, 1245184: 0, 1310720: 4160, 1376256: 2151678016, 1441792: 2151682048, 1507328: 2147487808, 1572864: 2151682112, 1638400: 2147483648, 1703936: 2151677952, 1769472: 4198464, 1835008: 2147487744, 1900544: 4194304, 1966080: 64, 2031616: 4096, 1081344: 2151677952, 1146880: 2151682112, 1212416: 0, 1277952: 4198400, 1343488: 4194368, 1409024: 2147483648, 1474560: 2147487808, 1540096: 64, 1605632: 2147483712, 1671168: 4096, 1736704: 2147487744, 1802240: 2151678016, 1867776: 4160, 1933312: 2151682048, 1998848: 4194304, 2064384: 4198464 }, { 0: 128, 4096: 17039360, 8192: 262144, 12288: 536870912, 16384: 537133184, 20480: 16777344, 24576: 553648256, 28672: 262272, 32768: 16777216, 36864: 537133056, 40960: 536871040, 45056: 553910400, 49152: 553910272, 53248: 0, 57344: 17039488, 61440: 553648128, 2048: 17039488, 6144: 553648256, 10240: 128, 14336: 17039360, 18432: 262144, 22528: 537133184, 26624: 553910272, 30720: 536870912, 34816: 537133056, 38912: 0, 43008: 553910400, 47104: 16777344, 51200: 536871040, 55296: 553648128, 59392: 16777216, 63488: 262272, 65536: 262144, 69632: 128, 73728: 536870912, 77824: 553648256, 81920: 16777344, 86016: 553910272, 90112: 537133184, 94208: 16777216, 98304: 553910400, 102400: 553648128, 106496: 17039360, 110592: 537133056, 114688: 262272, 118784: 536871040, 122880: 0, 126976: 17039488, 67584: 553648256, 71680: 16777216, 75776: 17039360, 79872: 537133184, 83968: 536870912, 88064: 17039488, 92160: 128, 96256: 553910272, 100352: 262272, 104448: 553910400, 108544: 0, 112640: 553648128, 116736: 16777344, 120832: 262144, 124928: 537133056, 129024: 536871040 }, { 0: 268435464, 256: 8192, 512: 270532608, 768: 270540808, 1024: 268443648, 1280: 2097152, 1536: 2097160, 1792: 268435456, 2048: 0, 2304: 268443656, 2560: 2105344, 2816: 8, 3072: 270532616, 3328: 2105352, 3584: 8200, 3840: 270540800, 128: 270532608, 384: 270540808, 640: 8, 896: 2097152, 1152: 2105352, 1408: 268435464, 1664: 268443648, 1920: 8200, 2176: 2097160, 2432: 8192, 2688: 268443656, 2944: 270532616, 3200: 0, 3456: 270540800, 3712: 2105344, 3968: 268435456, 4096: 268443648, 4352: 270532616, 4608: 270540808, 4864: 8200, 5120: 2097152, 5376: 268435456, 5632: 268435464, 5888: 2105344, 6144: 2105352, 6400: 0, 6656: 8, 6912: 270532608, 7168: 8192, 7424: 268443656, 7680: 270540800, 7936: 2097160, 4224: 8, 4480: 2105344, 4736: 2097152, 4992: 268435464, 5248: 268443648, 5504: 8200, 5760: 270540808, 6016: 270532608, 6272: 270540800, 6528: 270532616, 6784: 8192, 7040: 2105352, 7296: 2097160, 7552: 0, 7808: 268435456, 8064: 268443656 }, { 0: 1048576, 16: 33555457, 32: 1024, 48: 1049601, 64: 34604033, 80: 0, 96: 1, 112: 34603009, 128: 33555456, 144: 1048577, 160: 33554433, 176: 34604032, 192: 34603008, 208: 1025, 224: 1049600, 240: 33554432, 8: 34603009, 24: 0, 40: 33555457, 56: 34604032, 72: 1048576, 88: 33554433, 104: 33554432, 120: 1025, 136: 1049601, 152: 33555456, 168: 34603008, 184: 1048577, 200: 1024, 216: 34604033, 232: 1, 248: 1049600, 256: 33554432, 272: 1048576, 288: 33555457, 304: 34603009, 320: 1048577, 336: 33555456, 352: 34604032, 368: 1049601, 384: 1025, 400: 34604033, 416: 1049600, 432: 1, 448: 0, 464: 34603008, 480: 33554433, 496: 1024, 264: 1049600, 280: 33555457, 296: 34603009, 312: 1, 328: 33554432, 344: 1048576, 360: 1025, 376: 34604032, 392: 33554433, 408: 34603008, 424: 0, 440: 34604033, 456: 1049601, 472: 1024, 488: 33555456, 504: 1048577 }, { 0: 134219808, 1: 131072, 2: 134217728, 3: 32, 4: 131104, 5: 134350880, 6: 134350848, 7: 2048, 8: 134348800, 9: 134219776, 10: 133120, 11: 134348832, 12: 2080, 13: 0, 14: 134217760, 15: 133152, 2147483648: 2048, 2147483649: 134350880, 2147483650: 134219808, 2147483651: 134217728, 2147483652: 134348800, 2147483653: 133120, 2147483654: 133152, 2147483655: 32, 2147483656: 134217760, 2147483657: 2080, 2147483658: 131104, 2147483659: 134350848, 2147483660: 0, 2147483661: 134348832, 2147483662: 134219776, 2147483663: 131072, 16: 133152, 17: 134350848, 18: 32, 19: 2048, 20: 134219776, 21: 134217760, 22: 134348832, 23: 131072, 24: 0, 25: 131104, 26: 134348800, 27: 134219808, 28: 134350880, 29: 133120, 30: 2080, 31: 134217728, 2147483664: 131072, 2147483665: 2048, 2147483666: 134348832, 2147483667: 133152, 2147483668: 32, 2147483669: 134348800, 2147483670: 134217728, 2147483671: 134219808, 2147483672: 134350880, 2147483673: 134217760, 2147483674: 134219776, 2147483675: 0, 2147483676: 133120, 2147483677: 2080, 2147483678: 131104, 2147483679: 134350848 }], u = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679], d = a.DES = s.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = [], i = 0; i < 56; i++) { var n = c[i] - 1; e[i] = r[n >>> 5] >>> 31 - n % 32 & 1 } for (var o = this._subKeys = [], s = 0; s < 16; s++) { for (var a = o[s] = [], f = l[s], i = 0; i < 24; i++)a[i / 6 | 0] |= e[(h[i] - 1 + f) % 28] << 31 - i % 6, a[4 + (i / 6 | 0)] |= e[28 + (h[i + 24] - 1 + f) % 28] << 31 - i % 6; a[0] = a[0] << 1 | a[0] >>> 31; for (var i = 1; i < 7; i++)a[i] = a[i] >>> 4 * (i - 1) + 3; a[7] = a[7] << 5 | a[7] >>> 27 } for (var u = this._invSubKeys = [], i = 0; i < 16; i++)u[i] = o[15 - i] }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._subKeys) }, decryptBlock: function (t, r) { this._doCryptBlock(t, r, this._invSubKeys) }, _doCryptBlock: function (t, i, n) { this._lBlock = t[i], this._rBlock = t[i + 1], r.call(this, 4, 252645135), r.call(this, 16, 65535), e.call(this, 2, 858993459), e.call(this, 8, 16711935), r.call(this, 1, 1431655765); for (var o = 0; o < 16; o++) { for (var s = n[o], a = this._lBlock, c = this._rBlock, h = 0, l = 0; l < 8; l++)h |= f[l][((c ^ s[l]) & u[l]) >>> 0]; this._lBlock = c, this._rBlock = a ^ h } var d = this._lBlock; this._lBlock = this._rBlock, this._rBlock = d, r.call(this, 1, 1431655765), e.call(this, 8, 16711935), e.call(this, 2, 858993459), r.call(this, 16, 65535), r.call(this, 4, 252645135), t[i] = this._lBlock, t[i + 1] = this._rBlock }, keySize: 2, ivSize: 2, blockSize: 2 }); i.DES = s._createHelper(d); var v = a.TripleDES = s.extend({ _doReset: function () { var t = this._key, r = t.words; this._des1 = d.createEncryptor(o.create(r.slice(0, 2))), this._des2 = d.createEncryptor(o.create(r.slice(2, 4))), this._des3 = d.createEncryptor(o.create(r.slice(4, 6))) }, encryptBlock: function (t, r) { this._des1.encryptBlock(t, r), this._des2.decryptBlock(t, r), this._des3.encryptBlock(t, r) }, decryptBlock: function (t, r) { this._des3.decryptBlock(t, r), this._des2.encryptBlock(t, r), this._des1.decryptBlock(t, r) }, keySize: 6, ivSize: 2, blockSize: 2 }); i.TripleDES = s._createHelper(v) + }(), function () { function r() { for (var t = this._S, r = this._i, e = this._j, i = 0, n = 0; n < 4; n++) { r = (r + 1) % 256, e = (e + t[r]) % 256; var o = t[r]; t[r] = t[e], t[e] = o, i |= t[(t[r] + t[e]) % 256] << 24 - 8 * n } return this._i = r, this._j = e, i } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = o.RC4 = n.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = t.sigBytes, i = this._S = [], n = 0; n < 256; n++)i[n] = n; for (var n = 0, o = 0; n < 256; n++) { var s = n % e, a = r[s >>> 2] >>> 24 - s % 4 * 8 & 255; o = (o + i[n] + a) % 256; var c = i[n]; i[n] = i[o], i[o] = c } this._i = this._j = 0 }, _doProcessBlock: function (t, e) { t[e] ^= r.call(this) }, keySize: 8, ivSize: 0 }); e.RC4 = n._createHelper(s); var a = o.RC4Drop = s.extend({ cfg: s.cfg.extend({ drop: 192 }), _doReset: function () { s._doReset.call(this); for (var t = this.cfg.drop; t > 0; t--)r.call(this) } }); e.RC4Drop = n._createHelper(a) }(), t.mode.CTRGladman = function () { function r(t) { if (255 === (t >> 24 & 255)) { var r = t >> 16 & 255, e = t >> 8 & 255, i = 255 & t; 255 === r ? (r = 0, 255 === e ? (e = 0, 255 === i ? i = 0 : ++i) : ++e) : ++r, t = 0, t += r << 16, t += e << 8, t += i } else t += 1 << 24; return t } function e(t) { return 0 === (t[0] = r(t[0])) && (t[1] = r(t[1])), t } var i = t.lib.BlockCipherMode.extend(), n = i.Encryptor = i.extend({ processBlock: function (t, r) { var i = this._cipher, n = i.blockSize, o = this._iv, s = this._counter; o && (s = this._counter = o.slice(0), this._iv = void 0), e(s); var a = s.slice(0); i.encryptBlock(a, 0); for (var c = 0; c < n; c++)t[r + c] ^= a[c] } }); return i.Decryptor = n, i }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.Rabbit = n.extend({ _doReset: function () { for (var t = this._key.words, e = this.cfg.iv, i = 0; i < 4; i++)t[i] = 16711935 & (t[i] << 8 | t[i] >>> 24) | 4278255360 & (t[i] << 24 | t[i] >>> 8); var n = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], o = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var i = 0; i < 4; i++)r.call(this); for (var i = 0; i < 8; i++)o[i] ^= n[i + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; o[0] ^= h, o[1] ^= f, o[2] ^= l, o[3] ^= u, o[4] ^= h, o[5] ^= f, o[6] ^= l, o[7] ^= u; for (var i = 0; i < 4; i++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.Rabbit = n._createHelper(h) }(), t.mode.CTR = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._counter; n && (o = this._counter = n.slice(0), this._iv = void 0); var s = o.slice(0); e.encryptBlock(s, 0), o[i - 1] = o[i - 1] + 1 | 0; for (var a = 0; a < i; a++)t[r + a] ^= s[a] } }); return r.Decryptor = e, r }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.RabbitLegacy = n.extend({ _doReset: function () { var t = this._key.words, e = this.cfg.iv, i = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], n = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var o = 0; o < 4; o++)r.call(this); for (var o = 0; o < 8; o++)n[o] ^= i[o + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; n[0] ^= h, n[1] ^= f, n[2] ^= l, n[3] ^= u, n[4] ^= h, n[5] ^= f, n[6] ^= l, n[7] ^= u; for (var o = 0; o < 4; o++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.RabbitLegacy = n._createHelper(h) }(), t.pad.ZeroPadding = { pad: function (t, r) { var e = 4 * r; t.clamp(), t.sigBytes += e - (t.sigBytes % e || e) }, unpad: function (t) { for (var r = t.words, e = t.sigBytes - 1; !(r[e >>> 2] >>> 24 - e % 4 * 8 & 255);)e--; t.sigBytes = e + 1 } }, t +}); + const $ = new Env('什么值得买') $.VAL_cookies = $.getdata('chavy_cookie_smzdm') -$.VAl_accounts = $.getdata('chavy_accounts_smzdm') -$.CFG_tokens = 'chavy_tokens_smzdm' !(async () => { - await signapp() + $.CryptoJS = $.isNode() ? require('crypto-js') : CryptoJS + await signweb() + await $.wait(4000) + await signapp() await showmsg() })() .catch((e) => $.logErr(e)) @@ -21,7 +31,6 @@ function signweb() { try { $.web = JSON.parse(data) } catch (e) { - $.token = null $.logErr(e, resp) } finally { resove() @@ -30,34 +39,20 @@ function signweb() { }) } -async function signapp() { - const accounts = getAccounts() - for (let accIdx = 0; accIdx < accounts.length; accIdx++) { - const account = accounts[accIdx] - await loginapp(account) - await $.wait(account.isCached ? 0 : 3000) - await signinapp(account) - await $.wait(3000) - } - $.accounts = accounts -} - -function loginapp(account) { - const tokens = getTokens() - if (tokens[account.acc]) { - account.isCached = true - account.token = tokens[account.acc] - return - } +function signapp() { + const body = getBody() return new Promise((resove) => { - const url = { url: 'https://api.smzdm.com/v1/user/login', headers: {} } - url.body = `user_login=${account.acc}&user_pass=${account.pwd}&f=win` + const url = { + url: 'https://user-api.smzdm.com/checkin', + body, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': $.VAL_cookies + } + } $.post(url, (err, resp, data) => { try { - account.token = $.lodash_get(JSON.parse(data), 'data.token') - const tokens = getTokens() - tokens[account.acc] = account.token - $.setdata(JSON.stringify(tokens), $.CFG_tokens) + $.app = JSON.parse(data) } catch (e) { $.logErr(e, resp) } finally { @@ -67,64 +62,37 @@ function loginapp(account) { }) } -function signinapp(account) { - return new Promise((resove) => { - const url = { url: 'https://api.smzdm.com/v1/user/checkin', headers: {} } - url.body = `f=win&token=${account.token}` - $.post(url, (err, resp, data) => { - try { - const _data = JSON.parse(data) - const errCode = _data.error_code - if (errCode === '0' && _data.data.checkin_status === '0') account.issuc = true - else if (errCode === '0' && _data.data.checkin_status === '1') account.isrepeat = true - else account.msg = _data.error_msg - } catch (e) { - $.logErr(e, resp) - } finally { - resove() - } - }) - }) +function getToken() { + const [, token] = $.VAL_cookies.match(/sess=(.*?);/) + return token } -function getAccounts() { - const accounts = [] - $.VAl_accounts && - $.VAl_accounts.split('\n').forEach((account) => { - let [acc, pwd] = account.split(',') - acc = acc ? acc.trim() : acc - pwd = pwd ? pwd.trim() : pwd - if (acc && pwd) { - accounts.push({ acc, pwd }) - } - }) - return accounts +function getAppSign() { + const t = new Date().getTime() + const sign = 'f=android&sk=1&time=' + t + '&token=' + getToken() + '&v=10.0&weixin=0&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC' + return $.CryptoJS.MD5(sign).toString().toUpperCase() } -function getTokens() { - const tokendat = $.getdata($.CFG_tokens) - return [undefined, null, 'null', 'undefined', ''].includes(tokendat) ? {} : JSON.parse(tokendat) +function getBody() { + const t = new Date().getTime() + const token = getToken() + const sign = getAppSign() + return 'touchstone_event=&v=10.0&sign=' + sign + '&weixin=0&time=' + t + '&sk=1&token=' + token + '&f=android&captcha=' } function showmsg() { return new Promise((resolve) => { $.subt = '' $.desc = [] + console.log($.web) + console.log($.app) $.subt = $.web.error_code === 0 ? 'PC: 成功' : $.web.error_code === 99 ? 'PC: 未登录' : 'PC: 失败' if ($.web.error_code === 0 && $.web.data) { $.desc.push(`累计: ${$.web.data.checkin_num}次, 经验: ${$.web.data.exp}, 金币: ${$.web.data.gold}, 积分: ${$.web.data.point}`) } - if (Array.isArray($.accounts) && $.accounts.length > 0) { - $.desc.push('点击查看详情', '') - let signedCnt = 0 - for (let accIdx = 0; accIdx < $.accounts.length; accIdx++) { - const account = $.accounts[accIdx] - signedCnt += account.issuc || account.isrepeat ? 1 : 0 - $.desc.push(`${account.acc}: ${account.issuc ? '成功' : account.isrepeat ? '重复' : `失败. ${account.msg}`}`) - } - $.subt += `, APP: ${signedCnt}/${$.accounts.length}` - } else { - $.subt += ', APP: 在BoxJs设置签到账号' + if ($.app) { + $.subt += $.app.error_code === '0' ? ', APP: 成功' : ', APP: 失败' + $.desc.push($.app.error_msg) } $.msg($.name, $.subt, $.desc.join('\n')) resolve() @@ -132,4 +100,4 @@ function showmsg() { } // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=t;this.got.post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} From 1c9d0d3f505da1b106578b318871199d10ccad40 Mon Sep 17 00:00:00 2001 From: lowking Date: Mon, 29 Mar 2021 23:08:06 +0800 Subject: [PATCH 062/311] fix setWallpaper for ios14.5 beta5 --- box/chavy.boxjs.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 4e58980d2..d92c0df9e 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1932,11 +1932,11 @@

v{{ver.versio const darkbgimg = hasdark ? hasdark.url : `` const lightbgimg = haslight ? haslight.url : `` this.isDarkMode ? (bgimg = darkbgimg) : (bgimg = lightbgimg) - const bgStyle = [`background-image: linear-gradient(to bottom,rgba(0,0,0,.2) 0,transparent 76px), url(${bgimg})`] + const bgStyle = [`background-image: linear-gradient(to bottom,rgba(0,0,0,.2) 0,transparent 76px), url(${bgimg}?_=${Math.random()})`] document.querySelector('#BG').setAttribute('style', bgStyle.join('; ')) } else { const bgStyle = [ - `background-image: linear-gradient(to bottom,rgba(0,0,0,.2) 0,transparent 76px), url(${this.box.usercfgs.bgimg})` + `background-image: linear-gradient(to bottom,rgba(0,0,0,.2) 0,transparent 76px), url(${this.box.usercfgs.bgimg}?_=${Math.random()})` ] document.querySelector('#BG').setAttribute('style', bgStyle.join('; ')) } From 5c5be192bb894645ba786e33501857d7b8d7f213 Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 30 Mar 2021 01:11:02 +0800 Subject: [PATCH 063/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E5=80=BC=E5=BE=97=E4=B9=B0]:=20=E4=BF=AE=E5=A4=8D=20APP=20?= =?UTF-8?q?=E7=AB=AF=E7=AD=BE=E5=88=B0=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E6=84=9F=E8=B0=A2=20@wangfei021325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smzdm/quanx/smzdm.js | 7 ++----- smzdm/smzdm.js | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/smzdm/quanx/smzdm.js b/smzdm/quanx/smzdm.js index b6012380a..21c3709d7 100644 --- a/smzdm/quanx/smzdm.js +++ b/smzdm/quanx/smzdm.js @@ -67,8 +67,7 @@ function getToken() { return token } -function getAppSign() { - const t = new Date().getTime() +function getAppSign(t) { const sign = 'f=android&sk=1&time=' + t + '&token=' + getToken() + '&v=10.0&weixin=0&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC' return $.CryptoJS.MD5(sign).toString().toUpperCase() } @@ -76,7 +75,7 @@ function getAppSign() { function getBody() { const t = new Date().getTime() const token = getToken() - const sign = getAppSign() + const sign = getAppSign(t) return 'touchstone_event=&v=10.0&sign=' + sign + '&weixin=0&time=' + t + '&sk=1&token=' + token + '&f=android&captcha=' } @@ -84,8 +83,6 @@ function showmsg() { return new Promise((resolve) => { $.subt = '' $.desc = [] - console.log($.web) - console.log($.app) $.subt = $.web.error_code === 0 ? 'PC: 成功' : $.web.error_code === 99 ? 'PC: 未登录' : 'PC: 失败' if ($.web.error_code === 0 && $.web.data) { $.desc.push(`累计: ${$.web.data.checkin_num}次, 经验: ${$.web.data.exp}, 金币: ${$.web.data.gold}, 积分: ${$.web.data.point}`) diff --git a/smzdm/smzdm.js b/smzdm/smzdm.js index b6012380a..21c3709d7 100644 --- a/smzdm/smzdm.js +++ b/smzdm/smzdm.js @@ -67,8 +67,7 @@ function getToken() { return token } -function getAppSign() { - const t = new Date().getTime() +function getAppSign(t) { const sign = 'f=android&sk=1&time=' + t + '&token=' + getToken() + '&v=10.0&weixin=0&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC' return $.CryptoJS.MD5(sign).toString().toUpperCase() } @@ -76,7 +75,7 @@ function getAppSign() { function getBody() { const t = new Date().getTime() const token = getToken() - const sign = getAppSign() + const sign = getAppSign(t) return 'touchstone_event=&v=10.0&sign=' + sign + '&weixin=0&time=' + t + '&sk=1&token=' + token + '&f=android&captcha=' } @@ -84,8 +83,6 @@ function showmsg() { return new Promise((resolve) => { $.subt = '' $.desc = [] - console.log($.web) - console.log($.app) $.subt = $.web.error_code === 0 ? 'PC: 成功' : $.web.error_code === 99 ? 'PC: 未登录' : 'PC: 失败' if ($.web.error_code === 0 && $.web.data) { $.desc.push(`累计: ${$.web.data.checkin_num}次, 经验: ${$.web.data.exp}, 金币: ${$.web.data.gold}, 积分: ${$.web.data.point}`) From 8a12115f56545a4a4bef8a408caeb502e493878e Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 30 Mar 2021 17:40:23 +0800 Subject: [PATCH 064/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[BoxJs]:=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=E5=A3=81?= =?UTF-8?q?=E7=BA=B8=E6=A8=A1=E5=BC=8F=E4=B8=8A=E6=BB=91=E6=89=8B=E5=8A=BF?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index a0ead3546..1ec7aaf73 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.83' +$.version = '0.7.84' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 212dd5367..7246afa8e 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.7.84", + "tags": ["beta"], + "author": "@lowking", + "msg": "更新[BoxJs]: 修复部分情况下壁纸模式上滑手势失效问题", + "notes": [ + { + "name": "修复", + "descs": ["部分情况下壁纸模式上滑手势失效问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.7.83", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index aa09fa794..8c8622792 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.7.84", + "tags": ["beta"], + "author": "@lowking", + "msg": "更新[BoxJs]: 修复部分情况下壁纸模式上滑手势失效问题", + "notes": [ + { + "name": "修复", + "descs": ["部分情况下壁纸模式上滑手势失效问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.7.83", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index a0ead3546..1ec7aaf73 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.7.83' +$.version = '0.7.84' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From b236a674afe6de0e7d52a9fdef2f2315f75840fd Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 30 Mar 2021 20:28:04 +0800 Subject: [PATCH 065/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E5=A8=81=E9=94=8B?= =?UTF-8?q?=E7=BD=91]:=20=E6=81=A2=E5=A4=8D=20APP=20=E7=AB=AF=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=EF=BC=8C=E6=84=9F=E8=B0=A2=20@wangfei021325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.json | 313 +++++++++++++++++++++++++++++++++++-------- feng/README.md | 103 +++----------- feng/feng.cookie.js | 81 +++-------- feng/feng.js | 75 ++++++++++- 4 files changed, 374 insertions(+), 198 deletions(-) diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index 4d81d1b29..c40a886d2 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -9,16 +9,39 @@ "id": "10000", "name": "10000", "keys": [], - "settings": [{ "id": "chavy_mobile_10000", "name": "手机号码", "val": "", "type": "textarea", "placeholder": "18918920000,\n18918920000", "autoGrow": true, "rows": 5, "desc": "以英文逗号分隔多个号码, 可加回车" }], + "settings": [ + { + "id": "chavy_mobile_10000", + "name": "手机号码", + "val": "", + "type": "textarea", + "placeholder": "18918920000,\n18918920000", + "autoGrow": true, + "rows": 5, + "desc": "以英文逗号分隔多个号码, 可加回车" + } + ], "author": "@wangfei021325, @chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/10000/10000.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/10000/10000.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10000.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10000.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10000.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10000.png" + ] }, { "id": "10010", "name": "10010", - "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"], + "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" + ], "settings": [ { "id": "chavy_golottery_10010", "name": "天天抽奖", "val": true, "type": "boolean", "desc": "天天抽奖开关" }, { "id": "chavy_gosign_10010", "name": "签到", "val": true, "type": "boolean", "desc": "签到开关" } @@ -26,16 +49,29 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/10010", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10010.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10010.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10010.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10010.png" + ] }, { "id": "chavyleung.10086", "name": "10086", - "keys": ["chavy_autologin_cmcc", "chavy_getfee_cmcc", "chavy_tokenurl_10086", "chavy_tokenheader_10086", "chavy_signurl_10086", "chavy_signheader_10086"], + "keys": [ + "chavy_autologin_cmcc", + "chavy_getfee_cmcc", + "chavy_tokenurl_10086", + "chavy_tokenheader_10086", + "chavy_signurl_10086", + "chavy_signheader_10086" + ], "author": "@wangfei021325, @chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/10086/10086.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10086.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10086.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10086.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10086.png" + ] }, { "id": "bcz", @@ -44,7 +80,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/bcz", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bcz.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bcz.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bcz.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bcz.png" + ] }, { "id": "BAIDU", @@ -59,7 +98,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/tieba", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/baidu.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/baidu.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/baidu.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/baidu.png" + ] }, { "id": "pagoda", @@ -68,7 +110,10 @@ "author": "@chavyleung", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/pagoda/pagoda.js", "repo": "https://github.com/chavyleung/scripts/blob/master/pagoda", - "icons": ["https://raw.githubusercontent.com/58xinian/icon/master/pagoda_mini.png", "https://raw.githubusercontent.com/58xinian/icon/master/pagoda.png"] + "icons": [ + "https://raw.githubusercontent.com/58xinian/icon/master/pagoda_mini.png", + "https://raw.githubusercontent.com/58xinian/icon/master/pagoda.png" + ] }, { "id": "dbsj", @@ -77,7 +122,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/dbsj", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/dbsj.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/dbsj.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/dbsj.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/dbsj.png" + ] }, { "id": "fandeng", @@ -86,16 +134,28 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/fandeng", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/fandeng.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/fandeng.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/fandeng.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/fandeng.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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/fenqile.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/fenqile.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/fenqile.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/fenqile.png" + ] }, { "id": "gdoil", @@ -104,24 +164,54 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/gdoil", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/gdoil/gdoil.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/gdoil.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/gdoil.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/gdoil.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/gdoil.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_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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/jd/jd.618.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/jd.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/jd.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/jd.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/jd.png" + ] }, { "id": "chavyleung.mgtv", @@ -130,16 +220,28 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/mgtv/mgtv.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/mgtv.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/mgtv.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/mgtv.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/mgtv.png" + ] }, { "id": "chavyleung.meituan", "name": "美团", - "keys": ["chavy_tokenurl_meituan", "chavy_tokenheader_meituan", "chavy_signurl_meituan", "chavy_signheader_meituan", "chavy_signbody_meituan"], + "keys": [ + "chavy_tokenurl_meituan", + "chavy_tokenheader_meituan", + "chavy_signurl_meituan", + "chavy_signheader_meituan", + "chavy_signbody_meituan" + ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/meituan/meituan.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/meituan/meituan.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/meituan.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/meituan.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/meituan.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/meituan.png" + ] }, { "id": "qtt", @@ -148,7 +250,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/qtt", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/qtt/qtt.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/qtt.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/qtt.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/qtt.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/qtt.png" + ] }, { "id": "qmkg", @@ -157,7 +262,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/qmkg", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/qmkg.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/qmkg.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/qmkg.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/qmkg.png" + ] }, { "id": "smzdm", @@ -166,7 +274,10 @@ "author": "@wangfei021325, @chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/smzdm", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/smzdm/smzdm.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/smzdm.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/smzdm.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/smzdm.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/smzdm.png" + ] }, { "id": "sfexpress", @@ -175,7 +286,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/sfexpress", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/sfexpress.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/sfexpress.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/sfexpress.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/sfexpress.png" + ] }, { "id": "flyertea", @@ -184,26 +298,54 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/flyertea", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/flyertea/flyertea.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/flyertea.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/flyertea.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/flyertea.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/flyertea.png" + ] }, { "id": "chavyleung.suning", "name": "苏宁易购", "settings": [{ "id": "chavy_logflag_suning", "name": "响应日志", "val": false, "type": "boolean", "desc": "是否输出响应返回体" }], - "keys": ["chavy_login_url_suning", "chavy_login_body_suning", "chavy_login_header_suning", "chavy_sign_url_suning", "chavy_sign_header_suning", "chavy_signweb_url_suning", "snyg_userTokenKey", "chavy_signweb_header_suning", "chavy_signgame_url_suning", "chavy_signgame_header_suning", "chavy_signgetgame_url_suning", "chavy_signgetgame_header_suning"], + "keys": [ + "chavy_login_url_suning", + "chavy_login_body_suning", + "chavy_login_header_suning", + "chavy_sign_url_suning", + "chavy_sign_header_suning", + "chavy_signweb_url_suning", + "snyg_userTokenKey", + "chavy_signweb_header_suning", + "chavy_signgame_url_suning", + "chavy_signgame_header_suning", + "chavy_signgetgame_url_suning", + "chavy_signgetgame_header_suning" + ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/suning/suning.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/suning.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/suning.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/suning.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/suning.png" + ] }, { "id": "videoqq", "name": "腾讯视频", - "keys": ["chavy_cookie_videoqq", "chavy_auth_url_videoqq", "chavy_auth_header_videoqq", "chavy_msign_url_videoqq", "chavy_msign_header_videoqq"], + "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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/videoqq/videoqq.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/videoqq.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/videoqq.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/videoqq.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/videoqq.png" + ] }, { "id": "wanda", @@ -212,7 +354,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/wanda", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wanda.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wanda.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wanda.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wanda.png" + ] }, { "id": "ithome", @@ -221,7 +366,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/ithome", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/ithome/ithome.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/ithome.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/ithome.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/ithome.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/ithome.png" + ] }, { "id": "nfzm", @@ -230,7 +378,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/nfzm", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/nfzm/nfzm.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/nfzm.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/nfzm.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/nfzm.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/nfzm.png" + ] }, { "id": "NeteaseNews", @@ -239,7 +390,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/neteasenews", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/neteasenews/neteasenews.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/neteasenews.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/neteasenews.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/neteasenews.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/neteasenews.png" + ] }, { "id": "NeteaseMusic", @@ -247,22 +401,33 @@ "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": "每次重试间隔时间 (毫秒)!" } + { + "id": "CFG_neteasemusic_retryInterval", + "name": "重试间隔 (毫秒)", + "val": 500, + "type": "text", + "desc": "每次重试间隔时间 (毫秒)!" + } ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/neteasemusic", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/neteasemusic.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/neteasemusic.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/neteasemusic.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/neteasemusic.png" + ] }, { "id": "feng", "name": "威锋网", - "settings": [{ "id": "chavy_accounts_feng", "name": "威锋账号", "val": "", "type": "textarea", "placeholder": "账号,密码 (回车) 账号,密码", "autoGrow": true, "rows": 5, "desc": "以英文逗号分隔账号与密码, 回车添加多个账号" }], - "keys": [], + "keys": ["chavy_login_feng"], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/feng", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/feng.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/feng.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/feng.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/feng.png" + ] }, { "id": "NoteYoudao", @@ -272,9 +437,19 @@ "repo": "https://github.com/chavyleung/scripts/tree/master/noteyoudao", "url": "https://apps.apple.com/cn/app/有道云笔记-扫描王版/id450748070", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/noteyoudao/noteyoudao.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/noteyoudao.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/noteyoudao.png"], + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/noteyoudao.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/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 }] + "rewrites": [ + { + "type": "request", + "pattern": "^https://note.youdao.com/yws/mapi/user?method=checkin", + "script": "noteyoudao.cookie.js", + "body": true + } + ] }, { "id": "zxhc", @@ -283,7 +458,10 @@ "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/zxhc", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/zxhc/zxhc.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/zxhc.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/zxhc.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/zxhc.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/zxhc.png" + ] }, { "id": "zimuzu", @@ -292,7 +470,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/zimuzu", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/zimuzu.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/zimuzu.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/zimuzu.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/zimuzu.png" + ] }, { "id": "AcFun", @@ -301,7 +482,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/acfun", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/acfun.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/acfun.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/acfun.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/acfun.png" + ] }, { "id": "ApkTw", @@ -311,9 +495,14 @@ "repo": "https://github.com/chavyleung/scripts/tree/master/apktw", "url": "https://apk.tw/", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/apktw.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/apktw.png"], + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/apktw.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/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 }] + "rewrites": [ + { "type": "request", "pattern": "^https://apk.tw/member.php(.*?)action=login", "script": "apktw.cookie.js", "body": true } + ] }, { "id": "chavyleung.bilibili.live", @@ -322,7 +511,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/bilibili/bilibili.js", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bilibili.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bilibili.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bilibili.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bilibili.png" + ] }, { "id": "V2EX", @@ -331,7 +523,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/v2ex", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/v2ex.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/v2ex.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/v2ex.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/v2ex.png" + ] }, { "id": "WPS", @@ -341,7 +536,10 @@ "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/wps", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.js", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wps.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wps.png"] + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wps.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wps.png" + ] }, { "id": "ximalaya", @@ -349,7 +547,10 @@ "keys": ["chavy_cookie_ximalaya"], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/ximalaya", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/ximalaya.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/ximalaya.png"], + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/ximalaya.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/ximalaya.png" + ], "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/ximalaya/ximalaya.js" }, { @@ -358,7 +559,10 @@ "keys": ["chavy_cookie_rrtv"], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/rrtv", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/rrtv.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/rrtv.png"], + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/rrtv.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/rrtv.png" + ], "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/rrtv/rrtv.js" }, { @@ -367,7 +571,10 @@ "keys": ["chavy_sign_url_everphoto", "chavy_sign_header_everphoto"], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/everphoto", - "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/everphoto.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/everphoto.png"], + "icons": [ + "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/everphoto.png", + "https://raw.githubusercontent.com/Orz-3/mini/master/Color/everphoto.png" + ], "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js" } ] diff --git a/feng/README.md b/feng/README.md index c10a3ef27..288d21568 100644 --- a/feng/README.md +++ b/feng/README.md @@ -1,25 +1,13 @@ -# 威锋网 - -> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 - -> 注意了威锋网只能在一处登录, 如果你手机上登录了, 其他地方的登录会话会被踢掉 (重新登录需要重新获取 Cookie) - -> 2020.1.11 QuanX 在`190`版本开始, 获取 Cookie 方式需要从`script-response-body`改为`script-request-header` - -> 2020.2.6 威锋加了验证, 弃坑 - -> 2020.2.10 恢复签到: 增加参数签名 - -> 2020.2.11 威锋加了校验, 偶尔能签, 选择性弃坑吧! +# 威锋网 (APP) ## 配置 (Surge) ```properties [MITM] -*.feng.com +49.234.36.200:9091 [Script] -http-request ^https:\/\/(www\.)?feng\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js +Rewrite: feng = type=http-request,pattern=^http:\/\/49.234.36.200:9091\/v1\/auth\/signin,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js,requires-body=true cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js ``` @@ -27,84 +15,35 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr ```properties [MITM] -*.feng.com +49.234.36.200:9091 [rewrite_local] -# 189及以前版本 -^https:\/\/(www\.)?feng\.com\/?.? url script-response-body feng.cookie.js -# 190及以后版本 -^https:\/\/(www\.)?feng\.com\/?.? url script-request-header feng.cookie.js +^http:\/\/49.234.36.200:9091\/v1\/auth\/signin url script-response-body https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js [task_local] -1 0 * * * feng.js +1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js ``` -## 说明 - -1. 先在浏览器登录 `(先登录! 先登录! 先登录!)` - - 如果你找不到登录的入口: 随便找个帖子做个“回帖”的动作, 会提示你登录的. - - 可以试试: https://www.feng.com/newthread -2. 先把`*.feng.com`加到`[MITM]` -3. 再配置重写规则: - - Surge: 把两条远程脚本放到`[Script]` - - QuanX: 把`feng.cookie.js`和`feng.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) -4. 打开浏览器访问: https://www.feng.com -5. 系统提示: `获取Cookie: 成功` - - 如果一直取不到 Cookie, 请尝试一切你想到的姿势, 如: - - 访问: https://www.feng.com/newthread - - 然后刷新下 -6. 最后就可以把第 1 条脚本注释掉了 - -> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. - -> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次. - -## 常见问题 - -1. 无法写入 Cookie - - - 检查 Surge 系统通知权限放开了没 - - 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴) +## 配置 (Loon) -2. 写入 Cookie 成功, 但签到不成功 - - - 看看是不是在登录前就写入 Cookie 了 - - 如果是,请确保在登录成功后,再尝试写入 Cookie - -3. 为什么有时成功有时失败 - - - 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败) - - 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学): - - - `Surge`配置: - - ```properties - # 没有什么是一顿饭解决不了的: - cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次 - # 如果有,那就两顿: - cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次 - # 实在不行,三顿也能接受: - cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次 +```properties +[MITM] +49.234.36.200:9091 - # 再粗暴点,直接: - cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次 - ``` +[rewrite_local] +http-request ^http:\/\/49.234.36.200:9091\/v1\/auth\/signin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js, requires-body=true, tag=Rewrite: feng - - `QuanX`配置: +[task_local] +cron "1 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js +``` - ```properties - [task_local] - 1 0 * * * xxx.js # 每天00:01执行一次 - 2 0 * * * xxx.js # 每天00:02执行一次 - 3 0 * * * xxx.js # 每天00:03执行一次 +## 说明 - */60 * * * * xxx.js # 每60分执行一次 - ``` +1. 配置重写 +2. 在 `威锋网` APP 下使用 账号密码 方式登录 +3. 提示 `获取会话: 成功` +4. 注释重写 ## 感谢 -[@NobyDa](https://github.com/NobyDa) - -[@lhie1](https://github.com/lhie1) - -[@ConnersHua](https://github.com/ConnersHua) +[@wangfei021325](https://github.com/wangfei021325) diff --git a/feng/feng.cookie.js b/feng/feng.cookie.js index c20456343..d6dd61a41 100644 --- a/feng/feng.cookie.js +++ b/feng/feng.cookie.js @@ -1,61 +1,20 @@ -const cookieName = '威锋网' -const cookieKey = 'chavy_cookie_feng' -const chavy = init() -const cookieVal = $request.headers['Cookie'] -if (cookieVal.indexOf('userInfo') >= 0) { - if (cookieVal) { - if (chavy.setdata(cookieVal, cookieKey)) { - chavy.msg(`${cookieName}`, '获取Cookie: 成功', '') - chavy.log(`[${cookieName}] 获取Cookie: 成功, cookie: ${cookieVal}`) - } - } -} else { - let subTitle = '获取Cookie: 失败' - let detail = `请确保在已登录状态下获取Cookie` - chavy.msg(`${cookieName}`, subTitle, detail) - chavy.log(`[${cookieName}] ${subTitle}, cookie: ${cookieVal}`) -} -function init() { - isSurge = () => { - return undefined === this.$httpClient ? false : true - } - isQuanX = () => { - return undefined === this.$task ? false : true - } - getdata = (key) => { - if (isSurge()) return $persistentStore.read(key) - if (isQuanX()) return $prefs.valueForKey(key) - } - setdata = (key, val) => { - if (isSurge()) return $persistentStore.write(key, val) - if (isQuanX()) return $prefs.setValueForKey(key, val) - } - msg = (title, subtitle, body) => { - if (isSurge()) $notification.post(title, subtitle, body) - if (isQuanX()) $notify(title, subtitle, body) - } - log = (message) => console.log(message) - get = (url, cb) => { - if (isSurge()) { - $httpClient.get(url, cb) - } - if (isQuanX()) { - url.method = 'GET' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - post = (url, cb) => { - if (isSurge()) { - $httpClient.post(url, cb) - } - if (isQuanX()) { - url.method = 'POST' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - done = (value = {}) => { - $done(value) - } - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } -} -chavy.done() +const $ = new Env('威锋网') +$.KEY_login = 'chavy_login_feng' + +!(async () => { + const session = {} + session.url = $request.url + session.body = $request.body + session.headers = $request.headers + if ($.setdata(JSON.stringify(session), $.KEY_login)) { + $.subt = `获取会话: 成功!` + } else { + $.subt = `获取会话: 失败!` + } + $.msg($.name, $.subt, $.desc) +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done) + +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} diff --git a/feng/feng.js b/feng/feng.js index 8bc3659eb..7367287a3 100644 --- a/feng/feng.js +++ b/feng/feng.js @@ -1,6 +1,77 @@ +// prettier-ignore +!function (t, r) { "object" == typeof exports ? module.exports = exports = r() : "function" == typeof define && define.amd ? define([], r) : t.CryptoJS = r() }(this, function () { + var t = t || function (t, r) { var e = Object.create || function () { function t() { } return function (r) { var e; return t.prototype = r, e = new t, t.prototype = null, e } }(), i = {}, n = i.lib = {}, o = n.Base = function () { return { extend: function (t) { var r = e(this); return t && r.mixIn(t), r.hasOwnProperty("init") && this.init !== r.init || (r.init = function () { r.$super.init.apply(this, arguments) }), r.init.prototype = r, r.$super = this, r }, create: function () { var t = this.extend(); return t.init.apply(t, arguments), t }, init: function () { }, mixIn: function (t) { for (var r in t) t.hasOwnProperty(r) && (this[r] = t[r]); t.hasOwnProperty("toString") && (this.toString = t.toString) }, clone: function () { return this.init.prototype.extend(this) } } }(), s = n.WordArray = o.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 4 * t.length }, toString: function (t) { return (t || c).stringify(this) }, concat: function (t) { var r = this.words, e = t.words, i = this.sigBytes, n = t.sigBytes; if (this.clamp(), i % 4) for (var o = 0; o < n; o++) { var s = e[o >>> 2] >>> 24 - o % 4 * 8 & 255; r[i + o >>> 2] |= s << 24 - (i + o) % 4 * 8 } else for (var o = 0; o < n; o += 4)r[i + o >>> 2] = e[o >>> 2]; return this.sigBytes += n, this }, clamp: function () { var r = this.words, e = this.sigBytes; r[e >>> 2] &= 4294967295 << 32 - e % 4 * 8, r.length = t.ceil(e / 4) }, clone: function () { var t = o.clone.call(this); return t.words = this.words.slice(0), t }, random: function (r) { for (var e, i = [], n = function (r) { var r = r, e = 987654321, i = 4294967295; return function () { e = 36969 * (65535 & e) + (e >> 16) & i, r = 18e3 * (65535 & r) + (r >> 16) & i; var n = (e << 16) + r & i; return n /= 4294967296, n += .5, n * (t.random() > .5 ? 1 : -1) } }, o = 0; o < r; o += 4) { var a = n(4294967296 * (e || t.random())); e = 987654071 * a(), i.push(4294967296 * a() | 0) } return new s.init(i, r) } }), a = i.enc = {}, c = a.Hex = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push((o >>> 4).toString(16)), i.push((15 & o).toString(16)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i += 2)e[i >>> 3] |= parseInt(t.substr(i, 2), 16) << 24 - i % 8 * 4; return new s.init(e, r / 2) } }, h = a.Latin1 = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 2] |= (255 & t.charCodeAt(i)) << 24 - i % 4 * 8; return new s.init(e, r) } }, l = a.Utf8 = { stringify: function (t) { try { return decodeURIComponent(escape(h.stringify(t))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, parse: function (t) { return h.parse(unescape(encodeURIComponent(t))) } }, f = n.BufferedBlockAlgorithm = o.extend({ reset: function () { this._data = new s.init, this._nDataBytes = 0 }, _append: function (t) { "string" == typeof t && (t = l.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes }, _process: function (r) { var e = this._data, i = e.words, n = e.sigBytes, o = this.blockSize, a = 4 * o, c = n / a; c = r ? t.ceil(c) : t.max((0 | c) - this._minBufferSize, 0); var h = c * o, l = t.min(4 * h, n); if (h) { for (var f = 0; f < h; f += o)this._doProcessBlock(i, f); var u = i.splice(0, h); e.sigBytes -= l } return new s.init(u, l) }, clone: function () { var t = o.clone.call(this); return t._data = this._data.clone(), t }, _minBufferSize: 0 }), u = (n.Hasher = f.extend({ cfg: o.extend(), init: function (t) { this.cfg = this.cfg.extend(t), this.reset() }, reset: function () { f.reset.call(this), this._doReset() }, update: function (t) { return this._append(t), this._process(), this }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, blockSize: 16, _createHelper: function (t) { return function (r, e) { return new t.init(e).finalize(r) } }, _createHmacHelper: function (t) { return function (r, e) { return new u.HMAC.init(t, e).finalize(r) } } }), i.algo = {}); return i }(Math); return function () { function r(t, r, e) { for (var i = [], o = 0, s = 0; s < r; s++)if (s % 4) { var a = e[t.charCodeAt(s - 1)] << s % 4 * 2, c = e[t.charCodeAt(s)] >>> 6 - s % 4 * 2; i[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ } return n.create(i, o) } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Base64 = { stringify: function (t) { var r = t.words, e = t.sigBytes, i = this._map; t.clamp(); for (var n = [], o = 0; o < e; o += 3)for (var s = r[o >>> 2] >>> 24 - o % 4 * 8 & 255, a = r[o + 1 >>> 2] >>> 24 - (o + 1) % 4 * 8 & 255, c = r[o + 2 >>> 2] >>> 24 - (o + 2) % 4 * 8 & 255, h = s << 16 | a << 8 | c, l = 0; l < 4 && o + .75 * l < e; l++)n.push(i.charAt(h >>> 6 * (3 - l) & 63)); var f = i.charAt(64); if (f) for (; n.length % 4;)n.push(f); return n.join("") }, parse: function (t) { var e = t.length, i = this._map, n = this._reverseMap; if (!n) { n = this._reverseMap = []; for (var o = 0; o < i.length; o++)n[i.charCodeAt(o)] = o } var s = i.charAt(64); if (s) { var a = t.indexOf(s); a !== -1 && (e = a) } return r(t, e, n) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } }(), function (r) { function e(t, r, e, i, n, o, s) { var a = t + (r & e | ~r & i) + n + s; return (a << o | a >>> 32 - o) + r } function i(t, r, e, i, n, o, s) { var a = t + (r & i | e & ~i) + n + s; return (a << o | a >>> 32 - o) + r } function n(t, r, e, i, n, o, s) { var a = t + (r ^ e ^ i) + n + s; return (a << o | a >>> 32 - o) + r } function o(t, r, e, i, n, o, s) { var a = t + (e ^ (r | ~i)) + n + s; return (a << o | a >>> 32 - o) + r } var s = t, a = s.lib, c = a.WordArray, h = a.Hasher, l = s.algo, f = []; !function () { for (var t = 0; t < 64; t++)f[t] = 4294967296 * r.abs(r.sin(t + 1)) | 0 }(); var u = l.MD5 = h.extend({ _doReset: function () { this._hash = new c.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (t, r) { for (var s = 0; s < 16; s++) { var a = r + s, c = t[a]; t[a] = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8) } var h = this._hash.words, l = t[r + 0], u = t[r + 1], d = t[r + 2], v = t[r + 3], p = t[r + 4], _ = t[r + 5], y = t[r + 6], g = t[r + 7], B = t[r + 8], w = t[r + 9], k = t[r + 10], S = t[r + 11], m = t[r + 12], x = t[r + 13], b = t[r + 14], H = t[r + 15], z = h[0], A = h[1], C = h[2], D = h[3]; z = e(z, A, C, D, l, 7, f[0]), D = e(D, z, A, C, u, 12, f[1]), C = e(C, D, z, A, d, 17, f[2]), A = e(A, C, D, z, v, 22, f[3]), z = e(z, A, C, D, p, 7, f[4]), D = e(D, z, A, C, _, 12, f[5]), C = e(C, D, z, A, y, 17, f[6]), A = e(A, C, D, z, g, 22, f[7]), z = e(z, A, C, D, B, 7, f[8]), D = e(D, z, A, C, w, 12, f[9]), C = e(C, D, z, A, k, 17, f[10]), A = e(A, C, D, z, S, 22, f[11]), z = e(z, A, C, D, m, 7, f[12]), D = e(D, z, A, C, x, 12, f[13]), C = e(C, D, z, A, b, 17, f[14]), A = e(A, C, D, z, H, 22, f[15]), z = i(z, A, C, D, u, 5, f[16]), D = i(D, z, A, C, y, 9, f[17]), C = i(C, D, z, A, S, 14, f[18]), A = i(A, C, D, z, l, 20, f[19]), z = i(z, A, C, D, _, 5, f[20]), D = i(D, z, A, C, k, 9, f[21]), C = i(C, D, z, A, H, 14, f[22]), A = i(A, C, D, z, p, 20, f[23]), z = i(z, A, C, D, w, 5, f[24]), D = i(D, z, A, C, b, 9, f[25]), C = i(C, D, z, A, v, 14, f[26]), A = i(A, C, D, z, B, 20, f[27]), z = i(z, A, C, D, x, 5, f[28]), D = i(D, z, A, C, d, 9, f[29]), C = i(C, D, z, A, g, 14, f[30]), A = i(A, C, D, z, m, 20, f[31]), z = n(z, A, C, D, _, 4, f[32]), D = n(D, z, A, C, B, 11, f[33]), C = n(C, D, z, A, S, 16, f[34]), A = n(A, C, D, z, b, 23, f[35]), z = n(z, A, C, D, u, 4, f[36]), D = n(D, z, A, C, p, 11, f[37]), C = n(C, D, z, A, g, 16, f[38]), A = n(A, C, D, z, k, 23, f[39]), z = n(z, A, C, D, x, 4, f[40]), D = n(D, z, A, C, l, 11, f[41]), C = n(C, D, z, A, v, 16, f[42]), A = n(A, C, D, z, y, 23, f[43]), z = n(z, A, C, D, w, 4, f[44]), D = n(D, z, A, C, m, 11, f[45]), C = n(C, D, z, A, H, 16, f[46]), A = n(A, C, D, z, d, 23, f[47]), z = o(z, A, C, D, l, 6, f[48]), D = o(D, z, A, C, g, 10, f[49]), C = o(C, D, z, A, b, 15, f[50]), A = o(A, C, D, z, _, 21, f[51]), z = o(z, A, C, D, m, 6, f[52]), D = o(D, z, A, C, v, 10, f[53]), C = o(C, D, z, A, k, 15, f[54]), A = o(A, C, D, z, u, 21, f[55]), z = o(z, A, C, D, B, 6, f[56]), D = o(D, z, A, C, H, 10, f[57]), C = o(C, D, z, A, y, 15, f[58]), A = o(A, C, D, z, x, 21, f[59]), z = o(z, A, C, D, p, 6, f[60]), D = o(D, z, A, C, S, 10, f[61]), C = o(C, D, z, A, d, 15, f[62]), A = o(A, C, D, z, w, 21, f[63]), h[0] = h[0] + z | 0, h[1] = h[1] + A | 0, h[2] = h[2] + C | 0, h[3] = h[3] + D | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; e[n >>> 5] |= 128 << 24 - n % 32; var o = r.floor(i / 4294967296), s = i; e[(n + 64 >>> 9 << 4) + 15] = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), e[(n + 64 >>> 9 << 4) + 14] = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8), t.sigBytes = 4 * (e.length + 1), this._process(); for (var a = this._hash, c = a.words, h = 0; h < 4; h++) { var l = c[h]; c[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } return a }, clone: function () { var t = h.clone.call(this); return t._hash = this._hash.clone(), t } }); s.MD5 = h._createHelper(u), s.HmacMD5 = h._createHmacHelper(u) }(Math), function () { var r = t, e = r.lib, i = e.WordArray, n = e.Hasher, o = r.algo, s = [], a = o.SHA1 = n.extend({ _doReset: function () { this._hash = new i.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], a = e[3], c = e[4], h = 0; h < 80; h++) { if (h < 16) s[h] = 0 | t[r + h]; else { var l = s[h - 3] ^ s[h - 8] ^ s[h - 14] ^ s[h - 16]; s[h] = l << 1 | l >>> 31 } var f = (i << 5 | i >>> 27) + c + s[h]; f += h < 20 ? (n & o | ~n & a) + 1518500249 : h < 40 ? (n ^ o ^ a) + 1859775393 : h < 60 ? (n & o | n & a | o & a) - 1894007588 : (n ^ o ^ a) - 899497514, c = a, a = o, o = n << 30 | n >>> 2, n = i, i = f } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + a | 0, e[4] = e[4] + c | 0 }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; return r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = Math.floor(e / 4294967296), r[(i + 64 >>> 9 << 4) + 15] = e, t.sigBytes = 4 * r.length, this._process(), this._hash }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t } }); r.SHA1 = n._createHelper(a), r.HmacSHA1 = n._createHmacHelper(a) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.algo, a = [], c = []; !function () { function t(t) { for (var e = r.sqrt(t), i = 2; i <= e; i++)if (!(t % i)) return !1; return !0 } function e(t) { return 4294967296 * (t - (0 | t)) | 0 } for (var i = 2, n = 0; n < 64;)t(i) && (n < 8 && (a[n] = e(r.pow(i, .5))), c[n] = e(r.pow(i, 1 / 3)), n++), i++ }(); var h = [], l = s.SHA256 = o.extend({ _doReset: function () { this._hash = new n.init(a.slice(0)) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], l = e[5], f = e[6], u = e[7], d = 0; d < 64; d++) { if (d < 16) h[d] = 0 | t[r + d]; else { var v = h[d - 15], p = (v << 25 | v >>> 7) ^ (v << 14 | v >>> 18) ^ v >>> 3, _ = h[d - 2], y = (_ << 15 | _ >>> 17) ^ (_ << 13 | _ >>> 19) ^ _ >>> 10; h[d] = p + h[d - 7] + y + h[d - 16] } var g = a & l ^ ~a & f, B = i & n ^ i & o ^ n & o, w = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), k = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), S = u + k + g + c[d] + h[d], m = w + B; u = f, f = l, l = a, a = s + S | 0, s = o, o = n, n = i, i = S + m | 0 } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + s | 0, e[4] = e[4] + a | 0, e[5] = e[5] + l | 0, e[6] = e[6] + f | 0, e[7] = e[7] + u | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; return e[n >>> 5] |= 128 << 24 - n % 32, e[(n + 64 >>> 9 << 4) + 14] = r.floor(i / 4294967296), e[(n + 64 >>> 9 << 4) + 15] = i, t.sigBytes = 4 * e.length, this._process(), this._hash }, clone: function () { var t = o.clone.call(this); return t._hash = this._hash.clone(), t } }); e.SHA256 = o._createHelper(l), e.HmacSHA256 = o._createHmacHelper(l) }(Math), function () { function r(t) { return t << 8 & 4278255360 | t >>> 8 & 16711935 } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Utf16 = o.Utf16BE = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n += 2) { var o = r[n >>> 2] >>> 16 - n % 4 * 8 & 65535; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 1] |= t.charCodeAt(i) << 16 - i % 2 * 16; return n.create(e, 2 * r) } }; o.Utf16LE = { stringify: function (t) { for (var e = t.words, i = t.sigBytes, n = [], o = 0; o < i; o += 2) { var s = r(e[o >>> 2] >>> 16 - o % 4 * 8 & 65535); n.push(String.fromCharCode(s)) } return n.join("") }, parse: function (t) { for (var e = t.length, i = [], o = 0; o < e; o++)i[o >>> 1] |= r(t.charCodeAt(o) << 16 - o % 2 * 16); return n.create(i, 2 * e) } } }(), function () { if ("function" == typeof ArrayBuffer) { var r = t, e = r.lib, i = e.WordArray, n = i.init, o = i.init = function (t) { if (t instanceof ArrayBuffer && (t = new Uint8Array(t)), (t instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array) && (t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength)), t instanceof Uint8Array) { for (var r = t.byteLength, e = [], i = 0; i < r; i++)e[i >>> 2] |= t[i] << 24 - i % 4 * 8; n.call(this, e, r) } else n.apply(this, arguments) }; o.prototype = i } }(), function (r) { function e(t, r, e) { return t ^ r ^ e } function i(t, r, e) { return t & r | ~t & e } function n(t, r, e) { return (t | ~r) ^ e } function o(t, r, e) { return t & e | r & ~e } function s(t, r, e) { return t ^ (r | ~e) } function a(t, r) { return t << r | t >>> 32 - r } var c = t, h = c.lib, l = h.WordArray, f = h.Hasher, u = c.algo, d = l.create([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]), v = l.create([5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]), p = l.create([11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]), _ = l.create([8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]), y = l.create([0, 1518500249, 1859775393, 2400959708, 2840853838]), g = l.create([1352829926, 1548603684, 1836072691, 2053994217, 0]), B = u.RIPEMD160 = f.extend({ _doReset: function () { this._hash = l.create([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var c = 0; c < 16; c++) { var h = r + c, l = t[h]; t[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } var f, u, B, w, k, S, m, x, b, H, z = this._hash.words, A = y.words, C = g.words, D = d.words, R = v.words, E = p.words, M = _.words; S = f = z[0], m = u = z[1], x = B = z[2], b = w = z[3], H = k = z[4]; for (var F, c = 0; c < 80; c += 1)F = f + t[r + D[c]] | 0, F += c < 16 ? e(u, B, w) + A[0] : c < 32 ? i(u, B, w) + A[1] : c < 48 ? n(u, B, w) + A[2] : c < 64 ? o(u, B, w) + A[3] : s(u, B, w) + A[4], F |= 0, F = a(F, E[c]), F = F + k | 0, f = k, k = w, w = a(B, 10), B = u, u = F, F = S + t[r + R[c]] | 0, F += c < 16 ? s(m, x, b) + C[0] : c < 32 ? o(m, x, b) + C[1] : c < 48 ? n(m, x, b) + C[2] : c < 64 ? i(m, x, b) + C[3] : e(m, x, b) + C[4], F |= 0, F = a(F, M[c]), F = F + H | 0, S = H, H = b, b = a(x, 10), x = m, m = F; F = z[1] + B + b | 0, z[1] = z[2] + w + H | 0, z[2] = z[3] + k + S | 0, z[3] = z[4] + f + m | 0, z[4] = z[0] + u + x | 0, z[0] = F }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = 16711935 & (e << 8 | e >>> 24) | 4278255360 & (e << 24 | e >>> 8), t.sigBytes = 4 * (r.length + 1), this._process(); for (var n = this._hash, o = n.words, s = 0; s < 5; s++) { var a = o[s]; o[s] = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8) } return n }, clone: function () { var t = f.clone.call(this); return t._hash = this._hash.clone(), t } }); c.RIPEMD160 = f._createHelper(B), c.HmacRIPEMD160 = f._createHmacHelper(B) }(Math), function () { var r = t, e = r.lib, i = e.Base, n = r.enc, o = n.Utf8, s = r.algo; s.HMAC = i.extend({ init: function (t, r) { t = this._hasher = new t.init, "string" == typeof r && (r = o.parse(r)); var e = t.blockSize, i = 4 * e; r.sigBytes > i && (r = t.finalize(r)), r.clamp(); for (var n = this._oKey = r.clone(), s = this._iKey = r.clone(), a = n.words, c = s.words, h = 0; h < e; h++)a[h] ^= 1549556828, c[h] ^= 909522486; n.sigBytes = s.sigBytes = i, this.reset() }, reset: function () { var t = this._hasher; t.reset(), t.update(this._iKey) }, update: function (t) { return this._hasher.update(t), this }, finalize: function (t) { var r = this._hasher, e = r.finalize(t); r.reset(); var i = r.finalize(this._oKey.clone().concat(e)); return i } }) }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.SHA1, a = o.HMAC, c = o.PBKDF2 = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = a.create(e.hasher, t), o = n.create(), s = n.create([1]), c = o.words, h = s.words, l = e.keySize, f = e.iterations; c.length < l;) { var u = i.update(r).finalize(s); i.reset(); for (var d = u.words, v = d.length, p = u, _ = 1; _ < f; _++) { p = i.finalize(p), i.reset(); for (var y = p.words, g = 0; g < v; g++)d[g] ^= y[g] } o.concat(u), h[0]++ } return o.sigBytes = 4 * l, o } }); r.PBKDF2 = function (t, r, e) { return c.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.MD5, a = o.EvpKDF = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = e.hasher.create(), o = n.create(), s = o.words, a = e.keySize, c = e.iterations; s.length < a;) { h && i.update(h); var h = i.update(t).finalize(r); i.reset(); for (var l = 1; l < c; l++)h = i.finalize(h), i.reset(); o.concat(h) } return o.sigBytes = 4 * a, o } }); r.EvpKDF = function (t, r, e) { return a.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.WordArray, n = r.algo, o = n.SHA256, s = n.SHA224 = o.extend({ _doReset: function () { this._hash = new i.init([3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]) }, _doFinalize: function () { var t = o._doFinalize.call(this); return t.sigBytes -= 4, t } }); r.SHA224 = o._createHelper(s), r.HmacSHA224 = o._createHmacHelper(s) }(), function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = e.x64 = {}; s.Word = n.extend({ init: function (t, r) { this.high = t, this.low = r } }), s.WordArray = n.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 8 * t.length }, toX32: function () { for (var t = this.words, r = t.length, e = [], i = 0; i < r; i++) { var n = t[i]; e.push(n.high), e.push(n.low) } return o.create(e, this.sigBytes) }, clone: function () { for (var t = n.clone.call(this), r = t.words = this.words.slice(0), e = r.length, i = 0; i < e; i++)r[i] = r[i].clone(); return t } }) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.x64, a = s.Word, c = e.algo, h = [], l = [], f = []; !function () { for (var t = 1, r = 0, e = 0; e < 24; e++) { h[t + 5 * r] = (e + 1) * (e + 2) / 2 % 64; var i = r % 5, n = (2 * t + 3 * r) % 5; t = i, r = n } for (var t = 0; t < 5; t++)for (var r = 0; r < 5; r++)l[t + 5 * r] = r + (2 * t + 3 * r) % 5 * 5; for (var o = 1, s = 0; s < 24; s++) { for (var c = 0, u = 0, d = 0; d < 7; d++) { if (1 & o) { var v = (1 << d) - 1; v < 32 ? u ^= 1 << v : c ^= 1 << v - 32 } 128 & o ? o = o << 1 ^ 113 : o <<= 1 } f[s] = a.create(c, u) } }(); var u = []; !function () { for (var t = 0; t < 25; t++)u[t] = a.create() }(); var d = c.SHA3 = o.extend({ cfg: o.cfg.extend({ outputLength: 512 }), _doReset: function () { for (var t = this._state = [], r = 0; r < 25; r++)t[r] = new a.init; this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32 }, _doProcessBlock: function (t, r) { for (var e = this._state, i = this.blockSize / 2, n = 0; n < i; n++) { var o = t[r + 2 * n], s = t[r + 2 * n + 1]; o = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), s = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8); var a = e[n]; a.high ^= s, a.low ^= o } for (var c = 0; c < 24; c++) { for (var d = 0; d < 5; d++) { for (var v = 0, p = 0, _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; v ^= a.high, p ^= a.low } var y = u[d]; y.high = v, y.low = p } for (var d = 0; d < 5; d++)for (var g = u[(d + 4) % 5], B = u[(d + 1) % 5], w = B.high, k = B.low, v = g.high ^ (w << 1 | k >>> 31), p = g.low ^ (k << 1 | w >>> 31), _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; a.high ^= v, a.low ^= p } for (var S = 1; S < 25; S++) { var a = e[S], m = a.high, x = a.low, b = h[S]; if (b < 32) var v = m << b | x >>> 32 - b, p = x << b | m >>> 32 - b; else var v = x << b - 32 | m >>> 64 - b, p = m << b - 32 | x >>> 64 - b; var H = u[l[S]]; H.high = v, H.low = p } var z = u[0], A = e[0]; z.high = A.high, z.low = A.low; for (var d = 0; d < 5; d++)for (var _ = 0; _ < 5; _++) { var S = d + 5 * _, a = e[S], C = u[S], D = u[(d + 1) % 5 + 5 * _], R = u[(d + 2) % 5 + 5 * _]; a.high = C.high ^ ~D.high & R.high, a.low = C.low ^ ~D.low & R.low } var a = e[0], E = f[c]; a.high ^= E.high, a.low ^= E.low } }, _doFinalize: function () { var t = this._data, e = t.words, i = (8 * this._nDataBytes, 8 * t.sigBytes), o = 32 * this.blockSize; e[i >>> 5] |= 1 << 24 - i % 32, e[(r.ceil((i + 1) / o) * o >>> 5) - 1] |= 128, t.sigBytes = 4 * e.length, this._process(); for (var s = this._state, a = this.cfg.outputLength / 8, c = a / 8, h = [], l = 0; l < c; l++) { var f = s[l], u = f.high, d = f.low; u = 16711935 & (u << 8 | u >>> 24) | 4278255360 & (u << 24 | u >>> 8), d = 16711935 & (d << 8 | d >>> 24) | 4278255360 & (d << 24 | d >>> 8), h.push(d), h.push(u) } return new n.init(h, a) }, clone: function () { for (var t = o.clone.call(this), r = t._state = this._state.slice(0), e = 0; e < 25; e++)r[e] = r[e].clone(); return t } }); e.SHA3 = o._createHelper(d), e.HmacSHA3 = o._createHmacHelper(d) }(Math), function () { function r() { return s.create.apply(s, arguments) } var e = t, i = e.lib, n = i.Hasher, o = e.x64, s = o.Word, a = o.WordArray, c = e.algo, h = [r(1116352408, 3609767458), r(1899447441, 602891725), r(3049323471, 3964484399), r(3921009573, 2173295548), r(961987163, 4081628472), r(1508970993, 3053834265), r(2453635748, 2937671579), r(2870763221, 3664609560), r(3624381080, 2734883394), r(310598401, 1164996542), r(607225278, 1323610764), r(1426881987, 3590304994), r(1925078388, 4068182383), r(2162078206, 991336113), r(2614888103, 633803317), r(3248222580, 3479774868), r(3835390401, 2666613458), r(4022224774, 944711139), r(264347078, 2341262773), r(604807628, 2007800933), r(770255983, 1495990901), r(1249150122, 1856431235), r(1555081692, 3175218132), r(1996064986, 2198950837), r(2554220882, 3999719339), r(2821834349, 766784016), r(2952996808, 2566594879), r(3210313671, 3203337956), r(3336571891, 1034457026), r(3584528711, 2466948901), r(113926993, 3758326383), r(338241895, 168717936), r(666307205, 1188179964), r(773529912, 1546045734), r(1294757372, 1522805485), r(1396182291, 2643833823), r(1695183700, 2343527390), r(1986661051, 1014477480), r(2177026350, 1206759142), r(2456956037, 344077627), r(2730485921, 1290863460), r(2820302411, 3158454273), r(3259730800, 3505952657), r(3345764771, 106217008), r(3516065817, 3606008344), r(3600352804, 1432725776), r(4094571909, 1467031594), r(275423344, 851169720), r(430227734, 3100823752), r(506948616, 1363258195), r(659060556, 3750685593), r(883997877, 3785050280), r(958139571, 3318307427), r(1322822218, 3812723403), r(1537002063, 2003034995), r(1747873779, 3602036899), r(1955562222, 1575990012), r(2024104815, 1125592928), r(2227730452, 2716904306), r(2361852424, 442776044), r(2428436474, 593698344), r(2756734187, 3733110249), r(3204031479, 2999351573), r(3329325298, 3815920427), r(3391569614, 3928383900), r(3515267271, 566280711), r(3940187606, 3454069534), r(4118630271, 4000239992), r(116418474, 1914138554), r(174292421, 2731055270), r(289380356, 3203993006), r(460393269, 320620315), r(685471733, 587496836), r(852142971, 1086792851), r(1017036298, 365543100), r(1126000580, 2618297676), r(1288033470, 3409855158), r(1501505948, 4234509866), r(1607167915, 987167468), r(1816402316, 1246189591)], l = []; !function () { for (var t = 0; t < 80; t++)l[t] = r() }(); var f = c.SHA512 = n.extend({ _doReset: function () { this._hash = new a.init([new s.init(1779033703, 4089235720), new s.init(3144134277, 2227873595), new s.init(1013904242, 4271175723), new s.init(2773480762, 1595750129), new s.init(1359893119, 2917565137), new s.init(2600822924, 725511199), new s.init(528734635, 4215389547), new s.init(1541459225, 327033209)]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], c = e[5], f = e[6], u = e[7], d = i.high, v = i.low, p = n.high, _ = n.low, y = o.high, g = o.low, B = s.high, w = s.low, k = a.high, S = a.low, m = c.high, x = c.low, b = f.high, H = f.low, z = u.high, A = u.low, C = d, D = v, R = p, E = _, M = y, F = g, P = B, W = w, O = k, U = S, I = m, K = x, X = b, L = H, j = z, N = A, T = 0; T < 80; T++) { var Z = l[T]; if (T < 16) var q = Z.high = 0 | t[r + 2 * T], G = Z.low = 0 | t[r + 2 * T + 1]; else { var J = l[T - 15], $ = J.high, Q = J.low, V = ($ >>> 1 | Q << 31) ^ ($ >>> 8 | Q << 24) ^ $ >>> 7, Y = (Q >>> 1 | $ << 31) ^ (Q >>> 8 | $ << 24) ^ (Q >>> 7 | $ << 25), tt = l[T - 2], rt = tt.high, et = tt.low, it = (rt >>> 19 | et << 13) ^ (rt << 3 | et >>> 29) ^ rt >>> 6, nt = (et >>> 19 | rt << 13) ^ (et << 3 | rt >>> 29) ^ (et >>> 6 | rt << 26), ot = l[T - 7], st = ot.high, at = ot.low, ct = l[T - 16], ht = ct.high, lt = ct.low, G = Y + at, q = V + st + (G >>> 0 < Y >>> 0 ? 1 : 0), G = G + nt, q = q + it + (G >>> 0 < nt >>> 0 ? 1 : 0), G = G + lt, q = q + ht + (G >>> 0 < lt >>> 0 ? 1 : 0); Z.high = q, Z.low = G } var ft = O & I ^ ~O & X, ut = U & K ^ ~U & L, dt = C & R ^ C & M ^ R & M, vt = D & E ^ D & F ^ E & F, pt = (C >>> 28 | D << 4) ^ (C << 30 | D >>> 2) ^ (C << 25 | D >>> 7), _t = (D >>> 28 | C << 4) ^ (D << 30 | C >>> 2) ^ (D << 25 | C >>> 7), yt = (O >>> 14 | U << 18) ^ (O >>> 18 | U << 14) ^ (O << 23 | U >>> 9), gt = (U >>> 14 | O << 18) ^ (U >>> 18 | O << 14) ^ (U << 23 | O >>> 9), Bt = h[T], wt = Bt.high, kt = Bt.low, St = N + gt, mt = j + yt + (St >>> 0 < N >>> 0 ? 1 : 0), St = St + ut, mt = mt + ft + (St >>> 0 < ut >>> 0 ? 1 : 0), St = St + kt, mt = mt + wt + (St >>> 0 < kt >>> 0 ? 1 : 0), St = St + G, mt = mt + q + (St >>> 0 < G >>> 0 ? 1 : 0), xt = _t + vt, bt = pt + dt + (xt >>> 0 < _t >>> 0 ? 1 : 0); j = X, N = L, X = I, L = K, I = O, K = U, U = W + St | 0, O = P + mt + (U >>> 0 < W >>> 0 ? 1 : 0) | 0, P = M, W = F, M = R, F = E, R = C, E = D, D = St + xt | 0, C = mt + bt + (D >>> 0 < St >>> 0 ? 1 : 0) | 0 } v = i.low = v + D, i.high = d + C + (v >>> 0 < D >>> 0 ? 1 : 0), _ = n.low = _ + E, n.high = p + R + (_ >>> 0 < E >>> 0 ? 1 : 0), g = o.low = g + F, o.high = y + M + (g >>> 0 < F >>> 0 ? 1 : 0), w = s.low = w + W, s.high = B + P + (w >>> 0 < W >>> 0 ? 1 : 0), S = a.low = S + U, a.high = k + O + (S >>> 0 < U >>> 0 ? 1 : 0), x = c.low = x + K, c.high = m + I + (x >>> 0 < K >>> 0 ? 1 : 0), H = f.low = H + L, f.high = b + X + (H >>> 0 < L >>> 0 ? 1 : 0), A = u.low = A + N, u.high = z + j + (A >>> 0 < N >>> 0 ? 1 : 0) }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 128 >>> 10 << 5) + 30] = Math.floor(e / 4294967296), r[(i + 128 >>> 10 << 5) + 31] = e, t.sigBytes = 4 * r.length, this._process(); var n = this._hash.toX32(); return n }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t }, blockSize: 32 }); e.SHA512 = n._createHelper(f), e.HmacSHA512 = n._createHmacHelper(f) }(), function () { var r = t, e = r.x64, i = e.Word, n = e.WordArray, o = r.algo, s = o.SHA512, a = o.SHA384 = s.extend({ _doReset: function () { this._hash = new n.init([new i.init(3418070365, 3238371032), new i.init(1654270250, 914150663), new i.init(2438529370, 812702999), new i.init(355462360, 4144912697), new i.init(1731405415, 4290775857), new i.init(2394180231, 1750603025), new i.init(3675008525, 1694076839), new i.init(1203062813, 3204075428)]) }, _doFinalize: function () { var t = s._doFinalize.call(this); return t.sigBytes -= 16, t } }); r.SHA384 = s._createHelper(a), r.HmacSHA384 = s._createHmacHelper(a) }(), t.lib.Cipher || function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = i.BufferedBlockAlgorithm, a = e.enc, c = (a.Utf8, a.Base64), h = e.algo, l = h.EvpKDF, f = i.Cipher = s.extend({ cfg: n.extend(), createEncryptor: function (t, r) { return this.create(this._ENC_XFORM_MODE, t, r) }, createDecryptor: function (t, r) { return this.create(this._DEC_XFORM_MODE, t, r) }, init: function (t, r, e) { this.cfg = this.cfg.extend(e), this._xformMode = t, this._key = r, this.reset() }, reset: function () { s.reset.call(this), this._doReset() }, process: function (t) { return this._append(t), this._process() }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, keySize: 4, ivSize: 4, _ENC_XFORM_MODE: 1, _DEC_XFORM_MODE: 2, _createHelper: function () { function t(t) { return "string" == typeof t ? m : w } return function (r) { return { encrypt: function (e, i, n) { return t(i).encrypt(r, e, i, n) }, decrypt: function (e, i, n) { return t(i).decrypt(r, e, i, n) } } } }() }), u = (i.StreamCipher = f.extend({ _doFinalize: function () { var t = this._process(!0); return t }, blockSize: 1 }), e.mode = {}), d = i.BlockCipherMode = n.extend({ createEncryptor: function (t, r) { return this.Encryptor.create(t, r) }, createDecryptor: function (t, r) { return this.Decryptor.create(t, r) }, init: function (t, r) { this._cipher = t, this._iv = r } }), v = u.CBC = function () { function t(t, e, i) { var n = this._iv; if (n) { var o = n; this._iv = r } else var o = this._prevBlock; for (var s = 0; s < i; s++)t[e + s] ^= o[s] } var e = d.extend(); return e.Encryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize; t.call(this, r, e, n), i.encryptBlock(r, e), this._prevBlock = r.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize, o = r.slice(e, e + n); i.decryptBlock(r, e), t.call(this, r, e, n), this._prevBlock = o } }), e }(), p = e.pad = {}, _ = p.Pkcs7 = { pad: function (t, r) { for (var e = 4 * r, i = e - t.sigBytes % e, n = i << 24 | i << 16 | i << 8 | i, s = [], a = 0; a < i; a += 4)s.push(n); var c = o.create(s, i); t.concat(c) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, y = (i.BlockCipher = f.extend({ cfg: f.cfg.extend({ mode: v, padding: _ }), reset: function () { f.reset.call(this); var t = this.cfg, r = t.iv, e = t.mode; if (this._xformMode == this._ENC_XFORM_MODE) var i = e.createEncryptor; else { var i = e.createDecryptor; this._minBufferSize = 1 } this._mode && this._mode.__creator == i ? this._mode.init(this, r && r.words) : (this._mode = i.call(e, this, r && r.words), this._mode.__creator = i) }, _doProcessBlock: function (t, r) { this._mode.processBlock(t, r) }, _doFinalize: function () { var t = this.cfg.padding; if (this._xformMode == this._ENC_XFORM_MODE) { t.pad(this._data, this.blockSize); var r = this._process(!0) } else { var r = this._process(!0); t.unpad(r) } return r }, blockSize: 4 }), i.CipherParams = n.extend({ init: function (t) { this.mixIn(t) }, toString: function (t) { return (t || this.formatter).stringify(this) } })), g = e.format = {}, B = g.OpenSSL = { stringify: function (t) { var r = t.ciphertext, e = t.salt; if (e) var i = o.create([1398893684, 1701076831]).concat(e).concat(r); else var i = r; return i.toString(c) }, parse: function (t) { var r = c.parse(t), e = r.words; if (1398893684 == e[0] && 1701076831 == e[1]) { var i = o.create(e.slice(2, 4)); e.splice(0, 4), r.sigBytes -= 16 } return y.create({ ciphertext: r, salt: i }) } }, w = i.SerializableCipher = n.extend({ cfg: n.extend({ format: B }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = t.createEncryptor(e, i), o = n.finalize(r), s = n.cfg; return y.create({ ciphertext: o, key: e, iv: s.iv, algorithm: t, mode: s.mode, padding: s.padding, blockSize: t.blockSize, formatter: i.format }) }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = t.createDecryptor(e, i).finalize(r.ciphertext); return n }, _parse: function (t, r) { return "string" == typeof t ? r.parse(t, this) : t } }), k = e.kdf = {}, S = k.OpenSSL = { execute: function (t, r, e, i) { i || (i = o.random(8)); var n = l.create({ keySize: r + e }).compute(t, i), s = o.create(n.words.slice(r), 4 * e); return n.sigBytes = 4 * r, y.create({ key: n, iv: s, salt: i }) } }, m = i.PasswordBasedCipher = w.extend({ cfg: w.cfg.extend({ kdf: S }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = i.kdf.execute(e, t.keySize, t.ivSize); i.iv = n.iv; var o = w.encrypt.call(this, t, r, n.key, i); return o.mixIn(n), o }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = i.kdf.execute(e, t.keySize, t.ivSize, r.salt); i.iv = n.iv; var o = w.decrypt.call(this, t, r, n.key, i); return o } }) }(), t.mode.CFB = function () { function r(t, r, e, i) { var n = this._iv; if (n) { var o = n.slice(0); this._iv = void 0 } else var o = this._prevBlock; i.encryptBlock(o, 0); for (var s = 0; s < e; s++)t[r + s] ^= o[s] } var e = t.lib.BlockCipherMode.extend(); return e.Encryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize; r.call(this, t, e, n, i), this._prevBlock = t.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize, o = t.slice(e, e + n); r.call(this, t, e, n, i), this._prevBlock = o } }), e }(), t.mode.ECB = function () { var r = t.lib.BlockCipherMode.extend(); return r.Encryptor = r.extend({ processBlock: function (t, r) { this._cipher.encryptBlock(t, r) } }), r.Decryptor = r.extend({ processBlock: function (t, r) { this._cipher.decryptBlock(t, r) } }), r }(), t.pad.AnsiX923 = { pad: function (t, r) { var e = t.sigBytes, i = 4 * r, n = i - e % i, o = e + n - 1; t.clamp(), t.words[o >>> 2] |= n << 24 - o % 4 * 8, t.sigBytes += n }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso10126 = { pad: function (r, e) { var i = 4 * e, n = i - r.sigBytes % i; r.concat(t.lib.WordArray.random(n - 1)).concat(t.lib.WordArray.create([n << 24], 1)) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso97971 = { pad: function (r, e) { r.concat(t.lib.WordArray.create([2147483648], 1)), t.pad.ZeroPadding.pad(r, e) }, unpad: function (r) { t.pad.ZeroPadding.unpad(r), r.sigBytes-- } }, t.mode.OFB = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._keystream; n && (o = this._keystream = n.slice(0), this._iv = void 0), e.encryptBlock(o, 0); for (var s = 0; s < i; s++)t[r + s] ^= o[s] } }); return r.Decryptor = e, r }(), t.pad.NoPadding = { pad: function () { }, unpad: function () { } }, function (r) { var e = t, i = e.lib, n = i.CipherParams, o = e.enc, s = o.Hex, a = e.format; a.Hex = { stringify: function (t) { return t.ciphertext.toString(s) }, parse: function (t) { var r = s.parse(t); return n.create({ ciphertext: r }) } } }(), function () { var r = t, e = r.lib, i = e.BlockCipher, n = r.algo, o = [], s = [], a = [], c = [], h = [], l = [], f = [], u = [], d = [], v = []; !function () { for (var t = [], r = 0; r < 256; r++)r < 128 ? t[r] = r << 1 : t[r] = r << 1 ^ 283; for (var e = 0, i = 0, r = 0; r < 256; r++) { var n = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4; n = n >>> 8 ^ 255 & n ^ 99, o[e] = n, s[n] = e; var p = t[e], _ = t[p], y = t[_], g = 257 * t[n] ^ 16843008 * n; a[e] = g << 24 | g >>> 8, c[e] = g << 16 | g >>> 16, h[e] = g << 8 | g >>> 24, l[e] = g; var g = 16843009 * y ^ 65537 * _ ^ 257 * p ^ 16843008 * e; f[n] = g << 24 | g >>> 8, u[n] = g << 16 | g >>> 16, d[n] = g << 8 | g >>> 24, v[n] = g, e ? (e = p ^ t[t[t[y ^ p]]], i ^= t[t[i]]) : e = i = 1 } }(); var p = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], _ = n.AES = i.extend({ _doReset: function () { if (!this._nRounds || this._keyPriorReset !== this._key) { for (var t = this._keyPriorReset = this._key, r = t.words, e = t.sigBytes / 4, i = this._nRounds = e + 6, n = 4 * (i + 1), s = this._keySchedule = [], a = 0; a < n; a++)if (a < e) s[a] = r[a]; else { var c = s[a - 1]; a % e ? e > 6 && a % e == 4 && (c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c]) : (c = c << 8 | c >>> 24, c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c], c ^= p[a / e | 0] << 24), s[a] = s[a - e] ^ c } for (var h = this._invKeySchedule = [], l = 0; l < n; l++) { var a = n - l; if (l % 4) var c = s[a]; else var c = s[a - 4]; l < 4 || a <= 4 ? h[l] = c : h[l] = f[o[c >>> 24]] ^ u[o[c >>> 16 & 255]] ^ d[o[c >>> 8 & 255]] ^ v[o[255 & c]] } } }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._keySchedule, a, c, h, l, o) }, decryptBlock: function (t, r) { var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e, this._doCryptBlock(t, r, this._invKeySchedule, f, u, d, v, s); var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e }, _doCryptBlock: function (t, r, e, i, n, o, s, a) { for (var c = this._nRounds, h = t[r] ^ e[0], l = t[r + 1] ^ e[1], f = t[r + 2] ^ e[2], u = t[r + 3] ^ e[3], d = 4, v = 1; v < c; v++) { var p = i[h >>> 24] ^ n[l >>> 16 & 255] ^ o[f >>> 8 & 255] ^ s[255 & u] ^ e[d++], _ = i[l >>> 24] ^ n[f >>> 16 & 255] ^ o[u >>> 8 & 255] ^ s[255 & h] ^ e[d++], y = i[f >>> 24] ^ n[u >>> 16 & 255] ^ o[h >>> 8 & 255] ^ s[255 & l] ^ e[d++], g = i[u >>> 24] ^ n[h >>> 16 & 255] ^ o[l >>> 8 & 255] ^ s[255 & f] ^ e[d++]; h = p, l = _, f = y, u = g } var p = (a[h >>> 24] << 24 | a[l >>> 16 & 255] << 16 | a[f >>> 8 & 255] << 8 | a[255 & u]) ^ e[d++], _ = (a[l >>> 24] << 24 | a[f >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & h]) ^ e[d++], y = (a[f >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[h >>> 8 & 255] << 8 | a[255 & l]) ^ e[d++], g = (a[u >>> 24] << 24 | a[h >>> 16 & 255] << 16 | a[l >>> 8 & 255] << 8 | a[255 & f]) ^ e[d++]; t[r] = p, t[r + 1] = _, t[r + 2] = y, t[r + 3] = g }, keySize: 8 }); r.AES = i._createHelper(_) }(), function () { + function r(t, r) { var e = (this._lBlock >>> t ^ this._rBlock) & r; this._rBlock ^= e, this._lBlock ^= e << t } function e(t, r) { + var e = (this._rBlock >>> t ^ this._lBlock) & r; this._lBlock ^= e, this._rBlock ^= e << t; + } var i = t, n = i.lib, o = n.WordArray, s = n.BlockCipher, a = i.algo, c = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4], h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32], l = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28], f = [{ 0: 8421888, 268435456: 32768, 536870912: 8421378, 805306368: 2, 1073741824: 512, 1342177280: 8421890, 1610612736: 8389122, 1879048192: 8388608, 2147483648: 514, 2415919104: 8389120, 2684354560: 33280, 2952790016: 8421376, 3221225472: 32770, 3489660928: 8388610, 3758096384: 0, 4026531840: 33282, 134217728: 0, 402653184: 8421890, 671088640: 33282, 939524096: 32768, 1207959552: 8421888, 1476395008: 512, 1744830464: 8421378, 2013265920: 2, 2281701376: 8389120, 2550136832: 33280, 2818572288: 8421376, 3087007744: 8389122, 3355443200: 8388610, 3623878656: 32770, 3892314112: 514, 4160749568: 8388608, 1: 32768, 268435457: 2, 536870913: 8421888, 805306369: 8388608, 1073741825: 8421378, 1342177281: 33280, 1610612737: 512, 1879048193: 8389122, 2147483649: 8421890, 2415919105: 8421376, 2684354561: 8388610, 2952790017: 33282, 3221225473: 514, 3489660929: 8389120, 3758096385: 32770, 4026531841: 0, 134217729: 8421890, 402653185: 8421376, 671088641: 8388608, 939524097: 512, 1207959553: 32768, 1476395009: 8388610, 1744830465: 2, 2013265921: 33282, 2281701377: 32770, 2550136833: 8389122, 2818572289: 514, 3087007745: 8421888, 3355443201: 8389120, 3623878657: 0, 3892314113: 33280, 4160749569: 8421378 }, { 0: 1074282512, 16777216: 16384, 33554432: 524288, 50331648: 1074266128, 67108864: 1073741840, 83886080: 1074282496, 100663296: 1073758208, 117440512: 16, 134217728: 540672, 150994944: 1073758224, 167772160: 1073741824, 184549376: 540688, 201326592: 524304, 218103808: 0, 234881024: 16400, 251658240: 1074266112, 8388608: 1073758208, 25165824: 540688, 41943040: 16, 58720256: 1073758224, 75497472: 1074282512, 92274688: 1073741824, 109051904: 524288, 125829120: 1074266128, 142606336: 524304, 159383552: 0, 176160768: 16384, 192937984: 1074266112, 209715200: 1073741840, 226492416: 540672, 243269632: 1074282496, 260046848: 16400, 268435456: 0, 285212672: 1074266128, 301989888: 1073758224, 318767104: 1074282496, 335544320: 1074266112, 352321536: 16, 369098752: 540688, 385875968: 16384, 402653184: 16400, 419430400: 524288, 436207616: 524304, 452984832: 1073741840, 469762048: 540672, 486539264: 1073758208, 503316480: 1073741824, 520093696: 1074282512, 276824064: 540688, 293601280: 524288, 310378496: 1074266112, 327155712: 16384, 343932928: 1073758208, 360710144: 1074282512, 377487360: 16, 394264576: 1073741824, 411041792: 1074282496, 427819008: 1073741840, 444596224: 1073758224, 461373440: 524304, 478150656: 0, 494927872: 16400, 511705088: 1074266128, 528482304: 540672 }, { 0: 260, 1048576: 0, 2097152: 67109120, 3145728: 65796, 4194304: 65540, 5242880: 67108868, 6291456: 67174660, 7340032: 67174400, 8388608: 67108864, 9437184: 67174656, 10485760: 65792, 11534336: 67174404, 12582912: 67109124, 13631488: 65536, 14680064: 4, 15728640: 256, 524288: 67174656, 1572864: 67174404, 2621440: 0, 3670016: 67109120, 4718592: 67108868, 5767168: 65536, 6815744: 65540, 7864320: 260, 8912896: 4, 9961472: 256, 11010048: 67174400, 12058624: 65796, 13107200: 65792, 14155776: 67109124, 15204352: 67174660, 16252928: 67108864, 16777216: 67174656, 17825792: 65540, 18874368: 65536, 19922944: 67109120, 20971520: 256, 22020096: 67174660, 23068672: 67108868, 24117248: 0, 25165824: 67109124, 26214400: 67108864, 27262976: 4, 28311552: 65792, 29360128: 67174400, 30408704: 260, 31457280: 65796, 32505856: 67174404, 17301504: 67108864, 18350080: 260, 19398656: 67174656, 20447232: 0, 21495808: 65540, 22544384: 67109120, 23592960: 256, 24641536: 67174404, 25690112: 65536, 26738688: 67174660, 27787264: 65796, 28835840: 67108868, 29884416: 67109124, 30932992: 67174400, 31981568: 4, 33030144: 65792 }, { 0: 2151682048, 65536: 2147487808, 131072: 4198464, 196608: 2151677952, 262144: 0, 327680: 4198400, 393216: 2147483712, 458752: 4194368, 524288: 2147483648, 589824: 4194304, 655360: 64, 720896: 2147487744, 786432: 2151678016, 851968: 4160, 917504: 4096, 983040: 2151682112, 32768: 2147487808, 98304: 64, 163840: 2151678016, 229376: 2147487744, 294912: 4198400, 360448: 2151682112, 425984: 0, 491520: 2151677952, 557056: 4096, 622592: 2151682048, 688128: 4194304, 753664: 4160, 819200: 2147483648, 884736: 4194368, 950272: 4198464, 1015808: 2147483712, 1048576: 4194368, 1114112: 4198400, 1179648: 2147483712, 1245184: 0, 1310720: 4160, 1376256: 2151678016, 1441792: 2151682048, 1507328: 2147487808, 1572864: 2151682112, 1638400: 2147483648, 1703936: 2151677952, 1769472: 4198464, 1835008: 2147487744, 1900544: 4194304, 1966080: 64, 2031616: 4096, 1081344: 2151677952, 1146880: 2151682112, 1212416: 0, 1277952: 4198400, 1343488: 4194368, 1409024: 2147483648, 1474560: 2147487808, 1540096: 64, 1605632: 2147483712, 1671168: 4096, 1736704: 2147487744, 1802240: 2151678016, 1867776: 4160, 1933312: 2151682048, 1998848: 4194304, 2064384: 4198464 }, { 0: 128, 4096: 17039360, 8192: 262144, 12288: 536870912, 16384: 537133184, 20480: 16777344, 24576: 553648256, 28672: 262272, 32768: 16777216, 36864: 537133056, 40960: 536871040, 45056: 553910400, 49152: 553910272, 53248: 0, 57344: 17039488, 61440: 553648128, 2048: 17039488, 6144: 553648256, 10240: 128, 14336: 17039360, 18432: 262144, 22528: 537133184, 26624: 553910272, 30720: 536870912, 34816: 537133056, 38912: 0, 43008: 553910400, 47104: 16777344, 51200: 536871040, 55296: 553648128, 59392: 16777216, 63488: 262272, 65536: 262144, 69632: 128, 73728: 536870912, 77824: 553648256, 81920: 16777344, 86016: 553910272, 90112: 537133184, 94208: 16777216, 98304: 553910400, 102400: 553648128, 106496: 17039360, 110592: 537133056, 114688: 262272, 118784: 536871040, 122880: 0, 126976: 17039488, 67584: 553648256, 71680: 16777216, 75776: 17039360, 79872: 537133184, 83968: 536870912, 88064: 17039488, 92160: 128, 96256: 553910272, 100352: 262272, 104448: 553910400, 108544: 0, 112640: 553648128, 116736: 16777344, 120832: 262144, 124928: 537133056, 129024: 536871040 }, { 0: 268435464, 256: 8192, 512: 270532608, 768: 270540808, 1024: 268443648, 1280: 2097152, 1536: 2097160, 1792: 268435456, 2048: 0, 2304: 268443656, 2560: 2105344, 2816: 8, 3072: 270532616, 3328: 2105352, 3584: 8200, 3840: 270540800, 128: 270532608, 384: 270540808, 640: 8, 896: 2097152, 1152: 2105352, 1408: 268435464, 1664: 268443648, 1920: 8200, 2176: 2097160, 2432: 8192, 2688: 268443656, 2944: 270532616, 3200: 0, 3456: 270540800, 3712: 2105344, 3968: 268435456, 4096: 268443648, 4352: 270532616, 4608: 270540808, 4864: 8200, 5120: 2097152, 5376: 268435456, 5632: 268435464, 5888: 2105344, 6144: 2105352, 6400: 0, 6656: 8, 6912: 270532608, 7168: 8192, 7424: 268443656, 7680: 270540800, 7936: 2097160, 4224: 8, 4480: 2105344, 4736: 2097152, 4992: 268435464, 5248: 268443648, 5504: 8200, 5760: 270540808, 6016: 270532608, 6272: 270540800, 6528: 270532616, 6784: 8192, 7040: 2105352, 7296: 2097160, 7552: 0, 7808: 268435456, 8064: 268443656 }, { 0: 1048576, 16: 33555457, 32: 1024, 48: 1049601, 64: 34604033, 80: 0, 96: 1, 112: 34603009, 128: 33555456, 144: 1048577, 160: 33554433, 176: 34604032, 192: 34603008, 208: 1025, 224: 1049600, 240: 33554432, 8: 34603009, 24: 0, 40: 33555457, 56: 34604032, 72: 1048576, 88: 33554433, 104: 33554432, 120: 1025, 136: 1049601, 152: 33555456, 168: 34603008, 184: 1048577, 200: 1024, 216: 34604033, 232: 1, 248: 1049600, 256: 33554432, 272: 1048576, 288: 33555457, 304: 34603009, 320: 1048577, 336: 33555456, 352: 34604032, 368: 1049601, 384: 1025, 400: 34604033, 416: 1049600, 432: 1, 448: 0, 464: 34603008, 480: 33554433, 496: 1024, 264: 1049600, 280: 33555457, 296: 34603009, 312: 1, 328: 33554432, 344: 1048576, 360: 1025, 376: 34604032, 392: 33554433, 408: 34603008, 424: 0, 440: 34604033, 456: 1049601, 472: 1024, 488: 33555456, 504: 1048577 }, { 0: 134219808, 1: 131072, 2: 134217728, 3: 32, 4: 131104, 5: 134350880, 6: 134350848, 7: 2048, 8: 134348800, 9: 134219776, 10: 133120, 11: 134348832, 12: 2080, 13: 0, 14: 134217760, 15: 133152, 2147483648: 2048, 2147483649: 134350880, 2147483650: 134219808, 2147483651: 134217728, 2147483652: 134348800, 2147483653: 133120, 2147483654: 133152, 2147483655: 32, 2147483656: 134217760, 2147483657: 2080, 2147483658: 131104, 2147483659: 134350848, 2147483660: 0, 2147483661: 134348832, 2147483662: 134219776, 2147483663: 131072, 16: 133152, 17: 134350848, 18: 32, 19: 2048, 20: 134219776, 21: 134217760, 22: 134348832, 23: 131072, 24: 0, 25: 131104, 26: 134348800, 27: 134219808, 28: 134350880, 29: 133120, 30: 2080, 31: 134217728, 2147483664: 131072, 2147483665: 2048, 2147483666: 134348832, 2147483667: 133152, 2147483668: 32, 2147483669: 134348800, 2147483670: 134217728, 2147483671: 134219808, 2147483672: 134350880, 2147483673: 134217760, 2147483674: 134219776, 2147483675: 0, 2147483676: 133120, 2147483677: 2080, 2147483678: 131104, 2147483679: 134350848 }], u = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679], d = a.DES = s.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = [], i = 0; i < 56; i++) { var n = c[i] - 1; e[i] = r[n >>> 5] >>> 31 - n % 32 & 1 } for (var o = this._subKeys = [], s = 0; s < 16; s++) { for (var a = o[s] = [], f = l[s], i = 0; i < 24; i++)a[i / 6 | 0] |= e[(h[i] - 1 + f) % 28] << 31 - i % 6, a[4 + (i / 6 | 0)] |= e[28 + (h[i + 24] - 1 + f) % 28] << 31 - i % 6; a[0] = a[0] << 1 | a[0] >>> 31; for (var i = 1; i < 7; i++)a[i] = a[i] >>> 4 * (i - 1) + 3; a[7] = a[7] << 5 | a[7] >>> 27 } for (var u = this._invSubKeys = [], i = 0; i < 16; i++)u[i] = o[15 - i] }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._subKeys) }, decryptBlock: function (t, r) { this._doCryptBlock(t, r, this._invSubKeys) }, _doCryptBlock: function (t, i, n) { this._lBlock = t[i], this._rBlock = t[i + 1], r.call(this, 4, 252645135), r.call(this, 16, 65535), e.call(this, 2, 858993459), e.call(this, 8, 16711935), r.call(this, 1, 1431655765); for (var o = 0; o < 16; o++) { for (var s = n[o], a = this._lBlock, c = this._rBlock, h = 0, l = 0; l < 8; l++)h |= f[l][((c ^ s[l]) & u[l]) >>> 0]; this._lBlock = c, this._rBlock = a ^ h } var d = this._lBlock; this._lBlock = this._rBlock, this._rBlock = d, r.call(this, 1, 1431655765), e.call(this, 8, 16711935), e.call(this, 2, 858993459), r.call(this, 16, 65535), r.call(this, 4, 252645135), t[i] = this._lBlock, t[i + 1] = this._rBlock }, keySize: 2, ivSize: 2, blockSize: 2 }); i.DES = s._createHelper(d); var v = a.TripleDES = s.extend({ _doReset: function () { var t = this._key, r = t.words; this._des1 = d.createEncryptor(o.create(r.slice(0, 2))), this._des2 = d.createEncryptor(o.create(r.slice(2, 4))), this._des3 = d.createEncryptor(o.create(r.slice(4, 6))) }, encryptBlock: function (t, r) { this._des1.encryptBlock(t, r), this._des2.decryptBlock(t, r), this._des3.encryptBlock(t, r) }, decryptBlock: function (t, r) { this._des3.decryptBlock(t, r), this._des2.encryptBlock(t, r), this._des1.decryptBlock(t, r) }, keySize: 6, ivSize: 2, blockSize: 2 }); i.TripleDES = s._createHelper(v) + }(), function () { function r() { for (var t = this._S, r = this._i, e = this._j, i = 0, n = 0; n < 4; n++) { r = (r + 1) % 256, e = (e + t[r]) % 256; var o = t[r]; t[r] = t[e], t[e] = o, i |= t[(t[r] + t[e]) % 256] << 24 - 8 * n } return this._i = r, this._j = e, i } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = o.RC4 = n.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = t.sigBytes, i = this._S = [], n = 0; n < 256; n++)i[n] = n; for (var n = 0, o = 0; n < 256; n++) { var s = n % e, a = r[s >>> 2] >>> 24 - s % 4 * 8 & 255; o = (o + i[n] + a) % 256; var c = i[n]; i[n] = i[o], i[o] = c } this._i = this._j = 0 }, _doProcessBlock: function (t, e) { t[e] ^= r.call(this) }, keySize: 8, ivSize: 0 }); e.RC4 = n._createHelper(s); var a = o.RC4Drop = s.extend({ cfg: s.cfg.extend({ drop: 192 }), _doReset: function () { s._doReset.call(this); for (var t = this.cfg.drop; t > 0; t--)r.call(this) } }); e.RC4Drop = n._createHelper(a) }(), t.mode.CTRGladman = function () { function r(t) { if (255 === (t >> 24 & 255)) { var r = t >> 16 & 255, e = t >> 8 & 255, i = 255 & t; 255 === r ? (r = 0, 255 === e ? (e = 0, 255 === i ? i = 0 : ++i) : ++e) : ++r, t = 0, t += r << 16, t += e << 8, t += i } else t += 1 << 24; return t } function e(t) { return 0 === (t[0] = r(t[0])) && (t[1] = r(t[1])), t } var i = t.lib.BlockCipherMode.extend(), n = i.Encryptor = i.extend({ processBlock: function (t, r) { var i = this._cipher, n = i.blockSize, o = this._iv, s = this._counter; o && (s = this._counter = o.slice(0), this._iv = void 0), e(s); var a = s.slice(0); i.encryptBlock(a, 0); for (var c = 0; c < n; c++)t[r + c] ^= a[c] } }); return i.Decryptor = n, i }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.Rabbit = n.extend({ _doReset: function () { for (var t = this._key.words, e = this.cfg.iv, i = 0; i < 4; i++)t[i] = 16711935 & (t[i] << 8 | t[i] >>> 24) | 4278255360 & (t[i] << 24 | t[i] >>> 8); var n = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], o = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var i = 0; i < 4; i++)r.call(this); for (var i = 0; i < 8; i++)o[i] ^= n[i + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; o[0] ^= h, o[1] ^= f, o[2] ^= l, o[3] ^= u, o[4] ^= h, o[5] ^= f, o[6] ^= l, o[7] ^= u; for (var i = 0; i < 4; i++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.Rabbit = n._createHelper(h) }(), t.mode.CTR = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._counter; n && (o = this._counter = n.slice(0), this._iv = void 0); var s = o.slice(0); e.encryptBlock(s, 0), o[i - 1] = o[i - 1] + 1 | 0; for (var a = 0; a < i; a++)t[r + a] ^= s[a] } }); return r.Decryptor = e, r }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.RabbitLegacy = n.extend({ _doReset: function () { var t = this._key.words, e = this.cfg.iv, i = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], n = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var o = 0; o < 4; o++)r.call(this); for (var o = 0; o < 8; o++)n[o] ^= i[o + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; n[0] ^= h, n[1] ^= f, n[2] ^= l, n[3] ^= u, n[4] ^= h, n[5] ^= f, n[6] ^= l, n[7] ^= u; for (var o = 0; o < 4; o++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.RabbitLegacy = n._createHelper(h) }(), t.pad.ZeroPadding = { pad: function (t, r) { var e = 4 * r; t.clamp(), t.sigBytes += e - (t.sigBytes % e || e) }, unpad: function (t) { for (var r = t.words, e = t.sigBytes - 1; !(r[e >>> 2] >>> 24 - e % 4 * 8 & 255);)e--; t.sigBytes = e + 1 } }, t +}); + const $ = new Env('威锋网') +$.KEY_login = 'chavy_login_feng' + +!(async () => { + $.CryptoJS = $.isNode() ? require('crypto-js') : CryptoJS + await login() + await sign() + showmsg() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function login() { + const loginOpts = $.getjson($.KEY_login) + const url = { + url: `http://49.234.36.200:9091/v1/auth/signin`, + body: loginOpts['body'], + headers: { + 'X-Request-Id': encrypt(`url=/v1/auth/signin$time=${new Date().getTime()}`), + 'X-Running-Env': loginOpts['headers']['X-Running-Env'] + } + } + return $.http.post(url).then((resp) => { + $.login = JSON.parse(resp.body).data + }) +} + +function sign() { + const loginOpts = $.getjson($.KEY_login) + const url = { + url: `http://49.234.36.200:9091/v1/attendance/userSignIn`, + body: '', + headers: { + 'Content-Type': `application/x-www-form-urlencoded`, + 'User-Agent': `fengapp/6.4 (com.feng.New.WPForumClient; build:21.03.14; iOS 14.4.1) Alamofire/4.9.1`, + 'X-Request-Id': encrypt(`url=/v1/attendance/userSignIn$time=${new Date().getTime()}`), + 'X-Running-Env': loginOpts['headers']['X-Running-Env'], + 'X-Access-Token': $.login.accessToken + } + } + return $.http + .post(url) + .then((resp) => { + $.sign = JSON.parse(resp.body) + }) + .catch((err) => console.log(err)) +} + +function showmsg() { + const signCode = $.sign.status.code + const result = signCode === 0 ? '成功' : signCode === 1021 ? '重复' : '失败' + $.subt = `签到: ${result}` + $.desc = `说明: ${$.sign.status.message}` + $.msg($.name, $.subt, $.desc) +} -$.msg($.name, '脚本失效, 请移除!', '原因: 增加了登录验证') +function encrypt(str) { + const key = `aaf82c19ea3b090b` + const iv = $.CryptoJS.enc.Utf8.parse(key) + return $.CryptoJS.AES.encrypt($.CryptoJS.enc.Utf8.parse(str), iv, { + iv: iv, + mode: $.CryptoJS.mode.CBC, + padding: $.CryptoJS.pad.Pkcs7 + }).toString() +} // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=t;this.got.post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} From 4a3e4c2608326c34068f683be9340825f52b4f30 Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 30 Mar 2021 21:49:36 +0800 Subject: [PATCH 066/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E5=A8=81=E9=94=8B?= =?UTF-8?q?=E7=BD=91]:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96=20cookie=20?= =?UTF-8?q?=E6=97=B6=E6=97=A0=E6=B3=95=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.json | 2 +- feng/feng.cookie.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index c40a886d2..ad43edf61 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -420,7 +420,7 @@ { "id": "feng", "name": "威锋网", - "keys": ["chavy_login_feng"], + "keys": ["@wangfei021325, chavy_login_feng"], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/feng", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js", diff --git a/feng/feng.cookie.js b/feng/feng.cookie.js index d6dd61a41..c00c697c8 100644 --- a/feng/feng.cookie.js +++ b/feng/feng.cookie.js @@ -14,7 +14,7 @@ $.KEY_login = 'chavy_login_feng' $.msg($.name, $.subt, $.desc) })() .catch((e) => $.logErr(e)) - .finally(() => $.done) + .finally(() => $.done()) // prettier-ignore function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} From 16dfa0a16c45d5886795b3727ae12af9fce57ad8 Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 30 Mar 2021 22:24:26 +0800 Subject: [PATCH 067/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[chavy.boxjs.json]:?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=A0=BC=E5=BC=8F=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=9B=B4=E6=96=B0=E7=99=BD=E5=B1=8F=EF=BC=88?= =?UTF-8?q?=E5=B7=B2=E7=99=BD=E5=B1=8F=E9=9C=80=E6=80=A5=E6=95=91=E6=8A=B9?= =?UTF-8?q?=E6=8E=89=E8=AE=A2=E9=98=85=E7=BC=93=E5=AD=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index ad43edf61..89acea0d3 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -420,8 +420,8 @@ { "id": "feng", "name": "威锋网", - "keys": ["@wangfei021325, chavy_login_feng"], - "author": "@chavyleung", + "keys": ["chavy_login_feng"], + "author": "@wangfei021325, @chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/feng", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js", "icons": [ From 663b985a5a849a13f9d1ed7c53e14a5eb1ba9cb2 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 31 Mar 2021 08:57:09 +0800 Subject: [PATCH 068/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E5=A8=81=E9=94=8B?= =?UTF-8?q?=E7=BD=91]:=20=E8=B0=83=E6=95=B4=20QX=20=E8=8E=B7=E5=8F=96=20co?= =?UTF-8?q?okie=20=E7=9A=84=E9=87=8D=E5=86=99=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feng/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feng/README.md b/feng/README.md index 288d21568..847bb91de 100644 --- a/feng/README.md +++ b/feng/README.md @@ -18,7 +18,7 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr 49.234.36.200:9091 [rewrite_local] -^http:\/\/49.234.36.200:9091\/v1\/auth\/signin url script-response-body https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js +^http:\/\/49.234.36.200:9091\/v1\/auth\/signin url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.cookie.js [task_local] 1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/feng/feng.js From 91d7343cb9ec0f94863928684dcb916ed8c1e220 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 31 Mar 2021 22:52:50 +0800 Subject: [PATCH 069/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E9=A1=BA=E4=B8=B0?= =?UTF-8?q?=E9=80=9F=E8=BF=90]:=20=E6=81=A2=E5=A4=8D=20APP=20=E7=AB=AF?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=EF=BC=8C=E6=84=9F=E8=B0=A2=20@wangfei021325?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.json | 4 +- sfexpress/README.md | 103 ++++------------- sfexpress/sfexpress.cookie.js | 82 +++---------- sfexpress/sfexpress.js | 211 ++++++++++++++++++++++------------ 4 files changed, 182 insertions(+), 218 deletions(-) diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index 89acea0d3..2c6f0d375 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -282,8 +282,8 @@ { "id": "sfexpress", "name": "顺丰速运", - "keys": ["chavy_loginurl_sfexpress", "chavy_loginheader_sfexpress"], - "author": "@chavyleung", + "keys": ["chavy_login_sfexpress"], + "author": "@wangfei021325, @chavyleung", "repo": "https://github.com/chavyleung/scripts/blob/master/sfexpress", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js", "icons": [ diff --git a/sfexpress/README.md b/sfexpress/README.md index 4f2809dbb..09d435508 100644 --- a/sfexpress/README.md +++ b/sfexpress/README.md @@ -1,108 +1,49 @@ -# 顺丰速运 - -> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 - -> 2020.1.22 据实测顺丰的 Cookie 只能存活 1 天不到,大家先弃坑 - -> 2020.3.15 恢复顺丰签到 (更新脚本、更新配置、重取 Cookie) (QuanX&Surge、商店&TF 都支持) - -> 2020.3.20 修复多余的登录失败提示问题 & 修复没有 \$done() 问题 - -> 2020.3.30 增加 27 周年签到 (增加 1 条`mitm`和 1 条`rewrite`) - -> 2020.5.6 移除 27 周年签到 (活动结束) +# 顺丰速运 (APP) ## 配置 (Surge) ```properties [MITM] -hostname = sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com +hostname = ccsp-egmas.sf-express.com [Script] -http-request ^https:\/\/sf-integral-sign-in.weixinjia.net\/app\/index script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js -http-request ^https:\/\/mcs-mimp-web.sf-express.com\/mcs-mimp\/share\/(.*?)Redirect script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js -cron "*/10 * * * * *" script-path=scripts/sfexpress.js +Rewrite: 顺丰速运 = type=http-request, pattern=^https:\/\/ccsp-egmas.sf-express.com\/cx-app-member\/member\/app\/user\/universalSign,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js,requires-body=true +cron "*/10 * * * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js ``` ## 配置 (QuanX) ```properties [MITM] -hostname = sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com +hostname = ccsp-egmas.sf-express.com [rewrite_local] -# [商店版] -^https:\/\/sf-integral-sign-in.weixinjia.net\/app\/index url script-request-header sfexpress.cookie.js -^https:\/\/mcs-mimp-web.sf-express.com\/mcs-mimp\/share\/(.*?)Redirect url script-request-header sfexpress.cookie.js - -# [TF版] -^https:\/\/sf-integral-sign-in.weixinjia.net\/app\/index url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js -^https:\/\/mcs-mimp-web.sf-express.com\/mcs-mimp\/share\/(.*?)Redirect url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js +^https:\/\/ccsp-egmas.sf-express.com\/cx-app-member\/member\/app\/user\/universalSign url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js [task_local] -1 0 * * * sfexpress.js +1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js ``` -## 说明 - -1. 先把`sf-integral-sign-in.weixinjia.net`加到`[MITM]` -2. 再配置重写规则: - - Surge: 把两条远程脚本放到`[Script]` - - QuanX: 把`sfexpress.cookie.js`和`sfexpress.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) -3. 打开 APP, 访问下`我的顺丰` > `去签到` (访问下`去签到`的页面即可, 不用点`签到`), 系统提示: `获取Cookie: 成功` -4. 打开 APP, 访问下`27周年庆`, 系统提示: `获取Cookie: 成功 (27周年)` -5. 最后就可以把第 1 条脚本注释掉了 - -> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. - -> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次. - -## 常见问题 - -1. 无法写入 Cookie - - - 检查 Surge 系统通知权限放开了没 - - 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴) +## 配置 (Loon) -2. 写入 Cookie 成功, 但签到不成功 - - - 看看是不是在登录前就写入 Cookie 了 - - 如果是,请确保在登录成功后,再尝试写入 Cookie - -3. 为什么有时成功有时失败 - - - 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败) - - 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学): - - - `Surge`配置: - - ```properties - # 没有什么是一顿饭解决不了的: - cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次 - # 如果有,那就两顿: - cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次 - # 实在不行,三顿也能接受: - cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次 +```properties +[MITM] +hostname = ccsp-egmas.sf-express.com - # 再粗暴点,直接: - cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次 - ``` +[rewrite_local] +http-request ^https:\/\/ccsp-egmas.sf-express.com\/cx-app-member\/member\/app\/user\/universalSign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js, requires-body=true, tag=Rewrite: 顺丰速运 - - `QuanX`配置: +[task_local] +cron "1 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js +``` - ```properties - [task_local] - 1 0 * * * xxx.js # 每天00:01执行一次 - 2 0 * * * xxx.js # 每天00:02执行一次 - 3 0 * * * xxx.js # 每天00:03执行一次 +## 说明 - */60 * * * * xxx.js # 每60分执行一次 - ``` +1. 配置重写 +2. `APP` 我的顺丰 > 任务中心 > 去签到 +3. 提示 `获取会话: 成功` +4. 注释重写 ## 感谢 -[@NobyDa](https://github.com/NobyDa) - -[@lhie1](https://github.com/lhie1) - -[@ConnersHua](https://github.com/ConnersHua) +[@wangfei021325](https://github.com/wangfei021325) diff --git a/sfexpress/sfexpress.cookie.js b/sfexpress/sfexpress.cookie.js index 94a30fcb6..6541b3b00 100644 --- a/sfexpress/sfexpress.cookie.js +++ b/sfexpress/sfexpress.cookie.js @@ -1,65 +1,21 @@ -const chavy = init() -const cookieName = '顺丰速运' -const KEY_loginurl = 'chavy_loginurl_sfexpress' -const KEY_loginheader = 'chavy_loginheader_sfexpress' -const KEY_login27url = 'chavy_login27url_sfexpress' -const KEY_login27header = 'chavy_login27header_sfexpress' +const $ = new Env('顺丰速运') +$.KEY_login = 'chavy_login_sfexpress' -if ($request && $request.method != 'OPTIONS' && $request.url.match(/app\/index/)) { - const VAL_loginurl = $request.url - const VAL_loginheader = JSON.stringify($request.headers) - if (VAL_loginurl) chavy.setdata(VAL_loginurl, KEY_loginurl) - if (VAL_loginheader) chavy.setdata(VAL_loginheader, KEY_loginheader) - chavy.msg(cookieName, `获取Cookie: 成功`, ``) -} else if ($request && $request.method != 'OPTIONS' && $request.url.match(/mcs-mimp\/share\/(.*?)Redirect/)) { - const VAL_login27url = $request.url - const VAL_login27header = JSON.stringify($request.headers) - if (VAL_login27url) chavy.setdata(VAL_login27url, KEY_login27url) - if (VAL_login27header) chavy.setdata(VAL_login27header, KEY_login27header) - chavy.msg(cookieName, `获取Cookie: 成功 (27周年)`, ``) -} +!(async () => { + const session = {} + session.url = $request.url + session.body = $request.body + session.headers = $request.headers + console.log(JSON.stringify(session)) + if ($.setdata(JSON.stringify(session), $.KEY_login)) { + $.subt = `获取会话: 成功!` + } else { + $.subt = `获取会话: 失败!` + } + $.msg($.name, $.subt, $.desc) +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) -function init() { - isSurge = () => { - return undefined === this.$httpClient ? false : true - } - isQuanX = () => { - return undefined === this.$task ? false : true - } - getdata = (key) => { - if (isSurge()) return $persistentStore.read(key) - if (isQuanX()) return $prefs.valueForKey(key) - } - setdata = (key, val) => { - if (isSurge()) return $persistentStore.write(key, val) - if (isQuanX()) return $prefs.setValueForKey(key, val) - } - msg = (title, subtitle, body) => { - if (isSurge()) $notification.post(title, subtitle, body) - if (isQuanX()) $notify(title, subtitle, body) - } - log = (message) => console.log(message) - get = (url, cb) => { - if (isSurge()) { - $httpClient.get(url, cb) - } - if (isQuanX()) { - url.method = 'GET' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - post = (url, cb) => { - if (isSurge()) { - $httpClient.post(url, cb) - } - if (isQuanX()) { - url.method = 'POST' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - done = (value = {}) => { - $done(value) - } - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } -} -chavy.done() +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 3e8bc3142..7c9256509 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -1,101 +1,168 @@ +// prettier-ignore +!function (t, r) { "object" == typeof exports ? module.exports = exports = r() : "function" == typeof define && define.amd ? define([], r) : t.CryptoJS = r() }(this, function () { + var t = t || function (t, r) { var e = Object.create || function () { function t() { } return function (r) { var e; return t.prototype = r, e = new t, t.prototype = null, e } }(), i = {}, n = i.lib = {}, o = n.Base = function () { return { extend: function (t) { var r = e(this); return t && r.mixIn(t), r.hasOwnProperty("init") && this.init !== r.init || (r.init = function () { r.$super.init.apply(this, arguments) }), r.init.prototype = r, r.$super = this, r }, create: function () { var t = this.extend(); return t.init.apply(t, arguments), t }, init: function () { }, mixIn: function (t) { for (var r in t) t.hasOwnProperty(r) && (this[r] = t[r]); t.hasOwnProperty("toString") && (this.toString = t.toString) }, clone: function () { return this.init.prototype.extend(this) } } }(), s = n.WordArray = o.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 4 * t.length }, toString: function (t) { return (t || c).stringify(this) }, concat: function (t) { var r = this.words, e = t.words, i = this.sigBytes, n = t.sigBytes; if (this.clamp(), i % 4) for (var o = 0; o < n; o++) { var s = e[o >>> 2] >>> 24 - o % 4 * 8 & 255; r[i + o >>> 2] |= s << 24 - (i + o) % 4 * 8 } else for (var o = 0; o < n; o += 4)r[i + o >>> 2] = e[o >>> 2]; return this.sigBytes += n, this }, clamp: function () { var r = this.words, e = this.sigBytes; r[e >>> 2] &= 4294967295 << 32 - e % 4 * 8, r.length = t.ceil(e / 4) }, clone: function () { var t = o.clone.call(this); return t.words = this.words.slice(0), t }, random: function (r) { for (var e, i = [], n = function (r) { var r = r, e = 987654321, i = 4294967295; return function () { e = 36969 * (65535 & e) + (e >> 16) & i, r = 18e3 * (65535 & r) + (r >> 16) & i; var n = (e << 16) + r & i; return n /= 4294967296, n += .5, n * (t.random() > .5 ? 1 : -1) } }, o = 0; o < r; o += 4) { var a = n(4294967296 * (e || t.random())); e = 987654071 * a(), i.push(4294967296 * a() | 0) } return new s.init(i, r) } }), a = i.enc = {}, c = a.Hex = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push((o >>> 4).toString(16)), i.push((15 & o).toString(16)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i += 2)e[i >>> 3] |= parseInt(t.substr(i, 2), 16) << 24 - i % 8 * 4; return new s.init(e, r / 2) } }, h = a.Latin1 = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 2] |= (255 & t.charCodeAt(i)) << 24 - i % 4 * 8; return new s.init(e, r) } }, l = a.Utf8 = { stringify: function (t) { try { return decodeURIComponent(escape(h.stringify(t))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, parse: function (t) { return h.parse(unescape(encodeURIComponent(t))) } }, f = n.BufferedBlockAlgorithm = o.extend({ reset: function () { this._data = new s.init, this._nDataBytes = 0 }, _append: function (t) { "string" == typeof t && (t = l.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes }, _process: function (r) { var e = this._data, i = e.words, n = e.sigBytes, o = this.blockSize, a = 4 * o, c = n / a; c = r ? t.ceil(c) : t.max((0 | c) - this._minBufferSize, 0); var h = c * o, l = t.min(4 * h, n); if (h) { for (var f = 0; f < h; f += o)this._doProcessBlock(i, f); var u = i.splice(0, h); e.sigBytes -= l } return new s.init(u, l) }, clone: function () { var t = o.clone.call(this); return t._data = this._data.clone(), t }, _minBufferSize: 0 }), u = (n.Hasher = f.extend({ cfg: o.extend(), init: function (t) { this.cfg = this.cfg.extend(t), this.reset() }, reset: function () { f.reset.call(this), this._doReset() }, update: function (t) { return this._append(t), this._process(), this }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, blockSize: 16, _createHelper: function (t) { return function (r, e) { return new t.init(e).finalize(r) } }, _createHmacHelper: function (t) { return function (r, e) { return new u.HMAC.init(t, e).finalize(r) } } }), i.algo = {}); return i }(Math); return function () { function r(t, r, e) { for (var i = [], o = 0, s = 0; s < r; s++)if (s % 4) { var a = e[t.charCodeAt(s - 1)] << s % 4 * 2, c = e[t.charCodeAt(s)] >>> 6 - s % 4 * 2; i[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ } return n.create(i, o) } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Base64 = { stringify: function (t) { var r = t.words, e = t.sigBytes, i = this._map; t.clamp(); for (var n = [], o = 0; o < e; o += 3)for (var s = r[o >>> 2] >>> 24 - o % 4 * 8 & 255, a = r[o + 1 >>> 2] >>> 24 - (o + 1) % 4 * 8 & 255, c = r[o + 2 >>> 2] >>> 24 - (o + 2) % 4 * 8 & 255, h = s << 16 | a << 8 | c, l = 0; l < 4 && o + .75 * l < e; l++)n.push(i.charAt(h >>> 6 * (3 - l) & 63)); var f = i.charAt(64); if (f) for (; n.length % 4;)n.push(f); return n.join("") }, parse: function (t) { var e = t.length, i = this._map, n = this._reverseMap; if (!n) { n = this._reverseMap = []; for (var o = 0; o < i.length; o++)n[i.charCodeAt(o)] = o } var s = i.charAt(64); if (s) { var a = t.indexOf(s); a !== -1 && (e = a) } return r(t, e, n) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } }(), function (r) { function e(t, r, e, i, n, o, s) { var a = t + (r & e | ~r & i) + n + s; return (a << o | a >>> 32 - o) + r } function i(t, r, e, i, n, o, s) { var a = t + (r & i | e & ~i) + n + s; return (a << o | a >>> 32 - o) + r } function n(t, r, e, i, n, o, s) { var a = t + (r ^ e ^ i) + n + s; return (a << o | a >>> 32 - o) + r } function o(t, r, e, i, n, o, s) { var a = t + (e ^ (r | ~i)) + n + s; return (a << o | a >>> 32 - o) + r } var s = t, a = s.lib, c = a.WordArray, h = a.Hasher, l = s.algo, f = []; !function () { for (var t = 0; t < 64; t++)f[t] = 4294967296 * r.abs(r.sin(t + 1)) | 0 }(); var u = l.MD5 = h.extend({ _doReset: function () { this._hash = new c.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (t, r) { for (var s = 0; s < 16; s++) { var a = r + s, c = t[a]; t[a] = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8) } var h = this._hash.words, l = t[r + 0], u = t[r + 1], d = t[r + 2], v = t[r + 3], p = t[r + 4], _ = t[r + 5], y = t[r + 6], g = t[r + 7], B = t[r + 8], w = t[r + 9], k = t[r + 10], S = t[r + 11], m = t[r + 12], x = t[r + 13], b = t[r + 14], H = t[r + 15], z = h[0], A = h[1], C = h[2], D = h[3]; z = e(z, A, C, D, l, 7, f[0]), D = e(D, z, A, C, u, 12, f[1]), C = e(C, D, z, A, d, 17, f[2]), A = e(A, C, D, z, v, 22, f[3]), z = e(z, A, C, D, p, 7, f[4]), D = e(D, z, A, C, _, 12, f[5]), C = e(C, D, z, A, y, 17, f[6]), A = e(A, C, D, z, g, 22, f[7]), z = e(z, A, C, D, B, 7, f[8]), D = e(D, z, A, C, w, 12, f[9]), C = e(C, D, z, A, k, 17, f[10]), A = e(A, C, D, z, S, 22, f[11]), z = e(z, A, C, D, m, 7, f[12]), D = e(D, z, A, C, x, 12, f[13]), C = e(C, D, z, A, b, 17, f[14]), A = e(A, C, D, z, H, 22, f[15]), z = i(z, A, C, D, u, 5, f[16]), D = i(D, z, A, C, y, 9, f[17]), C = i(C, D, z, A, S, 14, f[18]), A = i(A, C, D, z, l, 20, f[19]), z = i(z, A, C, D, _, 5, f[20]), D = i(D, z, A, C, k, 9, f[21]), C = i(C, D, z, A, H, 14, f[22]), A = i(A, C, D, z, p, 20, f[23]), z = i(z, A, C, D, w, 5, f[24]), D = i(D, z, A, C, b, 9, f[25]), C = i(C, D, z, A, v, 14, f[26]), A = i(A, C, D, z, B, 20, f[27]), z = i(z, A, C, D, x, 5, f[28]), D = i(D, z, A, C, d, 9, f[29]), C = i(C, D, z, A, g, 14, f[30]), A = i(A, C, D, z, m, 20, f[31]), z = n(z, A, C, D, _, 4, f[32]), D = n(D, z, A, C, B, 11, f[33]), C = n(C, D, z, A, S, 16, f[34]), A = n(A, C, D, z, b, 23, f[35]), z = n(z, A, C, D, u, 4, f[36]), D = n(D, z, A, C, p, 11, f[37]), C = n(C, D, z, A, g, 16, f[38]), A = n(A, C, D, z, k, 23, f[39]), z = n(z, A, C, D, x, 4, f[40]), D = n(D, z, A, C, l, 11, f[41]), C = n(C, D, z, A, v, 16, f[42]), A = n(A, C, D, z, y, 23, f[43]), z = n(z, A, C, D, w, 4, f[44]), D = n(D, z, A, C, m, 11, f[45]), C = n(C, D, z, A, H, 16, f[46]), A = n(A, C, D, z, d, 23, f[47]), z = o(z, A, C, D, l, 6, f[48]), D = o(D, z, A, C, g, 10, f[49]), C = o(C, D, z, A, b, 15, f[50]), A = o(A, C, D, z, _, 21, f[51]), z = o(z, A, C, D, m, 6, f[52]), D = o(D, z, A, C, v, 10, f[53]), C = o(C, D, z, A, k, 15, f[54]), A = o(A, C, D, z, u, 21, f[55]), z = o(z, A, C, D, B, 6, f[56]), D = o(D, z, A, C, H, 10, f[57]), C = o(C, D, z, A, y, 15, f[58]), A = o(A, C, D, z, x, 21, f[59]), z = o(z, A, C, D, p, 6, f[60]), D = o(D, z, A, C, S, 10, f[61]), C = o(C, D, z, A, d, 15, f[62]), A = o(A, C, D, z, w, 21, f[63]), h[0] = h[0] + z | 0, h[1] = h[1] + A | 0, h[2] = h[2] + C | 0, h[3] = h[3] + D | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; e[n >>> 5] |= 128 << 24 - n % 32; var o = r.floor(i / 4294967296), s = i; e[(n + 64 >>> 9 << 4) + 15] = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), e[(n + 64 >>> 9 << 4) + 14] = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8), t.sigBytes = 4 * (e.length + 1), this._process(); for (var a = this._hash, c = a.words, h = 0; h < 4; h++) { var l = c[h]; c[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } return a }, clone: function () { var t = h.clone.call(this); return t._hash = this._hash.clone(), t } }); s.MD5 = h._createHelper(u), s.HmacMD5 = h._createHmacHelper(u) }(Math), function () { var r = t, e = r.lib, i = e.WordArray, n = e.Hasher, o = r.algo, s = [], a = o.SHA1 = n.extend({ _doReset: function () { this._hash = new i.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], a = e[3], c = e[4], h = 0; h < 80; h++) { if (h < 16) s[h] = 0 | t[r + h]; else { var l = s[h - 3] ^ s[h - 8] ^ s[h - 14] ^ s[h - 16]; s[h] = l << 1 | l >>> 31 } var f = (i << 5 | i >>> 27) + c + s[h]; f += h < 20 ? (n & o | ~n & a) + 1518500249 : h < 40 ? (n ^ o ^ a) + 1859775393 : h < 60 ? (n & o | n & a | o & a) - 1894007588 : (n ^ o ^ a) - 899497514, c = a, a = o, o = n << 30 | n >>> 2, n = i, i = f } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + a | 0, e[4] = e[4] + c | 0 }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; return r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = Math.floor(e / 4294967296), r[(i + 64 >>> 9 << 4) + 15] = e, t.sigBytes = 4 * r.length, this._process(), this._hash }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t } }); r.SHA1 = n._createHelper(a), r.HmacSHA1 = n._createHmacHelper(a) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.algo, a = [], c = []; !function () { function t(t) { for (var e = r.sqrt(t), i = 2; i <= e; i++)if (!(t % i)) return !1; return !0 } function e(t) { return 4294967296 * (t - (0 | t)) | 0 } for (var i = 2, n = 0; n < 64;)t(i) && (n < 8 && (a[n] = e(r.pow(i, .5))), c[n] = e(r.pow(i, 1 / 3)), n++), i++ }(); var h = [], l = s.SHA256 = o.extend({ _doReset: function () { this._hash = new n.init(a.slice(0)) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], l = e[5], f = e[6], u = e[7], d = 0; d < 64; d++) { if (d < 16) h[d] = 0 | t[r + d]; else { var v = h[d - 15], p = (v << 25 | v >>> 7) ^ (v << 14 | v >>> 18) ^ v >>> 3, _ = h[d - 2], y = (_ << 15 | _ >>> 17) ^ (_ << 13 | _ >>> 19) ^ _ >>> 10; h[d] = p + h[d - 7] + y + h[d - 16] } var g = a & l ^ ~a & f, B = i & n ^ i & o ^ n & o, w = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), k = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), S = u + k + g + c[d] + h[d], m = w + B; u = f, f = l, l = a, a = s + S | 0, s = o, o = n, n = i, i = S + m | 0 } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + s | 0, e[4] = e[4] + a | 0, e[5] = e[5] + l | 0, e[6] = e[6] + f | 0, e[7] = e[7] + u | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; return e[n >>> 5] |= 128 << 24 - n % 32, e[(n + 64 >>> 9 << 4) + 14] = r.floor(i / 4294967296), e[(n + 64 >>> 9 << 4) + 15] = i, t.sigBytes = 4 * e.length, this._process(), this._hash }, clone: function () { var t = o.clone.call(this); return t._hash = this._hash.clone(), t } }); e.SHA256 = o._createHelper(l), e.HmacSHA256 = o._createHmacHelper(l) }(Math), function () { function r(t) { return t << 8 & 4278255360 | t >>> 8 & 16711935 } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Utf16 = o.Utf16BE = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n += 2) { var o = r[n >>> 2] >>> 16 - n % 4 * 8 & 65535; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 1] |= t.charCodeAt(i) << 16 - i % 2 * 16; return n.create(e, 2 * r) } }; o.Utf16LE = { stringify: function (t) { for (var e = t.words, i = t.sigBytes, n = [], o = 0; o < i; o += 2) { var s = r(e[o >>> 2] >>> 16 - o % 4 * 8 & 65535); n.push(String.fromCharCode(s)) } return n.join("") }, parse: function (t) { for (var e = t.length, i = [], o = 0; o < e; o++)i[o >>> 1] |= r(t.charCodeAt(o) << 16 - o % 2 * 16); return n.create(i, 2 * e) } } }(), function () { if ("function" == typeof ArrayBuffer) { var r = t, e = r.lib, i = e.WordArray, n = i.init, o = i.init = function (t) { if (t instanceof ArrayBuffer && (t = new Uint8Array(t)), (t instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array) && (t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength)), t instanceof Uint8Array) { for (var r = t.byteLength, e = [], i = 0; i < r; i++)e[i >>> 2] |= t[i] << 24 - i % 4 * 8; n.call(this, e, r) } else n.apply(this, arguments) }; o.prototype = i } }(), function (r) { function e(t, r, e) { return t ^ r ^ e } function i(t, r, e) { return t & r | ~t & e } function n(t, r, e) { return (t | ~r) ^ e } function o(t, r, e) { return t & e | r & ~e } function s(t, r, e) { return t ^ (r | ~e) } function a(t, r) { return t << r | t >>> 32 - r } var c = t, h = c.lib, l = h.WordArray, f = h.Hasher, u = c.algo, d = l.create([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]), v = l.create([5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]), p = l.create([11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]), _ = l.create([8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]), y = l.create([0, 1518500249, 1859775393, 2400959708, 2840853838]), g = l.create([1352829926, 1548603684, 1836072691, 2053994217, 0]), B = u.RIPEMD160 = f.extend({ _doReset: function () { this._hash = l.create([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var c = 0; c < 16; c++) { var h = r + c, l = t[h]; t[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } var f, u, B, w, k, S, m, x, b, H, z = this._hash.words, A = y.words, C = g.words, D = d.words, R = v.words, E = p.words, M = _.words; S = f = z[0], m = u = z[1], x = B = z[2], b = w = z[3], H = k = z[4]; for (var F, c = 0; c < 80; c += 1)F = f + t[r + D[c]] | 0, F += c < 16 ? e(u, B, w) + A[0] : c < 32 ? i(u, B, w) + A[1] : c < 48 ? n(u, B, w) + A[2] : c < 64 ? o(u, B, w) + A[3] : s(u, B, w) + A[4], F |= 0, F = a(F, E[c]), F = F + k | 0, f = k, k = w, w = a(B, 10), B = u, u = F, F = S + t[r + R[c]] | 0, F += c < 16 ? s(m, x, b) + C[0] : c < 32 ? o(m, x, b) + C[1] : c < 48 ? n(m, x, b) + C[2] : c < 64 ? i(m, x, b) + C[3] : e(m, x, b) + C[4], F |= 0, F = a(F, M[c]), F = F + H | 0, S = H, H = b, b = a(x, 10), x = m, m = F; F = z[1] + B + b | 0, z[1] = z[2] + w + H | 0, z[2] = z[3] + k + S | 0, z[3] = z[4] + f + m | 0, z[4] = z[0] + u + x | 0, z[0] = F }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = 16711935 & (e << 8 | e >>> 24) | 4278255360 & (e << 24 | e >>> 8), t.sigBytes = 4 * (r.length + 1), this._process(); for (var n = this._hash, o = n.words, s = 0; s < 5; s++) { var a = o[s]; o[s] = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8) } return n }, clone: function () { var t = f.clone.call(this); return t._hash = this._hash.clone(), t } }); c.RIPEMD160 = f._createHelper(B), c.HmacRIPEMD160 = f._createHmacHelper(B) }(Math), function () { var r = t, e = r.lib, i = e.Base, n = r.enc, o = n.Utf8, s = r.algo; s.HMAC = i.extend({ init: function (t, r) { t = this._hasher = new t.init, "string" == typeof r && (r = o.parse(r)); var e = t.blockSize, i = 4 * e; r.sigBytes > i && (r = t.finalize(r)), r.clamp(); for (var n = this._oKey = r.clone(), s = this._iKey = r.clone(), a = n.words, c = s.words, h = 0; h < e; h++)a[h] ^= 1549556828, c[h] ^= 909522486; n.sigBytes = s.sigBytes = i, this.reset() }, reset: function () { var t = this._hasher; t.reset(), t.update(this._iKey) }, update: function (t) { return this._hasher.update(t), this }, finalize: function (t) { var r = this._hasher, e = r.finalize(t); r.reset(); var i = r.finalize(this._oKey.clone().concat(e)); return i } }) }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.SHA1, a = o.HMAC, c = o.PBKDF2 = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = a.create(e.hasher, t), o = n.create(), s = n.create([1]), c = o.words, h = s.words, l = e.keySize, f = e.iterations; c.length < l;) { var u = i.update(r).finalize(s); i.reset(); for (var d = u.words, v = d.length, p = u, _ = 1; _ < f; _++) { p = i.finalize(p), i.reset(); for (var y = p.words, g = 0; g < v; g++)d[g] ^= y[g] } o.concat(u), h[0]++ } return o.sigBytes = 4 * l, o } }); r.PBKDF2 = function (t, r, e) { return c.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.MD5, a = o.EvpKDF = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = e.hasher.create(), o = n.create(), s = o.words, a = e.keySize, c = e.iterations; s.length < a;) { h && i.update(h); var h = i.update(t).finalize(r); i.reset(); for (var l = 1; l < c; l++)h = i.finalize(h), i.reset(); o.concat(h) } return o.sigBytes = 4 * a, o } }); r.EvpKDF = function (t, r, e) { return a.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.WordArray, n = r.algo, o = n.SHA256, s = n.SHA224 = o.extend({ _doReset: function () { this._hash = new i.init([3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]) }, _doFinalize: function () { var t = o._doFinalize.call(this); return t.sigBytes -= 4, t } }); r.SHA224 = o._createHelper(s), r.HmacSHA224 = o._createHmacHelper(s) }(), function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = e.x64 = {}; s.Word = n.extend({ init: function (t, r) { this.high = t, this.low = r } }), s.WordArray = n.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 8 * t.length }, toX32: function () { for (var t = this.words, r = t.length, e = [], i = 0; i < r; i++) { var n = t[i]; e.push(n.high), e.push(n.low) } return o.create(e, this.sigBytes) }, clone: function () { for (var t = n.clone.call(this), r = t.words = this.words.slice(0), e = r.length, i = 0; i < e; i++)r[i] = r[i].clone(); return t } }) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.x64, a = s.Word, c = e.algo, h = [], l = [], f = []; !function () { for (var t = 1, r = 0, e = 0; e < 24; e++) { h[t + 5 * r] = (e + 1) * (e + 2) / 2 % 64; var i = r % 5, n = (2 * t + 3 * r) % 5; t = i, r = n } for (var t = 0; t < 5; t++)for (var r = 0; r < 5; r++)l[t + 5 * r] = r + (2 * t + 3 * r) % 5 * 5; for (var o = 1, s = 0; s < 24; s++) { for (var c = 0, u = 0, d = 0; d < 7; d++) { if (1 & o) { var v = (1 << d) - 1; v < 32 ? u ^= 1 << v : c ^= 1 << v - 32 } 128 & o ? o = o << 1 ^ 113 : o <<= 1 } f[s] = a.create(c, u) } }(); var u = []; !function () { for (var t = 0; t < 25; t++)u[t] = a.create() }(); var d = c.SHA3 = o.extend({ cfg: o.cfg.extend({ outputLength: 512 }), _doReset: function () { for (var t = this._state = [], r = 0; r < 25; r++)t[r] = new a.init; this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32 }, _doProcessBlock: function (t, r) { for (var e = this._state, i = this.blockSize / 2, n = 0; n < i; n++) { var o = t[r + 2 * n], s = t[r + 2 * n + 1]; o = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), s = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8); var a = e[n]; a.high ^= s, a.low ^= o } for (var c = 0; c < 24; c++) { for (var d = 0; d < 5; d++) { for (var v = 0, p = 0, _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; v ^= a.high, p ^= a.low } var y = u[d]; y.high = v, y.low = p } for (var d = 0; d < 5; d++)for (var g = u[(d + 4) % 5], B = u[(d + 1) % 5], w = B.high, k = B.low, v = g.high ^ (w << 1 | k >>> 31), p = g.low ^ (k << 1 | w >>> 31), _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; a.high ^= v, a.low ^= p } for (var S = 1; S < 25; S++) { var a = e[S], m = a.high, x = a.low, b = h[S]; if (b < 32) var v = m << b | x >>> 32 - b, p = x << b | m >>> 32 - b; else var v = x << b - 32 | m >>> 64 - b, p = m << b - 32 | x >>> 64 - b; var H = u[l[S]]; H.high = v, H.low = p } var z = u[0], A = e[0]; z.high = A.high, z.low = A.low; for (var d = 0; d < 5; d++)for (var _ = 0; _ < 5; _++) { var S = d + 5 * _, a = e[S], C = u[S], D = u[(d + 1) % 5 + 5 * _], R = u[(d + 2) % 5 + 5 * _]; a.high = C.high ^ ~D.high & R.high, a.low = C.low ^ ~D.low & R.low } var a = e[0], E = f[c]; a.high ^= E.high, a.low ^= E.low } }, _doFinalize: function () { var t = this._data, e = t.words, i = (8 * this._nDataBytes, 8 * t.sigBytes), o = 32 * this.blockSize; e[i >>> 5] |= 1 << 24 - i % 32, e[(r.ceil((i + 1) / o) * o >>> 5) - 1] |= 128, t.sigBytes = 4 * e.length, this._process(); for (var s = this._state, a = this.cfg.outputLength / 8, c = a / 8, h = [], l = 0; l < c; l++) { var f = s[l], u = f.high, d = f.low; u = 16711935 & (u << 8 | u >>> 24) | 4278255360 & (u << 24 | u >>> 8), d = 16711935 & (d << 8 | d >>> 24) | 4278255360 & (d << 24 | d >>> 8), h.push(d), h.push(u) } return new n.init(h, a) }, clone: function () { for (var t = o.clone.call(this), r = t._state = this._state.slice(0), e = 0; e < 25; e++)r[e] = r[e].clone(); return t } }); e.SHA3 = o._createHelper(d), e.HmacSHA3 = o._createHmacHelper(d) }(Math), function () { function r() { return s.create.apply(s, arguments) } var e = t, i = e.lib, n = i.Hasher, o = e.x64, s = o.Word, a = o.WordArray, c = e.algo, h = [r(1116352408, 3609767458), r(1899447441, 602891725), r(3049323471, 3964484399), r(3921009573, 2173295548), r(961987163, 4081628472), r(1508970993, 3053834265), r(2453635748, 2937671579), r(2870763221, 3664609560), r(3624381080, 2734883394), r(310598401, 1164996542), r(607225278, 1323610764), r(1426881987, 3590304994), r(1925078388, 4068182383), r(2162078206, 991336113), r(2614888103, 633803317), r(3248222580, 3479774868), r(3835390401, 2666613458), r(4022224774, 944711139), r(264347078, 2341262773), r(604807628, 2007800933), r(770255983, 1495990901), r(1249150122, 1856431235), r(1555081692, 3175218132), r(1996064986, 2198950837), r(2554220882, 3999719339), r(2821834349, 766784016), r(2952996808, 2566594879), r(3210313671, 3203337956), r(3336571891, 1034457026), r(3584528711, 2466948901), r(113926993, 3758326383), r(338241895, 168717936), r(666307205, 1188179964), r(773529912, 1546045734), r(1294757372, 1522805485), r(1396182291, 2643833823), r(1695183700, 2343527390), r(1986661051, 1014477480), r(2177026350, 1206759142), r(2456956037, 344077627), r(2730485921, 1290863460), r(2820302411, 3158454273), r(3259730800, 3505952657), r(3345764771, 106217008), r(3516065817, 3606008344), r(3600352804, 1432725776), r(4094571909, 1467031594), r(275423344, 851169720), r(430227734, 3100823752), r(506948616, 1363258195), r(659060556, 3750685593), r(883997877, 3785050280), r(958139571, 3318307427), r(1322822218, 3812723403), r(1537002063, 2003034995), r(1747873779, 3602036899), r(1955562222, 1575990012), r(2024104815, 1125592928), r(2227730452, 2716904306), r(2361852424, 442776044), r(2428436474, 593698344), r(2756734187, 3733110249), r(3204031479, 2999351573), r(3329325298, 3815920427), r(3391569614, 3928383900), r(3515267271, 566280711), r(3940187606, 3454069534), r(4118630271, 4000239992), r(116418474, 1914138554), r(174292421, 2731055270), r(289380356, 3203993006), r(460393269, 320620315), r(685471733, 587496836), r(852142971, 1086792851), r(1017036298, 365543100), r(1126000580, 2618297676), r(1288033470, 3409855158), r(1501505948, 4234509866), r(1607167915, 987167468), r(1816402316, 1246189591)], l = []; !function () { for (var t = 0; t < 80; t++)l[t] = r() }(); var f = c.SHA512 = n.extend({ _doReset: function () { this._hash = new a.init([new s.init(1779033703, 4089235720), new s.init(3144134277, 2227873595), new s.init(1013904242, 4271175723), new s.init(2773480762, 1595750129), new s.init(1359893119, 2917565137), new s.init(2600822924, 725511199), new s.init(528734635, 4215389547), new s.init(1541459225, 327033209)]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], c = e[5], f = e[6], u = e[7], d = i.high, v = i.low, p = n.high, _ = n.low, y = o.high, g = o.low, B = s.high, w = s.low, k = a.high, S = a.low, m = c.high, x = c.low, b = f.high, H = f.low, z = u.high, A = u.low, C = d, D = v, R = p, E = _, M = y, F = g, P = B, W = w, O = k, U = S, I = m, K = x, X = b, L = H, j = z, N = A, T = 0; T < 80; T++) { var Z = l[T]; if (T < 16) var q = Z.high = 0 | t[r + 2 * T], G = Z.low = 0 | t[r + 2 * T + 1]; else { var J = l[T - 15], $ = J.high, Q = J.low, V = ($ >>> 1 | Q << 31) ^ ($ >>> 8 | Q << 24) ^ $ >>> 7, Y = (Q >>> 1 | $ << 31) ^ (Q >>> 8 | $ << 24) ^ (Q >>> 7 | $ << 25), tt = l[T - 2], rt = tt.high, et = tt.low, it = (rt >>> 19 | et << 13) ^ (rt << 3 | et >>> 29) ^ rt >>> 6, nt = (et >>> 19 | rt << 13) ^ (et << 3 | rt >>> 29) ^ (et >>> 6 | rt << 26), ot = l[T - 7], st = ot.high, at = ot.low, ct = l[T - 16], ht = ct.high, lt = ct.low, G = Y + at, q = V + st + (G >>> 0 < Y >>> 0 ? 1 : 0), G = G + nt, q = q + it + (G >>> 0 < nt >>> 0 ? 1 : 0), G = G + lt, q = q + ht + (G >>> 0 < lt >>> 0 ? 1 : 0); Z.high = q, Z.low = G } var ft = O & I ^ ~O & X, ut = U & K ^ ~U & L, dt = C & R ^ C & M ^ R & M, vt = D & E ^ D & F ^ E & F, pt = (C >>> 28 | D << 4) ^ (C << 30 | D >>> 2) ^ (C << 25 | D >>> 7), _t = (D >>> 28 | C << 4) ^ (D << 30 | C >>> 2) ^ (D << 25 | C >>> 7), yt = (O >>> 14 | U << 18) ^ (O >>> 18 | U << 14) ^ (O << 23 | U >>> 9), gt = (U >>> 14 | O << 18) ^ (U >>> 18 | O << 14) ^ (U << 23 | O >>> 9), Bt = h[T], wt = Bt.high, kt = Bt.low, St = N + gt, mt = j + yt + (St >>> 0 < N >>> 0 ? 1 : 0), St = St + ut, mt = mt + ft + (St >>> 0 < ut >>> 0 ? 1 : 0), St = St + kt, mt = mt + wt + (St >>> 0 < kt >>> 0 ? 1 : 0), St = St + G, mt = mt + q + (St >>> 0 < G >>> 0 ? 1 : 0), xt = _t + vt, bt = pt + dt + (xt >>> 0 < _t >>> 0 ? 1 : 0); j = X, N = L, X = I, L = K, I = O, K = U, U = W + St | 0, O = P + mt + (U >>> 0 < W >>> 0 ? 1 : 0) | 0, P = M, W = F, M = R, F = E, R = C, E = D, D = St + xt | 0, C = mt + bt + (D >>> 0 < St >>> 0 ? 1 : 0) | 0 } v = i.low = v + D, i.high = d + C + (v >>> 0 < D >>> 0 ? 1 : 0), _ = n.low = _ + E, n.high = p + R + (_ >>> 0 < E >>> 0 ? 1 : 0), g = o.low = g + F, o.high = y + M + (g >>> 0 < F >>> 0 ? 1 : 0), w = s.low = w + W, s.high = B + P + (w >>> 0 < W >>> 0 ? 1 : 0), S = a.low = S + U, a.high = k + O + (S >>> 0 < U >>> 0 ? 1 : 0), x = c.low = x + K, c.high = m + I + (x >>> 0 < K >>> 0 ? 1 : 0), H = f.low = H + L, f.high = b + X + (H >>> 0 < L >>> 0 ? 1 : 0), A = u.low = A + N, u.high = z + j + (A >>> 0 < N >>> 0 ? 1 : 0) }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 128 >>> 10 << 5) + 30] = Math.floor(e / 4294967296), r[(i + 128 >>> 10 << 5) + 31] = e, t.sigBytes = 4 * r.length, this._process(); var n = this._hash.toX32(); return n }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t }, blockSize: 32 }); e.SHA512 = n._createHelper(f), e.HmacSHA512 = n._createHmacHelper(f) }(), function () { var r = t, e = r.x64, i = e.Word, n = e.WordArray, o = r.algo, s = o.SHA512, a = o.SHA384 = s.extend({ _doReset: function () { this._hash = new n.init([new i.init(3418070365, 3238371032), new i.init(1654270250, 914150663), new i.init(2438529370, 812702999), new i.init(355462360, 4144912697), new i.init(1731405415, 4290775857), new i.init(2394180231, 1750603025), new i.init(3675008525, 1694076839), new i.init(1203062813, 3204075428)]) }, _doFinalize: function () { var t = s._doFinalize.call(this); return t.sigBytes -= 16, t } }); r.SHA384 = s._createHelper(a), r.HmacSHA384 = s._createHmacHelper(a) }(), t.lib.Cipher || function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = i.BufferedBlockAlgorithm, a = e.enc, c = (a.Utf8, a.Base64), h = e.algo, l = h.EvpKDF, f = i.Cipher = s.extend({ cfg: n.extend(), createEncryptor: function (t, r) { return this.create(this._ENC_XFORM_MODE, t, r) }, createDecryptor: function (t, r) { return this.create(this._DEC_XFORM_MODE, t, r) }, init: function (t, r, e) { this.cfg = this.cfg.extend(e), this._xformMode = t, this._key = r, this.reset() }, reset: function () { s.reset.call(this), this._doReset() }, process: function (t) { return this._append(t), this._process() }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, keySize: 4, ivSize: 4, _ENC_XFORM_MODE: 1, _DEC_XFORM_MODE: 2, _createHelper: function () { function t(t) { return "string" == typeof t ? m : w } return function (r) { return { encrypt: function (e, i, n) { return t(i).encrypt(r, e, i, n) }, decrypt: function (e, i, n) { return t(i).decrypt(r, e, i, n) } } } }() }), u = (i.StreamCipher = f.extend({ _doFinalize: function () { var t = this._process(!0); return t }, blockSize: 1 }), e.mode = {}), d = i.BlockCipherMode = n.extend({ createEncryptor: function (t, r) { return this.Encryptor.create(t, r) }, createDecryptor: function (t, r) { return this.Decryptor.create(t, r) }, init: function (t, r) { this._cipher = t, this._iv = r } }), v = u.CBC = function () { function t(t, e, i) { var n = this._iv; if (n) { var o = n; this._iv = r } else var o = this._prevBlock; for (var s = 0; s < i; s++)t[e + s] ^= o[s] } var e = d.extend(); return e.Encryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize; t.call(this, r, e, n), i.encryptBlock(r, e), this._prevBlock = r.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize, o = r.slice(e, e + n); i.decryptBlock(r, e), t.call(this, r, e, n), this._prevBlock = o } }), e }(), p = e.pad = {}, _ = p.Pkcs7 = { pad: function (t, r) { for (var e = 4 * r, i = e - t.sigBytes % e, n = i << 24 | i << 16 | i << 8 | i, s = [], a = 0; a < i; a += 4)s.push(n); var c = o.create(s, i); t.concat(c) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, y = (i.BlockCipher = f.extend({ cfg: f.cfg.extend({ mode: v, padding: _ }), reset: function () { f.reset.call(this); var t = this.cfg, r = t.iv, e = t.mode; if (this._xformMode == this._ENC_XFORM_MODE) var i = e.createEncryptor; else { var i = e.createDecryptor; this._minBufferSize = 1 } this._mode && this._mode.__creator == i ? this._mode.init(this, r && r.words) : (this._mode = i.call(e, this, r && r.words), this._mode.__creator = i) }, _doProcessBlock: function (t, r) { this._mode.processBlock(t, r) }, _doFinalize: function () { var t = this.cfg.padding; if (this._xformMode == this._ENC_XFORM_MODE) { t.pad(this._data, this.blockSize); var r = this._process(!0) } else { var r = this._process(!0); t.unpad(r) } return r }, blockSize: 4 }), i.CipherParams = n.extend({ init: function (t) { this.mixIn(t) }, toString: function (t) { return (t || this.formatter).stringify(this) } })), g = e.format = {}, B = g.OpenSSL = { stringify: function (t) { var r = t.ciphertext, e = t.salt; if (e) var i = o.create([1398893684, 1701076831]).concat(e).concat(r); else var i = r; return i.toString(c) }, parse: function (t) { var r = c.parse(t), e = r.words; if (1398893684 == e[0] && 1701076831 == e[1]) { var i = o.create(e.slice(2, 4)); e.splice(0, 4), r.sigBytes -= 16 } return y.create({ ciphertext: r, salt: i }) } }, w = i.SerializableCipher = n.extend({ cfg: n.extend({ format: B }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = t.createEncryptor(e, i), o = n.finalize(r), s = n.cfg; return y.create({ ciphertext: o, key: e, iv: s.iv, algorithm: t, mode: s.mode, padding: s.padding, blockSize: t.blockSize, formatter: i.format }) }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = t.createDecryptor(e, i).finalize(r.ciphertext); return n }, _parse: function (t, r) { return "string" == typeof t ? r.parse(t, this) : t } }), k = e.kdf = {}, S = k.OpenSSL = { execute: function (t, r, e, i) { i || (i = o.random(8)); var n = l.create({ keySize: r + e }).compute(t, i), s = o.create(n.words.slice(r), 4 * e); return n.sigBytes = 4 * r, y.create({ key: n, iv: s, salt: i }) } }, m = i.PasswordBasedCipher = w.extend({ cfg: w.cfg.extend({ kdf: S }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = i.kdf.execute(e, t.keySize, t.ivSize); i.iv = n.iv; var o = w.encrypt.call(this, t, r, n.key, i); return o.mixIn(n), o }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = i.kdf.execute(e, t.keySize, t.ivSize, r.salt); i.iv = n.iv; var o = w.decrypt.call(this, t, r, n.key, i); return o } }) }(), t.mode.CFB = function () { function r(t, r, e, i) { var n = this._iv; if (n) { var o = n.slice(0); this._iv = void 0 } else var o = this._prevBlock; i.encryptBlock(o, 0); for (var s = 0; s < e; s++)t[r + s] ^= o[s] } var e = t.lib.BlockCipherMode.extend(); return e.Encryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize; r.call(this, t, e, n, i), this._prevBlock = t.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize, o = t.slice(e, e + n); r.call(this, t, e, n, i), this._prevBlock = o } }), e }(), t.mode.ECB = function () { var r = t.lib.BlockCipherMode.extend(); return r.Encryptor = r.extend({ processBlock: function (t, r) { this._cipher.encryptBlock(t, r) } }), r.Decryptor = r.extend({ processBlock: function (t, r) { this._cipher.decryptBlock(t, r) } }), r }(), t.pad.AnsiX923 = { pad: function (t, r) { var e = t.sigBytes, i = 4 * r, n = i - e % i, o = e + n - 1; t.clamp(), t.words[o >>> 2] |= n << 24 - o % 4 * 8, t.sigBytes += n }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso10126 = { pad: function (r, e) { var i = 4 * e, n = i - r.sigBytes % i; r.concat(t.lib.WordArray.random(n - 1)).concat(t.lib.WordArray.create([n << 24], 1)) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso97971 = { pad: function (r, e) { r.concat(t.lib.WordArray.create([2147483648], 1)), t.pad.ZeroPadding.pad(r, e) }, unpad: function (r) { t.pad.ZeroPadding.unpad(r), r.sigBytes-- } }, t.mode.OFB = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._keystream; n && (o = this._keystream = n.slice(0), this._iv = void 0), e.encryptBlock(o, 0); for (var s = 0; s < i; s++)t[r + s] ^= o[s] } }); return r.Decryptor = e, r }(), t.pad.NoPadding = { pad: function () { }, unpad: function () { } }, function (r) { var e = t, i = e.lib, n = i.CipherParams, o = e.enc, s = o.Hex, a = e.format; a.Hex = { stringify: function (t) { return t.ciphertext.toString(s) }, parse: function (t) { var r = s.parse(t); return n.create({ ciphertext: r }) } } }(), function () { var r = t, e = r.lib, i = e.BlockCipher, n = r.algo, o = [], s = [], a = [], c = [], h = [], l = [], f = [], u = [], d = [], v = []; !function () { for (var t = [], r = 0; r < 256; r++)r < 128 ? t[r] = r << 1 : t[r] = r << 1 ^ 283; for (var e = 0, i = 0, r = 0; r < 256; r++) { var n = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4; n = n >>> 8 ^ 255 & n ^ 99, o[e] = n, s[n] = e; var p = t[e], _ = t[p], y = t[_], g = 257 * t[n] ^ 16843008 * n; a[e] = g << 24 | g >>> 8, c[e] = g << 16 | g >>> 16, h[e] = g << 8 | g >>> 24, l[e] = g; var g = 16843009 * y ^ 65537 * _ ^ 257 * p ^ 16843008 * e; f[n] = g << 24 | g >>> 8, u[n] = g << 16 | g >>> 16, d[n] = g << 8 | g >>> 24, v[n] = g, e ? (e = p ^ t[t[t[y ^ p]]], i ^= t[t[i]]) : e = i = 1 } }(); var p = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], _ = n.AES = i.extend({ _doReset: function () { if (!this._nRounds || this._keyPriorReset !== this._key) { for (var t = this._keyPriorReset = this._key, r = t.words, e = t.sigBytes / 4, i = this._nRounds = e + 6, n = 4 * (i + 1), s = this._keySchedule = [], a = 0; a < n; a++)if (a < e) s[a] = r[a]; else { var c = s[a - 1]; a % e ? e > 6 && a % e == 4 && (c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c]) : (c = c << 8 | c >>> 24, c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c], c ^= p[a / e | 0] << 24), s[a] = s[a - e] ^ c } for (var h = this._invKeySchedule = [], l = 0; l < n; l++) { var a = n - l; if (l % 4) var c = s[a]; else var c = s[a - 4]; l < 4 || a <= 4 ? h[l] = c : h[l] = f[o[c >>> 24]] ^ u[o[c >>> 16 & 255]] ^ d[o[c >>> 8 & 255]] ^ v[o[255 & c]] } } }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._keySchedule, a, c, h, l, o) }, decryptBlock: function (t, r) { var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e, this._doCryptBlock(t, r, this._invKeySchedule, f, u, d, v, s); var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e }, _doCryptBlock: function (t, r, e, i, n, o, s, a) { for (var c = this._nRounds, h = t[r] ^ e[0], l = t[r + 1] ^ e[1], f = t[r + 2] ^ e[2], u = t[r + 3] ^ e[3], d = 4, v = 1; v < c; v++) { var p = i[h >>> 24] ^ n[l >>> 16 & 255] ^ o[f >>> 8 & 255] ^ s[255 & u] ^ e[d++], _ = i[l >>> 24] ^ n[f >>> 16 & 255] ^ o[u >>> 8 & 255] ^ s[255 & h] ^ e[d++], y = i[f >>> 24] ^ n[u >>> 16 & 255] ^ o[h >>> 8 & 255] ^ s[255 & l] ^ e[d++], g = i[u >>> 24] ^ n[h >>> 16 & 255] ^ o[l >>> 8 & 255] ^ s[255 & f] ^ e[d++]; h = p, l = _, f = y, u = g } var p = (a[h >>> 24] << 24 | a[l >>> 16 & 255] << 16 | a[f >>> 8 & 255] << 8 | a[255 & u]) ^ e[d++], _ = (a[l >>> 24] << 24 | a[f >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & h]) ^ e[d++], y = (a[f >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[h >>> 8 & 255] << 8 | a[255 & l]) ^ e[d++], g = (a[u >>> 24] << 24 | a[h >>> 16 & 255] << 16 | a[l >>> 8 & 255] << 8 | a[255 & f]) ^ e[d++]; t[r] = p, t[r + 1] = _, t[r + 2] = y, t[r + 3] = g }, keySize: 8 }); r.AES = i._createHelper(_) }(), function () { + function r(t, r) { var e = (this._lBlock >>> t ^ this._rBlock) & r; this._rBlock ^= e, this._lBlock ^= e << t } function e(t, r) { + var e = (this._rBlock >>> t ^ this._lBlock) & r; this._lBlock ^= e, this._rBlock ^= e << t; + } var i = t, n = i.lib, o = n.WordArray, s = n.BlockCipher, a = i.algo, c = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4], h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32], l = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28], f = [{ 0: 8421888, 268435456: 32768, 536870912: 8421378, 805306368: 2, 1073741824: 512, 1342177280: 8421890, 1610612736: 8389122, 1879048192: 8388608, 2147483648: 514, 2415919104: 8389120, 2684354560: 33280, 2952790016: 8421376, 3221225472: 32770, 3489660928: 8388610, 3758096384: 0, 4026531840: 33282, 134217728: 0, 402653184: 8421890, 671088640: 33282, 939524096: 32768, 1207959552: 8421888, 1476395008: 512, 1744830464: 8421378, 2013265920: 2, 2281701376: 8389120, 2550136832: 33280, 2818572288: 8421376, 3087007744: 8389122, 3355443200: 8388610, 3623878656: 32770, 3892314112: 514, 4160749568: 8388608, 1: 32768, 268435457: 2, 536870913: 8421888, 805306369: 8388608, 1073741825: 8421378, 1342177281: 33280, 1610612737: 512, 1879048193: 8389122, 2147483649: 8421890, 2415919105: 8421376, 2684354561: 8388610, 2952790017: 33282, 3221225473: 514, 3489660929: 8389120, 3758096385: 32770, 4026531841: 0, 134217729: 8421890, 402653185: 8421376, 671088641: 8388608, 939524097: 512, 1207959553: 32768, 1476395009: 8388610, 1744830465: 2, 2013265921: 33282, 2281701377: 32770, 2550136833: 8389122, 2818572289: 514, 3087007745: 8421888, 3355443201: 8389120, 3623878657: 0, 3892314113: 33280, 4160749569: 8421378 }, { 0: 1074282512, 16777216: 16384, 33554432: 524288, 50331648: 1074266128, 67108864: 1073741840, 83886080: 1074282496, 100663296: 1073758208, 117440512: 16, 134217728: 540672, 150994944: 1073758224, 167772160: 1073741824, 184549376: 540688, 201326592: 524304, 218103808: 0, 234881024: 16400, 251658240: 1074266112, 8388608: 1073758208, 25165824: 540688, 41943040: 16, 58720256: 1073758224, 75497472: 1074282512, 92274688: 1073741824, 109051904: 524288, 125829120: 1074266128, 142606336: 524304, 159383552: 0, 176160768: 16384, 192937984: 1074266112, 209715200: 1073741840, 226492416: 540672, 243269632: 1074282496, 260046848: 16400, 268435456: 0, 285212672: 1074266128, 301989888: 1073758224, 318767104: 1074282496, 335544320: 1074266112, 352321536: 16, 369098752: 540688, 385875968: 16384, 402653184: 16400, 419430400: 524288, 436207616: 524304, 452984832: 1073741840, 469762048: 540672, 486539264: 1073758208, 503316480: 1073741824, 520093696: 1074282512, 276824064: 540688, 293601280: 524288, 310378496: 1074266112, 327155712: 16384, 343932928: 1073758208, 360710144: 1074282512, 377487360: 16, 394264576: 1073741824, 411041792: 1074282496, 427819008: 1073741840, 444596224: 1073758224, 461373440: 524304, 478150656: 0, 494927872: 16400, 511705088: 1074266128, 528482304: 540672 }, { 0: 260, 1048576: 0, 2097152: 67109120, 3145728: 65796, 4194304: 65540, 5242880: 67108868, 6291456: 67174660, 7340032: 67174400, 8388608: 67108864, 9437184: 67174656, 10485760: 65792, 11534336: 67174404, 12582912: 67109124, 13631488: 65536, 14680064: 4, 15728640: 256, 524288: 67174656, 1572864: 67174404, 2621440: 0, 3670016: 67109120, 4718592: 67108868, 5767168: 65536, 6815744: 65540, 7864320: 260, 8912896: 4, 9961472: 256, 11010048: 67174400, 12058624: 65796, 13107200: 65792, 14155776: 67109124, 15204352: 67174660, 16252928: 67108864, 16777216: 67174656, 17825792: 65540, 18874368: 65536, 19922944: 67109120, 20971520: 256, 22020096: 67174660, 23068672: 67108868, 24117248: 0, 25165824: 67109124, 26214400: 67108864, 27262976: 4, 28311552: 65792, 29360128: 67174400, 30408704: 260, 31457280: 65796, 32505856: 67174404, 17301504: 67108864, 18350080: 260, 19398656: 67174656, 20447232: 0, 21495808: 65540, 22544384: 67109120, 23592960: 256, 24641536: 67174404, 25690112: 65536, 26738688: 67174660, 27787264: 65796, 28835840: 67108868, 29884416: 67109124, 30932992: 67174400, 31981568: 4, 33030144: 65792 }, { 0: 2151682048, 65536: 2147487808, 131072: 4198464, 196608: 2151677952, 262144: 0, 327680: 4198400, 393216: 2147483712, 458752: 4194368, 524288: 2147483648, 589824: 4194304, 655360: 64, 720896: 2147487744, 786432: 2151678016, 851968: 4160, 917504: 4096, 983040: 2151682112, 32768: 2147487808, 98304: 64, 163840: 2151678016, 229376: 2147487744, 294912: 4198400, 360448: 2151682112, 425984: 0, 491520: 2151677952, 557056: 4096, 622592: 2151682048, 688128: 4194304, 753664: 4160, 819200: 2147483648, 884736: 4194368, 950272: 4198464, 1015808: 2147483712, 1048576: 4194368, 1114112: 4198400, 1179648: 2147483712, 1245184: 0, 1310720: 4160, 1376256: 2151678016, 1441792: 2151682048, 1507328: 2147487808, 1572864: 2151682112, 1638400: 2147483648, 1703936: 2151677952, 1769472: 4198464, 1835008: 2147487744, 1900544: 4194304, 1966080: 64, 2031616: 4096, 1081344: 2151677952, 1146880: 2151682112, 1212416: 0, 1277952: 4198400, 1343488: 4194368, 1409024: 2147483648, 1474560: 2147487808, 1540096: 64, 1605632: 2147483712, 1671168: 4096, 1736704: 2147487744, 1802240: 2151678016, 1867776: 4160, 1933312: 2151682048, 1998848: 4194304, 2064384: 4198464 }, { 0: 128, 4096: 17039360, 8192: 262144, 12288: 536870912, 16384: 537133184, 20480: 16777344, 24576: 553648256, 28672: 262272, 32768: 16777216, 36864: 537133056, 40960: 536871040, 45056: 553910400, 49152: 553910272, 53248: 0, 57344: 17039488, 61440: 553648128, 2048: 17039488, 6144: 553648256, 10240: 128, 14336: 17039360, 18432: 262144, 22528: 537133184, 26624: 553910272, 30720: 536870912, 34816: 537133056, 38912: 0, 43008: 553910400, 47104: 16777344, 51200: 536871040, 55296: 553648128, 59392: 16777216, 63488: 262272, 65536: 262144, 69632: 128, 73728: 536870912, 77824: 553648256, 81920: 16777344, 86016: 553910272, 90112: 537133184, 94208: 16777216, 98304: 553910400, 102400: 553648128, 106496: 17039360, 110592: 537133056, 114688: 262272, 118784: 536871040, 122880: 0, 126976: 17039488, 67584: 553648256, 71680: 16777216, 75776: 17039360, 79872: 537133184, 83968: 536870912, 88064: 17039488, 92160: 128, 96256: 553910272, 100352: 262272, 104448: 553910400, 108544: 0, 112640: 553648128, 116736: 16777344, 120832: 262144, 124928: 537133056, 129024: 536871040 }, { 0: 268435464, 256: 8192, 512: 270532608, 768: 270540808, 1024: 268443648, 1280: 2097152, 1536: 2097160, 1792: 268435456, 2048: 0, 2304: 268443656, 2560: 2105344, 2816: 8, 3072: 270532616, 3328: 2105352, 3584: 8200, 3840: 270540800, 128: 270532608, 384: 270540808, 640: 8, 896: 2097152, 1152: 2105352, 1408: 268435464, 1664: 268443648, 1920: 8200, 2176: 2097160, 2432: 8192, 2688: 268443656, 2944: 270532616, 3200: 0, 3456: 270540800, 3712: 2105344, 3968: 268435456, 4096: 268443648, 4352: 270532616, 4608: 270540808, 4864: 8200, 5120: 2097152, 5376: 268435456, 5632: 268435464, 5888: 2105344, 6144: 2105352, 6400: 0, 6656: 8, 6912: 270532608, 7168: 8192, 7424: 268443656, 7680: 270540800, 7936: 2097160, 4224: 8, 4480: 2105344, 4736: 2097152, 4992: 268435464, 5248: 268443648, 5504: 8200, 5760: 270540808, 6016: 270532608, 6272: 270540800, 6528: 270532616, 6784: 8192, 7040: 2105352, 7296: 2097160, 7552: 0, 7808: 268435456, 8064: 268443656 }, { 0: 1048576, 16: 33555457, 32: 1024, 48: 1049601, 64: 34604033, 80: 0, 96: 1, 112: 34603009, 128: 33555456, 144: 1048577, 160: 33554433, 176: 34604032, 192: 34603008, 208: 1025, 224: 1049600, 240: 33554432, 8: 34603009, 24: 0, 40: 33555457, 56: 34604032, 72: 1048576, 88: 33554433, 104: 33554432, 120: 1025, 136: 1049601, 152: 33555456, 168: 34603008, 184: 1048577, 200: 1024, 216: 34604033, 232: 1, 248: 1049600, 256: 33554432, 272: 1048576, 288: 33555457, 304: 34603009, 320: 1048577, 336: 33555456, 352: 34604032, 368: 1049601, 384: 1025, 400: 34604033, 416: 1049600, 432: 1, 448: 0, 464: 34603008, 480: 33554433, 496: 1024, 264: 1049600, 280: 33555457, 296: 34603009, 312: 1, 328: 33554432, 344: 1048576, 360: 1025, 376: 34604032, 392: 33554433, 408: 34603008, 424: 0, 440: 34604033, 456: 1049601, 472: 1024, 488: 33555456, 504: 1048577 }, { 0: 134219808, 1: 131072, 2: 134217728, 3: 32, 4: 131104, 5: 134350880, 6: 134350848, 7: 2048, 8: 134348800, 9: 134219776, 10: 133120, 11: 134348832, 12: 2080, 13: 0, 14: 134217760, 15: 133152, 2147483648: 2048, 2147483649: 134350880, 2147483650: 134219808, 2147483651: 134217728, 2147483652: 134348800, 2147483653: 133120, 2147483654: 133152, 2147483655: 32, 2147483656: 134217760, 2147483657: 2080, 2147483658: 131104, 2147483659: 134350848, 2147483660: 0, 2147483661: 134348832, 2147483662: 134219776, 2147483663: 131072, 16: 133152, 17: 134350848, 18: 32, 19: 2048, 20: 134219776, 21: 134217760, 22: 134348832, 23: 131072, 24: 0, 25: 131104, 26: 134348800, 27: 134219808, 28: 134350880, 29: 133120, 30: 2080, 31: 134217728, 2147483664: 131072, 2147483665: 2048, 2147483666: 134348832, 2147483667: 133152, 2147483668: 32, 2147483669: 134348800, 2147483670: 134217728, 2147483671: 134219808, 2147483672: 134350880, 2147483673: 134217760, 2147483674: 134219776, 2147483675: 0, 2147483676: 133120, 2147483677: 2080, 2147483678: 131104, 2147483679: 134350848 }], u = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679], d = a.DES = s.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = [], i = 0; i < 56; i++) { var n = c[i] - 1; e[i] = r[n >>> 5] >>> 31 - n % 32 & 1 } for (var o = this._subKeys = [], s = 0; s < 16; s++) { for (var a = o[s] = [], f = l[s], i = 0; i < 24; i++)a[i / 6 | 0] |= e[(h[i] - 1 + f) % 28] << 31 - i % 6, a[4 + (i / 6 | 0)] |= e[28 + (h[i + 24] - 1 + f) % 28] << 31 - i % 6; a[0] = a[0] << 1 | a[0] >>> 31; for (var i = 1; i < 7; i++)a[i] = a[i] >>> 4 * (i - 1) + 3; a[7] = a[7] << 5 | a[7] >>> 27 } for (var u = this._invSubKeys = [], i = 0; i < 16; i++)u[i] = o[15 - i] }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._subKeys) }, decryptBlock: function (t, r) { this._doCryptBlock(t, r, this._invSubKeys) }, _doCryptBlock: function (t, i, n) { this._lBlock = t[i], this._rBlock = t[i + 1], r.call(this, 4, 252645135), r.call(this, 16, 65535), e.call(this, 2, 858993459), e.call(this, 8, 16711935), r.call(this, 1, 1431655765); for (var o = 0; o < 16; o++) { for (var s = n[o], a = this._lBlock, c = this._rBlock, h = 0, l = 0; l < 8; l++)h |= f[l][((c ^ s[l]) & u[l]) >>> 0]; this._lBlock = c, this._rBlock = a ^ h } var d = this._lBlock; this._lBlock = this._rBlock, this._rBlock = d, r.call(this, 1, 1431655765), e.call(this, 8, 16711935), e.call(this, 2, 858993459), r.call(this, 16, 65535), r.call(this, 4, 252645135), t[i] = this._lBlock, t[i + 1] = this._rBlock }, keySize: 2, ivSize: 2, blockSize: 2 }); i.DES = s._createHelper(d); var v = a.TripleDES = s.extend({ _doReset: function () { var t = this._key, r = t.words; this._des1 = d.createEncryptor(o.create(r.slice(0, 2))), this._des2 = d.createEncryptor(o.create(r.slice(2, 4))), this._des3 = d.createEncryptor(o.create(r.slice(4, 6))) }, encryptBlock: function (t, r) { this._des1.encryptBlock(t, r), this._des2.decryptBlock(t, r), this._des3.encryptBlock(t, r) }, decryptBlock: function (t, r) { this._des3.decryptBlock(t, r), this._des2.encryptBlock(t, r), this._des1.decryptBlock(t, r) }, keySize: 6, ivSize: 2, blockSize: 2 }); i.TripleDES = s._createHelper(v) + }(), function () { function r() { for (var t = this._S, r = this._i, e = this._j, i = 0, n = 0; n < 4; n++) { r = (r + 1) % 256, e = (e + t[r]) % 256; var o = t[r]; t[r] = t[e], t[e] = o, i |= t[(t[r] + t[e]) % 256] << 24 - 8 * n } return this._i = r, this._j = e, i } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = o.RC4 = n.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = t.sigBytes, i = this._S = [], n = 0; n < 256; n++)i[n] = n; for (var n = 0, o = 0; n < 256; n++) { var s = n % e, a = r[s >>> 2] >>> 24 - s % 4 * 8 & 255; o = (o + i[n] + a) % 256; var c = i[n]; i[n] = i[o], i[o] = c } this._i = this._j = 0 }, _doProcessBlock: function (t, e) { t[e] ^= r.call(this) }, keySize: 8, ivSize: 0 }); e.RC4 = n._createHelper(s); var a = o.RC4Drop = s.extend({ cfg: s.cfg.extend({ drop: 192 }), _doReset: function () { s._doReset.call(this); for (var t = this.cfg.drop; t > 0; t--)r.call(this) } }); e.RC4Drop = n._createHelper(a) }(), t.mode.CTRGladman = function () { function r(t) { if (255 === (t >> 24 & 255)) { var r = t >> 16 & 255, e = t >> 8 & 255, i = 255 & t; 255 === r ? (r = 0, 255 === e ? (e = 0, 255 === i ? i = 0 : ++i) : ++e) : ++r, t = 0, t += r << 16, t += e << 8, t += i } else t += 1 << 24; return t } function e(t) { return 0 === (t[0] = r(t[0])) && (t[1] = r(t[1])), t } var i = t.lib.BlockCipherMode.extend(), n = i.Encryptor = i.extend({ processBlock: function (t, r) { var i = this._cipher, n = i.blockSize, o = this._iv, s = this._counter; o && (s = this._counter = o.slice(0), this._iv = void 0), e(s); var a = s.slice(0); i.encryptBlock(a, 0); for (var c = 0; c < n; c++)t[r + c] ^= a[c] } }); return i.Decryptor = n, i }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.Rabbit = n.extend({ _doReset: function () { for (var t = this._key.words, e = this.cfg.iv, i = 0; i < 4; i++)t[i] = 16711935 & (t[i] << 8 | t[i] >>> 24) | 4278255360 & (t[i] << 24 | t[i] >>> 8); var n = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], o = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var i = 0; i < 4; i++)r.call(this); for (var i = 0; i < 8; i++)o[i] ^= n[i + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; o[0] ^= h, o[1] ^= f, o[2] ^= l, o[3] ^= u, o[4] ^= h, o[5] ^= f, o[6] ^= l, o[7] ^= u; for (var i = 0; i < 4; i++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.Rabbit = n._createHelper(h) }(), t.mode.CTR = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._counter; n && (o = this._counter = n.slice(0), this._iv = void 0); var s = o.slice(0); e.encryptBlock(s, 0), o[i - 1] = o[i - 1] + 1 | 0; for (var a = 0; a < i; a++)t[r + a] ^= s[a] } }); return r.Decryptor = e, r }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.RabbitLegacy = n.extend({ _doReset: function () { var t = this._key.words, e = this.cfg.iv, i = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], n = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var o = 0; o < 4; o++)r.call(this); for (var o = 0; o < 8; o++)n[o] ^= i[o + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; n[0] ^= h, n[1] ^= f, n[2] ^= l, n[3] ^= u, n[4] ^= h, n[5] ^= f, n[6] ^= l, n[7] ^= u; for (var o = 0; o < 4; o++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.RabbitLegacy = n._createHelper(h) }(), t.pad.ZeroPadding = { pad: function (t, r) { var e = 4 * r; t.clamp(), t.sigBytes += e - (t.sigBytes % e || e) }, unpad: function (t) { for (var r = t.words, e = t.sigBytes - 1; !(r[e >>> 2] >>> 24 - e % 4 * 8 & 255);)e--; t.sigBytes = e + 1 } }, t +}); + const $ = new Env('顺丰速运') -$.VAL_loginurl = $.getdata('chavy_loginurl_sfexpress') -$.VAL_loginheader = $.getdata('chavy_loginheader_sfexpress') +$.KEY_login = 'chavy_login_sfexpress' !(async () => { - await refresh() + $.CryptoJS = $.isNode() ? require('crypto-js') : CryptoJS + await loginapp() - await signapp() - await getinfo() - await showmsg() + await $.wait('1000') + await loginweb() + await $.wait('1000') + await sign() + await $.wait('1000') + await signDailyTasks() + showmsg() })() .catch((e) => $.logErr(e)) .finally(() => $.done()) -function refresh() { - if (!$.isQuanX()) return - return new Promise((resolve) => { - const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/signin`, headers: { Cookie: '' } } - url.body = `date=${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDate()}` - $.post(url, () => resolve()) +function loginapp() { + const loginOpts = $.getjson($.KEY_login) + delete loginOpts.headers.Cookie + + const timeInterval = new Date().getTime() + const bodyMD5 = $.CryptoJS.MD5(loginOpts.body) + + const sytToken = + loginOpts.headers.regionCode + + loginOpts.headers.languageCode + + bodyMD5 + + loginOpts.headers.clientVersion + + loginOpts.headers.deviceId + + loginOpts.headers.jsbundle + + timeInterval + + Object.assign(loginOpts.headers, { + timeInterval, + sytToken: $.CryptoJS.MD5(sytToken).toString() }) + + return $.http + .post(loginOpts) + .then((resp) => { + $.login = JSON.parse(resp.body) + }) + .catch((err) => { + console.log(err) + }) } -function loginapp() { - return new Promise((resolve) => { - const url = { url: $.VAL_loginurl } - $.get(url, () => resolve()) +function loginweb() { + const sign = encodeURIComponent($.login.obj.sign) + const loginOpts = { + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/share/app/shareRedirect?sign=${sign}&source=SFAPP&bizCode=647@RnlvejM1R3VTSVZ6d3BNaXJxRFpOUVVtQkp0ZnFpNDBKdytobm5TQWxMeHpVUXVrVzVGMHVmTU5BVFA1bXlwcw==` + } + return $.http.get(loginOpts) +} + +function sign() { + const signOpts = { + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/signFetchPoint`, + body: `{"channel": "SFAPP","pageType": "sign","from": "APP_MINE_TASK"}`, + headers: { + 'Content-Type': 'application/json' + } + } + return $.http.post(signOpts).then((resp) => { + $.sign = JSON.parse(resp.body) }) } -function signapp() { - return new Promise((resolve) => { - const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/signin`, headers: JSON.parse($.VAL_loginheader) } - delete url.headers['Cookie'] - url.headers['Origin'] = 'https://sf-integral-sign-in.weixinjia.net' - url.headers['Connection'] = 'keep-alive' - url.headers['Content-Type'] = 'application/x-www-form-urlencoded' - url.headers['Accept'] = 'application/json, text/plain, */*' - url.headers['Host'] = 'sf-integral-sign-in.weixinjia.net' - url.headers['Accept-Language'] = 'zh-cn' - url.headers['Accept-Encoding'] = 'gzip, deflate, br' - url.body = `date=${new Date().getFullYear()}-${new Date().getMonth() + 1}-${new Date().getDate()}` - $.post(url, (err, resp, data) => { - try { - $.signapp = JSON.parse(data) - } catch (e) { - $.logErr(e, resp) - } finally { - resolve() +function queryDailyTask() { + return $.http + .post({ + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/queryPointTaskAndSign`, + body: `{"channel":"SFAPP","pageType": "APP_MINE_TASK"}`, + headers: { + 'Content-Type': 'application/json' } }) + .then((resp) => { + $.tasks = JSON.parse(resp.body).obj.taskTitleLevels + }) +} + +async function signDailyTasks() { + await queryDailyTask() + + // 移除每日签到 + const skipType = ['sign', 'mailPerMonThan3'] + $.tasks = $.tasks.filter((t) => !skipType.includes(t.pageType)) + + for (let i = 0; i < $.tasks.length; i++) { + const task = $.tasks[i] + if (task.status === 2) { + await doTask(task) + await getPoint(task) + } else if (task.status === 3) { + task.result = '积分已领取!' + } else { + task.result = '未知' + } + } +} + +function doTask(task) { + return $.http.post({ + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/scanPageToRecord`, + body: `{"channel":"SFAPP","pageType": "${task.pageType}"}`, + headers: { + 'Content-Type': 'application/json' + } }) } -function getinfo() { - return new Promise((resolve) => { - const url = { url: `https://sf-integral-sign-in.weixinjia.net/app/init`, headers: JSON.parse($.VAL_loginheader) } - delete url.headers['Cookie'] - url.headers['Origin'] = 'https://sf-integral-sign-in.weixinjia.net' - url.headers['Connection'] = 'keep-alive' - url.headers['Content-Type'] = 'application/x-www-form-urlencoded' - url.headers['Accept'] = 'application/json, text/plain, */*' - url.headers['Host'] = 'sf-integral-sign-in.weixinjia.net' - url.headers['Accept-Encoding'] = 'gzip, deflate, br' - url.headers['Accept-Language'] = 'zh-cn' - $.post(url, (err, resp, data) => { - try { - $.info = JSON.parse(data) - } catch (e) { - $.logErr(e, resp) - } finally { - resolve() +function getPoint(task) { + return $.http + .post({ + url: 'https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/fetchPoint', + body: `{"channel": "SFAPP","pageType": "${task.pageType}"}`, + headers: { + 'Content-Type': 'application/json' } }) - }) + .then((resp) => { + const data = JSON.parse(resp.body) + task.result = data.success ? '成功' : data.errorMessage + console.log(task) + }) } function showmsg() { - return new Promise((resolve) => { - if ($.signapp.code == 0 && $.signapp.msg == 'success') { - $.subt = `签到: 成功` - } else if ($.signapp.code == -1) { - if ($.signapp.msg == 'ALREADY_CHECK') { - $.subt = `签到: 重复` - } else { - $.subt = `签到: 失败` - } + const success = $.sign && $.sign.success + $.subt = `签到: ` + $.desc = [] + if (success) { + $.subt += `成功` + $.desc.push(`说明: +${$.sign.obj} 积分`) + } else { + const errmsg = $.sign.errorMessage + if (errmsg === '已经发送过积分') { + $.subt += `重复` + $.desc.push(`说明: ${errmsg}`) } else { - $.subt = `签到: 未知` - $.desc = `说明: ${$.signapp.msg}` - } - if ($.info && $.info.code == 0) { - $.desc = `积分: ${$.info.data.member_info.integral}, 本周连签: ${$.info.data.check_count}天` + $.subt += `失败` } - $.msg($.name, $.subt, $.desc) - resolve() - }) + } + + $.desc.push('', `每日任务: `) + for (let i = 0; i < $.tasks.length; i++) { + const name = $.tasks[i].title + const result = $.tasks[i].result + $.desc.push(`${name}: ${result}`) + } + + $.msg($.name, $.subt, $.desc.join('\n')) } // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=t;this.got.post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} From e984207ca8de87a965cb26440b01881193762aa2 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 1 Apr 2021 00:22:05 +0800 Subject: [PATCH 070/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E9=A1=BA=E4=B8=B0?= =?UTF-8?q?=E9=80=9F=E8=BF=90]:=20=E4=BF=AE=E5=A4=8D=20APP=20=E7=AB=AF?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/README.md | 4 +--- sfexpress/sfexpress.js | 26 -------------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/sfexpress/README.md b/sfexpress/README.md index 09d435508..8e07e1c9a 100644 --- a/sfexpress/README.md +++ b/sfexpress/README.md @@ -30,10 +30,8 @@ hostname = ccsp-egmas.sf-express.com [MITM] hostname = ccsp-egmas.sf-express.com -[rewrite_local] +[Script] http-request ^https:\/\/ccsp-egmas.sf-express.com\/cx-app-member\/member\/app\/user\/universalSign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js, requires-body=true, tag=Rewrite: 顺丰速运 - -[task_local] cron "1 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js ``` diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 7c9256509..9d511b1f8 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -1,12 +1,3 @@ -// prettier-ignore -!function (t, r) { "object" == typeof exports ? module.exports = exports = r() : "function" == typeof define && define.amd ? define([], r) : t.CryptoJS = r() }(this, function () { - var t = t || function (t, r) { var e = Object.create || function () { function t() { } return function (r) { var e; return t.prototype = r, e = new t, t.prototype = null, e } }(), i = {}, n = i.lib = {}, o = n.Base = function () { return { extend: function (t) { var r = e(this); return t && r.mixIn(t), r.hasOwnProperty("init") && this.init !== r.init || (r.init = function () { r.$super.init.apply(this, arguments) }), r.init.prototype = r, r.$super = this, r }, create: function () { var t = this.extend(); return t.init.apply(t, arguments), t }, init: function () { }, mixIn: function (t) { for (var r in t) t.hasOwnProperty(r) && (this[r] = t[r]); t.hasOwnProperty("toString") && (this.toString = t.toString) }, clone: function () { return this.init.prototype.extend(this) } } }(), s = n.WordArray = o.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 4 * t.length }, toString: function (t) { return (t || c).stringify(this) }, concat: function (t) { var r = this.words, e = t.words, i = this.sigBytes, n = t.sigBytes; if (this.clamp(), i % 4) for (var o = 0; o < n; o++) { var s = e[o >>> 2] >>> 24 - o % 4 * 8 & 255; r[i + o >>> 2] |= s << 24 - (i + o) % 4 * 8 } else for (var o = 0; o < n; o += 4)r[i + o >>> 2] = e[o >>> 2]; return this.sigBytes += n, this }, clamp: function () { var r = this.words, e = this.sigBytes; r[e >>> 2] &= 4294967295 << 32 - e % 4 * 8, r.length = t.ceil(e / 4) }, clone: function () { var t = o.clone.call(this); return t.words = this.words.slice(0), t }, random: function (r) { for (var e, i = [], n = function (r) { var r = r, e = 987654321, i = 4294967295; return function () { e = 36969 * (65535 & e) + (e >> 16) & i, r = 18e3 * (65535 & r) + (r >> 16) & i; var n = (e << 16) + r & i; return n /= 4294967296, n += .5, n * (t.random() > .5 ? 1 : -1) } }, o = 0; o < r; o += 4) { var a = n(4294967296 * (e || t.random())); e = 987654071 * a(), i.push(4294967296 * a() | 0) } return new s.init(i, r) } }), a = i.enc = {}, c = a.Hex = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push((o >>> 4).toString(16)), i.push((15 & o).toString(16)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i += 2)e[i >>> 3] |= parseInt(t.substr(i, 2), 16) << 24 - i % 8 * 4; return new s.init(e, r / 2) } }, h = a.Latin1 = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n++) { var o = r[n >>> 2] >>> 24 - n % 4 * 8 & 255; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 2] |= (255 & t.charCodeAt(i)) << 24 - i % 4 * 8; return new s.init(e, r) } }, l = a.Utf8 = { stringify: function (t) { try { return decodeURIComponent(escape(h.stringify(t))) } catch (t) { throw new Error("Malformed UTF-8 data") } }, parse: function (t) { return h.parse(unescape(encodeURIComponent(t))) } }, f = n.BufferedBlockAlgorithm = o.extend({ reset: function () { this._data = new s.init, this._nDataBytes = 0 }, _append: function (t) { "string" == typeof t && (t = l.parse(t)), this._data.concat(t), this._nDataBytes += t.sigBytes }, _process: function (r) { var e = this._data, i = e.words, n = e.sigBytes, o = this.blockSize, a = 4 * o, c = n / a; c = r ? t.ceil(c) : t.max((0 | c) - this._minBufferSize, 0); var h = c * o, l = t.min(4 * h, n); if (h) { for (var f = 0; f < h; f += o)this._doProcessBlock(i, f); var u = i.splice(0, h); e.sigBytes -= l } return new s.init(u, l) }, clone: function () { var t = o.clone.call(this); return t._data = this._data.clone(), t }, _minBufferSize: 0 }), u = (n.Hasher = f.extend({ cfg: o.extend(), init: function (t) { this.cfg = this.cfg.extend(t), this.reset() }, reset: function () { f.reset.call(this), this._doReset() }, update: function (t) { return this._append(t), this._process(), this }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, blockSize: 16, _createHelper: function (t) { return function (r, e) { return new t.init(e).finalize(r) } }, _createHmacHelper: function (t) { return function (r, e) { return new u.HMAC.init(t, e).finalize(r) } } }), i.algo = {}); return i }(Math); return function () { function r(t, r, e) { for (var i = [], o = 0, s = 0; s < r; s++)if (s % 4) { var a = e[t.charCodeAt(s - 1)] << s % 4 * 2, c = e[t.charCodeAt(s)] >>> 6 - s % 4 * 2; i[o >>> 2] |= (a | c) << 24 - o % 4 * 8, o++ } return n.create(i, o) } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Base64 = { stringify: function (t) { var r = t.words, e = t.sigBytes, i = this._map; t.clamp(); for (var n = [], o = 0; o < e; o += 3)for (var s = r[o >>> 2] >>> 24 - o % 4 * 8 & 255, a = r[o + 1 >>> 2] >>> 24 - (o + 1) % 4 * 8 & 255, c = r[o + 2 >>> 2] >>> 24 - (o + 2) % 4 * 8 & 255, h = s << 16 | a << 8 | c, l = 0; l < 4 && o + .75 * l < e; l++)n.push(i.charAt(h >>> 6 * (3 - l) & 63)); var f = i.charAt(64); if (f) for (; n.length % 4;)n.push(f); return n.join("") }, parse: function (t) { var e = t.length, i = this._map, n = this._reverseMap; if (!n) { n = this._reverseMap = []; for (var o = 0; o < i.length; o++)n[i.charCodeAt(o)] = o } var s = i.charAt(64); if (s) { var a = t.indexOf(s); a !== -1 && (e = a) } return r(t, e, n) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } }(), function (r) { function e(t, r, e, i, n, o, s) { var a = t + (r & e | ~r & i) + n + s; return (a << o | a >>> 32 - o) + r } function i(t, r, e, i, n, o, s) { var a = t + (r & i | e & ~i) + n + s; return (a << o | a >>> 32 - o) + r } function n(t, r, e, i, n, o, s) { var a = t + (r ^ e ^ i) + n + s; return (a << o | a >>> 32 - o) + r } function o(t, r, e, i, n, o, s) { var a = t + (e ^ (r | ~i)) + n + s; return (a << o | a >>> 32 - o) + r } var s = t, a = s.lib, c = a.WordArray, h = a.Hasher, l = s.algo, f = []; !function () { for (var t = 0; t < 64; t++)f[t] = 4294967296 * r.abs(r.sin(t + 1)) | 0 }(); var u = l.MD5 = h.extend({ _doReset: function () { this._hash = new c.init([1732584193, 4023233417, 2562383102, 271733878]) }, _doProcessBlock: function (t, r) { for (var s = 0; s < 16; s++) { var a = r + s, c = t[a]; t[a] = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8) } var h = this._hash.words, l = t[r + 0], u = t[r + 1], d = t[r + 2], v = t[r + 3], p = t[r + 4], _ = t[r + 5], y = t[r + 6], g = t[r + 7], B = t[r + 8], w = t[r + 9], k = t[r + 10], S = t[r + 11], m = t[r + 12], x = t[r + 13], b = t[r + 14], H = t[r + 15], z = h[0], A = h[1], C = h[2], D = h[3]; z = e(z, A, C, D, l, 7, f[0]), D = e(D, z, A, C, u, 12, f[1]), C = e(C, D, z, A, d, 17, f[2]), A = e(A, C, D, z, v, 22, f[3]), z = e(z, A, C, D, p, 7, f[4]), D = e(D, z, A, C, _, 12, f[5]), C = e(C, D, z, A, y, 17, f[6]), A = e(A, C, D, z, g, 22, f[7]), z = e(z, A, C, D, B, 7, f[8]), D = e(D, z, A, C, w, 12, f[9]), C = e(C, D, z, A, k, 17, f[10]), A = e(A, C, D, z, S, 22, f[11]), z = e(z, A, C, D, m, 7, f[12]), D = e(D, z, A, C, x, 12, f[13]), C = e(C, D, z, A, b, 17, f[14]), A = e(A, C, D, z, H, 22, f[15]), z = i(z, A, C, D, u, 5, f[16]), D = i(D, z, A, C, y, 9, f[17]), C = i(C, D, z, A, S, 14, f[18]), A = i(A, C, D, z, l, 20, f[19]), z = i(z, A, C, D, _, 5, f[20]), D = i(D, z, A, C, k, 9, f[21]), C = i(C, D, z, A, H, 14, f[22]), A = i(A, C, D, z, p, 20, f[23]), z = i(z, A, C, D, w, 5, f[24]), D = i(D, z, A, C, b, 9, f[25]), C = i(C, D, z, A, v, 14, f[26]), A = i(A, C, D, z, B, 20, f[27]), z = i(z, A, C, D, x, 5, f[28]), D = i(D, z, A, C, d, 9, f[29]), C = i(C, D, z, A, g, 14, f[30]), A = i(A, C, D, z, m, 20, f[31]), z = n(z, A, C, D, _, 4, f[32]), D = n(D, z, A, C, B, 11, f[33]), C = n(C, D, z, A, S, 16, f[34]), A = n(A, C, D, z, b, 23, f[35]), z = n(z, A, C, D, u, 4, f[36]), D = n(D, z, A, C, p, 11, f[37]), C = n(C, D, z, A, g, 16, f[38]), A = n(A, C, D, z, k, 23, f[39]), z = n(z, A, C, D, x, 4, f[40]), D = n(D, z, A, C, l, 11, f[41]), C = n(C, D, z, A, v, 16, f[42]), A = n(A, C, D, z, y, 23, f[43]), z = n(z, A, C, D, w, 4, f[44]), D = n(D, z, A, C, m, 11, f[45]), C = n(C, D, z, A, H, 16, f[46]), A = n(A, C, D, z, d, 23, f[47]), z = o(z, A, C, D, l, 6, f[48]), D = o(D, z, A, C, g, 10, f[49]), C = o(C, D, z, A, b, 15, f[50]), A = o(A, C, D, z, _, 21, f[51]), z = o(z, A, C, D, m, 6, f[52]), D = o(D, z, A, C, v, 10, f[53]), C = o(C, D, z, A, k, 15, f[54]), A = o(A, C, D, z, u, 21, f[55]), z = o(z, A, C, D, B, 6, f[56]), D = o(D, z, A, C, H, 10, f[57]), C = o(C, D, z, A, y, 15, f[58]), A = o(A, C, D, z, x, 21, f[59]), z = o(z, A, C, D, p, 6, f[60]), D = o(D, z, A, C, S, 10, f[61]), C = o(C, D, z, A, d, 15, f[62]), A = o(A, C, D, z, w, 21, f[63]), h[0] = h[0] + z | 0, h[1] = h[1] + A | 0, h[2] = h[2] + C | 0, h[3] = h[3] + D | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; e[n >>> 5] |= 128 << 24 - n % 32; var o = r.floor(i / 4294967296), s = i; e[(n + 64 >>> 9 << 4) + 15] = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), e[(n + 64 >>> 9 << 4) + 14] = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8), t.sigBytes = 4 * (e.length + 1), this._process(); for (var a = this._hash, c = a.words, h = 0; h < 4; h++) { var l = c[h]; c[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } return a }, clone: function () { var t = h.clone.call(this); return t._hash = this._hash.clone(), t } }); s.MD5 = h._createHelper(u), s.HmacMD5 = h._createHmacHelper(u) }(Math), function () { var r = t, e = r.lib, i = e.WordArray, n = e.Hasher, o = r.algo, s = [], a = o.SHA1 = n.extend({ _doReset: function () { this._hash = new i.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], a = e[3], c = e[4], h = 0; h < 80; h++) { if (h < 16) s[h] = 0 | t[r + h]; else { var l = s[h - 3] ^ s[h - 8] ^ s[h - 14] ^ s[h - 16]; s[h] = l << 1 | l >>> 31 } var f = (i << 5 | i >>> 27) + c + s[h]; f += h < 20 ? (n & o | ~n & a) + 1518500249 : h < 40 ? (n ^ o ^ a) + 1859775393 : h < 60 ? (n & o | n & a | o & a) - 1894007588 : (n ^ o ^ a) - 899497514, c = a, a = o, o = n << 30 | n >>> 2, n = i, i = f } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + a | 0, e[4] = e[4] + c | 0 }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; return r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = Math.floor(e / 4294967296), r[(i + 64 >>> 9 << 4) + 15] = e, t.sigBytes = 4 * r.length, this._process(), this._hash }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t } }); r.SHA1 = n._createHelper(a), r.HmacSHA1 = n._createHmacHelper(a) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.algo, a = [], c = []; !function () { function t(t) { for (var e = r.sqrt(t), i = 2; i <= e; i++)if (!(t % i)) return !1; return !0 } function e(t) { return 4294967296 * (t - (0 | t)) | 0 } for (var i = 2, n = 0; n < 64;)t(i) && (n < 8 && (a[n] = e(r.pow(i, .5))), c[n] = e(r.pow(i, 1 / 3)), n++), i++ }(); var h = [], l = s.SHA256 = o.extend({ _doReset: function () { this._hash = new n.init(a.slice(0)) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], l = e[5], f = e[6], u = e[7], d = 0; d < 64; d++) { if (d < 16) h[d] = 0 | t[r + d]; else { var v = h[d - 15], p = (v << 25 | v >>> 7) ^ (v << 14 | v >>> 18) ^ v >>> 3, _ = h[d - 2], y = (_ << 15 | _ >>> 17) ^ (_ << 13 | _ >>> 19) ^ _ >>> 10; h[d] = p + h[d - 7] + y + h[d - 16] } var g = a & l ^ ~a & f, B = i & n ^ i & o ^ n & o, w = (i << 30 | i >>> 2) ^ (i << 19 | i >>> 13) ^ (i << 10 | i >>> 22), k = (a << 26 | a >>> 6) ^ (a << 21 | a >>> 11) ^ (a << 7 | a >>> 25), S = u + k + g + c[d] + h[d], m = w + B; u = f, f = l, l = a, a = s + S | 0, s = o, o = n, n = i, i = S + m | 0 } e[0] = e[0] + i | 0, e[1] = e[1] + n | 0, e[2] = e[2] + o | 0, e[3] = e[3] + s | 0, e[4] = e[4] + a | 0, e[5] = e[5] + l | 0, e[6] = e[6] + f | 0, e[7] = e[7] + u | 0 }, _doFinalize: function () { var t = this._data, e = t.words, i = 8 * this._nDataBytes, n = 8 * t.sigBytes; return e[n >>> 5] |= 128 << 24 - n % 32, e[(n + 64 >>> 9 << 4) + 14] = r.floor(i / 4294967296), e[(n + 64 >>> 9 << 4) + 15] = i, t.sigBytes = 4 * e.length, this._process(), this._hash }, clone: function () { var t = o.clone.call(this); return t._hash = this._hash.clone(), t } }); e.SHA256 = o._createHelper(l), e.HmacSHA256 = o._createHmacHelper(l) }(Math), function () { function r(t) { return t << 8 & 4278255360 | t >>> 8 & 16711935 } var e = t, i = e.lib, n = i.WordArray, o = e.enc; o.Utf16 = o.Utf16BE = { stringify: function (t) { for (var r = t.words, e = t.sigBytes, i = [], n = 0; n < e; n += 2) { var o = r[n >>> 2] >>> 16 - n % 4 * 8 & 65535; i.push(String.fromCharCode(o)) } return i.join("") }, parse: function (t) { for (var r = t.length, e = [], i = 0; i < r; i++)e[i >>> 1] |= t.charCodeAt(i) << 16 - i % 2 * 16; return n.create(e, 2 * r) } }; o.Utf16LE = { stringify: function (t) { for (var e = t.words, i = t.sigBytes, n = [], o = 0; o < i; o += 2) { var s = r(e[o >>> 2] >>> 16 - o % 4 * 8 & 65535); n.push(String.fromCharCode(s)) } return n.join("") }, parse: function (t) { for (var e = t.length, i = [], o = 0; o < e; o++)i[o >>> 1] |= r(t.charCodeAt(o) << 16 - o % 2 * 16); return n.create(i, 2 * e) } } }(), function () { if ("function" == typeof ArrayBuffer) { var r = t, e = r.lib, i = e.WordArray, n = i.init, o = i.init = function (t) { if (t instanceof ArrayBuffer && (t = new Uint8Array(t)), (t instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && t instanceof Uint8ClampedArray || t instanceof Int16Array || t instanceof Uint16Array || t instanceof Int32Array || t instanceof Uint32Array || t instanceof Float32Array || t instanceof Float64Array) && (t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength)), t instanceof Uint8Array) { for (var r = t.byteLength, e = [], i = 0; i < r; i++)e[i >>> 2] |= t[i] << 24 - i % 4 * 8; n.call(this, e, r) } else n.apply(this, arguments) }; o.prototype = i } }(), function (r) { function e(t, r, e) { return t ^ r ^ e } function i(t, r, e) { return t & r | ~t & e } function n(t, r, e) { return (t | ~r) ^ e } function o(t, r, e) { return t & e | r & ~e } function s(t, r, e) { return t ^ (r | ~e) } function a(t, r) { return t << r | t >>> 32 - r } var c = t, h = c.lib, l = h.WordArray, f = h.Hasher, u = c.algo, d = l.create([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]), v = l.create([5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]), p = l.create([11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]), _ = l.create([8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]), y = l.create([0, 1518500249, 1859775393, 2400959708, 2840853838]), g = l.create([1352829926, 1548603684, 1836072691, 2053994217, 0]), B = u.RIPEMD160 = f.extend({ _doReset: function () { this._hash = l.create([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (t, r) { for (var c = 0; c < 16; c++) { var h = r + c, l = t[h]; t[h] = 16711935 & (l << 8 | l >>> 24) | 4278255360 & (l << 24 | l >>> 8) } var f, u, B, w, k, S, m, x, b, H, z = this._hash.words, A = y.words, C = g.words, D = d.words, R = v.words, E = p.words, M = _.words; S = f = z[0], m = u = z[1], x = B = z[2], b = w = z[3], H = k = z[4]; for (var F, c = 0; c < 80; c += 1)F = f + t[r + D[c]] | 0, F += c < 16 ? e(u, B, w) + A[0] : c < 32 ? i(u, B, w) + A[1] : c < 48 ? n(u, B, w) + A[2] : c < 64 ? o(u, B, w) + A[3] : s(u, B, w) + A[4], F |= 0, F = a(F, E[c]), F = F + k | 0, f = k, k = w, w = a(B, 10), B = u, u = F, F = S + t[r + R[c]] | 0, F += c < 16 ? s(m, x, b) + C[0] : c < 32 ? o(m, x, b) + C[1] : c < 48 ? n(m, x, b) + C[2] : c < 64 ? i(m, x, b) + C[3] : e(m, x, b) + C[4], F |= 0, F = a(F, M[c]), F = F + H | 0, S = H, H = b, b = a(x, 10), x = m, m = F; F = z[1] + B + b | 0, z[1] = z[2] + w + H | 0, z[2] = z[3] + k + S | 0, z[3] = z[4] + f + m | 0, z[4] = z[0] + u + x | 0, z[0] = F }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 64 >>> 9 << 4) + 14] = 16711935 & (e << 8 | e >>> 24) | 4278255360 & (e << 24 | e >>> 8), t.sigBytes = 4 * (r.length + 1), this._process(); for (var n = this._hash, o = n.words, s = 0; s < 5; s++) { var a = o[s]; o[s] = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8) } return n }, clone: function () { var t = f.clone.call(this); return t._hash = this._hash.clone(), t } }); c.RIPEMD160 = f._createHelper(B), c.HmacRIPEMD160 = f._createHmacHelper(B) }(Math), function () { var r = t, e = r.lib, i = e.Base, n = r.enc, o = n.Utf8, s = r.algo; s.HMAC = i.extend({ init: function (t, r) { t = this._hasher = new t.init, "string" == typeof r && (r = o.parse(r)); var e = t.blockSize, i = 4 * e; r.sigBytes > i && (r = t.finalize(r)), r.clamp(); for (var n = this._oKey = r.clone(), s = this._iKey = r.clone(), a = n.words, c = s.words, h = 0; h < e; h++)a[h] ^= 1549556828, c[h] ^= 909522486; n.sigBytes = s.sigBytes = i, this.reset() }, reset: function () { var t = this._hasher; t.reset(), t.update(this._iKey) }, update: function (t) { return this._hasher.update(t), this }, finalize: function (t) { var r = this._hasher, e = r.finalize(t); r.reset(); var i = r.finalize(this._oKey.clone().concat(e)); return i } }) }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.SHA1, a = o.HMAC, c = o.PBKDF2 = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = a.create(e.hasher, t), o = n.create(), s = n.create([1]), c = o.words, h = s.words, l = e.keySize, f = e.iterations; c.length < l;) { var u = i.update(r).finalize(s); i.reset(); for (var d = u.words, v = d.length, p = u, _ = 1; _ < f; _++) { p = i.finalize(p), i.reset(); for (var y = p.words, g = 0; g < v; g++)d[g] ^= y[g] } o.concat(u), h[0]++ } return o.sigBytes = 4 * l, o } }); r.PBKDF2 = function (t, r, e) { return c.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.Base, n = e.WordArray, o = r.algo, s = o.MD5, a = o.EvpKDF = i.extend({ cfg: i.extend({ keySize: 4, hasher: s, iterations: 1 }), init: function (t) { this.cfg = this.cfg.extend(t) }, compute: function (t, r) { for (var e = this.cfg, i = e.hasher.create(), o = n.create(), s = o.words, a = e.keySize, c = e.iterations; s.length < a;) { h && i.update(h); var h = i.update(t).finalize(r); i.reset(); for (var l = 1; l < c; l++)h = i.finalize(h), i.reset(); o.concat(h) } return o.sigBytes = 4 * a, o } }); r.EvpKDF = function (t, r, e) { return a.create(e).compute(t, r) } }(), function () { var r = t, e = r.lib, i = e.WordArray, n = r.algo, o = n.SHA256, s = n.SHA224 = o.extend({ _doReset: function () { this._hash = new i.init([3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]) }, _doFinalize: function () { var t = o._doFinalize.call(this); return t.sigBytes -= 4, t } }); r.SHA224 = o._createHelper(s), r.HmacSHA224 = o._createHmacHelper(s) }(), function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = e.x64 = {}; s.Word = n.extend({ init: function (t, r) { this.high = t, this.low = r } }), s.WordArray = n.extend({ init: function (t, e) { t = this.words = t || [], e != r ? this.sigBytes = e : this.sigBytes = 8 * t.length }, toX32: function () { for (var t = this.words, r = t.length, e = [], i = 0; i < r; i++) { var n = t[i]; e.push(n.high), e.push(n.low) } return o.create(e, this.sigBytes) }, clone: function () { for (var t = n.clone.call(this), r = t.words = this.words.slice(0), e = r.length, i = 0; i < e; i++)r[i] = r[i].clone(); return t } }) }(), function (r) { var e = t, i = e.lib, n = i.WordArray, o = i.Hasher, s = e.x64, a = s.Word, c = e.algo, h = [], l = [], f = []; !function () { for (var t = 1, r = 0, e = 0; e < 24; e++) { h[t + 5 * r] = (e + 1) * (e + 2) / 2 % 64; var i = r % 5, n = (2 * t + 3 * r) % 5; t = i, r = n } for (var t = 0; t < 5; t++)for (var r = 0; r < 5; r++)l[t + 5 * r] = r + (2 * t + 3 * r) % 5 * 5; for (var o = 1, s = 0; s < 24; s++) { for (var c = 0, u = 0, d = 0; d < 7; d++) { if (1 & o) { var v = (1 << d) - 1; v < 32 ? u ^= 1 << v : c ^= 1 << v - 32 } 128 & o ? o = o << 1 ^ 113 : o <<= 1 } f[s] = a.create(c, u) } }(); var u = []; !function () { for (var t = 0; t < 25; t++)u[t] = a.create() }(); var d = c.SHA3 = o.extend({ cfg: o.cfg.extend({ outputLength: 512 }), _doReset: function () { for (var t = this._state = [], r = 0; r < 25; r++)t[r] = new a.init; this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32 }, _doProcessBlock: function (t, r) { for (var e = this._state, i = this.blockSize / 2, n = 0; n < i; n++) { var o = t[r + 2 * n], s = t[r + 2 * n + 1]; o = 16711935 & (o << 8 | o >>> 24) | 4278255360 & (o << 24 | o >>> 8), s = 16711935 & (s << 8 | s >>> 24) | 4278255360 & (s << 24 | s >>> 8); var a = e[n]; a.high ^= s, a.low ^= o } for (var c = 0; c < 24; c++) { for (var d = 0; d < 5; d++) { for (var v = 0, p = 0, _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; v ^= a.high, p ^= a.low } var y = u[d]; y.high = v, y.low = p } for (var d = 0; d < 5; d++)for (var g = u[(d + 4) % 5], B = u[(d + 1) % 5], w = B.high, k = B.low, v = g.high ^ (w << 1 | k >>> 31), p = g.low ^ (k << 1 | w >>> 31), _ = 0; _ < 5; _++) { var a = e[d + 5 * _]; a.high ^= v, a.low ^= p } for (var S = 1; S < 25; S++) { var a = e[S], m = a.high, x = a.low, b = h[S]; if (b < 32) var v = m << b | x >>> 32 - b, p = x << b | m >>> 32 - b; else var v = x << b - 32 | m >>> 64 - b, p = m << b - 32 | x >>> 64 - b; var H = u[l[S]]; H.high = v, H.low = p } var z = u[0], A = e[0]; z.high = A.high, z.low = A.low; for (var d = 0; d < 5; d++)for (var _ = 0; _ < 5; _++) { var S = d + 5 * _, a = e[S], C = u[S], D = u[(d + 1) % 5 + 5 * _], R = u[(d + 2) % 5 + 5 * _]; a.high = C.high ^ ~D.high & R.high, a.low = C.low ^ ~D.low & R.low } var a = e[0], E = f[c]; a.high ^= E.high, a.low ^= E.low } }, _doFinalize: function () { var t = this._data, e = t.words, i = (8 * this._nDataBytes, 8 * t.sigBytes), o = 32 * this.blockSize; e[i >>> 5] |= 1 << 24 - i % 32, e[(r.ceil((i + 1) / o) * o >>> 5) - 1] |= 128, t.sigBytes = 4 * e.length, this._process(); for (var s = this._state, a = this.cfg.outputLength / 8, c = a / 8, h = [], l = 0; l < c; l++) { var f = s[l], u = f.high, d = f.low; u = 16711935 & (u << 8 | u >>> 24) | 4278255360 & (u << 24 | u >>> 8), d = 16711935 & (d << 8 | d >>> 24) | 4278255360 & (d << 24 | d >>> 8), h.push(d), h.push(u) } return new n.init(h, a) }, clone: function () { for (var t = o.clone.call(this), r = t._state = this._state.slice(0), e = 0; e < 25; e++)r[e] = r[e].clone(); return t } }); e.SHA3 = o._createHelper(d), e.HmacSHA3 = o._createHmacHelper(d) }(Math), function () { function r() { return s.create.apply(s, arguments) } var e = t, i = e.lib, n = i.Hasher, o = e.x64, s = o.Word, a = o.WordArray, c = e.algo, h = [r(1116352408, 3609767458), r(1899447441, 602891725), r(3049323471, 3964484399), r(3921009573, 2173295548), r(961987163, 4081628472), r(1508970993, 3053834265), r(2453635748, 2937671579), r(2870763221, 3664609560), r(3624381080, 2734883394), r(310598401, 1164996542), r(607225278, 1323610764), r(1426881987, 3590304994), r(1925078388, 4068182383), r(2162078206, 991336113), r(2614888103, 633803317), r(3248222580, 3479774868), r(3835390401, 2666613458), r(4022224774, 944711139), r(264347078, 2341262773), r(604807628, 2007800933), r(770255983, 1495990901), r(1249150122, 1856431235), r(1555081692, 3175218132), r(1996064986, 2198950837), r(2554220882, 3999719339), r(2821834349, 766784016), r(2952996808, 2566594879), r(3210313671, 3203337956), r(3336571891, 1034457026), r(3584528711, 2466948901), r(113926993, 3758326383), r(338241895, 168717936), r(666307205, 1188179964), r(773529912, 1546045734), r(1294757372, 1522805485), r(1396182291, 2643833823), r(1695183700, 2343527390), r(1986661051, 1014477480), r(2177026350, 1206759142), r(2456956037, 344077627), r(2730485921, 1290863460), r(2820302411, 3158454273), r(3259730800, 3505952657), r(3345764771, 106217008), r(3516065817, 3606008344), r(3600352804, 1432725776), r(4094571909, 1467031594), r(275423344, 851169720), r(430227734, 3100823752), r(506948616, 1363258195), r(659060556, 3750685593), r(883997877, 3785050280), r(958139571, 3318307427), r(1322822218, 3812723403), r(1537002063, 2003034995), r(1747873779, 3602036899), r(1955562222, 1575990012), r(2024104815, 1125592928), r(2227730452, 2716904306), r(2361852424, 442776044), r(2428436474, 593698344), r(2756734187, 3733110249), r(3204031479, 2999351573), r(3329325298, 3815920427), r(3391569614, 3928383900), r(3515267271, 566280711), r(3940187606, 3454069534), r(4118630271, 4000239992), r(116418474, 1914138554), r(174292421, 2731055270), r(289380356, 3203993006), r(460393269, 320620315), r(685471733, 587496836), r(852142971, 1086792851), r(1017036298, 365543100), r(1126000580, 2618297676), r(1288033470, 3409855158), r(1501505948, 4234509866), r(1607167915, 987167468), r(1816402316, 1246189591)], l = []; !function () { for (var t = 0; t < 80; t++)l[t] = r() }(); var f = c.SHA512 = n.extend({ _doReset: function () { this._hash = new a.init([new s.init(1779033703, 4089235720), new s.init(3144134277, 2227873595), new s.init(1013904242, 4271175723), new s.init(2773480762, 1595750129), new s.init(1359893119, 2917565137), new s.init(2600822924, 725511199), new s.init(528734635, 4215389547), new s.init(1541459225, 327033209)]) }, _doProcessBlock: function (t, r) { for (var e = this._hash.words, i = e[0], n = e[1], o = e[2], s = e[3], a = e[4], c = e[5], f = e[6], u = e[7], d = i.high, v = i.low, p = n.high, _ = n.low, y = o.high, g = o.low, B = s.high, w = s.low, k = a.high, S = a.low, m = c.high, x = c.low, b = f.high, H = f.low, z = u.high, A = u.low, C = d, D = v, R = p, E = _, M = y, F = g, P = B, W = w, O = k, U = S, I = m, K = x, X = b, L = H, j = z, N = A, T = 0; T < 80; T++) { var Z = l[T]; if (T < 16) var q = Z.high = 0 | t[r + 2 * T], G = Z.low = 0 | t[r + 2 * T + 1]; else { var J = l[T - 15], $ = J.high, Q = J.low, V = ($ >>> 1 | Q << 31) ^ ($ >>> 8 | Q << 24) ^ $ >>> 7, Y = (Q >>> 1 | $ << 31) ^ (Q >>> 8 | $ << 24) ^ (Q >>> 7 | $ << 25), tt = l[T - 2], rt = tt.high, et = tt.low, it = (rt >>> 19 | et << 13) ^ (rt << 3 | et >>> 29) ^ rt >>> 6, nt = (et >>> 19 | rt << 13) ^ (et << 3 | rt >>> 29) ^ (et >>> 6 | rt << 26), ot = l[T - 7], st = ot.high, at = ot.low, ct = l[T - 16], ht = ct.high, lt = ct.low, G = Y + at, q = V + st + (G >>> 0 < Y >>> 0 ? 1 : 0), G = G + nt, q = q + it + (G >>> 0 < nt >>> 0 ? 1 : 0), G = G + lt, q = q + ht + (G >>> 0 < lt >>> 0 ? 1 : 0); Z.high = q, Z.low = G } var ft = O & I ^ ~O & X, ut = U & K ^ ~U & L, dt = C & R ^ C & M ^ R & M, vt = D & E ^ D & F ^ E & F, pt = (C >>> 28 | D << 4) ^ (C << 30 | D >>> 2) ^ (C << 25 | D >>> 7), _t = (D >>> 28 | C << 4) ^ (D << 30 | C >>> 2) ^ (D << 25 | C >>> 7), yt = (O >>> 14 | U << 18) ^ (O >>> 18 | U << 14) ^ (O << 23 | U >>> 9), gt = (U >>> 14 | O << 18) ^ (U >>> 18 | O << 14) ^ (U << 23 | O >>> 9), Bt = h[T], wt = Bt.high, kt = Bt.low, St = N + gt, mt = j + yt + (St >>> 0 < N >>> 0 ? 1 : 0), St = St + ut, mt = mt + ft + (St >>> 0 < ut >>> 0 ? 1 : 0), St = St + kt, mt = mt + wt + (St >>> 0 < kt >>> 0 ? 1 : 0), St = St + G, mt = mt + q + (St >>> 0 < G >>> 0 ? 1 : 0), xt = _t + vt, bt = pt + dt + (xt >>> 0 < _t >>> 0 ? 1 : 0); j = X, N = L, X = I, L = K, I = O, K = U, U = W + St | 0, O = P + mt + (U >>> 0 < W >>> 0 ? 1 : 0) | 0, P = M, W = F, M = R, F = E, R = C, E = D, D = St + xt | 0, C = mt + bt + (D >>> 0 < St >>> 0 ? 1 : 0) | 0 } v = i.low = v + D, i.high = d + C + (v >>> 0 < D >>> 0 ? 1 : 0), _ = n.low = _ + E, n.high = p + R + (_ >>> 0 < E >>> 0 ? 1 : 0), g = o.low = g + F, o.high = y + M + (g >>> 0 < F >>> 0 ? 1 : 0), w = s.low = w + W, s.high = B + P + (w >>> 0 < W >>> 0 ? 1 : 0), S = a.low = S + U, a.high = k + O + (S >>> 0 < U >>> 0 ? 1 : 0), x = c.low = x + K, c.high = m + I + (x >>> 0 < K >>> 0 ? 1 : 0), H = f.low = H + L, f.high = b + X + (H >>> 0 < L >>> 0 ? 1 : 0), A = u.low = A + N, u.high = z + j + (A >>> 0 < N >>> 0 ? 1 : 0) }, _doFinalize: function () { var t = this._data, r = t.words, e = 8 * this._nDataBytes, i = 8 * t.sigBytes; r[i >>> 5] |= 128 << 24 - i % 32, r[(i + 128 >>> 10 << 5) + 30] = Math.floor(e / 4294967296), r[(i + 128 >>> 10 << 5) + 31] = e, t.sigBytes = 4 * r.length, this._process(); var n = this._hash.toX32(); return n }, clone: function () { var t = n.clone.call(this); return t._hash = this._hash.clone(), t }, blockSize: 32 }); e.SHA512 = n._createHelper(f), e.HmacSHA512 = n._createHmacHelper(f) }(), function () { var r = t, e = r.x64, i = e.Word, n = e.WordArray, o = r.algo, s = o.SHA512, a = o.SHA384 = s.extend({ _doReset: function () { this._hash = new n.init([new i.init(3418070365, 3238371032), new i.init(1654270250, 914150663), new i.init(2438529370, 812702999), new i.init(355462360, 4144912697), new i.init(1731405415, 4290775857), new i.init(2394180231, 1750603025), new i.init(3675008525, 1694076839), new i.init(1203062813, 3204075428)]) }, _doFinalize: function () { var t = s._doFinalize.call(this); return t.sigBytes -= 16, t } }); r.SHA384 = s._createHelper(a), r.HmacSHA384 = s._createHmacHelper(a) }(), t.lib.Cipher || function (r) { var e = t, i = e.lib, n = i.Base, o = i.WordArray, s = i.BufferedBlockAlgorithm, a = e.enc, c = (a.Utf8, a.Base64), h = e.algo, l = h.EvpKDF, f = i.Cipher = s.extend({ cfg: n.extend(), createEncryptor: function (t, r) { return this.create(this._ENC_XFORM_MODE, t, r) }, createDecryptor: function (t, r) { return this.create(this._DEC_XFORM_MODE, t, r) }, init: function (t, r, e) { this.cfg = this.cfg.extend(e), this._xformMode = t, this._key = r, this.reset() }, reset: function () { s.reset.call(this), this._doReset() }, process: function (t) { return this._append(t), this._process() }, finalize: function (t) { t && this._append(t); var r = this._doFinalize(); return r }, keySize: 4, ivSize: 4, _ENC_XFORM_MODE: 1, _DEC_XFORM_MODE: 2, _createHelper: function () { function t(t) { return "string" == typeof t ? m : w } return function (r) { return { encrypt: function (e, i, n) { return t(i).encrypt(r, e, i, n) }, decrypt: function (e, i, n) { return t(i).decrypt(r, e, i, n) } } } }() }), u = (i.StreamCipher = f.extend({ _doFinalize: function () { var t = this._process(!0); return t }, blockSize: 1 }), e.mode = {}), d = i.BlockCipherMode = n.extend({ createEncryptor: function (t, r) { return this.Encryptor.create(t, r) }, createDecryptor: function (t, r) { return this.Decryptor.create(t, r) }, init: function (t, r) { this._cipher = t, this._iv = r } }), v = u.CBC = function () { function t(t, e, i) { var n = this._iv; if (n) { var o = n; this._iv = r } else var o = this._prevBlock; for (var s = 0; s < i; s++)t[e + s] ^= o[s] } var e = d.extend(); return e.Encryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize; t.call(this, r, e, n), i.encryptBlock(r, e), this._prevBlock = r.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (r, e) { var i = this._cipher, n = i.blockSize, o = r.slice(e, e + n); i.decryptBlock(r, e), t.call(this, r, e, n), this._prevBlock = o } }), e }(), p = e.pad = {}, _ = p.Pkcs7 = { pad: function (t, r) { for (var e = 4 * r, i = e - t.sigBytes % e, n = i << 24 | i << 16 | i << 8 | i, s = [], a = 0; a < i; a += 4)s.push(n); var c = o.create(s, i); t.concat(c) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, y = (i.BlockCipher = f.extend({ cfg: f.cfg.extend({ mode: v, padding: _ }), reset: function () { f.reset.call(this); var t = this.cfg, r = t.iv, e = t.mode; if (this._xformMode == this._ENC_XFORM_MODE) var i = e.createEncryptor; else { var i = e.createDecryptor; this._minBufferSize = 1 } this._mode && this._mode.__creator == i ? this._mode.init(this, r && r.words) : (this._mode = i.call(e, this, r && r.words), this._mode.__creator = i) }, _doProcessBlock: function (t, r) { this._mode.processBlock(t, r) }, _doFinalize: function () { var t = this.cfg.padding; if (this._xformMode == this._ENC_XFORM_MODE) { t.pad(this._data, this.blockSize); var r = this._process(!0) } else { var r = this._process(!0); t.unpad(r) } return r }, blockSize: 4 }), i.CipherParams = n.extend({ init: function (t) { this.mixIn(t) }, toString: function (t) { return (t || this.formatter).stringify(this) } })), g = e.format = {}, B = g.OpenSSL = { stringify: function (t) { var r = t.ciphertext, e = t.salt; if (e) var i = o.create([1398893684, 1701076831]).concat(e).concat(r); else var i = r; return i.toString(c) }, parse: function (t) { var r = c.parse(t), e = r.words; if (1398893684 == e[0] && 1701076831 == e[1]) { var i = o.create(e.slice(2, 4)); e.splice(0, 4), r.sigBytes -= 16 } return y.create({ ciphertext: r, salt: i }) } }, w = i.SerializableCipher = n.extend({ cfg: n.extend({ format: B }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = t.createEncryptor(e, i), o = n.finalize(r), s = n.cfg; return y.create({ ciphertext: o, key: e, iv: s.iv, algorithm: t, mode: s.mode, padding: s.padding, blockSize: t.blockSize, formatter: i.format }) }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = t.createDecryptor(e, i).finalize(r.ciphertext); return n }, _parse: function (t, r) { return "string" == typeof t ? r.parse(t, this) : t } }), k = e.kdf = {}, S = k.OpenSSL = { execute: function (t, r, e, i) { i || (i = o.random(8)); var n = l.create({ keySize: r + e }).compute(t, i), s = o.create(n.words.slice(r), 4 * e); return n.sigBytes = 4 * r, y.create({ key: n, iv: s, salt: i }) } }, m = i.PasswordBasedCipher = w.extend({ cfg: w.cfg.extend({ kdf: S }), encrypt: function (t, r, e, i) { i = this.cfg.extend(i); var n = i.kdf.execute(e, t.keySize, t.ivSize); i.iv = n.iv; var o = w.encrypt.call(this, t, r, n.key, i); return o.mixIn(n), o }, decrypt: function (t, r, e, i) { i = this.cfg.extend(i), r = this._parse(r, i.format); var n = i.kdf.execute(e, t.keySize, t.ivSize, r.salt); i.iv = n.iv; var o = w.decrypt.call(this, t, r, n.key, i); return o } }) }(), t.mode.CFB = function () { function r(t, r, e, i) { var n = this._iv; if (n) { var o = n.slice(0); this._iv = void 0 } else var o = this._prevBlock; i.encryptBlock(o, 0); for (var s = 0; s < e; s++)t[r + s] ^= o[s] } var e = t.lib.BlockCipherMode.extend(); return e.Encryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize; r.call(this, t, e, n, i), this._prevBlock = t.slice(e, e + n) } }), e.Decryptor = e.extend({ processBlock: function (t, e) { var i = this._cipher, n = i.blockSize, o = t.slice(e, e + n); r.call(this, t, e, n, i), this._prevBlock = o } }), e }(), t.mode.ECB = function () { var r = t.lib.BlockCipherMode.extend(); return r.Encryptor = r.extend({ processBlock: function (t, r) { this._cipher.encryptBlock(t, r) } }), r.Decryptor = r.extend({ processBlock: function (t, r) { this._cipher.decryptBlock(t, r) } }), r }(), t.pad.AnsiX923 = { pad: function (t, r) { var e = t.sigBytes, i = 4 * r, n = i - e % i, o = e + n - 1; t.clamp(), t.words[o >>> 2] |= n << 24 - o % 4 * 8, t.sigBytes += n }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso10126 = { pad: function (r, e) { var i = 4 * e, n = i - r.sigBytes % i; r.concat(t.lib.WordArray.random(n - 1)).concat(t.lib.WordArray.create([n << 24], 1)) }, unpad: function (t) { var r = 255 & t.words[t.sigBytes - 1 >>> 2]; t.sigBytes -= r } }, t.pad.Iso97971 = { pad: function (r, e) { r.concat(t.lib.WordArray.create([2147483648], 1)), t.pad.ZeroPadding.pad(r, e) }, unpad: function (r) { t.pad.ZeroPadding.unpad(r), r.sigBytes-- } }, t.mode.OFB = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._keystream; n && (o = this._keystream = n.slice(0), this._iv = void 0), e.encryptBlock(o, 0); for (var s = 0; s < i; s++)t[r + s] ^= o[s] } }); return r.Decryptor = e, r }(), t.pad.NoPadding = { pad: function () { }, unpad: function () { } }, function (r) { var e = t, i = e.lib, n = i.CipherParams, o = e.enc, s = o.Hex, a = e.format; a.Hex = { stringify: function (t) { return t.ciphertext.toString(s) }, parse: function (t) { var r = s.parse(t); return n.create({ ciphertext: r }) } } }(), function () { var r = t, e = r.lib, i = e.BlockCipher, n = r.algo, o = [], s = [], a = [], c = [], h = [], l = [], f = [], u = [], d = [], v = []; !function () { for (var t = [], r = 0; r < 256; r++)r < 128 ? t[r] = r << 1 : t[r] = r << 1 ^ 283; for (var e = 0, i = 0, r = 0; r < 256; r++) { var n = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4; n = n >>> 8 ^ 255 & n ^ 99, o[e] = n, s[n] = e; var p = t[e], _ = t[p], y = t[_], g = 257 * t[n] ^ 16843008 * n; a[e] = g << 24 | g >>> 8, c[e] = g << 16 | g >>> 16, h[e] = g << 8 | g >>> 24, l[e] = g; var g = 16843009 * y ^ 65537 * _ ^ 257 * p ^ 16843008 * e; f[n] = g << 24 | g >>> 8, u[n] = g << 16 | g >>> 16, d[n] = g << 8 | g >>> 24, v[n] = g, e ? (e = p ^ t[t[t[y ^ p]]], i ^= t[t[i]]) : e = i = 1 } }(); var p = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], _ = n.AES = i.extend({ _doReset: function () { if (!this._nRounds || this._keyPriorReset !== this._key) { for (var t = this._keyPriorReset = this._key, r = t.words, e = t.sigBytes / 4, i = this._nRounds = e + 6, n = 4 * (i + 1), s = this._keySchedule = [], a = 0; a < n; a++)if (a < e) s[a] = r[a]; else { var c = s[a - 1]; a % e ? e > 6 && a % e == 4 && (c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c]) : (c = c << 8 | c >>> 24, c = o[c >>> 24] << 24 | o[c >>> 16 & 255] << 16 | o[c >>> 8 & 255] << 8 | o[255 & c], c ^= p[a / e | 0] << 24), s[a] = s[a - e] ^ c } for (var h = this._invKeySchedule = [], l = 0; l < n; l++) { var a = n - l; if (l % 4) var c = s[a]; else var c = s[a - 4]; l < 4 || a <= 4 ? h[l] = c : h[l] = f[o[c >>> 24]] ^ u[o[c >>> 16 & 255]] ^ d[o[c >>> 8 & 255]] ^ v[o[255 & c]] } } }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._keySchedule, a, c, h, l, o) }, decryptBlock: function (t, r) { var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e, this._doCryptBlock(t, r, this._invKeySchedule, f, u, d, v, s); var e = t[r + 1]; t[r + 1] = t[r + 3], t[r + 3] = e }, _doCryptBlock: function (t, r, e, i, n, o, s, a) { for (var c = this._nRounds, h = t[r] ^ e[0], l = t[r + 1] ^ e[1], f = t[r + 2] ^ e[2], u = t[r + 3] ^ e[3], d = 4, v = 1; v < c; v++) { var p = i[h >>> 24] ^ n[l >>> 16 & 255] ^ o[f >>> 8 & 255] ^ s[255 & u] ^ e[d++], _ = i[l >>> 24] ^ n[f >>> 16 & 255] ^ o[u >>> 8 & 255] ^ s[255 & h] ^ e[d++], y = i[f >>> 24] ^ n[u >>> 16 & 255] ^ o[h >>> 8 & 255] ^ s[255 & l] ^ e[d++], g = i[u >>> 24] ^ n[h >>> 16 & 255] ^ o[l >>> 8 & 255] ^ s[255 & f] ^ e[d++]; h = p, l = _, f = y, u = g } var p = (a[h >>> 24] << 24 | a[l >>> 16 & 255] << 16 | a[f >>> 8 & 255] << 8 | a[255 & u]) ^ e[d++], _ = (a[l >>> 24] << 24 | a[f >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & h]) ^ e[d++], y = (a[f >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[h >>> 8 & 255] << 8 | a[255 & l]) ^ e[d++], g = (a[u >>> 24] << 24 | a[h >>> 16 & 255] << 16 | a[l >>> 8 & 255] << 8 | a[255 & f]) ^ e[d++]; t[r] = p, t[r + 1] = _, t[r + 2] = y, t[r + 3] = g }, keySize: 8 }); r.AES = i._createHelper(_) }(), function () { - function r(t, r) { var e = (this._lBlock >>> t ^ this._rBlock) & r; this._rBlock ^= e, this._lBlock ^= e << t } function e(t, r) { - var e = (this._rBlock >>> t ^ this._lBlock) & r; this._lBlock ^= e, this._rBlock ^= e << t; - } var i = t, n = i.lib, o = n.WordArray, s = n.BlockCipher, a = i.algo, c = [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4], h = [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32], l = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28], f = [{ 0: 8421888, 268435456: 32768, 536870912: 8421378, 805306368: 2, 1073741824: 512, 1342177280: 8421890, 1610612736: 8389122, 1879048192: 8388608, 2147483648: 514, 2415919104: 8389120, 2684354560: 33280, 2952790016: 8421376, 3221225472: 32770, 3489660928: 8388610, 3758096384: 0, 4026531840: 33282, 134217728: 0, 402653184: 8421890, 671088640: 33282, 939524096: 32768, 1207959552: 8421888, 1476395008: 512, 1744830464: 8421378, 2013265920: 2, 2281701376: 8389120, 2550136832: 33280, 2818572288: 8421376, 3087007744: 8389122, 3355443200: 8388610, 3623878656: 32770, 3892314112: 514, 4160749568: 8388608, 1: 32768, 268435457: 2, 536870913: 8421888, 805306369: 8388608, 1073741825: 8421378, 1342177281: 33280, 1610612737: 512, 1879048193: 8389122, 2147483649: 8421890, 2415919105: 8421376, 2684354561: 8388610, 2952790017: 33282, 3221225473: 514, 3489660929: 8389120, 3758096385: 32770, 4026531841: 0, 134217729: 8421890, 402653185: 8421376, 671088641: 8388608, 939524097: 512, 1207959553: 32768, 1476395009: 8388610, 1744830465: 2, 2013265921: 33282, 2281701377: 32770, 2550136833: 8389122, 2818572289: 514, 3087007745: 8421888, 3355443201: 8389120, 3623878657: 0, 3892314113: 33280, 4160749569: 8421378 }, { 0: 1074282512, 16777216: 16384, 33554432: 524288, 50331648: 1074266128, 67108864: 1073741840, 83886080: 1074282496, 100663296: 1073758208, 117440512: 16, 134217728: 540672, 150994944: 1073758224, 167772160: 1073741824, 184549376: 540688, 201326592: 524304, 218103808: 0, 234881024: 16400, 251658240: 1074266112, 8388608: 1073758208, 25165824: 540688, 41943040: 16, 58720256: 1073758224, 75497472: 1074282512, 92274688: 1073741824, 109051904: 524288, 125829120: 1074266128, 142606336: 524304, 159383552: 0, 176160768: 16384, 192937984: 1074266112, 209715200: 1073741840, 226492416: 540672, 243269632: 1074282496, 260046848: 16400, 268435456: 0, 285212672: 1074266128, 301989888: 1073758224, 318767104: 1074282496, 335544320: 1074266112, 352321536: 16, 369098752: 540688, 385875968: 16384, 402653184: 16400, 419430400: 524288, 436207616: 524304, 452984832: 1073741840, 469762048: 540672, 486539264: 1073758208, 503316480: 1073741824, 520093696: 1074282512, 276824064: 540688, 293601280: 524288, 310378496: 1074266112, 327155712: 16384, 343932928: 1073758208, 360710144: 1074282512, 377487360: 16, 394264576: 1073741824, 411041792: 1074282496, 427819008: 1073741840, 444596224: 1073758224, 461373440: 524304, 478150656: 0, 494927872: 16400, 511705088: 1074266128, 528482304: 540672 }, { 0: 260, 1048576: 0, 2097152: 67109120, 3145728: 65796, 4194304: 65540, 5242880: 67108868, 6291456: 67174660, 7340032: 67174400, 8388608: 67108864, 9437184: 67174656, 10485760: 65792, 11534336: 67174404, 12582912: 67109124, 13631488: 65536, 14680064: 4, 15728640: 256, 524288: 67174656, 1572864: 67174404, 2621440: 0, 3670016: 67109120, 4718592: 67108868, 5767168: 65536, 6815744: 65540, 7864320: 260, 8912896: 4, 9961472: 256, 11010048: 67174400, 12058624: 65796, 13107200: 65792, 14155776: 67109124, 15204352: 67174660, 16252928: 67108864, 16777216: 67174656, 17825792: 65540, 18874368: 65536, 19922944: 67109120, 20971520: 256, 22020096: 67174660, 23068672: 67108868, 24117248: 0, 25165824: 67109124, 26214400: 67108864, 27262976: 4, 28311552: 65792, 29360128: 67174400, 30408704: 260, 31457280: 65796, 32505856: 67174404, 17301504: 67108864, 18350080: 260, 19398656: 67174656, 20447232: 0, 21495808: 65540, 22544384: 67109120, 23592960: 256, 24641536: 67174404, 25690112: 65536, 26738688: 67174660, 27787264: 65796, 28835840: 67108868, 29884416: 67109124, 30932992: 67174400, 31981568: 4, 33030144: 65792 }, { 0: 2151682048, 65536: 2147487808, 131072: 4198464, 196608: 2151677952, 262144: 0, 327680: 4198400, 393216: 2147483712, 458752: 4194368, 524288: 2147483648, 589824: 4194304, 655360: 64, 720896: 2147487744, 786432: 2151678016, 851968: 4160, 917504: 4096, 983040: 2151682112, 32768: 2147487808, 98304: 64, 163840: 2151678016, 229376: 2147487744, 294912: 4198400, 360448: 2151682112, 425984: 0, 491520: 2151677952, 557056: 4096, 622592: 2151682048, 688128: 4194304, 753664: 4160, 819200: 2147483648, 884736: 4194368, 950272: 4198464, 1015808: 2147483712, 1048576: 4194368, 1114112: 4198400, 1179648: 2147483712, 1245184: 0, 1310720: 4160, 1376256: 2151678016, 1441792: 2151682048, 1507328: 2147487808, 1572864: 2151682112, 1638400: 2147483648, 1703936: 2151677952, 1769472: 4198464, 1835008: 2147487744, 1900544: 4194304, 1966080: 64, 2031616: 4096, 1081344: 2151677952, 1146880: 2151682112, 1212416: 0, 1277952: 4198400, 1343488: 4194368, 1409024: 2147483648, 1474560: 2147487808, 1540096: 64, 1605632: 2147483712, 1671168: 4096, 1736704: 2147487744, 1802240: 2151678016, 1867776: 4160, 1933312: 2151682048, 1998848: 4194304, 2064384: 4198464 }, { 0: 128, 4096: 17039360, 8192: 262144, 12288: 536870912, 16384: 537133184, 20480: 16777344, 24576: 553648256, 28672: 262272, 32768: 16777216, 36864: 537133056, 40960: 536871040, 45056: 553910400, 49152: 553910272, 53248: 0, 57344: 17039488, 61440: 553648128, 2048: 17039488, 6144: 553648256, 10240: 128, 14336: 17039360, 18432: 262144, 22528: 537133184, 26624: 553910272, 30720: 536870912, 34816: 537133056, 38912: 0, 43008: 553910400, 47104: 16777344, 51200: 536871040, 55296: 553648128, 59392: 16777216, 63488: 262272, 65536: 262144, 69632: 128, 73728: 536870912, 77824: 553648256, 81920: 16777344, 86016: 553910272, 90112: 537133184, 94208: 16777216, 98304: 553910400, 102400: 553648128, 106496: 17039360, 110592: 537133056, 114688: 262272, 118784: 536871040, 122880: 0, 126976: 17039488, 67584: 553648256, 71680: 16777216, 75776: 17039360, 79872: 537133184, 83968: 536870912, 88064: 17039488, 92160: 128, 96256: 553910272, 100352: 262272, 104448: 553910400, 108544: 0, 112640: 553648128, 116736: 16777344, 120832: 262144, 124928: 537133056, 129024: 536871040 }, { 0: 268435464, 256: 8192, 512: 270532608, 768: 270540808, 1024: 268443648, 1280: 2097152, 1536: 2097160, 1792: 268435456, 2048: 0, 2304: 268443656, 2560: 2105344, 2816: 8, 3072: 270532616, 3328: 2105352, 3584: 8200, 3840: 270540800, 128: 270532608, 384: 270540808, 640: 8, 896: 2097152, 1152: 2105352, 1408: 268435464, 1664: 268443648, 1920: 8200, 2176: 2097160, 2432: 8192, 2688: 268443656, 2944: 270532616, 3200: 0, 3456: 270540800, 3712: 2105344, 3968: 268435456, 4096: 268443648, 4352: 270532616, 4608: 270540808, 4864: 8200, 5120: 2097152, 5376: 268435456, 5632: 268435464, 5888: 2105344, 6144: 2105352, 6400: 0, 6656: 8, 6912: 270532608, 7168: 8192, 7424: 268443656, 7680: 270540800, 7936: 2097160, 4224: 8, 4480: 2105344, 4736: 2097152, 4992: 268435464, 5248: 268443648, 5504: 8200, 5760: 270540808, 6016: 270532608, 6272: 270540800, 6528: 270532616, 6784: 8192, 7040: 2105352, 7296: 2097160, 7552: 0, 7808: 268435456, 8064: 268443656 }, { 0: 1048576, 16: 33555457, 32: 1024, 48: 1049601, 64: 34604033, 80: 0, 96: 1, 112: 34603009, 128: 33555456, 144: 1048577, 160: 33554433, 176: 34604032, 192: 34603008, 208: 1025, 224: 1049600, 240: 33554432, 8: 34603009, 24: 0, 40: 33555457, 56: 34604032, 72: 1048576, 88: 33554433, 104: 33554432, 120: 1025, 136: 1049601, 152: 33555456, 168: 34603008, 184: 1048577, 200: 1024, 216: 34604033, 232: 1, 248: 1049600, 256: 33554432, 272: 1048576, 288: 33555457, 304: 34603009, 320: 1048577, 336: 33555456, 352: 34604032, 368: 1049601, 384: 1025, 400: 34604033, 416: 1049600, 432: 1, 448: 0, 464: 34603008, 480: 33554433, 496: 1024, 264: 1049600, 280: 33555457, 296: 34603009, 312: 1, 328: 33554432, 344: 1048576, 360: 1025, 376: 34604032, 392: 33554433, 408: 34603008, 424: 0, 440: 34604033, 456: 1049601, 472: 1024, 488: 33555456, 504: 1048577 }, { 0: 134219808, 1: 131072, 2: 134217728, 3: 32, 4: 131104, 5: 134350880, 6: 134350848, 7: 2048, 8: 134348800, 9: 134219776, 10: 133120, 11: 134348832, 12: 2080, 13: 0, 14: 134217760, 15: 133152, 2147483648: 2048, 2147483649: 134350880, 2147483650: 134219808, 2147483651: 134217728, 2147483652: 134348800, 2147483653: 133120, 2147483654: 133152, 2147483655: 32, 2147483656: 134217760, 2147483657: 2080, 2147483658: 131104, 2147483659: 134350848, 2147483660: 0, 2147483661: 134348832, 2147483662: 134219776, 2147483663: 131072, 16: 133152, 17: 134350848, 18: 32, 19: 2048, 20: 134219776, 21: 134217760, 22: 134348832, 23: 131072, 24: 0, 25: 131104, 26: 134348800, 27: 134219808, 28: 134350880, 29: 133120, 30: 2080, 31: 134217728, 2147483664: 131072, 2147483665: 2048, 2147483666: 134348832, 2147483667: 133152, 2147483668: 32, 2147483669: 134348800, 2147483670: 134217728, 2147483671: 134219808, 2147483672: 134350880, 2147483673: 134217760, 2147483674: 134219776, 2147483675: 0, 2147483676: 133120, 2147483677: 2080, 2147483678: 131104, 2147483679: 134350848 }], u = [4160749569, 528482304, 33030144, 2064384, 129024, 8064, 504, 2147483679], d = a.DES = s.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = [], i = 0; i < 56; i++) { var n = c[i] - 1; e[i] = r[n >>> 5] >>> 31 - n % 32 & 1 } for (var o = this._subKeys = [], s = 0; s < 16; s++) { for (var a = o[s] = [], f = l[s], i = 0; i < 24; i++)a[i / 6 | 0] |= e[(h[i] - 1 + f) % 28] << 31 - i % 6, a[4 + (i / 6 | 0)] |= e[28 + (h[i + 24] - 1 + f) % 28] << 31 - i % 6; a[0] = a[0] << 1 | a[0] >>> 31; for (var i = 1; i < 7; i++)a[i] = a[i] >>> 4 * (i - 1) + 3; a[7] = a[7] << 5 | a[7] >>> 27 } for (var u = this._invSubKeys = [], i = 0; i < 16; i++)u[i] = o[15 - i] }, encryptBlock: function (t, r) { this._doCryptBlock(t, r, this._subKeys) }, decryptBlock: function (t, r) { this._doCryptBlock(t, r, this._invSubKeys) }, _doCryptBlock: function (t, i, n) { this._lBlock = t[i], this._rBlock = t[i + 1], r.call(this, 4, 252645135), r.call(this, 16, 65535), e.call(this, 2, 858993459), e.call(this, 8, 16711935), r.call(this, 1, 1431655765); for (var o = 0; o < 16; o++) { for (var s = n[o], a = this._lBlock, c = this._rBlock, h = 0, l = 0; l < 8; l++)h |= f[l][((c ^ s[l]) & u[l]) >>> 0]; this._lBlock = c, this._rBlock = a ^ h } var d = this._lBlock; this._lBlock = this._rBlock, this._rBlock = d, r.call(this, 1, 1431655765), e.call(this, 8, 16711935), e.call(this, 2, 858993459), r.call(this, 16, 65535), r.call(this, 4, 252645135), t[i] = this._lBlock, t[i + 1] = this._rBlock }, keySize: 2, ivSize: 2, blockSize: 2 }); i.DES = s._createHelper(d); var v = a.TripleDES = s.extend({ _doReset: function () { var t = this._key, r = t.words; this._des1 = d.createEncryptor(o.create(r.slice(0, 2))), this._des2 = d.createEncryptor(o.create(r.slice(2, 4))), this._des3 = d.createEncryptor(o.create(r.slice(4, 6))) }, encryptBlock: function (t, r) { this._des1.encryptBlock(t, r), this._des2.decryptBlock(t, r), this._des3.encryptBlock(t, r) }, decryptBlock: function (t, r) { this._des3.decryptBlock(t, r), this._des2.encryptBlock(t, r), this._des1.decryptBlock(t, r) }, keySize: 6, ivSize: 2, blockSize: 2 }); i.TripleDES = s._createHelper(v) - }(), function () { function r() { for (var t = this._S, r = this._i, e = this._j, i = 0, n = 0; n < 4; n++) { r = (r + 1) % 256, e = (e + t[r]) % 256; var o = t[r]; t[r] = t[e], t[e] = o, i |= t[(t[r] + t[e]) % 256] << 24 - 8 * n } return this._i = r, this._j = e, i } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = o.RC4 = n.extend({ _doReset: function () { for (var t = this._key, r = t.words, e = t.sigBytes, i = this._S = [], n = 0; n < 256; n++)i[n] = n; for (var n = 0, o = 0; n < 256; n++) { var s = n % e, a = r[s >>> 2] >>> 24 - s % 4 * 8 & 255; o = (o + i[n] + a) % 256; var c = i[n]; i[n] = i[o], i[o] = c } this._i = this._j = 0 }, _doProcessBlock: function (t, e) { t[e] ^= r.call(this) }, keySize: 8, ivSize: 0 }); e.RC4 = n._createHelper(s); var a = o.RC4Drop = s.extend({ cfg: s.cfg.extend({ drop: 192 }), _doReset: function () { s._doReset.call(this); for (var t = this.cfg.drop; t > 0; t--)r.call(this) } }); e.RC4Drop = n._createHelper(a) }(), t.mode.CTRGladman = function () { function r(t) { if (255 === (t >> 24 & 255)) { var r = t >> 16 & 255, e = t >> 8 & 255, i = 255 & t; 255 === r ? (r = 0, 255 === e ? (e = 0, 255 === i ? i = 0 : ++i) : ++e) : ++r, t = 0, t += r << 16, t += e << 8, t += i } else t += 1 << 24; return t } function e(t) { return 0 === (t[0] = r(t[0])) && (t[1] = r(t[1])), t } var i = t.lib.BlockCipherMode.extend(), n = i.Encryptor = i.extend({ processBlock: function (t, r) { var i = this._cipher, n = i.blockSize, o = this._iv, s = this._counter; o && (s = this._counter = o.slice(0), this._iv = void 0), e(s); var a = s.slice(0); i.encryptBlock(a, 0); for (var c = 0; c < n; c++)t[r + c] ^= a[c] } }); return i.Decryptor = n, i }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.Rabbit = n.extend({ _doReset: function () { for (var t = this._key.words, e = this.cfg.iv, i = 0; i < 4; i++)t[i] = 16711935 & (t[i] << 8 | t[i] >>> 24) | 4278255360 & (t[i] << 24 | t[i] >>> 8); var n = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], o = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var i = 0; i < 4; i++)r.call(this); for (var i = 0; i < 8; i++)o[i] ^= n[i + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; o[0] ^= h, o[1] ^= f, o[2] ^= l, o[3] ^= u, o[4] ^= h, o[5] ^= f, o[6] ^= l, o[7] ^= u; for (var i = 0; i < 4; i++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.Rabbit = n._createHelper(h) }(), t.mode.CTR = function () { var r = t.lib.BlockCipherMode.extend(), e = r.Encryptor = r.extend({ processBlock: function (t, r) { var e = this._cipher, i = e.blockSize, n = this._iv, o = this._counter; n && (o = this._counter = n.slice(0), this._iv = void 0); var s = o.slice(0); e.encryptBlock(s, 0), o[i - 1] = o[i - 1] + 1 | 0; for (var a = 0; a < i; a++)t[r + a] ^= s[a] } }); return r.Decryptor = e, r }(), function () { function r() { for (var t = this._X, r = this._C, e = 0; e < 8; e++)a[e] = r[e]; r[0] = r[0] + 1295307597 + this._b | 0, r[1] = r[1] + 3545052371 + (r[0] >>> 0 < a[0] >>> 0 ? 1 : 0) | 0, r[2] = r[2] + 886263092 + (r[1] >>> 0 < a[1] >>> 0 ? 1 : 0) | 0, r[3] = r[3] + 1295307597 + (r[2] >>> 0 < a[2] >>> 0 ? 1 : 0) | 0, r[4] = r[4] + 3545052371 + (r[3] >>> 0 < a[3] >>> 0 ? 1 : 0) | 0, r[5] = r[5] + 886263092 + (r[4] >>> 0 < a[4] >>> 0 ? 1 : 0) | 0, r[6] = r[6] + 1295307597 + (r[5] >>> 0 < a[5] >>> 0 ? 1 : 0) | 0, r[7] = r[7] + 3545052371 + (r[6] >>> 0 < a[6] >>> 0 ? 1 : 0) | 0, this._b = r[7] >>> 0 < a[7] >>> 0 ? 1 : 0; for (var e = 0; e < 8; e++) { var i = t[e] + r[e], n = 65535 & i, o = i >>> 16, s = ((n * n >>> 17) + n * o >>> 15) + o * o, h = ((4294901760 & i) * i | 0) + ((65535 & i) * i | 0); c[e] = s ^ h } t[0] = c[0] + (c[7] << 16 | c[7] >>> 16) + (c[6] << 16 | c[6] >>> 16) | 0, t[1] = c[1] + (c[0] << 8 | c[0] >>> 24) + c[7] | 0, t[2] = c[2] + (c[1] << 16 | c[1] >>> 16) + (c[0] << 16 | c[0] >>> 16) | 0, t[3] = c[3] + (c[2] << 8 | c[2] >>> 24) + c[1] | 0, t[4] = c[4] + (c[3] << 16 | c[3] >>> 16) + (c[2] << 16 | c[2] >>> 16) | 0, t[5] = c[5] + (c[4] << 8 | c[4] >>> 24) + c[3] | 0, t[6] = c[6] + (c[5] << 16 | c[5] >>> 16) + (c[4] << 16 | c[4] >>> 16) | 0, t[7] = c[7] + (c[6] << 8 | c[6] >>> 24) + c[5] | 0 } var e = t, i = e.lib, n = i.StreamCipher, o = e.algo, s = [], a = [], c = [], h = o.RabbitLegacy = n.extend({ _doReset: function () { var t = this._key.words, e = this.cfg.iv, i = this._X = [t[0], t[3] << 16 | t[2] >>> 16, t[1], t[0] << 16 | t[3] >>> 16, t[2], t[1] << 16 | t[0] >>> 16, t[3], t[2] << 16 | t[1] >>> 16], n = this._C = [t[2] << 16 | t[2] >>> 16, 4294901760 & t[0] | 65535 & t[1], t[3] << 16 | t[3] >>> 16, 4294901760 & t[1] | 65535 & t[2], t[0] << 16 | t[0] >>> 16, 4294901760 & t[2] | 65535 & t[3], t[1] << 16 | t[1] >>> 16, 4294901760 & t[3] | 65535 & t[0]]; this._b = 0; for (var o = 0; o < 4; o++)r.call(this); for (var o = 0; o < 8; o++)n[o] ^= i[o + 4 & 7]; if (e) { var s = e.words, a = s[0], c = s[1], h = 16711935 & (a << 8 | a >>> 24) | 4278255360 & (a << 24 | a >>> 8), l = 16711935 & (c << 8 | c >>> 24) | 4278255360 & (c << 24 | c >>> 8), f = h >>> 16 | 4294901760 & l, u = l << 16 | 65535 & h; n[0] ^= h, n[1] ^= f, n[2] ^= l, n[3] ^= u, n[4] ^= h, n[5] ^= f, n[6] ^= l, n[7] ^= u; for (var o = 0; o < 4; o++)r.call(this) } }, _doProcessBlock: function (t, e) { var i = this._X; r.call(this), s[0] = i[0] ^ i[5] >>> 16 ^ i[3] << 16, s[1] = i[2] ^ i[7] >>> 16 ^ i[5] << 16, s[2] = i[4] ^ i[1] >>> 16 ^ i[7] << 16, s[3] = i[6] ^ i[3] >>> 16 ^ i[1] << 16; for (var n = 0; n < 4; n++)s[n] = 16711935 & (s[n] << 8 | s[n] >>> 24) | 4278255360 & (s[n] << 24 | s[n] >>> 8), t[e + n] ^= s[n] }, blockSize: 4, ivSize: 2 }); e.RabbitLegacy = n._createHelper(h) }(), t.pad.ZeroPadding = { pad: function (t, r) { var e = 4 * r; t.clamp(), t.sigBytes += e - (t.sigBytes % e || e) }, unpad: function (t) { for (var r = t.words, e = t.sigBytes - 1; !(r[e >>> 2] >>> 24 - e % 4 * 8 & 255);)e--; t.sigBytes = e + 1 } }, t -}); - const $ = new Env('顺丰速运') $.KEY_login = 'chavy_login_sfexpress' @@ -29,23 +20,6 @@ function loginapp() { const loginOpts = $.getjson($.KEY_login) delete loginOpts.headers.Cookie - const timeInterval = new Date().getTime() - const bodyMD5 = $.CryptoJS.MD5(loginOpts.body) - - const sytToken = - loginOpts.headers.regionCode + - loginOpts.headers.languageCode + - bodyMD5 + - loginOpts.headers.clientVersion + - loginOpts.headers.deviceId + - loginOpts.headers.jsbundle + - timeInterval - - Object.assign(loginOpts.headers, { - timeInterval, - sytToken: $.CryptoJS.MD5(sytToken).toString() - }) - return $.http .post(loginOpts) .then((resp) => { From a2c3d236534375a6b0afc6a6b76dc6d7a2847305 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 1 Apr 2021 00:30:45 +0800 Subject: [PATCH 071/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E9=A1=BA=E4=B8=B0?= =?UTF-8?q?=E9=80=9F=E8=BF=90]:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/README.md | 2 +- sfexpress/sfexpress.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/sfexpress/README.md b/sfexpress/README.md index 8e07e1c9a..2fdbfc19b 100644 --- a/sfexpress/README.md +++ b/sfexpress/README.md @@ -8,7 +8,7 @@ hostname = ccsp-egmas.sf-express.com [Script] Rewrite: 顺丰速运 = type=http-request, pattern=^https:\/\/ccsp-egmas.sf-express.com\/cx-app-member\/member\/app\/user\/universalSign,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.cookie.js,requires-body=true -cron "*/10 * * * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js +cron "1 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js ``` ## 配置 (QuanX) diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 9d511b1f8..13bf5417d 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -2,8 +2,6 @@ const $ = new Env('顺丰速运') $.KEY_login = 'chavy_login_sfexpress' !(async () => { - $.CryptoJS = $.isNode() ? require('crypto-js') : CryptoJS - await loginapp() await $.wait('1000') await loginweb() From 531ae8717f97a37001a8a1c1c1de1a5e78ea2fb8 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 1 Apr 2021 20:12:21 +0800 Subject: [PATCH 072/311] feat(boxjs): add languages (zh-CN & en-US) --- box/chavy.boxjs.html | 627 ++++++++++++++++++++++++-------- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 16 + box/release/box.release.tf.json | 16 + chavy.box.js | 2 +- 5 files changed, 501 insertions(+), 162 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index d92c0df9e..bc5d7dd1d 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1,5 +1,5 @@ - + BoxJs @@ -238,11 +238,23 @@ + + + + + + @@ -250,27 +262,27 @@ @@ -280,13 +292,13 @@ @@ -296,13 +308,13 @@ @@ -312,13 +324,13 @@ @@ -328,13 +340,13 @@ @@ -344,13 +356,13 @@ @@ -376,13 +388,13 @@ --> @@ -391,13 +403,13 @@ @@ -406,13 +418,13 @@ @@ -423,13 +435,13 @@ @@ -441,10 +453,10 @@ @@ -471,13 +483,13 @@ @@ -487,13 +499,13 @@ @@ -552,7 +564,7 @@ - 收藏应用 ({{favApps.length}}) + {{ $t('apps.fav') }} ({{favApps.length}}) - 上移 + {{ $t('base.sort.up') }} - 下移 + {{ $t('base.sort.dn') }} - 取消收藏 + {{ $t('base.sort.unStar') }} @@ -618,7 +630,7 @@ - 内置应用 ({{sysApps.length}}) + {{ $t('apps.sysApps') }} ({{sysApps.length}}) - 仓库 + {{ $t('subs.repo') }} - 复制 + {{ $t('base.cmd.cp') }} - 上移 + {{ $t('base.sort.up') }} - 下移 + {{ $t('base.sort.dn') }} - 删除 + {{ $t('base.cmd.del') }} @@ -711,24 +725,26 @@ - 添加订阅 + {{ $t('subs.addDialog.title') }} - 取消 - 添加 + {{$t('base.dialog.close')}} + + {{$t('base.dialog.save')}} + @@ -737,35 +753,45 @@ - {{box.usercfgs.name ? box.usercfgs.name : '大侠, 留个名字吧!'}} + {{box.usercfgs.name ? box.usercfgs.name : $t('profile.leaveName')}} - 个人资料 + {{ $t('profile.editor.title') }} - - + + - 取消 - 保存 + {{ $t('base.dialog.close') }} + + {{ $t('base.dialog.save') }} + - 我的数据 + {{ $t('profile.datas') }} - 应用: {{this.apps.length}} - 订阅: {{this.appSubs.length}} - 会话: {{this.sessions.length}} + {{ $t('profile.apps') }}: {{this.apps.length}} + {{ $t('profile.subs') }}: {{this.appSubs.length}} + {{ $t('profile.sessions') }}: {{this.sessions.length}} @@ -773,30 +799,30 @@ - 导入备份 + {{ $t('profile.impDialog.title') }} - 取消 - 导入 + {{ $t('base.dialog.close') }} + {{ $t('profile.imp') }} - 备份 + {{ $t('profile.bak') }} @@ -821,7 +847,7 @@ -

脚本编辑器

+

{{ $t('codding.title') }}

mdi-play-circle @@ -853,7 +879,7 @@

{{curapp.name}}

+ {{ $t('subs.repo') }} @@ -749,6 +755,19 @@ + + + {{ ui.installConfirmDialog.title }} + {{ ui.installConfirmDialog.message }} + + + {{$t('base.dialog.close')}} + + {{$t('base.dialog.ok')}} + + + +
@@ -1374,7 +1393,8 @@

v{{ver.versio apply: 'Apply', save: 'Save', view: 'View', - close: 'Close' + close: 'Close', + ok: 'OK' }, sort: { up: 'Up', @@ -1430,6 +1450,7 @@

v{{ver.versio avatar: 'Avatar (Optional)', avatarDesc: 'Your avatar link' }, + install: 'Install', add: 'Add Subscription', subs: 'More Subscriptions', appSubs: 'App Subscriptions', @@ -1529,7 +1550,8 @@

v{{ver.versio dialog: { apply: '应用', save: '保存', - close: '关闭' + close: '关闭', + ok: '好' }, sort: { up: '上移', @@ -1581,6 +1603,7 @@

v{{ver.versio title: '修改会话', name: '会话名称' }, + install: '安装', add: '添加订阅', moreSubs: '更多订阅', appSubs: '应用订阅', @@ -1721,6 +1744,7 @@

v{{ver.versio impGlobalBakDialog: { show: false, impval: '' }, impAppDatasDialog: { show: false, impval: '' }, addAppSubDialog: { show: false, url: '' }, + installConfirmDialog: { show: false, title: '安装确认', message: '是否自动安装外部资源?' }, defaultIcons: [ 'https://raw.githubusercontent.com/Orz-3/mini/master/appstore.png', 'https://raw.githubusercontent.com/Orz-3/task/master/appstore.png' @@ -2079,6 +2103,7 @@

v{{ver.versio // 深拷贝一份数据, 避免污染`usercfgs` const subs = JSON.parse(JSON.stringify(this.box.usercfgs.appsubs)) subs.forEach((sub) => { + const raw = JSON.parse(JSON.stringify(sub)) const cacheSub = this.appSubCaches[sub.url] const isValidSub = cacheSub && Array.isArray(cacheSub.apps) && cacheSub.apps.length > 0 const isValidSubApps = isValidSub && !cacheSub.apps.find((app) => !app.id) @@ -2091,6 +2116,7 @@

v{{ver.versio sub.name = sub.name ? sub.name : '匿名订阅' sub.author = sub.author ? sub.author : '@anonymous' sub.repo = sub.repo ? sub.repo : sub.url + sub.raw = raw }) return subs }, @@ -2294,7 +2320,7 @@

v{{ver.versio this.path = defview } // 监听浏览器后退事件 - window.addEventListener('popstate', (e) => (this.path = e.state.url), false) + window.addEventListener('popstate', (e) => (this.path = e.state ? e.state.url : '/'), false) // 如果后端没有渲染数据, 则发出请求获取数据 if (this.boxServerData) { this.box = this.boxServerData @@ -2307,7 +2333,7 @@

v{{ver.versio } // 延时执行, 避免多个请求抢占资源 - setTimeout(this.getVersions, 3000) + this.getVersions() this.loadTheme() }, mounted() { @@ -2355,6 +2381,23 @@

v{{ver.versio this.ui.versionSheet.show = false this.ui.reloadDialog.show = true }, + openInstall(subId) { + const newsub = this.appSubs.find((s) => s.raw.id === subId) + const event = newsub.onInstall + if (event) { + const install = event.install + const redirect = install[this.env.id] + if (!redirect) return + this.ui.installConfirmDialog.show = true + this.ui.installConfirmDialog.title = event.title + this.ui.installConfirmDialog.message = event.message + this.ui.installConfirmDialog.url = redirect + } + }, + install(url) { + this.open(url) + this.ui.installConfirmDialog.show = false + }, // 记录每个页面的滚动值 onScroll(event) { const currentY = event.currentTarget.scrollY @@ -2741,6 +2784,8 @@

v{{ver.versio this.ui.snackbar.msg = '一键订阅: 成功!' this.ui.snackbar.color = 'success' } + + this.openInstall(sub.id) }) .finally(() => (this.addAppSubDialog = false)) }, diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 7b6e35da5..ae26482e3 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.11.3' +$.version = '0.12.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/chavy.boxjs.test.json b/box/chavy.boxjs.test.json index d082f5483..c8b33236b 100644 --- a/box/chavy.boxjs.test.json +++ b/box/chavy.boxjs.test.json @@ -4,6 +4,14 @@ "author": "@chavyleung", "icon": "https://avatars3.githubusercontent.com/u/29748519?s=460&u=392a19e85465abbcb1791c9b8b32184a16e6795e&v=4", "repo": "https://github.com/chavyleung/scripts", + "onInstall": { + "title": "安装确认", + "message": "本订阅包含重写资源, 是否需要自动安装?", + "install": { + "QuanX": "quantumult-x:///add-resource?remote-resource=%7B%22rewrite_remote%22%3A%5B%22https%3A%2F%2Fgithub.com%2Fchavyleung%2Fscripts%2Fraw%2Fmaster%2Fbox%2Frewrite%2Fboxjs.rewrite.quanx.conf%2Ctag%3Dboxjs%22%5D%7D", + "Loon": "loon://import?plugin=https://raw.githubusercontent.com/chavyleung/scripts/master/box/rewrite/boxjs.rewrite.loon.plugin" + } + }, "apps": [ { "id": "chavy_test_sub", diff --git a/box/release/box.release.json b/box/release/box.release.json index ba7cf1753..6b4fdf151 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,27 @@ { "releases": [ + { + "version": "0.12.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 添加订阅事件 onInstall", + "notes": [ + { + "name": "新增 (本次更新主要面向开发者)", + "descs": [ + "添加订阅时, 可自动触发资源安装, 如: 自动安装重写等)", + "订阅列表中, 可通过`更多 > 安装`来手动触发安装", + "", + "开发文档:", + "https://docs.boxjs.app/dev/configure#scenes-oninstall", + "", + "目前支持 (TestFlight):", + "1. Loon: v2.1.19 (386) 及以上", + "2. Quantumult X: v1.0.29 (670) 及以上" + ] + } + ] + }, { "version": "0.11.3", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index b3393e058..fba719683 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,27 @@ { "releases": [ + { + "version": "0.12.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 订阅添加事件 onInstall", + "notes": [ + { + "name": "新增", + "descs": [ + "添加订阅时, 可自动触发重写安装 (需要 App 支持)", + "订阅列表中, 可通过`更多 > 安装`来手动触发安装", + "", + "开发文档:", + "https://docs.boxjs.app/dev/configure#scenes-oninstall", + "", + "目前支持 (TestFlight):", + "1. Loon: v2.1.19 (386) 及以上", + "2. Quantumult X: v1.0.29 (670) 及以上" + ] + } + ] + }, { "version": "0.11.3", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 7b6e35da5..ae26482e3 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.11.3' +$.version = '0.12.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From c1da61887f5b6d48d5fab4c52073a95c91fa2690 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 20 May 2022 17:22:56 +0800 Subject: [PATCH 132/311] =?UTF-8?q?fix(boxjs):=20=E8=BF=98=E5=8E=9F=20gist?= =?UTF-8?q?=20=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E7=9A=84=E7=99=BD?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 6 +++--- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ box/scripts/boxjs.revert.usercfgs.sessions.js | 4 ++-- chavy.box.js | 6 +++--- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index ae26482e3..a5f5acc63 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.0' +$.version = '0.12.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -505,14 +505,14 @@ function getUserApps() { * 获取应用会话 */ function getAppSessions() { - return $.getjson($.KEY_sessions, []) + return $.getjson($.KEY_sessions, []) || [] } /** * 获取当前切换到哪个会话 */ function getCurSessions() { - return $.getjson($.KEY_cursessions, {}) + return $.getjson($.KEY_cursessions, {}) || {} } /** diff --git a/box/release/box.release.json b/box/release/box.release.json index 6b4fdf151..45355b39c 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 还原 gist 可能导致的白屏", + "notes": [ + { + "name": "修复", + "descs": ["还原 gist 可能导致的白屏"] + } + ] + }, { "version": "0.12.0", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index fba719683..5eb67854e 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 还原 gist 可能导致的白屏", + "notes": [ + { + "name": "修复", + "descs": ["还原 gist 可能导致的白屏"] + } + ] + }, { "version": "0.12.0", "tags": ["beta"], diff --git a/box/scripts/boxjs.revert.usercfgs.sessions.js b/box/scripts/boxjs.revert.usercfgs.sessions.js index 2079a5bbb..d5ee0852b 100644 --- a/box/scripts/boxjs.revert.usercfgs.sessions.js +++ b/box/scripts/boxjs.revert.usercfgs.sessions.js @@ -3,8 +3,8 @@ const $ = new Env('BoxJs - 抹掉会话') $.KEY_sessions = 'chavy_boxjs_sessions' $.KEY_cursessions = 'chavy_boxjs_cur_sessions' -$.setjson([], $.KEY_sessions) -$.setjson({}, $.chavy_boxjs_cur_sessions) +$.setdata('[]', $.KEY_sessions) +$.setdata('{}', $.chavy_boxjs_cur_sessions) $.done() /** diff --git a/chavy.box.js b/chavy.box.js index ae26482e3..a5f5acc63 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.0' +$.version = '0.12.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -505,14 +505,14 @@ function getUserApps() { * 获取应用会话 */ function getAppSessions() { - return $.getjson($.KEY_sessions, []) + return $.getjson($.KEY_sessions, []) || [] } /** * 获取当前切换到哪个会话 */ function getCurSessions() { - return $.getjson($.KEY_cursessions, {}) + return $.getjson($.KEY_cursessions, {}) || {} } /** From bfe1e74aaf83c985a24911901c9948bad42813e1 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 25 May 2022 14:39:57 +0800 Subject: [PATCH 133/311] =?UTF-8?q?feat(env.js):=20node=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=20$.done()=20=E4=BC=9A=E4=BD=BF=E7=94=A8=20p?= =?UTF-8?q?rocess.exit(1)=20=E9=80=80=E5=87=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 2 ++ Env.min.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index f4678ccd6..1db169529 100644 --- a/Env.js +++ b/Env.js @@ -487,6 +487,8 @@ function Env(name, opts) { this.log() if (this.isSurge() || this.isQuanX() || this.isLoon()) { $done(val) + } else if (this.isNode()) { + process.exit(1) } } })(name, opts) diff --git a/Env.min.js b/Env.min.js index f29a5c862..52741fc43 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:i,statusCode:r,headers:o,rawBody:h},s.decode(h,this.encoding))},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:s,statusCode:r,headers:o,rawBody:h},i.decode(h,this.encoding))},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:i,statusCode:r,headers:o,rawBody:h},s.decode(h,this.encoding))},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:s,statusCode:r,headers:o,rawBody:h},i.decode(h,this.encoding))},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 7a86b697bc336c622ddb021d5eb6bfd3a7ec2b9f Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 25 May 2022 16:12:59 +0800 Subject: [PATCH 134/311] =?UTF-8?q?fix(env.js):=20=E4=BF=AE=E5=A4=8D=20$.h?= =?UTF-8?q?ttp=20=E5=9C=A8=20node=20=E7=8E=AF=E5=A2=83=E4=B8=8B=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=BF=94=E5=9B=9E=20resp.body=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 6 ++++-- Env.min.js | 2 +- package.json | 4 +--- yarn.lock | 12 ++++++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Env.js b/Env.js index 1db169529..1eadc9510 100644 --- a/Env.js +++ b/Env.js @@ -315,7 +315,8 @@ function Env(name, opts) { .then( (resp) => { const { statusCode: status, statusCode, headers, rawBody } = resp - callback(null, { status, statusCode, headers, rawBody }, iconv.decode(rawBody, this.encoding)) + const body = iconv.decode(rawBody, this.encoding) + callback(null, { status, statusCode, headers, rawBody, body }, body) }, (err) => { const { message: error, response: resp } = err @@ -364,7 +365,8 @@ function Env(name, opts) { this.got[method](url, _opts).then( (resp) => { const { statusCode: status, statusCode, headers, rawBody } = resp - callback(null, { status, statusCode, headers, rawBody }, iconv.decode(rawBody, this.encoding)) + const body = iconv.decode(rawBody, this.encoding) + callback(null, { status, statusCode, headers, rawBody, body }, body) }, (err) => { const { message: error, response: resp } = err diff --git a/Env.min.js b/Env.min.js index 52741fc43..a356bcd06 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:i,statusCode:r,headers:o,rawBody:h},s.decode(h,this.encoding))},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:s,statusCode:r,headers:o,rawBody:h},i.decode(h,this.encoding))},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,n=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:n},n)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,n=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file diff --git a/package.json b/package.json index f9fed906c..03e8453d3 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,11 @@ "scripts": { "dev": "http-server ." }, - "repository": "https://github.com/chavyleung/scripts.git", - "author": "Chavy ", - "license": "MIT", "dependencies": { "crypto-js": "^4.0.0", "got": "^11.5.1", "http-server": "^0.12.3", + "iconv-lite": "0.6.3", "tough-cookie": "^4.0.0" } } diff --git a/yarn.lock b/yarn.lock index 00d90a8a7..a2f8762bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -213,6 +213,13 @@ http2-wrapper@^1.0.0-beta.5.2: quick-lru "^5.1.1" resolve-alpn "^1.0.0" +iconv-lite@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" + integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== + dependencies: + safer-buffer ">= 2.1.2 < 3.0.0" + json-buffer@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" @@ -343,6 +350,11 @@ responselike@^2.0.0: dependencies: lowercase-keys "^2.0.0" +"safer-buffer@>= 2.1.2 < 3.0.0": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + secure-compare@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/secure-compare/-/secure-compare-3.0.1.tgz#f1a0329b308b221fae37b9974f3d578d0ca999e3" From cd276b00b6f5d5c45ebf79cc5193475d50dc44b8 Mon Sep 17 00:00:00 2001 From: Chavy Date: Sat, 4 Jun 2022 16:30:42 +0800 Subject: [PATCH 135/311] =?UTF-8?q?fix(env.js):=20=E4=BF=AE=E5=A4=8D=20sta?= =?UTF-8?q?tus=20&=20statusCode=20=E5=9C=A8=E5=90=84=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 6 ++++-- Env.min.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Env.js b/Env.js index 1eadc9510..2316b6b9a 100644 --- a/Env.js +++ b/Env.js @@ -278,7 +278,8 @@ function Env(name, opts) { $httpClient.get(opts, (err, resp, body) => { if (!err && resp) { resp.body = body - resp.statusCode = resp.status + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode } callback(err, resp, body) }) @@ -341,7 +342,8 @@ function Env(name, opts) { $httpClient[method](opts, (err, resp, body) => { if (!err && resp) { resp.body = body - resp.statusCode = resp.status + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode } callback(err, resp, body) }) diff --git a/Env.min.js b/Env.min.js index a356bcd06..9822ecea3 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,n=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:n},n)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,n=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),h={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"}};this.post(h,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,h=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:h},h)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,h=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:h},h)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",o){const r=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,r(o)):this.isQuanX()&&$notify(e,s,i,r(o))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From bb965a9f71aca7f41b982cf0e761edb7ebdda5be Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 7 Jun 2022 11:22:57 +0800 Subject: [PATCH 136/311] =?UTF-8?q?fix(env.js):=20=E4=BF=AE=E5=A4=8D=20qx?= =?UTF-8?q?=20=E7=8E=AF=E5=A2=83=E4=B8=8B=E6=8A=A5=E9=94=99=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9A=84=20error=20=E5=AF=B9=E8=B1=A1=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=B8=8E=E5=85=B6=E4=BB=96=20app=20=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 4 ++-- Env.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Env.js b/Env.js index 2316b6b9a..03608a89e 100644 --- a/Env.js +++ b/Env.js @@ -293,7 +293,7 @@ function Env(name, opts) { const { statusCode: status, statusCode, headers, body } = resp callback(null, { status, statusCode, headers, body }, body) }, - (err) => callback(err) + (err) => callback((err && err.error) || 'UndefinedError') ) } else if (this.isNode()) { let iconv = require('iconv-lite') @@ -358,7 +358,7 @@ function Env(name, opts) { const { statusCode: status, statusCode, headers, body } = resp callback(null, { status, statusCode, headers, body }, body) }, - (err) => callback(err) + (err) => callback((err && err.error) || 'UndefinedError') ) } else if (this.isNode()) { let iconv = require('iconv-lite') diff --git a/Env.min.js b/Env.min.js index 9822ecea3..929957fbb 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),h={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"}};this.post(h,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,h=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:h},h)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,h=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:h},h)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",o){const r=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,r(o)):this.isQuanX()&&$notify(e,s,i,r(o))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),a=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:a,body:n},n)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 786ecd827879d3c359b6263b48ea40f325c03a22 Mon Sep 17 00:00:00 2001 From: Yi Jiu Date: Wed, 15 Jun 2022 23:13:50 +0800 Subject: [PATCH 137/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E3=80=90=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E8=A7=86=E9=A2=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- videoqq/videoqq.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/videoqq/videoqq.js b/videoqq/videoqq.js index 13dbc2646..d32efd6f9 100644 --- a/videoqq/videoqq.js +++ b/videoqq/videoqq.js @@ -42,9 +42,9 @@ function login() { function signapp() { return new Promise((resolve, reject) => { const timestamp = Math.round(new Date().getTime() / 1000).toString() - const VAL_signurl = `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2&_=${timestamp}` + const VAL_signurl = `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_checkin&cmd=2&_=${timestamp}` let url = { url: VAL_signurl, headers: {} } - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' + url.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1' chavy.get(url, (error, response, data) => { try { signinfo.signapp = JSON.parse(data.match(/\((.*)\);/)[1]) @@ -62,9 +62,9 @@ function signapp() { function getexp() { return new Promise((resolve, reject) => { const timestamp = Math.round(new Date().getTime() / 1000).toString() - const VAL_getexpurl = `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=spp_PropertyNum&cmd=1&growth_value=1&otype=json&_=${timestamp}` + const VAL_getexpurl = `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=spp_vscore_user_mashup&type=1&_=${timestamp}` let url = { url: VAL_getexpurl, headers: {} } - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' + url.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1' chavy.get(url, (error, response, data) => { try { signinfo.expinfo = JSON.parse(data.match(/\((.*)\);/)[1]) @@ -85,8 +85,9 @@ function showmsg() { if (signinfo.signapp.ret == 0) { subTitle = '签到结果: 成功' if (signinfo.expinfo) { - subTitle += !signinfo.signapp.checkin_score ? ' (重复签到)' : '' - detail = `V力值: ${signinfo.expinfo.GrowthValue.num} (+${signinfo.signapp.checkin_score}), 观影券: ${signinfo.expinfo.MovieTicket.num}, 赠片资格: ${signinfo.expinfo.GiveMovie.num}` + subTitle += ! +Number(signinfo.signapp.checkin_score) ? ' (重复签到)' : '' + detail = `V力值: ${signinfo.expinfo.lscore_info.score} (+${signinfo.signapp.checkin_score}), 积分: ${signinfo.expinfo.cscore_info.vip_score_total}` } } else if (signinfo.signapp.ret == -10006) { subTitle = '签到结果: 失败' @@ -99,6 +100,8 @@ function showmsg() { detail = `编码: ${signinfo.signapp.ret}, 说明: ${signinfo.signapp.msg}` } chavy.msg(cookieName, subTitle, detail) + chavy.log(subTitle) + chavy.log(detail) } } From fa84271d7cbdc430fd049cd9c51baf004a4c91ac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jun 2022 20:46:14 +0000 Subject: [PATCH 138/311] chore(deps): bump got from 11.8.1 to 11.8.5 Bumps [got](https://github.com/sindresorhus/got) from 11.8.1 to 11.8.5. - [Release notes](https://github.com/sindresorhus/got/releases) - [Commits](https://github.com/sindresorhus/got/compare/v11.8.1...v11.8.5) --- updated-dependencies: - dependency-name: got dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 03e8453d3..b32cfe07f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ }, "dependencies": { "crypto-js": "^4.0.0", - "got": "^11.5.1", + "got": "^11.8.5", "http-server": "^0.12.3", "iconv-lite": "0.6.3", "tough-cookie": "^4.0.0" diff --git a/yarn.lock b/yarn.lock index a2f8762bb..fa368e3ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -65,17 +65,17 @@ cacheable-lookup@^5.0.3: resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz#5a6b865b2c44357be3d5ebc2a467b032719a7005" integrity sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA== -cacheable-request@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.1.tgz#062031c2856232782ed694a257fa35da93942a58" - integrity sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw== +cacheable-request@^7.0.2: + version "7.0.2" + resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.2.tgz#ea0d0b889364a25854757301ca12b2da77f91d27" + integrity sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew== dependencies: clone-response "^1.0.2" get-stream "^5.1.0" http-cache-semantics "^4.0.0" keyv "^4.0.0" lowercase-keys "^2.0.0" - normalize-url "^4.1.0" + normalize-url "^6.0.1" responselike "^2.0.0" clone-response@^1.0.2: @@ -153,17 +153,17 @@ get-stream@^5.1.0: dependencies: pump "^3.0.0" -got@^11.5.1: - version "11.8.1" - resolved "https://registry.yarnpkg.com/got/-/got-11.8.1.tgz#df04adfaf2e782babb3daabc79139feec2f7e85d" - integrity sha512-9aYdZL+6nHmvJwHALLwKSUZ0hMwGaJGYv3hoPLPgnT8BoBXm1SjnZeky+91tfwJaDzun2s4RsBRy48IEYv2q2Q== +got@^11.8.5: + version "11.8.5" + resolved "https://registry.yarnpkg.com/got/-/got-11.8.5.tgz#ce77d045136de56e8f024bebb82ea349bc730046" + integrity sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ== dependencies: "@sindresorhus/is" "^4.0.0" "@szmarczak/http-timer" "^4.0.5" "@types/cacheable-request" "^6.0.1" "@types/responselike" "^1.0.0" cacheable-lookup "^5.0.3" - cacheable-request "^7.0.1" + cacheable-request "^7.0.2" decompress-response "^6.0.0" http2-wrapper "^1.0.0-beta.5.2" lowercase-keys "^2.0.0" @@ -274,10 +274,10 @@ ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -normalize-url@^4.1.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129" - integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ== +normalize-url@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a" + integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== once@^1.3.1, once@^1.4.0: version "1.4.0" From da279330066f4ad3771f3a71b008a104da4820f9 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 6 Jul 2022 23:50:31 +0800 Subject: [PATCH 139/311] feat: add queryStr api --- Env.js | 22 ++++++++++++++++++++++ Env.min.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 03608a89e..834156e66 100644 --- a/Env.js +++ b/Env.js @@ -405,6 +405,28 @@ function Env(name, opts) { return fmt } + /** + * + * @param {Object} options + * @returns {String} 将 Object 对象 转换成 queryStr: key=val&name=senku + */ + queryStr(options) { + let queryString = '' + + for (const key in options) { + let value = options[key] + if (value != null && value !== '') { + if (typeof value === 'object') { + value = JSON.stringify(value) + } + queryString += `${key}=${value}&` + } + } + queryString = queryString.substring(0, queryString.length - 1) + + return queryString + } + /** * 系统通知 * diff --git a/Env.min.js b/Env.min.js index 929957fbb..d71e8b985 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),a=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:a,body:n},n)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From cb2ab8201f9042263f719a134063866c688ec474 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Thu, 7 Jul 2022 15:46:00 +0800 Subject: [PATCH 140/311] feat: update bili live --- .gitignore | 2 + bilibili/README.md | 4 +- bilibili/bilibili.js | 291 ++++++++++++++++++++++++++++++------------- surge.tasks.sgmodule | 2 +- 4 files changed, 208 insertions(+), 91 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..0a3676b83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/* +.DS_Store \ No newline at end of file diff --git a/bilibili/README.md b/bilibili/README.md index 5bb24aeee..5a2644709 100644 --- a/bilibili/README.md +++ b/bilibili/README.md @@ -16,7 +16,9 @@ [Script] http-request ^https:\/\/(www|live)\.bilibili\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js -cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js + +bilibili = type=cron,cronexp=10 0 0 * * *,wake-system=1,timeout=60,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js + # 如需银瓜子转硬币,添加以下内容 cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js ``` diff --git a/bilibili/bilibili.js b/bilibili/bilibili.js index 349ca9d13..0a3b1cebe 100644 --- a/bilibili/bilibili.js +++ b/bilibili/bilibili.js @@ -1,108 +1,221 @@ -const cookieName = 'bilibili' -const cookieKey = 'chavy_cookie_bilibili' -const chavy = init() -const cookieVal = chavy.getdata(cookieKey) +const $ = new Env('B站直播') +$.bilibiliLive = 'chavy_cookie_bilibili' +const cookie = $.getdata($.bilibiliLive) +const csrf = cookie.match(/.*?bili_jct=(.*?);/)?.[1] -sign() +$.desc = [] -function sign() { - let url = { - url: `https://api.live.bilibili.com/sign/doSign`, - headers: { - Cookie: cookieVal +!(async () => { + await sign() + if ($.sign?.code == 1011040) { + await getSignInfo() + } + await getMedalList() + for (let i = 0; i < $.medalList.length; i++) { + const roomId = $.medalList[i].roomId + $.desc.push(`执行粉丝牌任务(${i+1}/${$.medalList.length}): ${$.medalList[i].nickname}`) + for (let index = 0; index < 5; index++) { + await like(roomId) + await $.wait(1600) + await share(roomId) + await $.wait(1600) } + await $.wait(1600) + await sendMsg(roomId) } - url.headers['Origin'] = 'api.live.bilibili.com' - url.headers['Referer'] = 'http://live.bilibili.com/' - url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01' - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' + await notify() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function notify() { + return new Promise((resolve) => { + $.subt = `签到:${$.sign.message}` + $.msg($.name, $.subt, $.desc.join('\n')) + resolve() + }) +} - chavy.get(url, (error, response, data) => { - let result = JSON.parse(data) - let title = `${cookieName}` - // 签到成功 - if (result && result.code == 0) { - let subTitle = `签到结果: 成功` - let detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}` - chavy.msg(title, subTitle, detail) +function sign() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + } } - // 签到重复 - else if (result && result.code == 1011040) { - getsigninfo() + $.get(url, (err, resp, data) => { + try { + $.sign = JSON.parse(data) + const result = JSON.parse(data) + if (result && result.code == 0) { + $.desc.push(`本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function getSignInfo() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/sign/GetSignInfo', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15', + 'cookie': cookie + } } - // 签到失败 - else { - let subTitle = `签到结果: 失败` - let detail = `说明: ${result.message}` - chavy.msg(title, subTitle, detail) + $.get(url, (err, resp, data) => { + try { + const result = JSON.parse(data) + if (result && result.code == 0) { + $.desc.push(`本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function getMedalList() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/app-ucenter/v1/fansMedal/panel?page_size=50&page=1', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + } } - chavy.log(`${cookieName}, data: ${data}`) - chavy.done() + $.get(url, (err, resp, data) => { + try { + const res = JSON.parse(data) + $.medalList = res.data.special_list.map((e) => { + return { + roomId: e?.room_info?.room_id, + nickname: e?.medal?.medal_name, + } + }) + console.log('getMedalList', $.medalList) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) }) } -function getsigninfo() { - let url = { - url: `https://api.live.bilibili.com/sign/GetSignInfo`, - headers: { - Cookie: cookieVal + +function sendMsg(roomId) { + return new Promise((resolve) => { + const body = { + bubble: 0, + msg: '打卡', + color: 16777215, + mode: 2, + fontsize: 25, + rnd: Math.round(new Date().getTime() / 1000).toString(), + roomid: roomId, + csrf: csrf, + csrf_token: csrf + } + const url = { + url: 'https://api.live.bilibili.com/msg/send', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data' + }, + body: $.queryStr(body) } - } - url.headers['Host'] = 'api.live.bilibili.com' - url.headers['Origin'] = 'http://live.bilibili.com' - url.headers['Referer'] = 'http://live.bilibili.com/' - url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01' - url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15' - chavy.get(url, (error, response, data) => { - let title = `${cookieName}` - let subTitle = `签到结果: 成功 (重复签到)` - let detail = `` - let result = JSON.parse(data) - if (result && result.code == 0) detail = `本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}` - chavy.msg(title, subTitle, detail) - chavy.done() + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) }) } -function init() { - isSurge = () => { - return undefined === this.$httpClient ? false : true - } - isQuanX = () => { - return undefined === this.$task ? false : true - } - getdata = (key) => { - if (isSurge()) return $persistentStore.read(key) - if (isQuanX()) return $prefs.valueForKey(key) - } - setdata = (key, val) => { - if (isSurge()) return $persistentStore.write(key, val) - if (isQuanX()) return $prefs.setValueForKey(key, val) - } - msg = (title, subtitle, body) => { - if (isSurge()) $notification.post(title, subtitle, body) - if (isQuanX()) $notify(title, subtitle, body) - } - log = (message) => console.log(message) - get = (url, cb) => { - if (isSurge()) { - $httpClient.get(url, cb) + +function like(roomId) { + return new Promise((resolve) => { + const body = { + roomid: roomId, + csrf: csrf } - if (isQuanX()) { - url.method = 'GET' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + const url = { + url: 'https://api.live.bilibili.com/xlive/web-ucenter/v1/interact/likeInteract', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + }, + body: $.queryStr(body) } - } - post = (url, cb) => { - if (isSurge()) { - $httpClient.post(url, cb) + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function share(roomId) { + return new Promise((resolve) => { + const body = { + roomid: roomId, + csrf: csrf, + interact_type: 3 } - if (isQuanX()) { - url.method = 'POST' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + const url = { + url: 'https://api.live.bilibili.com/xlive/app-room/v1/index/TrigerInteract', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data', + 'sec-fetch-site': 'same-site', + 'origin': 'https://www.bilibili.com' + }, + body: $.queryStr(body) } - } - done = (value = {}) => { - $done(value) - } - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } + + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) } + +// pre-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file diff --git a/surge.tasks.sgmodule b/surge.tasks.sgmodule index a3ab9109f..669296b1b 100644 --- a/surge.tasks.sgmodule +++ b/surge.tasks.sgmodule @@ -9,7 +9,7 @@ Tasks: 腾讯视频 = type=cron,cronexp=3 0 * * *,script-path=https://raw.github Tasks: 10010 = type=cron,cronexp=0 9 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.js,wake-system=true Tasks: AcFun = type=cron,cronexp=3 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.js,wake-system=true Tasks: ApkTw = type=cron,cronexp=0 8 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.js,wake-system=true -Tasks: BiliBili = type=cron,cronexp=2 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js,wake-system=true +Tasks: BiliBili = type=cron,cronexp=2 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js,wake-system=true, timeout = 60 Tasks: V2EX = type=cron,cronexp=2 9 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/v2ex/v2ex.js,wake-system=true Tasks: WPS = type=cron,cronexp=0 9 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.js,wake-system=true Tasks: 叮咚买菜 = type=cron,cronexp=7 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.js,wake-system=true From 703aa07136dca197edb4d7290253e29fb2acb30f Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Thu, 7 Jul 2022 15:47:00 +0800 Subject: [PATCH 141/311] chore: update readme --- bilibili/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/bilibili/README.md b/bilibili/README.md index 5a2644709..d84525956 100644 --- a/bilibili/README.md +++ b/bilibili/README.md @@ -8,6 +8,7 @@ > 2020.3.16 添加银瓜子转硬币脚本 感谢[@lcandy2](https://github.com/lcandy2) PR +> 2022.7.7 添加粉丝牌升级任务 ## 配置 (Surge) ```properties From 4e663a1f01b61868d329981e8eec24251431f4c7 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Thu, 7 Jul 2022 17:05:35 +0800 Subject: [PATCH 142/311] Update zsfc.js --- zsfc/zsfc.js | 293 +++++++++++++++++++++++++++++---------------------- 1 file changed, 165 insertions(+), 128 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 80a6774aa..dd9b3df8e 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,146 +1,183 @@ -/* -Regex: ^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month -Host: mwegame.qq.com -*/ -var appName = '掌上飞车' -var speed = init() -var URL = speed.getdata("UrlFC") -var KEY = speed.getdata("CookieFC") +const $ = new Env(`🏎️ 掌上飞车`) +const date = new Date() +const illustrate = `掌上飞车APP => 发现 => 每日签到 => 点击签到` +typeof $request !== `undefined` ? start() : main() + +function start () { + if ($request.url && $request.headers) { + try {userId = $request.url.match(/userId=([^&]+)/)[1]} catch {userId = ``} + try {areaId = $request.url.match(/areaId=([^&]+)/)[1]} catch {areaId = ``} + try {roleId = $request.url.match(/roleId=([^&]+)/)[1]} catch {roleId = ``} + try {token = $request.url.match(/token=([^&]+)/)[1]} catch {token = ``} + try {uin = $request.url.match(/uin=([^&]+)/)[1]} catch {uin = ``} + $.write($request.url.replace(/&gift_id=\d+/, ""), `zsfc_url`) + $.write($.toStr($request.headers), `zsfc_headers`) + $.write(`userId=${userId}&areaId=${areaId}&roleId=${roleId}&token=${token}&uin=${uin}`, `zsfc_query`) + $.notice($.name, `✅ 获取签到数据成功!`, `请不要再次打开掌上飞车APP, 否则 Cookie 将失效!`) + } else { + $.notice($.name, ``, `⭕ 无法读取请求头, 请检查配置`) + } + $.done() +} -let isGetCookie = typeof $request !== 'undefined' +async function main () { + if (!$.read(`zsfc_url`)) { + $.log(`❌ 当前 Cookie 为空, 请先获取`) + $.notice($.name, `❌ 当前 Cookie 为空, 请先获取`, illustrate) + } else if ($.read(`zsfc_query`).indexOf(`&token=&`) != -1) { + $.log(`❌ 当前 Cookie 错误, 请重新获取`) + $.notice($.name, `❌ 当前 Cookie 错误, 请重新获取`, illustrate) + } else { + await sign(await index()) + if ($.expired != 0) { + await speed() + if ($.giftid) await handle($.giftid, `第 ${$.day_award } 天奖励`) + if ($.giftdays) await handle($.giftdays, ` ${$.day_welfare} 特别福利`) + } else { + $.notice($.name, `❌ 当前Cookie 已失效, 请重新获取`, illustrate) + } + } + $.done() +} -if (isGetCookie) { - getcookie() -} else { - sign() +function index() { + return new Promise(resolve => { + const options = { + url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + headers: $.toObj($.read(`zsfc_headers`)) + } + $.get(options, (error, response, data) => { + if (data) { + successive = data.match(/giftid="([^"]+)"/g)[0].match(/(\d+)/)[1] + } else if (error) { + $.log(`❌ 获取签到页面信息时发生错误`) + $.log($.toStr(error)) + } + resolve(successive) + }) + } + ) } -function getcookie() { - var url = $request.url; - if (url) { - var UrlKeyFC = "UrlFC"; - var UrlValueFC = url; - if (speed.getdata(UrlKeyFC) != (undefined || null)) { - if (speed.getdata(UrlKeyFC) != UrlValueFC) { - var url = speed.setdata(UrlValueFC, UrlKeyFC); - if (!url) { - speed.msg("更新" + appName + "Url失败‼️", "", ""); - } else { - speed.msg("更新" + appName + "Url成功🎉", "", ""); - } - } else { - speed.msg(appName + "Url未变化❗️", "", ""); - } - } else { - var url = speed.setdata(UrlValueFC, UrlKeyFC); - if (!url) { - speed.msg("首次写入" + appName + "Url失败‼️", "", ""); - } else { - speed.msg("首次写入" + appName + "Url成功🎉", "", ""); - } - } - } else { - speed.msg("写入" + appName + "Url失败‼️", "", "配置错误, 无法读取URL, "); - } - if ($request.headers) { - var CookieKeyFC = "CookieFC"; - var CookieValueFC = JSON.stringify($request.headers); - if (speed.getdata(CookieKeyFC) != (undefined || null)) { - if (speed.getdata(CookieKeyFC) != CookieValueFC) { - var cookie = speed.setdata(CookieValueFC, CookieKeyFC); - if (!cookie) { - speed.msg("更新" + appName + "Cookie失败‼️", "", ""); - } else { - speed.msg("更新" + appName + "Cookie成功🎉", "", ""); - } - } else { - speed.msg(appName + "Cookie未变化❗️", "", ""); - } +function sign (_id) { + return new Promise(resolve => { + const options = { + url: `${$.read("zsfc_url")}&gift_id=${_id}`, + headers: $.toObj($.read(`zsfc_headers`)) + } + $.log(`🧑‍💻 开始检查 Cookie 并进行每日签到`) + $.get(options, (error, response, data) => { + if (data) { + let result = $.toObj(data.replace(/\r|\n/ig, ``)) + let message = result.message + if (message.indexOf(`重试`) > -1) { + $.expired = 0 + $.log(`❌ 当前 Cookie 已失效, 请重新获取`) + } else if (message.indexOf(`已经`) > -1) { + $.log(`✅ 检查结果: 当前 Cookie 有效`) + $.log(`⭕ 签到结果: ${message}`) } else { - var cookie = speed.setdata(CookieValueFC, CookieKeyFC); - if (!cookie) { - speed.msg("首次写入" + appName + "Cookie失败‼️", "", ""); - } else { - speed.msg("首次写入" + appName + "Cookie成功🎉", "", ""); - } + sMsg = result.send_result.sMsg + $.log(`✅ 检查结果: 当前 Cookie 有效`) + $.log(`✅ ${sMsg}`) + $.notice($.name, `✅ ${message}`, sMsg, ``) } - } else { - speed.msg("写入" + appName + "Cookie失败‼️", "", "配置错误, 无法读取请求头, "); - } - speed.done() + } else if (error) { + $.log(`❌ 无法完成每日签到`) + $.log(error) + } + resolve() + }) + } + ) } - -function sign() { - const url = { url: URL, headers: JSON.parse(KEY) } - speed.get(url, (error, response, data) => { - speed.log(`${appName}, data: ${data}`) - const title = `${appName}` - let subTitle = '' - let detail = '' - const obj = JSON.parse(data) - if (obj.status == 1 && obj.data == 1) { - subTitle = `签到结果: 成功` - } else if (obj.status == 11 && obj.data == false) { - subTitle = `签到结果: 成功(重复)` - detail = `说明: ${obj.message}` - } else { - subTitle = `签到结果: 失败` - detail = `说明: ${obj.message}` + +function speed() { + return new Promise(resolve => { + const options = { + url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + headers: $.toObj($.read(`zsfc_headers`)) } - speed.msg(title, subTitle, detail) - speed.done() - }) + $.log(`🧑‍💻 开始获取累计签到天数`) + $.get(options, (error, response, data) => { + if (data) { + let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16] + $.day_award = data.match(/(\d+)<\/span> 天/)[1] * 1 + $.log(`✅ 当前 ${date.getMonth() + 1} 月累计签到 ${$.day_award} 天`) + if (arr[$.day_award] != 0) { + $.giftid = data.match(/giftid="([^"]+)"/g)[arr[$.day_award]].match(/(\d+)/)[1] + } + try { + if (data.match(/月(\d+)日/g)[0].match(/(\d+)/)[1] * 1 == date.getDate()) { + $.day_welfare = `${date.getMonth() + 1}月${date.getDate()}日` + $.giftdays = data.match(/"giftdays([^"]+)"/g)[0].match(/(\d+)/)[1] + } + } catch {} + } else if (error) { + $.log(`❌ 获取累计签到天数时发生错误`) + $.log($.toStr(error)) + } + resolve() + }) + } + ) } -function init() { - isSurge = () => { - return undefined === this.$httpClient ? false : true - } - isQuanX = () => { - return undefined === this.$task ? false : true +function handle (_id, _award) { + return new Promise(resolve => { + const options = { + url: `https://mwegame.qq.com/ams/send/handle`, + headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_query`)}&gift_id=${_id}` + } + $.log(`🧑‍💻 开始领取${_award}`) + $.post(options, (error, response, data) => { + if (data) { + let result = $.toObj(data.replace(/\r|\n/ig, ``)) + if (result.data.indexOf(`成功`) != -1) { + sPackageName = result.send_result.sPackageName + $.log(`✅ 领取结果: 获得${sPackageName}`) + } else { + $.log(`⭕ 领取结果: ${result.message}`) + } + } else if (error) { + $.log(`❌ 领取${_award}时发生错误`) + $.log($.toStr(error)) + } + resolve() + }) } - getdata = (key) => { - if (isSurge()) return $persistentStore.read(key) - if (isQuanX()) return $prefs.valueForKey(key) + ) +} + +function Env(name) { + LN = typeof $loon != `undefined` + SG = typeof $httpClient != `undefined` && !LN + QX = typeof $task != `undefined` + read = (key) => { + if (LN || SG) return $persistentStore.read(key) + if (QX) return $prefs.valueForKey(key) } - setdata = (key, val) => { - if (isSurge()) return $persistentStore.write(key, val) - if (isQuanX()) return $prefs.setValueForKey(key, val) + write = (key, val) => { + if (LN || SG) return $persistentStore.write(key, val); + if (QX) return $prefs.setValueForKey(key, val) } - msg = (title, subtitle, body) => { - if (isSurge()) $notification.post(title, subtitle, body) - if (isQuanX()) $notify(title, subtitle, body) + notice = (title, subtitle, message, url) => { + if (LN) $notification.post(title, subtitle, message, url) + if (SG) $notification.post(title, subtitle, message, { url: url }) + if (QX) $notify(title, subtitle, message, { 'open-url': url }) } - log = (message) => console.log(message) get = (url, cb) => { - if (isSurge()) { - $httpClient.get(url, cb) - } - if (isQuanX()) { - url.method = 'GET' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } + if (LN || SG) {$httpClient.get(url, cb)} + if (QX) {url.method = `GET`; $task.fetch(url).then((resp) => cb(null, {}, resp.body))} } post = (url, cb) => { - if (isSurge()) { - $httpClient.post(url, cb) - } - if (isQuanX()) { - url.method = 'POST' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - put = (url, cb) => { - if (isSurge()) { - $httpClient.put(url, cb) - } - if (isQuanX()) { - url.method = 'PUT' - $task.fetch(url).then((resp) => cb(null, {}, resp.body)) - } - } - done = (value = {}) => { - $done(value) + if (LN || SG) {$httpClient.post(url, cb)} + if (QX) {url.method = `POST`; $task.fetch(url).then((resp) => cb(null, {}, resp.body))} } - return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done } -} \ No newline at end of file + toObj = (str) => JSON.parse(str) + toStr = (obj) => JSON.stringify(obj) + log = (message) => console.log(message) + done = (value = {}) => {$done(value)} + return { name, read, write, notice, get, post, toObj, toStr, log, done } +} From a733ea190ddde1fb2066c7ec1ba78b2f3c153565 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Tue, 12 Jul 2022 10:29:18 +0800 Subject: [PATCH 143/311] feat: update bili --- bilibili/README.md | 3 ++- bilibili/bilibili.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bilibili/README.md b/bilibili/README.md index d84525956..5946de616 100644 --- a/bilibili/README.md +++ b/bilibili/README.md @@ -18,7 +18,7 @@ [Script] http-request ^https:\/\/(www|live)\.bilibili\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js -bilibili = type=cron,cronexp=10 0 0 * * *,wake-system=1,timeout=60,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js +bilibili = type=cron,cronexp=10 0 0 * * *,wake-system=1,timeout=100,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js # 如需银瓜子转硬币,添加以下内容 cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js @@ -52,6 +52,7 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr 4. 打开浏览器访问: https://www.bilibili.com 或 https://live.bilibili.com 5. 系统提示: `获取Cookie: 成功` 6. 最后就可以把第 1 条脚本注释掉了 +7. 请根据自己的粉丝牌数设置脚本超时时间,一个粉丝牌预计执行20s > 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. diff --git a/bilibili/bilibili.js b/bilibili/bilibili.js index 0a3b1cebe..439ab8831 100644 --- a/bilibili/bilibili.js +++ b/bilibili/bilibili.js @@ -52,8 +52,10 @@ function sign() { try { $.sign = JSON.parse(data) const result = JSON.parse(data) - if (result && result.code == 0) { + if (result?.code == 0) { $.desc.push(`本月累计: ${result.data.hadSignDays}/${result.data.allDays}次, 说明: ${result.data.text}`) + } else if (result?.code == -101) { + $.desc.push('Cookie已过期, 请重新获取Cookie') } } catch (e) { $.logErr(e, resp) @@ -104,13 +106,13 @@ function getMedalList() { $.get(url, (err, resp, data) => { try { const res = JSON.parse(data) - $.medalList = res.data.special_list.map((e) => { + const items = [...res.data.list, ...res.data.special_list] + $.medalList = items.filter(e => e?.medal?.level < 21).map((e) => { return { roomId: e?.room_info?.room_id, nickname: e?.medal?.medal_name, } }) - console.log('getMedalList', $.medalList) } catch (e) { $.logErr(e, resp) } finally { From 43d2c9d4476a9f1bdcfb512a2d705225a6239b27 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 13 Jul 2022 18:22:29 +0800 Subject: [PATCH 144/311] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EB=E7=AB=99?= =?UTF-8?q?=E6=8A=BD=E7=BA=A2=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bilibili/README.md | 3 + bilibili/redpocket.js | 152 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 bilibili/redpocket.js diff --git a/bilibili/README.md b/bilibili/README.md index 5946de616..01937b3c2 100644 --- a/bilibili/README.md +++ b/bilibili/README.md @@ -22,6 +22,9 @@ bilibili = type=cron,cronexp=10 0 0 * * *,wake-system=1,timeout=100,script-path= # 如需银瓜子转硬币,添加以下内容 cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js + +# 如需抽直播红包,添加以下内容 +bilibili = type=cron,cronexp=10 10 0 * * *,wake-system=1,timeout=100,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/redpocket.js ``` ## 配置 (QuanX) diff --git a/bilibili/redpocket.js b/bilibili/redpocket.js new file mode 100644 index 000000000..9136750b2 --- /dev/null +++ b/bilibili/redpocket.js @@ -0,0 +1,152 @@ +const $ = new Env('B站抽红包') +$.bilibiliLive = 'chavy_cookie_bilibili' +const cookie = $.getdata($.bilibiliLive) +const csrf = cookie.match(/.*?bili_jct=(.*?);/)?.[1] + +$.desc = [] + +!(async () => { + await getRedPocketList() + for (let i = 0; i < $.list.length; i++) { + const redPocket = $.list[i] + await getLotteryInfoWeb(redPocket.roomId, redPocket.runame) + await redPocketDraw(redPocket) + await sendMsg(redPocket.roomId) + await $.wait(1000) + } + await notify() +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function notify() { + return new Promise((resolve) => { + $.subt = `红包主播列表` + $.msg($.name, $.subt, $.desc.join('\n')) + resolve() + }) +} + +function getRedPocketList() { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/fuxi-interface/JuneRedPacket2022Controller/redPocketPlaying', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'sec-fetch-site': 'same-site', + "Referer": "https://live.bilibili.com/", + 'cookie': cookie + } + } + $.get(url, (err, resp, data) => { + try { + const { _ts_rpc_return_ } = JSON.parse(data) + $.list = _ts_rpc_return_?.data?.list.filter(e => e.countDown > 10) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function getLotteryInfoWeb(roomid, runame) { + return new Promise((resolve) => { + const url = { + url: 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfoWeb?roomid=' + roomid, + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15', + 'cookie': cookie + } + } + $.get(url, (err, resp, data) => { + try { + const result = JSON.parse(data) + if (result?.code == 0) { + const { popularity_red_pocket } = result?.data + const total_price = popularity_red_pocket?.[0]?.total_price / 1000 || 0 + $.desc.push(`${runame}: 电池价值${total_price}元`) + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + + +function redPocketDraw(redPocket) { + return new Promise((resolve) => { + const body = { + ruid: redPocket.ruid, + room_id: redPocket.roomId, + lot_id: redPocket.lotId, + csrf: csrf, + csrf_token: csrf, + } + const url = { + url: 'https://api.live.bilibili.com/xlive/lottery-interface/v1/popularityRedPocket/RedPocketDraw', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'origin': 'https://www.bilibili.com', + 'sec-fetch-site': 'same-site', + 'cookie': cookie + }, + body: $.queryStr(body) + } + $.post(url, (err, resp, data) => { + try { + // nothing + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +function sendMsg(roomId) { + return new Promise((resolve) => { + const body = { + bubble: 0, + msg: '老板大气!点点红包抽礼物!', + color: 16777215, + mode: 2, + fontsize: 25, + rnd: Math.round(new Date().getTime() / 1000).toString(), + roomid: roomId, + csrf: csrf, + csrf_token: csrf + } + const url = { + url: 'https://api.live.bilibili.com/msg/send', + headers: { + 'User-Agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36', + 'cookie': cookie, + 'content-type': 'multipart/form-data' + }, + body: $.queryStr(body) + } + + $.post(url, (err, resp, data) => { + try { + $.log('sendMsg: ', roomId) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} + +// pre-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 40adf6238dc9237ef25b605229fea5f4e15d0329 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 15 Aug 2022 10:10:22 +0800 Subject: [PATCH 145/311] feat(emby): add emby unlock script --- .gitignore | 10 +++++++++- .prettierrc | 6 ++++++ emby/emby.js | 20 ++++++++++++++++++++ emby/emby.sgmodule | 8 ++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .prettierrc create mode 100644 emby/emby.js create mode 100644 emby/emby.sgmodule diff --git a/.gitignore b/.gitignore index 0a3676b83..467d8153a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,10 @@ node_modules/* -.DS_Store \ No newline at end of file +.DS_Store + +.vscode + +tncj/* +*/unblock/* +*.private.* +*.dat +*copy.js \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..6b1caa4ee --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "quoteProps": "consistent", + "semi": false, + "singleQuote": true, + "trailingComma": "none" +} diff --git a/emby/emby.js b/emby/emby.js new file mode 100644 index 000000000..7386dcd83 --- /dev/null +++ b/emby/emby.js @@ -0,0 +1,20 @@ +const CHECK_URL = 'mb3admin.com/admin/service/registration/validateDevice' + +const url = $request.url +const isCheckURL = (url) => url.includes(CHECK_URL) + +if (isCheckUrl(url) && $response.status != 200) { + const unlock = { + cacheExpirationDays: 999, + resultCode: 'GOOD', + message: 'Device Valid' + } + + const status = 200 + const headers = $response.headers + const body = JSON.stringify(unlock) + + $done({ status, headers, body }) +} else { + $done({}) +} diff --git a/emby/emby.sgmodule b/emby/emby.sgmodule new file mode 100644 index 000000000..fa615bc0a --- /dev/null +++ b/emby/emby.sgmodule @@ -0,0 +1,8 @@ +#!name=embyUnlock +#!desc=embyUnlock + +[Script] +emby.js = type=http-response,pattern=^https?:\/\/mb3admin.com\/admin\/service\/registration\/validateDevice,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/emby/emby.js + +[MITM] +hostname = %APPEND% mb3admin.com \ No newline at end of file From 5ccc59750cf558de912d662fa5d18a41858b5fbc Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 15 Aug 2022 10:26:38 +0800 Subject: [PATCH 146/311] chore(emby): fix typo --- emby/emby.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emby/emby.js b/emby/emby.js index 7386dcd83..b34b409cc 100644 --- a/emby/emby.js +++ b/emby/emby.js @@ -1,7 +1,7 @@ const CHECK_URL = 'mb3admin.com/admin/service/registration/validateDevice' const url = $request.url -const isCheckURL = (url) => url.includes(CHECK_URL) +const isCheckUrl = (url) => url.includes(CHECK_URL) if (isCheckUrl(url) && $response.status != 200) { const unlock = { From 7123c003b2be7bf33850e9edf01c99fa942cc581 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 15 Aug 2022 10:27:23 +0800 Subject: [PATCH 147/311] chore(emby): rename module --- emby/emby.sgmodule | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emby/emby.sgmodule b/emby/emby.sgmodule index fa615bc0a..44fefc2ce 100644 --- a/emby/emby.sgmodule +++ b/emby/emby.sgmodule @@ -1,5 +1,5 @@ -#!name=embyUnlock -#!desc=embyUnlock +#!name=Emby Unlock +#!desc=Emby Unlock [Script] emby.js = type=http-response,pattern=^https?:\/\/mb3admin.com\/admin\/service\/registration\/validateDevice,requires-body=1,max-size=0,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/emby/emby.js From 947c3c2ada6f969d3da2f870c3fbb35dbd43ab42 Mon Sep 17 00:00:00 2001 From: 42vio Date: Wed, 24 Aug 2022 10:51:44 +0800 Subject: [PATCH 148/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E9=A1=BA=E4=B8=B0?= =?UTF-8?q?=E9=80=9F=E8=BF=90]:=20=E6=81=A2=E5=A4=8D=20APP=20=E7=AB=AF?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E5=92=8C=E6=AF=8F=E6=97=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/sfexpress.js | 49 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 13bf5417d..a2b58084e 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -38,8 +38,8 @@ function loginweb() { function sign() { const signOpts = { - url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/signFetchPoint`, - body: `{"channel": "SFAPP","pageType": "sign","from": "APP_MINE_TASK"}`, + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/integralTaskSignPlusService/automaticSignFetchPackage`, + body: `{"comeFrom": "vioin", "channelFrom": "SFAPP"}`, headers: { 'Content-Type': 'application/json' } @@ -52,8 +52,8 @@ function sign() { function queryDailyTask() { return $.http .post({ - url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/queryPointTaskAndSign`, - body: `{"channel":"SFAPP","pageType": "APP_MINE_TASK"}`, + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/commonPost/~memberNonactivity~integralTaskStrategyService~queryPointTaskAndSignFromES`, + body: `{"channelType":"1"}`, headers: { 'Content-Type': 'application/json' } @@ -66,13 +66,16 @@ function queryDailyTask() { async function signDailyTasks() { await queryDailyTask() - // 移除每日签到 - const skipType = ['sign', 'mailPerMonThan3'] - $.tasks = $.tasks.filter((t) => !skipType.includes(t.pageType)) + // 移除参与积分活动 手动参加活动 + // 移除完成每月任务 因需要手动完成每月积分活动 +// const skipTitles = ['参与积分活动', '完成每月任务'] +// $.tasks = $.tasks.filter((t) => !skipTitles.includes(t.title)) for (let i = 0; i < $.tasks.length; i++) { const task = $.tasks[i] - if (task.status === 2) { + if (task.status === 1) { + await getPoint(task) + } else if (task.status === 2) { await doTask(task) await getPoint(task) } else if (task.status === 3) { @@ -84,20 +87,18 @@ async function signDailyTasks() { } function doTask(task) { - return $.http.post({ - url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/scanPageToRecord`, - body: `{"channel":"SFAPP","pageType": "${task.pageType}"}`, - headers: { - 'Content-Type': 'application/json' - } + return $.http.get({ + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/task/finishTask?id=${task.taskCode}`, + body: ``, + headers: {} }) } function getPoint(task) { return $.http .post({ - url: 'https://mcs-mimp-web.sf-express.com/mcs-mimp/appTask/fetchPoint', - body: `{"channel": "SFAPP","pageType": "${task.pageType}"}`, + url: 'https://mcs-mimp-web.sf-express.com/mcs-mimp/commonPost/~memberNonactivity~integralTaskStrategyService~fetchIntegral', + body: `{"strategyId":${task.strategyId},"taskId":"${task.taskId}","taskCode":"${task.taskCode}"}`, headers: { 'Content-Type': 'application/json' } @@ -105,7 +106,6 @@ function getPoint(task) { .then((resp) => { const data = JSON.parse(resp.body) task.result = data.success ? '成功' : data.errorMessage - console.log(task) }) } @@ -114,16 +114,17 @@ function showmsg() { $.subt = `签到: ` $.desc = [] if (success) { - $.subt += `成功` - $.desc.push(`说明: +${$.sign.obj} 积分`) - } else { - const errmsg = $.sign.errorMessage - if (errmsg === '已经发送过积分') { + if ($.sign.obj.hasFinishSign){ $.subt += `重复` - $.desc.push(`说明: ${errmsg}`) + $.desc.push(`说明: 连续签到${$.sign.obj.countDay}天`) } else { - $.subt += `失败` + $.subt += `成功` + $.desc.push(`说明: 连续签到${$.sign.obj.countDay}天`) } + } else { + const errmsg = $.sign.errorMessage + $.subt += `失败` + $.desc.push(`说明: ${errmsg}`) } $.desc.push('', `每日任务: `) From ee1bd4e8e9ac540709332969115aa996817c11bf Mon Sep 17 00:00:00 2001 From: 42vio Date: Wed, 24 Aug 2022 10:55:58 +0800 Subject: [PATCH 149/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E9=A1=BA=E4=B8=B0?= =?UTF-8?q?=E9=80=9F=E8=BF=90]:=20=E6=81=A2=E5=A4=8D=20APP=20=E7=AB=AF?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E5=92=8C=E6=AF=8F=E6=97=A5=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/sfexpress.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index a2b58084e..13528a269 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -66,11 +66,6 @@ function queryDailyTask() { async function signDailyTasks() { await queryDailyTask() - // 移除参与积分活动 手动参加活动 - // 移除完成每月任务 因需要手动完成每月积分活动 -// const skipTitles = ['参与积分活动', '完成每月任务'] -// $.tasks = $.tasks.filter((t) => !skipTitles.includes(t.title)) - for (let i = 0; i < $.tasks.length; i++) { const task = $.tasks[i] if (task.status === 1) { From c275532082afc1fd9dadd30371262ca54aefc6bf Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Sat, 17 Sep 2022 14:38:45 +0800 Subject: [PATCH 150/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=88=E5=B0=BE?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=97=A0=E6=B3=95=E8=BF=90=E8=A1=8C=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index dd9b3df8e..9560c9f59 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -43,20 +43,20 @@ async function main () { function index() { return new Promise(resolve => { const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + url: `https://mwegame.qq.com/ams/sign/month/speed?` + + `${$.read(`zsfc_query`)}`, headers: $.toObj($.read(`zsfc_headers`)) } $.get(options, (error, response, data) => { if (data) { successive = data.match(/giftid="([^"]+)"/g)[0].match(/(\d+)/)[1] - } else if (error) { + } else { $.log(`❌ 获取签到页面信息时发生错误`) $.log($.toStr(error)) } resolve(successive) }) - } - ) + }) } function sign (_id) { @@ -82,26 +82,26 @@ function sign (_id) { $.log(`✅ ${sMsg}`) $.notice($.name, `✅ ${message}`, sMsg, ``) } - } else if (error) { + } else { $.log(`❌ 无法完成每日签到`) $.log(error) } resolve() }) - } - ) + }) } function speed() { return new Promise(resolve => { const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + url: `https://mwegame.qq.com/ams/sign/month/speed?` + + `${$.read(`zsfc_query`)}`, headers: $.toObj($.read(`zsfc_headers`)) } $.log(`🧑‍💻 开始获取累计签到天数`) $.get(options, (error, response, data) => { if (data) { - let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16] + let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16,0,0,0,0,0] $.day_award = data.match(/(\d+)<\/span> 天/)[1] * 1 $.log(`✅ 当前 ${date.getMonth() + 1} 月累计签到 ${$.day_award} 天`) if (arr[$.day_award] != 0) { @@ -113,14 +113,13 @@ function speed() { $.giftdays = data.match(/"giftdays([^"]+)"/g)[0].match(/(\d+)/)[1] } } catch {} - } else if (error) { + } else { $.log(`❌ 获取累计签到天数时发生错误`) $.log($.toStr(error)) } resolve() }) - } - ) + }) } function handle (_id, _award) { @@ -140,14 +139,13 @@ function handle (_id, _award) { } else { $.log(`⭕ 领取结果: ${result.message}`) } - } else if (error) { + } else { $.log(`❌ 领取${_award}时发生错误`) $.log($.toStr(error)) } resolve() }) - } - ) + }) } function Env(name) { From 125d06cff3371e2f69533a32c88c964a726b9c9c Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 28 Sep 2022 08:59:11 +0800 Subject: [PATCH 151/311] chore: add .idea to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 467d8153a..944583120 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/* .DS_Store .vscode +.idea tncj/* */unblock/* From c890c1d23dd8911d4b14ccc4584f90881233608e Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 13 Oct 2022 13:50:57 +0800 Subject: [PATCH 152/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D=20stas?= =?UTF-8?q?h=20=E6=97=A0=E6=B3=95=E8=BF=90=E8=A1=8C=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 49 +++++++-- box/release/box.release.json | 180 ++++++++++++++++++++++++++------ box/release/box.release.tf.json | 104 +++++++++++++++--- chavy.box.js | 49 +++++++-- 4 files changed, 312 insertions(+), 70 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index a5f5acc63..17e898ee6 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.1' +$.version = '0.12.2' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -44,7 +44,9 @@ $.json = $.name // `接口`类请求的响应体 $.html = $.name // `页面`类请求的响应体 // 页面源码地址 -$.web = `https://cdn.jsdelivr.net/gh/chavyleung/scripts@${$.version}/box/chavy.boxjs.html?_=${new Date().getTime()}` +$.web = `https://cdn.jsdelivr.net/gh/chavyleung/scripts@${ + $.version +}/box/chavy.boxjs.html?_=${new Date().getTime()}` // 版本说明地址 (Release Note) $.ver = `https://raw.githubusercontent.com/chavyleung/scripts/master/box/release/box.release.json` @@ -135,7 +137,9 @@ async function handlePage() { boxdata.syscfgs.isDebugMode = false // 调试模式: 是否每次都获取新的页面 - const isDebugWeb = [true, 'true'].includes($.getdata('@chavy_boxjs_userCfgs.isDebugWeb')) + const isDebugWeb = [true, 'true'].includes( + $.getdata('@chavy_boxjs_userCfgs.isDebugWeb') + ) const debugger_web = $.getdata('@chavy_boxjs_userCfgs.debugger_web') const cache = $.getjson($.KEY_web_cache, null) @@ -148,7 +152,9 @@ async function handlePage() { if (isDebugWeb && debugger_web) { // 调试地址后面拼时间缀, 避免 GET 缓存 const isQueryUrl = debugger_web.includes('?') - $.web = `${debugger_web}${isQueryUrl ? '&' : '?'}_=${new Date().getTime()}` + $.web = `${debugger_web}${ + isQueryUrl ? '&' : '?' + }_=${new Date().getTime()}` boxdata.syscfgs.isDebugMode = true console.log(`[WARN] 调试模式: $.web = : ${$.web}`) } @@ -187,7 +193,10 @@ async function handlePage() { * 如果直接渲染到 box: null 会出现双向绑定问题 * 所以先渲染到 `boxServerData: null` 再由前端 `this.box = this.boxServerData` 实现双向绑定 */ - $.html = $.html.replace('boxServerData: null', 'boxServerData:' + JSON.stringify(boxdata)) + $.html = $.html.replace( + 'boxServerData: null', + 'boxServerData:' + JSON.stringify(boxdata) + ) // 调试模式支持 vue Devtools (只有在同时开启调试模式和指定了调试地址才生效) // vue.min.js 生效时, 会导致 @click="window.open()" 报 "window" is not defined 错误 @@ -274,7 +283,16 @@ function getBoxData() { } }) - const box = { datas, usercfgs, sessions, curSessions, sysapps, syscfgs, appSubCaches, globalbaks } + const box = { + datas, + usercfgs, + sessions, + curSessions, + sysapps, + syscfgs, + appSubCaches, + globalbaks + } return box } @@ -611,8 +629,11 @@ async function apiRevertGlobalBak() { $.setdata(JSON.stringify(chavy_boxjs_userCfgs), $.KEY_usercfgs) $.setdata(JSON.stringify(chavy_boxjs_cur_sessions), $.KEY_cursessions) $.setdata(JSON.stringify(chavy_boxjs_app_subCaches), $.KEY_app_subCaches) - const isNull = (val) => [undefined, null, 'null', 'undefined', ''].includes(val) - Object.keys(datas).forEach((datkey) => $.setdata(isNull(datas[datkey]) ? '' : `${datas[datkey]}`, datkey)) + const isNull = (val) => + [undefined, null, 'null', 'undefined', ''].includes(val) + Object.keys(datas).forEach((datkey) => + $.setdata(isNull(datas[datkey]) ? '' : `${datas[datkey]}`, datkey) + ) } const boxdata = getBoxData() $.json = boxdata @@ -657,9 +678,17 @@ async function apiRunScript() { } else { script_text = opts.script } - if ($.isSurge() && !$.isLoon() && !$.isShadowrocket() && ishttpapi) { + if ( + $.isSurge() && + !$.isLoon() && + !$.isShadowrocket() && + !$.isStash() && + ishttpapi + ) { const runOpts = { timeout: opts.timeout } - await $.runScript(script_text, runOpts).then((resp) => ($.json = JSON.parse(resp))) + await $.runScript(script_text, runOpts).then( + (resp) => ($.json = JSON.parse(resp)) + ) } else { await new Promise((resolve) => { $eval_env.resolve = resolve diff --git a/box/release/box.release.json b/box/release/box.release.json index 45355b39c..9dfc41664 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.2", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 修复 stash 无法运行脚本问题", + "notes": [ + { + "name": "修复", + "descs": ["stash 无法运行脚本问题"] + } + ] + }, { "version": "0.12.1", "tags": ["beta"], @@ -102,7 +114,10 @@ }, { "name": "QX 用户注意", - "descs": ["仅配置 httpbackend 的 QX 用户无法使用一键订阅", "需要配置 `重写` 或同时配置 `重写` 及 `httpbackend` 才能使用一键订阅"] + "descs": [ + "仅配置 httpbackend 的 QX 用户无法使用一键订阅", + "需要配置 `重写` 或同时配置 `重写` 及 `httpbackend` 才能使用一键订阅" + ] }, { "name": "其他", @@ -118,7 +133,10 @@ "notes": [ { "name": "新增", - "descs": ["支持 Stash TF (v1.5.0 Build 203+)", "https://chavyleung.gitbook.io/boxjs/#stash"] + "descs": [ + "支持 Stash TF (v1.5.0 Build 203+)", + "https://chavyleung.gitbook.io/boxjs/#stash" + ] } ] }, @@ -130,7 +148,11 @@ "notes": [ { "name": "新增", - "descs": ["新增 selects (下拉) 控件", "type: 'selects'", "items: [{key: '', label: ''}]"] + "descs": [ + "新增 selects (下拉) 控件", + "type: 'selects'", + "items: [{key: '', label: ''}]" + ] } ] }, @@ -493,7 +515,9 @@ }, { "name": "注意", - "descs": ["如果订阅里有旧的图标路径,BoxJs 会自动转换为新路径,有问题请反馈"] + "descs": [ + "如果订阅里有旧的图标路径,BoxJs 会自动转换为新路径,有问题请反馈" + ] } ] }, @@ -561,7 +585,9 @@ "notes": [ { "name": "修复", - "descs": ["由于网络问题,导致订阅数据异常后,访问页面时仅显示 BoxJs 字样问题。"] + "descs": [ + "由于网络问题,导致订阅数据异常后,访问页面时仅显示 BoxJs 字样问题。" + ] } ] }, @@ -597,7 +623,10 @@ "notes": [ { "name": "优化", - "descs": ["BoxJs 内的请求会可以被重写", "刷新订阅添加时间缀避免网络缓存"] + "descs": [ + "BoxJs 内的请求会可以被重写", + "刷新订阅添加时间缀避免网络缓存" + ] } ] }, @@ -667,7 +696,10 @@ "notes": [ { "name": "移除", - "descs": ["主屏幕的左右滑动手势", "原因: 与浏览器前进后退容易发生冲突"] + "descs": [ + "主屏幕的左右滑动手势", + "原因: 与浏览器前进后退容易发生冲突" + ] }, { "name": "修复", @@ -718,7 +750,10 @@ "notes": [ { "name": "修复", - "descs": ["代码编辑器高度问题", "部分界面只能在有内容的范围左右滑动问题"] + "descs": [ + "代码编辑器高度问题", + "部分界面只能在有内容的范围左右滑动问题" + ] } ] }, @@ -732,7 +767,10 @@ "notes": [ { "name": "优化", - "descs": ["勿扰模式下运行脚本不弹出结果页", "壁纸模式下滑更容易退出壁纸模式"] + "descs": [ + "勿扰模式下运行脚本不弹出结果页", + "壁纸模式下滑更容易退出壁纸模式" + ] }, { "name": "移除", @@ -768,7 +806,10 @@ "notes": [ { "name": "新增", - "descs": ["Surge、QuanX、Loon 手动运行脚本时都可以显示执行结果", "主屏幕左右滑动可切换 首页、应用、订阅、我的 页面"] + "descs": [ + "Surge、QuanX、Loon 手动运行脚本时都可以显示执行结果", + "主屏幕左右滑动可切换 首页、应用、订阅、我的 页面" + ] }, { "name": "修复", @@ -786,11 +827,19 @@ "notes": [ { "name": "新增", - "descs": ["在顶栏上滑可隐藏顶栏", "在底栏下滑可以隐藏底栏", "壁纸模式上滑可以重新渲染壁纸"] + "descs": [ + "在顶栏上滑可隐藏顶栏", + "在底栏下滑可以隐藏底栏", + "壁纸模式上滑可以重新渲染壁纸" + ] }, { "name": "修复", - "descs": ["代码编辑器不显示问题", "二次进入搜索界面无法自动获取焦点", "非壁纸模式下上滑仍然重新渲染壁纸"] + "descs": [ + "代码编辑器不显示问题", + "二次进入搜索界面无法自动获取焦点", + "非壁纸模式下上滑仍然重新渲染壁纸" + ] } ] }, @@ -812,11 +861,19 @@ }, { "name": "悬浮按钮手势", - "descs": ["上滑: 重渲染&切换壁纸", "左滑: 悬浮按钮左靠", "右滑: 悬浮按钮右靠", "下滑: 切换壁纸模式"] + "descs": [ + "上滑: 重渲染&切换壁纸", + "左滑: 悬浮按钮左靠", + "右滑: 悬浮按钮右靠", + "下滑: 切换壁纸模式" + ] }, { "name": "说明", - "descs": ["壁纸模式下: 下滑取消壁纸模式", "非壁纸模式: 下滑显示\\隐藏顶栏"] + "descs": [ + "壁纸模式下: 下滑取消壁纸模式", + "非壁纸模式: 下滑显示\\隐藏顶栏" + ] } ] }, @@ -834,7 +891,12 @@ }, { "name": "悬浮按钮手势", - "descs": ["上滑: 刷新页面 (效果同双击)", "左滑: 悬浮按钮左靠", "右滑: 悬浮按钮右靠", "下滑: 切换壁纸模式"] + "descs": [ + "上滑: 刷新页面 (效果同双击)", + "左滑: 悬浮按钮左靠", + "右滑: 悬浮按钮右靠", + "下滑: 切换壁纸模式" + ] } ] }, @@ -948,7 +1010,11 @@ }, { "name": "修复", - "descs": ["底栏事件无效问题", "部分情况下贡献者重复加载问题", "手势前进后退会白屏&卡屏问题"] + "descs": [ + "底栏事件无效问题", + "部分情况下贡献者重复加载问题", + "手势前进后退会白屏&卡屏问题" + ] } ] }, @@ -1161,7 +1227,11 @@ }, { "name": "修复", - "descs": ["首页图标点击无效问题", "首页图标有轻微位移问题", "帮助页面打开空白"] + "descs": [ + "首页图标点击无效问题", + "首页图标有轻微位移问题", + "帮助页面打开空白" + ] } ] }, @@ -1229,7 +1299,10 @@ "notes": [ { "name": "优化", - "descs": ["BoxJs 内的请求会可以被重写", "刷新订阅添加时间缀避免网络缓存"] + "descs": [ + "BoxJs 内的请求会可以被重写", + "刷新订阅添加时间缀避免网络缓存" + ] } ] }, @@ -1272,7 +1345,10 @@ "notes": [ { "name": "订阅配置", - "descs": ["新增: desc、descs、desc_html、descs_html 属性", "与 id、name 同级"] + "descs": [ + "新增: desc、descs、desc_html、descs_html 属性", + "与 id、name 同级" + ] }, { "name": "示例", @@ -1299,7 +1375,9 @@ }, { "name": "订阅配置", - "descs": ["增加 script_timeout 属性, 与 script 同级, 可指定 http-api 超时时间, 单位: 秒"] + "descs": [ + "增加 script_timeout 属性, 与 script 同级, 可指定 http-api 超时时间, 单位: 秒" + ] } ] }, @@ -1420,7 +1498,11 @@ "notes": [ { "name": "新增", - "descs": ["内置应用: 偏好设置", "可以设置多个 http-api (设置完后在侧栏选择)", "可以分别设置暗黑、明亮主题下的主色调"] + "descs": [ + "内置应用: 偏好设置", + "可以设置多个 http-api (设置完后在侧栏选择)", + "可以分别设置暗黑、明亮主题下的主色调" + ] }, { "name": "控件", @@ -1428,7 +1510,9 @@ }, { "name": "注意", - "descs": ["设置多个 http-api 时, 建议以逗号开头, 侧栏中选择空白的那个就是走 eval() 方案"] + "descs": [ + "设置多个 http-api 时, 建议以逗号开头, 侧栏中选择空白的那个就是走 eval() 方案" + ] } ] }, @@ -1462,7 +1546,9 @@ "notes": [ { "name": "重写", - "descs": ["BoxJs Surge 的重写超时改为 120 秒 (避免手动运行脚本容易超时)"] + "descs": [ + "BoxJs Surge 的重写超时改为 120 秒 (避免手动运行脚本容易超时)" + ] }, { "name": "调整", @@ -1482,7 +1568,10 @@ "notes": [ { "name": "调整", - "descs": ["迁移 腾讯新闻 至原作者订阅: @Sunert", "https://raw.githubusercontent.com/Sunert/Scripts/master/Task/sunert.boxjs.json"] + "descs": [ + "迁移 腾讯新闻 至原作者订阅: @Sunert", + "https://raw.githubusercontent.com/Sunert/Scripts/master/Task/sunert.boxjs.json" + ] } ] }, @@ -1676,7 +1765,10 @@ "notes": [ { "name": "新增", - "descs": ["抹掉数据: https://8.8.8.8/revert (更新完需要重启代理)", "出现问题时可单独访问页面抹掉数据"] + "descs": [ + "抹掉数据: https://8.8.8.8/revert (更新完需要重启代理)", + "出现问题时可单独访问页面抹掉数据" + ] }, { "name": "调整", @@ -1768,7 +1860,10 @@ "notes": [ { "name": "新增", - "descs": ["仓库协作者&贡献者信息 (带跳转)", "点击订阅可以跳转至作者仓库"] + "descs": [ + "仓库协作者&贡献者信息 (带跳转)", + "点击订阅可以跳转至作者仓库" + ] }, { "name": "修复", @@ -1880,7 +1975,9 @@ "notes": [ { "name": "调整", - "descs": ["京东, 请使用野比大佬的订阅: https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json"] + "descs": [ + "京东, 请使用野比大佬的订阅: https://raw.githubusercontent.com/NobyDa/Script/master/NobyDa_BoxJs.json" + ] } ] }, @@ -1927,7 +2024,9 @@ "notes": [ { "name": "修复", - "descs": ["部分情况下无法清空会话数值问题 (更新脚本后, 需要手动刷新下订阅)"] + "descs": [ + "部分情况下无法清空会话数值问题 (更新脚本后, 需要手动刷新下订阅)" + ] } ] }, @@ -1992,7 +2091,10 @@ "notes": [ { "name": "修复", - "descs": ["部分情况下保存数据不生效问题 (实验)", "Rewrite正则 (注意更新正则)"] + "descs": [ + "部分情况下保存数据不生效问题 (实验)", + "Rewrite正则 (注意更新正则)" + ] }, { "name": "移除", @@ -2035,7 +2137,10 @@ "notes": [ { "name": "优化", - "descs": ["可以把当前会话保存至指定会话 (注意先保存设置再使用`保存至`)", "可以设置刷新等待秒数 (为 0 时直接刷新不弹窗)"] + "descs": [ + "可以把当前会话保存至指定会话 (注意先保存设置再使用`保存至`)", + "可以设置刷新等待秒数 (为 0 时直接刷新不弹窗)" + ] } ] }, @@ -2048,7 +2153,10 @@ "notes": [ { "name": "优化", - "descs": ["可以复制单个应用订阅地址", "增加底部间距避免界面被悬浮按钮遮挡"] + "descs": [ + "可以复制单个应用订阅地址", + "增加底部间距避免界面被悬浮按钮遮挡" + ] } ] }, @@ -2079,7 +2187,9 @@ "notes": [ { "name": "修复", - "descs": ["部分情况下导入空数据产生的问题 (如: 京东没有账号2, 导入后提示账号 2 签到失败问题)"] + "descs": [ + "部分情况下导入空数据产生的问题 (如: 京东没有账号2, 导入后提示账号 2 签到失败问题)" + ] } ] }, @@ -2118,7 +2228,11 @@ "notes": [ { "name": "优化", - "descs": ["页面渲染时会先出现一串代码问题", "进入应用订阅页面提示手动刷新", "可以隐藏|显示`我的`标题"] + "descs": [ + "页面渲染时会先出现一串代码问题", + "进入应用订阅页面提示手动刷新", + "可以隐藏|显示`我的`标题" + ] } ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 5eb67854e..fbae8e09b 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.2", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 修复 stash 无法运行脚本问题", + "notes": [ + { + "name": "修复", + "descs": ["stash 无法运行脚本问题"] + } + ] + }, { "version": "0.12.1", "tags": ["beta"], @@ -102,7 +114,10 @@ }, { "name": "QX 用户注意", - "descs": ["仅配置 httpbackend 的 QX 用户无法使用一键订阅", "需要配置 `重写` 或同时配置 `重写` 及 `httpbackend` 才能使用一键订阅"] + "descs": [ + "仅配置 httpbackend 的 QX 用户无法使用一键订阅", + "需要配置 `重写` 或同时配置 `重写` 及 `httpbackend` 才能使用一键订阅" + ] }, { "name": "其他", @@ -118,7 +133,10 @@ "notes": [ { "name": "新增", - "descs": ["支持 Stash TF (v1.5.0 Build 203+)", "https://chavyleung.gitbook.io/boxjs/#stash"] + "descs": [ + "支持 Stash TF (v1.5.0 Build 203+)", + "https://chavyleung.gitbook.io/boxjs/#stash" + ] } ] }, @@ -130,7 +148,11 @@ "notes": [ { "name": "新增", - "descs": ["新增 selects (下拉) 控件", "type: 'selects'", "items: [{key: '', label: ''}]"] + "descs": [ + "新增 selects (下拉) 控件", + "type: 'selects'", + "items: [{key: '', label: ''}]" + ] } ] }, @@ -493,7 +515,9 @@ }, { "name": "注意", - "descs": ["如果订阅里有旧的图标路径,BoxJs 会自动转换为新路径,有问题请反馈"] + "descs": [ + "如果订阅里有旧的图标路径,BoxJs 会自动转换为新路径,有问题请反馈" + ] } ] }, @@ -561,7 +585,9 @@ "notes": [ { "name": "修复", - "descs": ["由于网络问题,导致订阅数据异常后,访问页面时仅显示 BoxJs 字样问题。"] + "descs": [ + "由于网络问题,导致订阅数据异常后,访问页面时仅显示 BoxJs 字样问题。" + ] } ] }, @@ -597,7 +623,10 @@ "notes": [ { "name": "优化", - "descs": ["BoxJs 内的请求会可以被重写", "刷新订阅添加时间缀避免网络缓存"] + "descs": [ + "BoxJs 内的请求会可以被重写", + "刷新订阅添加时间缀避免网络缓存" + ] } ] }, @@ -667,7 +696,10 @@ "notes": [ { "name": "移除", - "descs": ["主屏幕的左右滑动手势", "原因: 与浏览器前进后退容易发生冲突"] + "descs": [ + "主屏幕的左右滑动手势", + "原因: 与浏览器前进后退容易发生冲突" + ] }, { "name": "修复", @@ -718,7 +750,10 @@ "notes": [ { "name": "修复", - "descs": ["代码编辑器高度问题", "部分界面只能在有内容的范围左右滑动问题"] + "descs": [ + "代码编辑器高度问题", + "部分界面只能在有内容的范围左右滑动问题" + ] } ] }, @@ -732,7 +767,10 @@ "notes": [ { "name": "优化", - "descs": ["勿扰模式下运行脚本不弹出结果页", "壁纸模式下滑更容易退出壁纸模式"] + "descs": [ + "勿扰模式下运行脚本不弹出结果页", + "壁纸模式下滑更容易退出壁纸模式" + ] }, { "name": "移除", @@ -768,7 +806,10 @@ "notes": [ { "name": "新增", - "descs": ["Surge、QuanX、Loon 手动运行脚本时都可以显示执行结果", "主屏幕左右滑动可切换 首页、应用、订阅、我的 页面"] + "descs": [ + "Surge、QuanX、Loon 手动运行脚本时都可以显示执行结果", + "主屏幕左右滑动可切换 首页、应用、订阅、我的 页面" + ] }, { "name": "修复", @@ -786,11 +827,19 @@ "notes": [ { "name": "新增", - "descs": ["在顶栏上滑可隐藏顶栏", "在底栏下滑可以隐藏底栏", "壁纸模式上滑可以重新渲染壁纸"] + "descs": [ + "在顶栏上滑可隐藏顶栏", + "在底栏下滑可以隐藏底栏", + "壁纸模式上滑可以重新渲染壁纸" + ] }, { "name": "修复", - "descs": ["代码编辑器不显示问题", "二次进入搜索界面无法自动获取焦点", "非壁纸模式下上滑仍然重新渲染壁纸"] + "descs": [ + "代码编辑器不显示问题", + "二次进入搜索界面无法自动获取焦点", + "非壁纸模式下上滑仍然重新渲染壁纸" + ] } ] }, @@ -812,11 +861,19 @@ }, { "name": "悬浮按钮手势", - "descs": ["上滑: 重渲染&切换壁纸", "左滑: 悬浮按钮左靠", "右滑: 悬浮按钮右靠", "下滑: 切换壁纸模式"] + "descs": [ + "上滑: 重渲染&切换壁纸", + "左滑: 悬浮按钮左靠", + "右滑: 悬浮按钮右靠", + "下滑: 切换壁纸模式" + ] }, { "name": "说明", - "descs": ["壁纸模式下: 下滑取消壁纸模式", "非壁纸模式: 下滑显示\\隐藏顶栏"] + "descs": [ + "壁纸模式下: 下滑取消壁纸模式", + "非壁纸模式: 下滑显示\\隐藏顶栏" + ] } ] }, @@ -834,7 +891,12 @@ }, { "name": "悬浮按钮手势", - "descs": ["上滑: 刷新页面 (效果同双击)", "左滑: 悬浮按钮左靠", "右滑: 悬浮按钮右靠", "下滑: 切换壁纸模式"] + "descs": [ + "上滑: 刷新页面 (效果同双击)", + "左滑: 悬浮按钮左靠", + "右滑: 悬浮按钮右靠", + "下滑: 切换壁纸模式" + ] } ] }, @@ -948,7 +1010,11 @@ }, { "name": "修复", - "descs": ["底栏事件无效问题", "部分情况下贡献者重复加载问题", "手势前进后退会白屏&卡屏问题"] + "descs": [ + "底栏事件无效问题", + "部分情况下贡献者重复加载问题", + "手势前进后退会白屏&卡屏问题" + ] } ] }, @@ -1161,7 +1227,11 @@ }, { "name": "修复", - "descs": ["首页图标点击无效问题", "首页图标有轻微位移问题", "帮助页面打开空白"] + "descs": [ + "首页图标点击无效问题", + "首页图标有轻微位移问题", + "帮助页面打开空白" + ] } ] }, diff --git a/chavy.box.js b/chavy.box.js index a5f5acc63..17e898ee6 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.1' +$.version = '0.12.2' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -44,7 +44,9 @@ $.json = $.name // `接口`类请求的响应体 $.html = $.name // `页面`类请求的响应体 // 页面源码地址 -$.web = `https://cdn.jsdelivr.net/gh/chavyleung/scripts@${$.version}/box/chavy.boxjs.html?_=${new Date().getTime()}` +$.web = `https://cdn.jsdelivr.net/gh/chavyleung/scripts@${ + $.version +}/box/chavy.boxjs.html?_=${new Date().getTime()}` // 版本说明地址 (Release Note) $.ver = `https://raw.githubusercontent.com/chavyleung/scripts/master/box/release/box.release.json` @@ -135,7 +137,9 @@ async function handlePage() { boxdata.syscfgs.isDebugMode = false // 调试模式: 是否每次都获取新的页面 - const isDebugWeb = [true, 'true'].includes($.getdata('@chavy_boxjs_userCfgs.isDebugWeb')) + const isDebugWeb = [true, 'true'].includes( + $.getdata('@chavy_boxjs_userCfgs.isDebugWeb') + ) const debugger_web = $.getdata('@chavy_boxjs_userCfgs.debugger_web') const cache = $.getjson($.KEY_web_cache, null) @@ -148,7 +152,9 @@ async function handlePage() { if (isDebugWeb && debugger_web) { // 调试地址后面拼时间缀, 避免 GET 缓存 const isQueryUrl = debugger_web.includes('?') - $.web = `${debugger_web}${isQueryUrl ? '&' : '?'}_=${new Date().getTime()}` + $.web = `${debugger_web}${ + isQueryUrl ? '&' : '?' + }_=${new Date().getTime()}` boxdata.syscfgs.isDebugMode = true console.log(`[WARN] 调试模式: $.web = : ${$.web}`) } @@ -187,7 +193,10 @@ async function handlePage() { * 如果直接渲染到 box: null 会出现双向绑定问题 * 所以先渲染到 `boxServerData: null` 再由前端 `this.box = this.boxServerData` 实现双向绑定 */ - $.html = $.html.replace('boxServerData: null', 'boxServerData:' + JSON.stringify(boxdata)) + $.html = $.html.replace( + 'boxServerData: null', + 'boxServerData:' + JSON.stringify(boxdata) + ) // 调试模式支持 vue Devtools (只有在同时开启调试模式和指定了调试地址才生效) // vue.min.js 生效时, 会导致 @click="window.open()" 报 "window" is not defined 错误 @@ -274,7 +283,16 @@ function getBoxData() { } }) - const box = { datas, usercfgs, sessions, curSessions, sysapps, syscfgs, appSubCaches, globalbaks } + const box = { + datas, + usercfgs, + sessions, + curSessions, + sysapps, + syscfgs, + appSubCaches, + globalbaks + } return box } @@ -611,8 +629,11 @@ async function apiRevertGlobalBak() { $.setdata(JSON.stringify(chavy_boxjs_userCfgs), $.KEY_usercfgs) $.setdata(JSON.stringify(chavy_boxjs_cur_sessions), $.KEY_cursessions) $.setdata(JSON.stringify(chavy_boxjs_app_subCaches), $.KEY_app_subCaches) - const isNull = (val) => [undefined, null, 'null', 'undefined', ''].includes(val) - Object.keys(datas).forEach((datkey) => $.setdata(isNull(datas[datkey]) ? '' : `${datas[datkey]}`, datkey)) + const isNull = (val) => + [undefined, null, 'null', 'undefined', ''].includes(val) + Object.keys(datas).forEach((datkey) => + $.setdata(isNull(datas[datkey]) ? '' : `${datas[datkey]}`, datkey) + ) } const boxdata = getBoxData() $.json = boxdata @@ -657,9 +678,17 @@ async function apiRunScript() { } else { script_text = opts.script } - if ($.isSurge() && !$.isLoon() && !$.isShadowrocket() && ishttpapi) { + if ( + $.isSurge() && + !$.isLoon() && + !$.isShadowrocket() && + !$.isStash() && + ishttpapi + ) { const runOpts = { timeout: opts.timeout } - await $.runScript(script_text, runOpts).then((resp) => ($.json = JSON.parse(resp))) + await $.runScript(script_text, runOpts).then( + (resp) => ($.json = JSON.parse(resp)) + ) } else { await new Promise((resolve) => { $eval_env.resolve = resolve From a6ead621b1bf8f80b0ba1a817c425cae2b99ddb3 Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 22 Nov 2022 09:08:15 +0800 Subject: [PATCH 153/311] =?UTF-8?q?fix(=E9=A1=BA=E4=B8=B0=E9=80=9F?= =?UTF-8?q?=E8=BF=90):=20=E4=BF=AE=E5=A4=8D=E7=AD=BE=E5=88=B0=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/sfexpress.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 13528a269..890deb768 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -38,7 +38,7 @@ function loginweb() { function sign() { const signOpts = { - url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/integralTaskSignPlusService/automaticSignFetchPackage`, + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/commonPost/~memberNonactivity~integralTaskSignPlusService~automaticSignFetchPackage`, body: `{"comeFrom": "vioin", "channelFrom": "SFAPP"}`, headers: { 'Content-Type': 'application/json' From 25324157dd45aaa5f6c9830f0ed7c08ba7e39d35 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 14 Dec 2022 16:28:56 +0800 Subject: [PATCH 154/311] feat(testflight): add script --- box/chavy.boxjs.json | 153 ++++++++++++++++++--- testflight/rewrite/testflight.har.sgmodule | 8 ++ testflight/rewrite/testflight.sgmodule | 5 + testflight/testflight.har.js | 13 ++ testflight/testflight.js | 114 +++++++++++++++ 5 files changed, 276 insertions(+), 17 deletions(-) create mode 100644 testflight/rewrite/testflight.har.sgmodule create mode 100644 testflight/rewrite/testflight.sgmodule create mode 100644 testflight/testflight.har.js create mode 100644 testflight/testflight.js diff --git a/box/chavy.boxjs.json b/box/chavy.boxjs.json index 82dc0a67b..fc1ce512c 100644 --- a/box/chavy.boxjs.json +++ b/box/chavy.boxjs.json @@ -43,8 +43,20 @@ "chavy_findlotteryheader_10010" ], "settings": [ - { "id": "chavy_golottery_10010", "name": "天天抽奖", "val": true, "type": "boolean", "desc": "天天抽奖开关" }, - { "id": "chavy_gosign_10010", "name": "签到", "val": true, "type": "boolean", "desc": "签到开关" } + { + "id": "chavy_golottery_10010", + "name": "天天抽奖", + "val": true, + "type": "boolean", + "desc": "天天抽奖开关" + }, + { + "id": "chavy_gosign_10010", + "name": "签到", + "val": true, + "type": "boolean", + "desc": "签到开关" + } ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/10010", @@ -90,10 +102,34 @@ "name": "百度签到", "keys": ["chavy_cookie_tieba"], "settings": [ - { "id": "CFG_tieba_isOrderBars", "name": "按连签排序", "val": false, "type": "boolean", "desc": "默认按经验排序" }, - { "id": "CFG_tieba_maxShowBars", "name": "每页显示数", "val": 15, "type": "number", "desc": "每页最显示多少个吧信息" }, - { "id": "CFG_tieba_maxSignBars", "name": "每次并发", "val": 5, "type": "number", "desc": "每次并发签到多少个吧" }, - { "id": "CFG_tieba_signWaitTime", "name": "并发间隔 (毫秒)", "val": 2000, "type": "number", "desc": "每次并发间隔时间" } + { + "id": "CFG_tieba_isOrderBars", + "name": "按连签排序", + "val": false, + "type": "boolean", + "desc": "默认按经验排序" + }, + { + "id": "CFG_tieba_maxShowBars", + "name": "每页显示数", + "val": 15, + "type": "number", + "desc": "每页最显示多少个吧信息" + }, + { + "id": "CFG_tieba_maxSignBars", + "name": "每次并发", + "val": 5, + "type": "number", + "desc": "每次并发签到多少个吧" + }, + { + "id": "CFG_tieba_signWaitTime", + "name": "并发间隔 (毫秒)", + "val": 2000, + "type": "number", + "desc": "每次并发间隔时间" + } ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/tieba", @@ -118,7 +154,11 @@ { "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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.js", @@ -130,7 +170,11 @@ { "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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js", @@ -202,8 +246,20 @@ "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" } + { + "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", @@ -246,7 +302,11 @@ { "id": "qmkg", "name": "全民K歌", - "keys": ["senku_signurl_qmkg", "senku_signheader_qmkg", "senku_signbody_qmkg"], + "keys": [ + "senku_signurl_qmkg", + "senku_signheader_qmkg", + "senku_signbody_qmkg" + ], "author": "@GideonSenku", "repo": "https://github.com/chavyleung/scripts/tree/master/qmkg", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.js", @@ -294,7 +354,15 @@ { "id": "chavyleung.suning", "name": "苏宁易购", - "settings": [{ "id": "chavy_logflag_suning", "name": "响应日志", "val": false, "type": "boolean", "desc": "是否输出响应返回体" }], + "settings": [ + { + "id": "chavy_logflag_suning", + "name": "响应日志", + "val": false, + "type": "boolean", + "desc": "是否输出响应返回体" + } + ], "keys": [ "chavy_login_url_suning", "chavy_login_body_suning", @@ -388,7 +456,13 @@ "name": "网易云音乐", "keys": ["chavy_cookie_neteasemusic"], "settings": [ - { "id": "CFG_neteasemusic_retryCnt", "name": "重试次数", "val": 10, "type": "text", "desc": "一直尝试签到直至出现“重复签到”标识!" }, + { + "id": "CFG_neteasemusic_retryCnt", + "name": "重试次数", + "val": 10, + "type": "text", + "desc": "一直尝试签到直至出现“重复签到”标识!" + }, { "id": "CFG_neteasemusic_retryInterval", "name": "重试间隔 (毫秒)", @@ -420,7 +494,11 @@ { "id": "NoteYoudao", "name": "有道云笔记", - "keys": ["chavy_signurl_noteyoudao", "chavy_signbody_noteyoudao", "chavy_signheaders_noteyoudao"], + "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", @@ -442,7 +520,11 @@ { "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", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/zxhc/zxhc.js", @@ -489,7 +571,12 @@ ], "tasks": [{ "cron": "3 0 * * *", "script": "apktw.js" }], "rewrites": [ - { "type": "request", "pattern": "^https://apk.tw/member.php(.*?)action=login", "script": "apktw.cookie.js", "body": true } + { + "type": "request", + "pattern": "^https://apk.tw/member.php(.*?)action=login", + "script": "apktw.cookie.js", + "body": true + } ] }, { @@ -520,7 +607,15 @@ "id": "WPS", "name": "WPS", "keys": ["chavy_signhomeurl_wps", "chavy_signhomeheader_wps"], - "settings": [{ "id": "CFG_wps_inviteTime", "name": "邀请间隔 (毫秒)", "val": 2000, "type": "number", "desc": "每次邀请间隔时间" }], + "settings": [ + { + "id": "CFG_wps_inviteTime", + "name": "邀请间隔 (毫秒)", + "val": 2000, + "type": "number", + "desc": "每次邀请间隔时间" + } + ], "author": "@chavyleung", "repo": "https://github.com/chavyleung/scripts/tree/master/wps", "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/wps/wps.js", @@ -564,6 +659,30 @@ "https://raw.githubusercontent.com/Orz-3/mini/master/Color/everphoto.png" ], "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js" + }, + { + "id": "testflight", + "name": "TestFlight", + "keys": ["boxapp_testflight_har"], + "settings": [ + { + "id": "boxapp_testflight_app", + "name": "应用编号", + "val": "", + "type": "textarea", + "placeholder": "McBV96Wi,lNmLTx8d,ZfyeFB1S,srPJRks9,uEXBDwt2", + "autoGrow": true, + "rows": 5, + "desc": "以英文逗号分隔多个号码" + } + ], + "author": "@chavyleung", + "repo": "https://github.com/chavyleung/scripts/blob/master/testflight", + "script": "https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/testflight.js", + "icons": [ + "https://raw.githubusercontent.com/githubdulong/Script/master/Images/testflight.png", + "https://raw.githubusercontent.com/githubdulong/Script/master/Images/testflight.png" + ] } ] } diff --git a/testflight/rewrite/testflight.har.sgmodule b/testflight/rewrite/testflight.har.sgmodule new file mode 100644 index 000000000..cfb067978 --- /dev/null +++ b/testflight/rewrite/testflight.har.sgmodule @@ -0,0 +1,8 @@ +#!name=@boxapp/script-testflight +#!desc=Get TestFlight Har + +[Script] +TestFlight HAR = type=http-request,pattern=^https:\/\/testflight\.apple\.com\/v3\/accounts/.*\/apps$,requires-body=0,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/testflight.har.js + +[MITM] +hostname = testflight.apple.com diff --git a/testflight/rewrite/testflight.sgmodule b/testflight/rewrite/testflight.sgmodule new file mode 100644 index 000000000..bedef060b --- /dev/null +++ b/testflight/rewrite/testflight.sgmodule @@ -0,0 +1,5 @@ +#!name=@boxapp/script-testflight +#!desc=Auto Join TestFlight + +[Script] +TestFlight = type=cron,cronexp=*/1 * * * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/testflight.js,wake-system=0,timeout=180 diff --git a/testflight/testflight.har.js b/testflight/testflight.har.js new file mode 100644 index 000000000..502708f5f --- /dev/null +++ b/testflight/testflight.har.js @@ -0,0 +1,13 @@ +const $ = new Env('TestFlight') + +!(async () => { + const KEY = 'boxapp_testflight_har' + const har = { url: $request.url, headers: $request.headers } + $.setjson(har, KEY) + console.log(har) +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} diff --git a/testflight/testflight.js b/testflight/testflight.js new file mode 100644 index 000000000..1aac4ebef --- /dev/null +++ b/testflight/testflight.js @@ -0,0 +1,114 @@ +const $ = new Env('TestFlight') + +!(async () => { + const KEY_har = 'boxapp_testflight_har' + const KEY_app = 'boxapp_testflight_app' + const har = $.getjson(KEY_har) + const appIds = $.getdata(KEY_app) + + if (!appIds) { + $.msg($.name, '请先指定需要加入测试的应用') + return + } + + if (!har) { + $.msg($.name, '请先使用脚本获取 TestFlight 账号信息') + return + } + + const ids = appIds.split(',') + for (let i = 0; i < ids.length; i++) { + const id = ids[i].trim() + const result = await join(id, har) + const success = result[0] + const message = result[1] + const data = result[2] + + if (success) { + $.msg($.name, `[${data.data.name} (${id})]: ${message}`) + + const newIds = ids.filter((i) => i !== id).join(',') + $.setdata(newIds, KEY_app) + continue + } + + if (!success && !data) { + $.msg($.name, message) + continue + } + } +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +function join(id, har) { + const key = har.url.replace(/(.*accounts\/)(.*)(\/apps)/, '$2') + return $.http + .get({ + url: `https://testflight.apple.com/v3/accounts/${key}/ru/${id}`, + headers: getHeaders(har) + }) + .then(async (resp) => { + const result = JSON.parse(resp.body) + + // {"data":null,"messages":[{"message":"This beta isn't accepting any new testers right now.","messageType":"ERROR","code":1110}]} + if (result.data === null) { + const message = + (result.messages && + result.messages[0] && + result.messages[0].message) || + '名额已满' + console.log(`[${id}]: ${message}`) + return [false, message, result] + } + + // {"data":{"status":"FULL","message":"This beta is full.", + if (result.data && result.data.status === 'FULL') { + const message = result.data.message || '名额已满' + console.log(`[${id}]: ${message}`) + return [false, message, result] + } + + return await accept(id, har) + }) + .catch((error) => { + console.log('-------------') + console.log(error) + if (error.status === 404) { + return [false, '不存在应用', null] + } + return [false, '未知错误', null] + }) +} + +function accept(id, har) { + const key = har.url.replace(/(.*accounts\/)(.*)(\/apps)/, '$2') + return $.http + .post({ + url: `https://testflight.apple.com/v3/accounts/${key}/ru/${id}/accept`, + headers: getHeaders(har) + }) + .then((resp) => { + const result = JSON.parse(resp.body) + return [true, '加入成功', result] + }) + .catch(() => { + return [false, '加入失败', null] + }) +} + +function getHeaders(har) { + const userAgent = har.headers['user-agent'] + const xRequestId = har.headers['x-request-id'] + const xSessionDigest = har.headers['x-session-digest'] + const xSessionId = har.headers['x-session-id'] + return { + 'user-agent': userAgent, + 'x-request-id': xRequestId, + 'x-session-digest': xSessionDigest, + 'x-session-id': xSessionId + } +} + +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} From c2013d5d6812c7656b0b5e8f5ceefe0d22956b13 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 14 Dec 2022 16:59:07 +0800 Subject: [PATCH 155/311] chore(testflight): add README.md --- testflight/README.md | 24 ++++++++++++++++++++++++ testflight/testflight.har.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 testflight/README.md diff --git a/testflight/README.md b/testflight/README.md new file mode 100644 index 000000000..3f0817afb --- /dev/null +++ b/testflight/README.md @@ -0,0 +1,24 @@ +# TestFlight +自动加入 TF (公测) + +## Surge + +### 说明: + +本脚本包含两个模块 +1. [testflight.har.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.har.sgmodule) + 1. 用于获取 TestFlight 账号信息, 获取完即可关掉 + 2. 与 `TestFlight账户管理` 冲突, 使用前请先临时关闭 + +2. [testflight.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.sgmodule) + 1. 定时任务, 每 `1分钟` 运行一次尝试加入 `TF` + +### 使用: +1. 安装远程 [testflight.har.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.har.sgmodule) 模块 +2. 打开 `TestFlight`, 脚本提示 `获取 TestFlight 账户成功` +3. 安装 [BoxJs订阅](http://boxjs.com/#/sub/add/https%3A%2F%2Fraw.githubusercontent.com%2Fchavyleung%2Fscripts%2Fmaster%2Fbox%2Fchavy.boxjs.json +) (如果之前已安装, 请直接更新订阅) +4. 打开 [BoxJs](http://boxjs.com/#/app/testflight), 并填写 `应用编号` (如: McBV96Wi,uEXBDwt2) + 1. 请使用`英文逗号`分隔`应用编号` +5. 关闭 [testflight.har.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.har.sgmodule) 模块 +6. 安装 [testflight.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.sgmodule) 模块 diff --git a/testflight/testflight.har.js b/testflight/testflight.har.js index 502708f5f..35a0ac3a0 100644 --- a/testflight/testflight.har.js +++ b/testflight/testflight.har.js @@ -4,7 +4,7 @@ const $ = new Env('TestFlight') const KEY = 'boxapp_testflight_har' const har = { url: $request.url, headers: $request.headers } $.setjson(har, KEY) - console.log(har) + $.msg($.name, '获取 TestFlight 账户成功') })() .catch((e) => $.logErr(e)) .finally(() => $.done()) From f6114d1ba74d773c45f8825c3d21a00937927612 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 14 Dec 2022 17:29:28 +0800 Subject: [PATCH 156/311] chore(testflight): update README.md --- testflight/README.md | 2 +- testflight/testflight.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testflight/README.md b/testflight/README.md index 3f0817afb..04200710e 100644 --- a/testflight/README.md +++ b/testflight/README.md @@ -11,7 +11,7 @@ 2. 与 `TestFlight账户管理` 冲突, 使用前请先临时关闭 2. [testflight.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.sgmodule) - 1. 定时任务, 每 `1分钟` 运行一次尝试加入 `TF` + 1. 定时任务, 每 `1秒` 运行一次尝试加入 `TF` ### 使用: 1. 安装远程 [testflight.har.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.har.sgmodule) 模块 diff --git a/testflight/testflight.js b/testflight/testflight.js index 1aac4ebef..9fc32f400 100644 --- a/testflight/testflight.js +++ b/testflight/testflight.js @@ -7,7 +7,7 @@ const $ = new Env('TestFlight') const appIds = $.getdata(KEY_app) if (!appIds) { - $.msg($.name, '请先指定需要加入测试的应用') + console.log('请先指定需要加入测试的应用') return } From 170507fd912ddc698b6b0077924551affcdd1403 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 14 Dec 2022 18:09:16 +0800 Subject: [PATCH 157/311] feat(testflight): auto close sgmodule --- testflight/testflight.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/testflight/testflight.js b/testflight/testflight.js index 9fc32f400..381299b03 100644 --- a/testflight/testflight.js +++ b/testflight/testflight.js @@ -1,4 +1,5 @@ const $ = new Env('TestFlight') +$.isDisableModule = false !(async () => { const KEY_har = 'boxapp_testflight_har' @@ -7,7 +8,8 @@ const $ = new Env('TestFlight') const appIds = $.getdata(KEY_app) if (!appIds) { - console.log('请先指定需要加入测试的应用') + $.isDisableModule = true + $.msg($.name, '请先指定需要加入测试的应用, 并重新打开模块') return } @@ -39,7 +41,23 @@ const $ = new Env('TestFlight') } })() .catch((e) => $.logErr(e)) - .finally(() => $.done()) + .finally(() => { + if ( + $.isDisableModule && + $.isSurge() && + !$.isLoon() && + !$.isShadowrocket() && + !$.isStash() + ) { + $.done( + $httpAPI('POST', '/v1/modules', { + '@boxapp/script-testflight': 'false' + }) + ) + } else { + $.done() + } + }) function join(id, har) { const key = har.url.replace(/(.*accounts\/)(.*)(\/apps)/, '$2') From a0d38aa46341eec07853d94708f2b9796f7bdc21 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 15 Dec 2022 09:24:39 +0800 Subject: [PATCH 158/311] chore: add thanks --- testflight/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testflight/README.md b/testflight/README.md index 04200710e..7e3bfdec3 100644 --- a/testflight/README.md +++ b/testflight/README.md @@ -22,3 +22,8 @@ 1. 请使用`英文逗号`分隔`应用编号` 5. 关闭 [testflight.har.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.har.sgmodule) 模块 6. 安装 [testflight.sgmodule](https://raw.githubusercontent.com/chavyleung/scripts/master/testflight/rewrite/testflight.sgmodule) 模块 + +## 感谢 +[@githubdulong](https://github.com/githubdulong) + +[@DecoAri](https://github.com/DecoAri) \ No newline at end of file From 515efc0f3fe57eb3b7c278cdf53a1f1cde77fd22 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Thu, 15 Dec 2022 15:50:27 +0800 Subject: [PATCH 159/311] fix(env.js): isSurge() Update Env.js --- Env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 834156e66..d57658ad5 100644 --- a/Env.js +++ b/Env.js @@ -52,7 +52,7 @@ function Env(name, opts) { } isSurge() { - return 'undefined' !== typeof $httpClient && 'undefined' === typeof $loon + return 'undefined' !== typeof $environment && $environment['surge-version'] } isLoon() { From cafe09a3d17c70ec168fe489f2880402f9057a7b Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Thu, 15 Dec 2022 15:56:55 +0800 Subject: [PATCH 160/311] fix(env.js): this.isStash() Update Env.js --- Env.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Env.js b/Env.js index d57658ad5..d8f1cacc1 100644 --- a/Env.js +++ b/Env.js @@ -226,7 +226,7 @@ function Env(name, opts) { } getval(key) { - if (this.isSurge() || this.isLoon()) { + if (this.isSurge() || this.isLoon() || this.isStash()) { return $persistentStore.read(key) } else if (this.isQuanX()) { return $prefs.valueForKey(key) @@ -239,7 +239,7 @@ function Env(name, opts) { } setval(val, key) { - if (this.isSurge() || this.isLoon()) { + if (this.isSurge() || this.isLoon() || this.isStash()) { return $persistentStore.write(val, key) } else if (this.isQuanX()) { return $prefs.setValueForKey(val, key) @@ -270,8 +270,8 @@ function Env(name, opts) { delete opts.headers['Content-Type'] delete opts.headers['Content-Length'] } - if (this.isSurge() || this.isLoon()) { - if (this.isSurge() && this.isNeedRewrite) { + if (this.isSurge() || this.isLoon() || this.isStash()) { + if ((this.isSurge() || this.isStash()) && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) } @@ -334,8 +334,8 @@ function Env(name, opts) { opts.headers['Content-Type'] = 'application/x-www-form-urlencoded' } if (opts.headers) delete opts.headers['Content-Length'] - if (this.isSurge() || this.isLoon()) { - if (this.isSurge() && this.isNeedRewrite) { + if (this.isSurge() || this.isLoon() || this.isStash()) { + if ((this.isSurge() || this.isStash()) && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) } @@ -449,7 +449,7 @@ function Env(name, opts) { if (typeof rawopts === 'string') { if (this.isLoon()) return rawopts else if (this.isQuanX()) return { 'open-url': rawopts } - else if (this.isSurge()) return { url: rawopts } + else if (this.isSurge() || this.isStash()) return { url: rawopts } else return undefined } else if (typeof rawopts === 'object') { if (this.isLoon()) { @@ -461,7 +461,7 @@ function Env(name, opts) { let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl let updatePasteboard = rawopts['update-pasteboard'] || rawopts.updatePasteboard return { 'open-url': openUrl, 'media-url': mediaUrl, 'update-pasteboard': updatePasteboard } - } else if (this.isSurge()) { + } else if (this.isSurge() || this.isStash()) { let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] return { url: openUrl } } @@ -470,7 +470,7 @@ function Env(name, opts) { } } if (!this.isMute) { - if (this.isSurge() || this.isLoon()) { + if (this.isSurge() || this.isLoon()|| this.isStash()) { $notification.post(title, subt, desc, toEnvOpts(opts)) } else if (this.isQuanX()) { $notify(title, subt, desc, toEnvOpts(opts)) @@ -494,7 +494,7 @@ function Env(name, opts) { } logErr(err, msg) { - const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon() + const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon()&& !this.isStash() if (!isPrintSack) { this.log('', `❗️${this.name}, 错误!`, err) } else { @@ -511,7 +511,7 @@ function Env(name, opts) { const costTime = (endTime - this.startTime) / 1000 this.log('', `🔔${this.name}, 结束! 🕛 ${costTime} 秒`) this.log() - if (this.isSurge() || this.isQuanX() || this.isLoon()) { + if (this.isSurge() || this.isQuanX() || this.isLoon() || this.isStash()) { $done(val) } else if (this.isNode()) { process.exit(1) From 8df29a9e64beec44213452c5b696a1d986668f2e Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 15 Dec 2022 16:03:39 +0800 Subject: [PATCH 161/311] fix(env.js): isSurge() exclude X-Surge-Skip-Scripting header --- Env.js | 2 +- Env.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Env.js b/Env.js index d8f1cacc1..5e1093ce5 100644 --- a/Env.js +++ b/Env.js @@ -335,7 +335,7 @@ function Env(name, opts) { } if (opts.headers) delete opts.headers['Content-Length'] if (this.isSurge() || this.isLoon() || this.isStash()) { - if ((this.isSurge() || this.isStash()) && this.isNeedRewrite) { + if (this.isSurge() && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) } diff --git a/Env.min.js b/Env.min.js index d71e8b985..d88e6c324 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()||this.isStash())(this.isSurge()||this.isStash())&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()||this.isStash()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 521ea0af94e32cc13ba9a46473f418744f28dd9a Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Thu, 15 Dec 2022 16:33:25 +0800 Subject: [PATCH 162/311] fix(env.js): isSurge() exclude X-Surge-Skip-Scripting header Update Env.js --- Env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 5e1093ce5..728fd4278 100644 --- a/Env.js +++ b/Env.js @@ -271,7 +271,7 @@ function Env(name, opts) { delete opts.headers['Content-Length'] } if (this.isSurge() || this.isLoon() || this.isStash()) { - if ((this.isSurge() || this.isStash()) && this.isNeedRewrite) { + if (this.isSurge() && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) } From 3a2c592b4465d325971dfd567fd36bb51f6a6920 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 15 Dec 2022 16:38:02 +0800 Subject: [PATCH 163/311] feat(env.js): env.min.js --- Env.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Env.min.js b/Env.min.js index d88e6c324..3f7f1521c 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()||this.isStash())(this.isSurge()||this.isStash())&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()||this.isStash()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()||this.isStash()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 899ff692b311880da8053c6818c578073112aef2 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 13 Jan 2023 08:47:38 +0800 Subject: [PATCH 164/311] fix(boxjs): add mitm hosts --- box/rewrite/boxjs.rewrite.loon.plugin | 3 +++ box/rewrite/boxjs.rewrite.loon.tf.plugin | 3 +++ box/rewrite/boxjs.rewrite.quanx.conf | 3 +++ box/rewrite/boxjs.rewrite.quanx.tf.conf | 5 ++++- box/rewrite/boxjs.rewrite.surge.sgmodule | 5 ++++- box/rewrite/boxjs.rewrite.surge.tf.sgmodule | 5 ++++- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.loon.plugin b/box/rewrite/boxjs.rewrite.loon.plugin index a2fa2a5f7..a312464a9 100644 --- a/box/rewrite/boxjs.rewrite.loon.plugin +++ b/box/rewrite/boxjs.rewrite.loon.plugin @@ -7,3 +7,6 @@ [Script] http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.loon.tf.plugin b/box/rewrite/boxjs.rewrite.loon.tf.plugin index a2fa2a5f7..a312464a9 100644 --- a/box/rewrite/boxjs.rewrite.loon.tf.plugin +++ b/box/rewrite/boxjs.rewrite.loon.tf.plugin @@ -7,3 +7,6 @@ [Script] http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.quanx.conf b/box/rewrite/boxjs.rewrite.quanx.conf index 7b808f9e4..477f37a4e 100644 --- a/box/rewrite/boxjs.rewrite.quanx.conf +++ b/box/rewrite/boxjs.rewrite.quanx.conf @@ -1 +1,4 @@ https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.quanx.tf.conf b/box/rewrite/boxjs.rewrite.quanx.tf.conf index 5cc55c23b..477f37a4e 100644 --- a/box/rewrite/boxjs.rewrite.quanx.tf.conf +++ b/box/rewrite/boxjs.rewrite.quanx.tf.conf @@ -1 +1,4 @@ -https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js \ No newline at end of file +https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.surge.sgmodule b/box/rewrite/boxjs.rewrite.surge.sgmodule index 29ebfc2f9..057dc2f7c 100644 --- a/box/rewrite/boxjs.rewrite.surge.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.sgmodule @@ -5,4 +5,7 @@ force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net [Script] -Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 \ No newline at end of file +Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule index 29ebfc2f9..057dc2f7c 100644 --- a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule @@ -5,4 +5,7 @@ force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net [Script] -Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 \ No newline at end of file +Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 + +[MITM] +hostname = %INSERT%, boxjs.com, boxjs.net From 9cb020d8db3b51ffaa5622270401aef94a613942 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 13 Jan 2023 08:59:07 +0800 Subject: [PATCH 165/311] fix(boxjs): remove qx mitm --- box/rewrite/boxjs.rewrite.quanx.conf | 3 --- box/rewrite/boxjs.rewrite.quanx.tf.conf | 3 --- 2 files changed, 6 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.quanx.conf b/box/rewrite/boxjs.rewrite.quanx.conf index 477f37a4e..7b808f9e4 100644 --- a/box/rewrite/boxjs.rewrite.quanx.conf +++ b/box/rewrite/boxjs.rewrite.quanx.conf @@ -1,4 +1 @@ https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js - -[MITM] -hostname = %INSERT%, boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.quanx.tf.conf b/box/rewrite/boxjs.rewrite.quanx.tf.conf index 477f37a4e..7b808f9e4 100644 --- a/box/rewrite/boxjs.rewrite.quanx.tf.conf +++ b/box/rewrite/boxjs.rewrite.quanx.tf.conf @@ -1,4 +1 @@ https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js - -[MITM] -hostname = %INSERT%, boxjs.com, boxjs.net From 1f2ef7ee0715a25e03726471f85820556ed2158c Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 13 Jan 2023 09:09:41 +0800 Subject: [PATCH 166/311] fix(boxjs): qx hostname --- box/rewrite/boxjs.rewrite.quanx.conf | 2 ++ box/rewrite/boxjs.rewrite.quanx.tf.conf | 2 ++ 2 files changed, 4 insertions(+) diff --git a/box/rewrite/boxjs.rewrite.quanx.conf b/box/rewrite/boxjs.rewrite.quanx.conf index 7b808f9e4..d1a9a2bd0 100644 --- a/box/rewrite/boxjs.rewrite.quanx.conf +++ b/box/rewrite/boxjs.rewrite.quanx.conf @@ -1 +1,3 @@ +hostname = boxjs.com, boxjs.net + https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js diff --git a/box/rewrite/boxjs.rewrite.quanx.tf.conf b/box/rewrite/boxjs.rewrite.quanx.tf.conf index 7b808f9e4..d1a9a2bd0 100644 --- a/box/rewrite/boxjs.rewrite.quanx.tf.conf +++ b/box/rewrite/boxjs.rewrite.quanx.tf.conf @@ -1 +1,3 @@ +hostname = boxjs.com, boxjs.net + https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js From 9f1d91d09cecce84691c30e6a31c812ab00667af Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 13 Jan 2023 09:15:33 +0800 Subject: [PATCH 167/311] fix(env.js): shadowrocket env --- Env.js | 98 +++++++++++++++++++++++++++++++++++++++++++----------- Env.min.js | 2 +- 2 files changed, 80 insertions(+), 20 deletions(-) diff --git a/Env.js b/Env.js index 728fd4278..90c977cbe 100644 --- a/Env.js +++ b/Env.js @@ -226,7 +226,12 @@ function Env(name, opts) { } getval(key) { - if (this.isSurge() || this.isLoon() || this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isLoon() || + this.isStash() + ) { return $persistentStore.read(key) } else if (this.isQuanX()) { return $prefs.valueForKey(key) @@ -239,7 +244,12 @@ function Env(name, opts) { } setval(val, key) { - if (this.isSurge() || this.isLoon() || this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isLoon() || + this.isStash() + ) { return $persistentStore.write(val, key) } else if (this.isQuanX()) { return $prefs.setValueForKey(val, key) @@ -270,7 +280,12 @@ function Env(name, opts) { delete opts.headers['Content-Type'] delete opts.headers['Content-Length'] } - if (this.isSurge() || this.isLoon() || this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isLoon() || + this.isStash() + ) { if (this.isSurge() && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) @@ -302,7 +317,9 @@ function Env(name, opts) { .on('redirect', (resp, nextOpts) => { try { if (resp.headers['set-cookie']) { - const ck = resp.headers['set-cookie'].map(this.cktough.Cookie.parse).toString() + const ck = resp.headers['set-cookie'] + .map(this.cktough.Cookie.parse) + .toString() if (ck) { this.ckjar.setCookieSync(ck, null) } @@ -314,15 +331,23 @@ function Env(name, opts) { // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) }) .then( - (resp) => { + ;(resp) => { const { statusCode: status, statusCode, headers, rawBody } = resp const body = iconv.decode(rawBody, this.encoding) - callback(null, { status, statusCode, headers, rawBody, body }, body) + callback( + null, + { status, statusCode, headers, rawBody, body }, + body + ) }, - (err) => { - const { message: error, response: resp } = err - callback(error, resp, resp && iconv.decode(resp.rawBody, this.encoding)) - } + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } ) } } @@ -334,7 +359,12 @@ function Env(name, opts) { opts.headers['Content-Type'] = 'application/x-www-form-urlencoded' } if (opts.headers) delete opts.headers['Content-Length'] - if (this.isSurge() || this.isLoon() || this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isLoon() || + this.isStash() + ) { if (this.isSurge() && this.isNeedRewrite) { opts.headers = opts.headers || {} Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) @@ -372,7 +402,11 @@ function Env(name, opts) { }, (err) => { const { message: error, response: resp } = err - callback(error, resp, resp && iconv.decode(resp.rawBody, this.encoding)) + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) } ) } @@ -449,7 +483,8 @@ function Env(name, opts) { if (typeof rawopts === 'string') { if (this.isLoon()) return rawopts else if (this.isQuanX()) return { 'open-url': rawopts } - else if (this.isSurge() || this.isStash()) return { url: rawopts } + else if (this.isSurge() || this.isShadowrocket() || this.isStash()) + return { url: rawopts } else return undefined } else if (typeof rawopts === 'object') { if (this.isLoon()) { @@ -459,9 +494,18 @@ function Env(name, opts) { } else if (this.isQuanX()) { let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl - let updatePasteboard = rawopts['update-pasteboard'] || rawopts.updatePasteboard - return { 'open-url': openUrl, 'media-url': mediaUrl, 'update-pasteboard': updatePasteboard } - } else if (this.isSurge() || this.isStash()) { + let updatePasteboard = + rawopts['update-pasteboard'] || rawopts.updatePasteboard + return { + 'open-url': openUrl, + 'media-url': mediaUrl, + 'update-pasteboard': updatePasteboard + } + } else if ( + this.isSurge() || + this.isShadowrocket() || + this.isStash() + ) { let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] return { url: openUrl } } @@ -470,7 +514,12 @@ function Env(name, opts) { } } if (!this.isMute) { - if (this.isSurge() || this.isLoon()|| this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isLoon() || + this.isStash() + ) { $notification.post(title, subt, desc, toEnvOpts(opts)) } else if (this.isQuanX()) { $notify(title, subt, desc, toEnvOpts(opts)) @@ -494,7 +543,12 @@ function Env(name, opts) { } logErr(err, msg) { - const isPrintSack = !this.isSurge() && !this.isQuanX() && !this.isLoon()&& !this.isStash() + const isPrintSack = + !this.isSurge() && + !this.isShadowrocket() && + !this.isQuanX() && + !this.isLoon() && + !this.isStash() if (!isPrintSack) { this.log('', `❗️${this.name}, 错误!`, err) } else { @@ -511,7 +565,13 @@ function Env(name, opts) { const costTime = (endTime - this.startTime) / 1000 this.log('', `🔔${this.name}, 结束! 🕛 ${costTime} 秒`) this.log() - if (this.isSurge() || this.isQuanX() || this.isLoon() || this.isStash()) { + if ( + this.isSurge() || + this.isShadowrocket() || + this.isQuanX() || + this.isLoon() || + this.isStash() + ) { $done(val) } else if (this.isNode()) { process.exit(1) diff --git a/Env.min.js b/Env.min.js index 3f7f1521c..b88cb681c 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=s.decode(h,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()||this.isStash()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()||this.isShadowrocket()&&!this.isQuanX()&&!this.isLoon()&&!this.isStash();e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file From 2c93d1e1b4b7bb545826f497ce368ad113dcc24c Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 2 Feb 2023 08:41:08 +0800 Subject: [PATCH 168/311] chore(boxjs): improve sgmodule --- box/rewrite/boxjs.rewrite.surge.sgmodule | 2 +- box/rewrite/boxjs.rewrite.surge.tf.sgmodule | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.surge.sgmodule b/box/rewrite/boxjs.rewrite.surge.sgmodule index 057dc2f7c..d5f0383ad 100644 --- a/box/rewrite/boxjs.rewrite.surge.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.sgmodule @@ -8,4 +8,4 @@ force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 [MITM] -hostname = %INSERT%, boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule index 057dc2f7c..d5f0383ad 100644 --- a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule @@ -8,4 +8,4 @@ force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 [MITM] -hostname = %INSERT%, boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net From d46332ef5a52deb5266db9ce0b2f88ef9a67d10a Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Tue, 7 Feb 2023 14:25:20 +0800 Subject: [PATCH 169/311] feat(boxjs.rewrite.loon.plugin): add Rule supported --- box/rewrite/boxjs.rewrite.loon.plugin | 5 ++++- box/rewrite/boxjs.rewrite.loon.tf.plugin | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.loon.plugin b/box/rewrite/boxjs.rewrite.loon.plugin index a2fa2a5f7..c0488b393 100644 --- a/box/rewrite/boxjs.rewrite.loon.plugin +++ b/box/rewrite/boxjs.rewrite.loon.plugin @@ -3,7 +3,10 @@ #!openUrl=http://boxjs.com #!author=chavyleung #!homepage=https://chavyleung.gitbook.io/boxjs/ -#!icon= https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png +#!icon=https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png + +[Rule] +DOMAIN-SUFFIX,jsdelivr.net,PROXY [Script] http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs diff --git a/box/rewrite/boxjs.rewrite.loon.tf.plugin b/box/rewrite/boxjs.rewrite.loon.tf.plugin index a2fa2a5f7..0ffd75184 100644 --- a/box/rewrite/boxjs.rewrite.loon.tf.plugin +++ b/box/rewrite/boxjs.rewrite.loon.tf.plugin @@ -1,9 +1,12 @@ #!name=BoxJs -#!desc=Data manager -#!openUrl=http://boxjs.com +#!desc=(TF)Data manager +#!openUrl=http://boxjs.net #!author=chavyleung #!homepage=https://chavyleung.gitbook.io/boxjs/ -#!icon= https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png +#!icon=https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png + +[Rule] +DOMAIN-SUFFIX,jsdelivr.net,PROXY [Script] http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs From d215e1dda4242be7e140f62281e4be7980acb9e0 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 8 Feb 2023 08:25:15 +0800 Subject: [PATCH 170/311] chore(boxjs): improve loon plugin --- box/rewrite/boxjs.rewrite.loon.plugin | 2 +- box/rewrite/boxjs.rewrite.loon.tf.plugin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.loon.plugin b/box/rewrite/boxjs.rewrite.loon.plugin index 1a4d129fa..542e74bef 100644 --- a/box/rewrite/boxjs.rewrite.loon.plugin +++ b/box/rewrite/boxjs.rewrite.loon.plugin @@ -12,4 +12,4 @@ DOMAIN-SUFFIX,jsdelivr.net,PROXY http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs [MITM] -hostname = %INSERT%, boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net diff --git a/box/rewrite/boxjs.rewrite.loon.tf.plugin b/box/rewrite/boxjs.rewrite.loon.tf.plugin index b5e3f71ca..79e712bdf 100644 --- a/box/rewrite/boxjs.rewrite.loon.tf.plugin +++ b/box/rewrite/boxjs.rewrite.loon.tf.plugin @@ -12,4 +12,4 @@ DOMAIN-SUFFIX,jsdelivr.net,PROXY http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs [MITM] -hostname = %INSERT%, boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net From ab9ec24805bf733a2de6f271cd52a19fd8c4292c Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Wed, 8 Feb 2023 10:24:43 +0800 Subject: [PATCH 171/311] fix(boxjs): regex for *.boxjs.com/net --- box/rewrite/boxjs.rewrite.loon.plugin | 4 ++-- box/rewrite/boxjs.rewrite.loon.tf.plugin | 4 ++-- box/rewrite/boxjs.rewrite.quanx.conf | 4 ++-- box/rewrite/boxjs.rewrite.quanx.tf.conf | 4 ++-- box/rewrite/boxjs.rewrite.stash.stoverride | 6 +++++- box/rewrite/boxjs.rewrite.stash.tf.stoverride | 8 ++++++-- box/rewrite/boxjs.rewrite.surge.sgmodule | 6 +++--- box/rewrite/boxjs.rewrite.surge.tf.sgmodule | 8 ++++---- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.loon.plugin b/box/rewrite/boxjs.rewrite.loon.plugin index 542e74bef..7ba1bb70d 100644 --- a/box/rewrite/boxjs.rewrite.loon.plugin +++ b/box/rewrite/boxjs.rewrite.loon.plugin @@ -9,7 +9,7 @@ DOMAIN-SUFFIX,jsdelivr.net,PROXY [Script] -http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs +http-request ^https?:\/\/(.+\.)?boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs [MITM] -hostname = %INSERT% boxjs.com, boxjs.net +hostname = boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net diff --git a/box/rewrite/boxjs.rewrite.loon.tf.plugin b/box/rewrite/boxjs.rewrite.loon.tf.plugin index 79e712bdf..78b01baf9 100644 --- a/box/rewrite/boxjs.rewrite.loon.tf.plugin +++ b/box/rewrite/boxjs.rewrite.loon.tf.plugin @@ -9,7 +9,7 @@ DOMAIN-SUFFIX,jsdelivr.net,PROXY [Script] -http-request ^https?:\/\/boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs +http-request ^https?:\/\/(.+\.)?boxjs\.(com|net) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120, tag=BoxJs [MITM] -hostname = %INSERT% boxjs.com, boxjs.net +hostname = boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net diff --git a/box/rewrite/boxjs.rewrite.quanx.conf b/box/rewrite/boxjs.rewrite.quanx.conf index d1a9a2bd0..0955c0896 100644 --- a/box/rewrite/boxjs.rewrite.quanx.conf +++ b/box/rewrite/boxjs.rewrite.quanx.conf @@ -1,3 +1,3 @@ -hostname = boxjs.com, boxjs.net +hostname = boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net -https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js +^https?:\/\/(.+\.)?boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js diff --git a/box/rewrite/boxjs.rewrite.quanx.tf.conf b/box/rewrite/boxjs.rewrite.quanx.tf.conf index d1a9a2bd0..0955c0896 100644 --- a/box/rewrite/boxjs.rewrite.quanx.tf.conf +++ b/box/rewrite/boxjs.rewrite.quanx.tf.conf @@ -1,3 +1,3 @@ -hostname = boxjs.com, boxjs.net +hostname = boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net -https?:\/\/boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js +^https?:\/\/(.+\.)?boxjs\.(com|net) url script-analyze-echo-response https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js diff --git a/box/rewrite/boxjs.rewrite.stash.stoverride b/box/rewrite/boxjs.rewrite.stash.stoverride index 788385789..b0506f54c 100644 --- a/box/rewrite/boxjs.rewrite.stash.stoverride +++ b/box/rewrite/boxjs.rewrite.stash.stoverride @@ -5,11 +5,15 @@ http: force-http-engine: - "boxjs.com:80" - "boxjs.net:80" + - "*.boxjs.com:80" + - "*.boxjs.net:80" mitm: - "boxjs.com" - "boxjs.net" + - "*.boxjs.com" + - "*.boxjs.net" script: - - match: https?:\/\/boxjs\.(com|net) + - match: ^https?:\/\/(.+\.)?boxjs\.(com|net) name: BoxJs type: request require-body: true diff --git a/box/rewrite/boxjs.rewrite.stash.tf.stoverride b/box/rewrite/boxjs.rewrite.stash.tf.stoverride index 788385789..79018947f 100644 --- a/box/rewrite/boxjs.rewrite.stash.tf.stoverride +++ b/box/rewrite/boxjs.rewrite.stash.tf.stoverride @@ -1,15 +1,19 @@ name: BoxJs -desc: http://boxjs.com +desc: http://boxjs.net http: force-http-engine: - "boxjs.com:80" - "boxjs.net:80" + - "*.boxjs.com:80" + - "*.boxjs.net:80" mitm: - "boxjs.com" - "boxjs.net" + - "*.boxjs.com" + - "*.boxjs.net" script: - - match: https?:\/\/boxjs\.(com|net) + - match: ^https?:\/\/(.+\.)?boxjs\.(com|net) name: BoxJs type: request require-body: true diff --git a/box/rewrite/boxjs.rewrite.surge.sgmodule b/box/rewrite/boxjs.rewrite.surge.sgmodule index d5f0383ad..f87d90d82 100644 --- a/box/rewrite/boxjs.rewrite.surge.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.sgmodule @@ -2,10 +2,10 @@ #!desc=http://boxjs.com [General] -force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net +force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net [Script] -Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 +Rewrite: BoxJs = type=http-request,pattern=^https?:\/\/(.+\.)?boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 [MITM] -hostname = %INSERT% boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net diff --git a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule index d5f0383ad..98a9d8e1d 100644 --- a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule @@ -1,11 +1,11 @@ #!name=BoxJs -#!desc=http://boxjs.com +#!desc=http://boxjs.net [General] -force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net +force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net [Script] -Rewrite: BoxJs = type=http-request,pattern=https?:\/\/boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 +Rewrite: BoxJs = type=http-request,pattern=^https?:\/\/(.+\.)?boxjs\.(com|net),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/chavy.boxjs.js, requires-body=true, timeout=120 [MITM] -hostname = %INSERT% boxjs.com, boxjs.net +hostname = %INSERT% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net From 9faa4215367991be0ed851662dee06078d6f51df Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Thu, 9 Feb 2023 15:34:12 +0800 Subject: [PATCH 172/311] feat: add citybox sign --- citybox/citybox.cookie.js | 32 ++++++++++++++++++++++++++++++++ citybox/citybox.js | 35 +++++++++++++++++++++++++++++++++++ surge.cookies.sgmodule | 1 + surge.tasks.sgmodule | 1 + 4 files changed, 69 insertions(+) create mode 100644 citybox/citybox.cookie.js create mode 100644 citybox/citybox.js diff --git a/citybox/citybox.cookie.js b/citybox/citybox.cookie.js new file mode 100644 index 000000000..1800835e8 --- /dev/null +++ b/citybox/citybox.cookie.js @@ -0,0 +1,32 @@ +/** + * + * hostname = api.icitybox.cn + * + * # Surge + * Rewrite: citybox = type=http-request,pattern=^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_info,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js,debug=true + * Tasks: citybox-签到 = type=cron,cronexp=10 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js,wake-system=true + * + * # QuanX + * ^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_info url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js + * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js, tag=citybox-签到 + * + * # Loon + * http-request ^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_infoscript-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js, tag=citybox + * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js + * + * # 获取方式:进入签到页面获取,进入citybox小程序即可 + */ + +const $ = new Env('魔盒') + +!(async () => { + const KEY = 'boxapp_citybox_har' + const har = { url: $request.url, headers: $request.headers } + $.setjson(har, KEY) + $.msg($.name, '获取 CityBox 账户成功') +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) + +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file diff --git a/citybox/citybox.js b/citybox/citybox.js new file mode 100644 index 000000000..af0addf81 --- /dev/null +++ b/citybox/citybox.js @@ -0,0 +1,35 @@ +const $ = new Env('魔盒') + +!(async () => { + const KEY_har = 'boxapp_citybox_har' + const har = $.getjson(KEY_har) + const headers = har?.headers + await sign(headers) + if ($.sign?.signnum) { + $.msg($.name, `第${$.sign.signnum}天 签到成功`) + } else if ($.sign?.message) { + $.msg($.name, $.sign?.message) + } else { + $.msg($.name, '签到失败') + } +})() + +function sign(headers) { + return new Promise((resolve) => { + const url = { + url: 'https://api.icitybox.cn/index.php/api/user/up_sign', + headers, + } + $.get(url, (err, resp, data) => { + try { + $.sign = JSON.parse(data) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} diff --git a/surge.cookies.sgmodule b/surge.cookies.sgmodule index 312996635..91fec1960 100644 --- a/surge.cookies.sgmodule +++ b/surge.cookies.sgmodule @@ -54,6 +54,7 @@ Rewrite: 喜马拉雅 = type=http-request,pattern=^https?:\/\/.*\/mobile\-user\/ Rewrite: 字幕组 = type=http-request,pattern=^http:\/\/ios.zmzapi.com\/index.php.*a=(mobile_)?login,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js Rewrite: 字幕组 = type=http-request,pattern=^https?:\/\/(www\.)?rrys2020\.com\/?.?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.cookie.js Rewrite: 智行火车 = type=http-request,pattern=^https:\/\/m\.ctrip\.com/restapi/soa2/14593/json/attendanceDay?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zxhc/zxhc.cookie.js,requires-body=true +Rewrite: citybox = type=http-request,pattern=^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_info,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js,debug=true [MITM] hostname = %INSERT%, apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning.com, passport.suning.com, sign.suning.com, gameapi.suning.com, m.ctrip.com, 110.43.90.61, zt.wps.cn, m-bean.kaola.com, daojia.jd.com, app.nio.com, wxprdapplet.gac-nio.com, node.kg.qq.com, api.dushu.io, pm.m.fenqile.com, maicai.api.ddxq.mobi, group.baicizhan.com, api.everphoto.cn, i.meituan.com, promotion.waimai.meituan.com, wx.10086.cn, www.maomicd.com, m.client.10010.com, act.10010.com, api-takumi.mihoyo.com, m.gdoil.cn, credits.bz.mgtv.com, *.csdn.net, wapside.189.cn, *.acfun.cn, apk.tw, *.bilibili.com, api.dongqiudi.com, *.feng.com, www.flyertea.com, music.163.com, *.m.163.com, user.qunar.com, *.rr.tv, sf-integral-sign-in.weixinjia.net, mcs-mimp-web.sf-express.com, *.smzdm.com, tieba.baidu.com, *.v2ex.com, *.video.qq.com, 113.96.156.178, *.ximalaya.com, *.you.163.com, *.rrys2020.com, ios.zmzapi.com \ No newline at end of file diff --git a/surge.tasks.sgmodule b/surge.tasks.sgmodule index 669296b1b..d1edf170a 100644 --- a/surge.tasks.sgmodule +++ b/surge.tasks.sgmodule @@ -28,6 +28,7 @@ Tasks: 苏宁易购 = type=cron,cronexp=7 0 * * *,script-path=https://raw.github Tasks: 顺丰速运 = type=cron,cronexp=6 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/sfexpress/sfexpress.js,wake-system=true Tasks: 网易云音乐 = type=cron,cronexp=1 7 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/neteasemusic.js,wake-system=true Tasks: 字幕组 = type=cron,cronexp=3 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zimuzu/zimuzu.js,wake-system=true +Tasks: citybox-签到 = type=cron,cronexp=10 10 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js,wake-system=true # Tasks: 美团外卖 = type=cron,cronexp=8 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.js Rewrite: 头脑吃鸡 = type=http-response,pattern=^https://tncj.hortorgames.com/chicken/fight/(answer|findQuiz),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tncj/tncj.min.js,requires-body=true,max-size=0 From 9d0ebe60404c4a886841bf6f3fd5200df7770440 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Thu, 9 Feb 2023 16:44:37 +0800 Subject: [PATCH 173/311] fix: citybox done --- citybox/citybox.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/citybox/citybox.js b/citybox/citybox.js index af0addf81..dc973bb8a 100644 --- a/citybox/citybox.js +++ b/citybox/citybox.js @@ -13,6 +13,8 @@ const $ = new Env('魔盒') $.msg($.name, '签到失败') } })() +.catch((e) => $.logErr(e)) +.finally(() => $.done()) function sign(headers) { return new Promise((resolve) => { From 9008c53a491f711823d708fd5203e556556bbf0b Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 15 Mar 2023 15:10:29 +0800 Subject: [PATCH 174/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=8E=A7=E4=BB=B6=20=E5=8F=8A=20=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E6=8E=A7=E4=BB=B6=20=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=BB=98=E8=AE=A4=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 6 ++++-- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ chavy.box.js | 2 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index badbd71b1..f4cb655c3 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2576,12 +2576,14 @@

v{{ver.versio const key = setting.id const datval = this.datas[key] if (setting.type === 'boolean') { - setting.val = datval === null ? setting.val : datval === 'true' + setting.val = _.isEmpty(datval) ? setting.val : (datval === 'true' || datval === true) } else if (setting.type === 'int') { setting.val = datval * 1 || setting.val } else if (setting.type === 'checkboxes') { - if (!_.isNil(datval)) { + if (!_.isEmpty(datval)) { setting.val = datval ? datval.split(',') : [] + } else { + setting.val = Array.isArray(setting.val) ? setting.val : setting.val.split(',') } } else { setting.val = datval || setting.val diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 17e898ee6..b7d15aaf9 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.2' +$.version = '0.12.3' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 9dfc41664..f91f9242d 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.3", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 修复 开关控件 及 多选控件 不正确显示默认值问题", + "notes": [ + { + "name": "修复", + "descs": ["开关控件 及 多选控件 不正确显示默认值问题"] + } + ] + }, { "version": "0.12.2", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index fbae8e09b..024838225 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.3", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 修复 开关控件 及 多选控件 不正确显示默认值问题", + "notes": [ + { + "name": "修复", + "descs": ["开关控件 及 多选控件 不正确显示默认值问题"] + } + ] + }, { "version": "0.12.2", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 17e898ee6..b7d15aaf9 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.2' +$.version = '0.12.3' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From ae9f9be0076e9b92222ffbea38519f10da2a4f11 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 15 Mar 2023 15:13:17 +0800 Subject: [PATCH 175/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=8E=A7=E4=BB=B6=20=E5=8F=8A=20=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E6=8E=A7=E4=BB=B6=20=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=BB=98=E8=AE=A4=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/release/box.release.json | 4 ++++ box/release/box.release.tf.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/box/release/box.release.json b/box/release/box.release.json index f91f9242d..cf71f9d97 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -9,6 +9,10 @@ { "name": "修复", "descs": ["开关控件 及 多选控件 不正确显示默认值问题"] + }, + { + "name": "感谢", + "descs": ["@Virgil_C 反馈及协助"] } ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 024838225..31285086c 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -9,6 +9,10 @@ { "name": "修复", "descs": ["开关控件 及 多选控件 不正确显示默认值问题"] + }, + { + "name": "感谢", + "descs": ["@Virgil_C 反馈及协助"] } ] }, From e13e1c25245d6ce036fa1413c91be7908ca25ffd Mon Sep 17 00:00:00 2001 From: lowking Date: Wed, 15 Mar 2023 18:21:08 +0800 Subject: [PATCH 176/311] =?UTF-8?q?fix(Env):=20=E5=9C=A8boxjs=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E8=BF=9C=E7=A8=8B=E8=B0=83=E7=94=A8=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=97=B6=E6=9C=AA=E6=A0=B9=E6=8D=AEboxjs=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=BF=94=E5=9B=9E=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=98=AF=E7=A9=BA=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 90c977cbe..eb8504e57 100644 --- a/Env.js +++ b/Env.js @@ -119,7 +119,8 @@ function Env(name, opts) { const opts = { url: `http://${addr}/v1/scripting/evaluate`, body: { script_text: script, mock_type: 'cron', timeout: httpapi_timeout }, - headers: { 'X-Key': key, 'Accept': '*/*' } + headers: { 'X-Key': key, 'Accept': '*/*' }, + timeout: httpapi_timeout } this.post(opts, (err, resp, body) => resolve(body)) }).catch((e) => this.logErr(e)) From c978d1c6cc8585de5fc1bf432577ecb7fc060051 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 16 Mar 2023 08:46:44 +0800 Subject: [PATCH 177/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D=20Surg?= =?UTF-8?q?e=20=E7=8E=AF=E5=A2=83=E4=B8=8B=E6=89=A7=E8=A1=8C=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E8=B6=85=E6=97=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 94 +++++++++++++++++++++++---------- Env.min.js | 2 +- box/chavy.boxjs.js | 11 ++-- box/release/box.release.json | 16 ++++++ box/release/box.release.tf.json | 16 ++++++ chavy.box.js | 11 ++-- 6 files changed, 113 insertions(+), 37 deletions(-) diff --git a/Env.js b/Env.js index eb8504e57..029f00188 100644 --- a/Env.js +++ b/Env.js @@ -52,7 +52,9 @@ function Env(name, opts) { } isSurge() { - return 'undefined' !== typeof $environment && $environment['surge-version'] + return ( + 'undefined' !== typeof $environment && $environment['surge-version'] + ) } isLoon() { @@ -64,7 +66,9 @@ function Env(name, opts) { } isStash() { - return 'undefined' !== typeof $environment && $environment['stash-version'] + return ( + 'undefined' !== typeof $environment && $environment['stash-version'] + ) } toObj(str, defaultValue = null) { @@ -112,13 +116,20 @@ function Env(name, opts) { return new Promise((resolve) => { let httpapi = this.getdata('@chavy_boxjs_userCfgs.httpapi') httpapi = httpapi ? httpapi.replace(/\n/g, '').trim() : httpapi - let httpapi_timeout = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout') + let httpapi_timeout = this.getdata( + '@chavy_boxjs_userCfgs.httpapi_timeout' + ) httpapi_timeout = httpapi_timeout ? httpapi_timeout * 1 : 20 - httpapi_timeout = runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout + httpapi_timeout = + runOpts && runOpts.timeout ? runOpts.timeout : httpapi_timeout const [key, addr] = httpapi.split('@') const opts = { url: `http://${addr}/v1/scripting/evaluate`, - body: { script_text: script, mock_type: 'cron', timeout: httpapi_timeout }, + body: { + script_text: script, + mock_type: 'cron', + timeout: httpapi_timeout + }, headers: { 'X-Key': key, 'Accept': '*/*' }, timeout: httpapi_timeout } @@ -131,11 +142,17 @@ function Env(name, opts) { this.fs = this.fs ? this.fs : require('fs') this.path = this.path ? this.path : require('path') const curDirDataFilePath = this.path.resolve(this.dataFile) - const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) + const rootDirDataFilePath = this.path.resolve( + process.cwd(), + this.dataFile + ) const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) - const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) + const isRootDirDataFile = + !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) if (isCurDirDataFile || isRootDirDataFile) { - const datPath = isCurDirDataFile ? curDirDataFilePath : rootDirDataFilePath + const datPath = isCurDirDataFile + ? curDirDataFilePath + : rootDirDataFilePath try { return JSON.parse(this.fs.readFileSync(datPath)) } catch (e) { @@ -150,9 +167,13 @@ function Env(name, opts) { this.fs = this.fs ? this.fs : require('fs') this.path = this.path ? this.path : require('path') const curDirDataFilePath = this.path.resolve(this.dataFile) - const rootDirDataFilePath = this.path.resolve(process.cwd(), this.dataFile) + const rootDirDataFilePath = this.path.resolve( + process.cwd(), + this.dataFile + ) const isCurDirDataFile = this.fs.existsSync(curDirDataFilePath) - const isRootDirDataFile = !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) + const isRootDirDataFile = + !isCurDirDataFile && this.fs.existsSync(rootDirDataFilePath) const jsondata = JSON.stringify(this.data) if (isCurDirDataFile) { this.fs.writeFileSync(curDirDataFilePath, jsondata) @@ -181,9 +202,13 @@ function Env(name, opts) { if (!Array.isArray(path)) path = path.toString().match(/[^.[\]]+/g) || [] path .slice(0, -1) - .reduce((a, c, i) => (Object(a[c]) === a[c] ? a[c] : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {})), obj)[ - path[path.length - 1] - ] = value + .reduce( + (a, c, i) => + Object(a[c]) === a[c] + ? a[c] + : (a[c] = Math.abs(path[i + 1]) >> 0 === +path[i + 1] ? [] : {}), + obj + )[path[path.length - 1]] = value return obj } @@ -210,7 +235,11 @@ function Env(name, opts) { if (/^@/.test(key)) { const [, objkey, paths] = /^@(.*?)\.(.*?)$/.exec(key) const objdat = this.getval(objkey) - const objval = objkey ? (objdat === 'null' ? null : objdat || '{}') : '{}' + const objval = objkey + ? objdat === 'null' + ? null + : objdat || '{}' + : '{}' try { const objedval = JSON.parse(objval) this.lodash_set(objedval, paths, val) @@ -332,7 +361,7 @@ function Env(name, opts) { // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) }) .then( - ;(resp) => { + (resp) => { const { statusCode: status, statusCode, headers, rawBody } = resp const body = iconv.decode(rawBody, this.encoding) callback( @@ -341,14 +370,14 @@ function Env(name, opts) { body ) }, - (err) => { - const { message: error, response: resp } = err - callback( - error, - resp, - resp && iconv.decode(resp.rawBody, this.encoding) - ) - } + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } ) } } @@ -433,16 +462,25 @@ function Env(name, opts) { 'q+': Math.floor((date.getMonth() + 3) / 3), 'S': date.getMilliseconds() } - if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) + if (/(y+)/.test(fmt)) + fmt = fmt.replace( + RegExp.$1, + (date.getFullYear() + '').substr(4 - RegExp.$1.length) + ) for (let k in o) if (new RegExp('(' + k + ')').test(fmt)) - fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)) + fmt = fmt.replace( + RegExp.$1, + RegExp.$1.length == 1 + ? o[k] + : ('00' + o[k]).substr(('' + o[k]).length) + ) return fmt } /** - * - * @param {Object} options + * + * @param {Object} options * @returns {String} 将 Object 对象 转换成 queryStr: key=val&name=senku */ queryStr(options) { @@ -458,7 +496,7 @@ function Env(name, opts) { } } queryString = queryString.substring(0, queryString.length - 1) - + return queryString } diff --git a/Env.min.js b/Env.min.js index b88cb681c..84e9e557f 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()||this.isShadowrocket()&&!this.isQuanX()&&!this.isLoon()&&!this.isStash();e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index b7d15aaf9..def415752 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.3' +$.version = '0.12.4' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -742,7 +742,9 @@ async function apiSaveData() { function reloadAppSubCache(url) { // 地址后面拼时间缀, 避免 GET 缓存 - const requrl = `${url}${url.includes('?') ? '&' : '?'}_=${new Date().getTime()}` + const requrl = `${url}${ + url.includes('?') ? '&' : '?' + }_=${new Date().getTime()}` return $.http.get(requrl).then((resp) => { try { const subcaches = getAppSubCaches() @@ -850,7 +852,8 @@ function getBaseDoneHeaders(mixHeaders = {}) { { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PUT,DELETE', - 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' + 'Access-Control-Allow-Headers': + 'Origin, X-Requested-With, Content-Type, Accept' }, mixHeaders ) @@ -915,4 +918,4 @@ function GistBox(e){const t=function(e,t={}){const{isQX:s,isLoon:n,isSurge:o}=fu * EnvJs */ // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:i,statusCode:r,headers:o,rawBody:h},s.decode(h,this.encoding))},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:s,statusCode:r,headers:o,rawBody:h},i.decode(h,this.encoding))},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} diff --git a/box/release/box.release.json b/box/release/box.release.json index cf71f9d97..ee9822474 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.4", + "tags": ["beta"], + "author": "@lowking", + "msg": "fix(boxjs): 修复 Surge 环境下执行脚本超时问题", + "notes": [ + { + "name": "修复", + "descs": ["Surge 环境下执行脚本超时问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.12.3", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 31285086c..85de32bf7 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.4", + "tags": ["beta"], + "author": "@lowking", + "msg": "fix(boxjs): 修复 Surge 环境下执行脚本超时问题", + "notes": [ + { + "name": "修复", + "descs": ["Surge 环境下执行脚本超时问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.12.3", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index b7d15aaf9..def415752 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.3' +$.version = '0.12.4' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -742,7 +742,9 @@ async function apiSaveData() { function reloadAppSubCache(url) { // 地址后面拼时间缀, 避免 GET 缓存 - const requrl = `${url}${url.includes('?') ? '&' : '?'}_=${new Date().getTime()}` + const requrl = `${url}${ + url.includes('?') ? '&' : '?' + }_=${new Date().getTime()}` return $.http.get(requrl).then((resp) => { try { const subcaches = getAppSubCaches() @@ -850,7 +852,8 @@ function getBaseDoneHeaders(mixHeaders = {}) { { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PUT,DELETE', - 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' + 'Access-Control-Allow-Headers': + 'Origin, X-Requested-With, Content-Type, Accept' }, mixHeaders ) @@ -915,4 +918,4 @@ function GistBox(e){const t=function(e,t={}){const{isQX:s,isLoon:n,isSurge:o}=fu * EnvJs */ // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:i,statusCode:r,headers:o,rawBody:h},s.decode(h,this.encoding))},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:h}=t;e(null,{status:s,statusCode:r,headers:o,rawBody:h},i.decode(h,this.encoding))},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} From e5c8ea9f9979752a3c49207fbaffd426be3bb098 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Sat, 18 Mar 2023 00:13:21 +0800 Subject: [PATCH 178/311] fix(BoxJs): done*() at ShadowRocket and Stash Update chavy.boxjs.js --- box/chavy.boxjs.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index def415752..91dc38705 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -872,39 +872,29 @@ function getJsonDoneHeaders() { function doneOptions() { const headers = getBaseDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { headers } }) - } else if ($.isQuanX()) { - $.done({ headers }) - } + if ($.isQuanX()) $.done({ headers }) + else $.done({ response: { headers } }) } function donePage() { const headers = getHtmlDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.html } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.html }) - } + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.html }) + else $.done({ response: { status: 200, headers, body: $.html } }) } function doneQuery() { $.json = $.toStr($.json) const headers = getJsonDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.json } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) - } + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) + else $.done({ response: { status: 200, headers, body: $.json } }) } function doneApi() { $.json = $.toStr($.json) const headers = getJsonDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.json } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) + else $.done({ response: { status: 200, headers, body: $.json } }) + } } From 979884ad9eb6f5fd207a3074fa5b534b6ccb33fe Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Sat, 18 Mar 2023 00:16:20 +0800 Subject: [PATCH 179/311] fix(boxjs): format error Update chavy.boxjs.js --- box/chavy.boxjs.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 91dc38705..d153a9e94 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -894,8 +894,6 @@ function doneApi() { const headers = getJsonDoneHeaders() if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) else $.done({ response: { status: 200, headers, body: $.json } }) - - } } /** From 239adb24dd366ea177ec8d8667d2c520c0392dba Mon Sep 17 00:00:00 2001 From: Chavy Date: Sat, 18 Mar 2023 18:48:26 +0800 Subject: [PATCH 180/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D=20Stas?= =?UTF-8?q?h=20&=20ShadowRocket=20=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 30 +++++++++--------------------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index d153a9e94..cea994ae4 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.4' +$.version = '0.12.5' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index ee9822474..44faad7ac 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.5", + "tags": ["beta"], + "author": "@VirgilClyne", + "msg": "fix(boxjs): 修复 Stash & ShadowRocket 报错问题", + "notes": [ + { + "name": "修复", + "descs": ["修复 Stash & ShadowRocket 报错问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne PR", "Stash 团队反馈及协助定位问题"] + } + ] + }, { "version": "0.12.4", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 85de32bf7..092e0a17f 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.5", + "tags": ["beta"], + "author": "@VirgilClyne", + "msg": "fix(boxjs): 修复 Stash & ShadowRocket 报错问题", + "notes": [ + { + "name": "修复", + "descs": ["修复 Stash & ShadowRocket 报错问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne PR", "Stash 团队反馈及协助定位问题"] + } + ] + }, { "version": "0.12.4", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index def415752..cea994ae4 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.4' +$.version = '0.12.5' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -872,40 +872,28 @@ function getJsonDoneHeaders() { function doneOptions() { const headers = getBaseDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { headers } }) - } else if ($.isQuanX()) { - $.done({ headers }) - } + if ($.isQuanX()) $.done({ headers }) + else $.done({ response: { headers } }) } function donePage() { const headers = getHtmlDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.html } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.html }) - } + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.html }) + else $.done({ response: { status: 200, headers, body: $.html } }) } function doneQuery() { $.json = $.toStr($.json) const headers = getJsonDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.json } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) - } + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) + else $.done({ response: { status: 200, headers, body: $.json } }) } function doneApi() { $.json = $.toStr($.json) const headers = getJsonDoneHeaders() - if ($.isSurge() || $.isLoon()) { - $.done({ response: { status: 200, headers, body: $.json } }) - } else if ($.isQuanX()) { - $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) - } + if ($.isQuanX()) $.done({ status: 'HTTP/1.1 200', headers, body: $.json }) + else $.done({ response: { status: 200, headers, body: $.json } }) } /** From 0d254fb80df47568f78d3493d210d06d62a78601 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Wed, 22 Mar 2023 13:51:42 +0800 Subject: [PATCH 181/311] fix(Env.js): msg() on Shadowrocket Update Env.js --- Env.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Env.js b/Env.js index 029f00188..9bc72a97a 100644 --- a/Env.js +++ b/Env.js @@ -520,9 +520,9 @@ function Env(name, opts) { const toEnvOpts = (rawopts) => { if (!rawopts) return rawopts if (typeof rawopts === 'string') { - if (this.isLoon()) return rawopts + if (this.isLoon() || this.isShadowrocket()) return rawopts else if (this.isQuanX()) return { 'open-url': rawopts } - else if (this.isSurge() || this.isShadowrocket() || this.isStash()) + else if (this.isSurge() || this.isStash()) return { url: rawopts } else return undefined } else if (typeof rawopts === 'object') { From 5192f78bde8fa5e1139b662b22a4f3544910823b Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 22 Mar 2023 14:02:20 +0800 Subject: [PATCH 182/311] fix(boxjs): msg() on Shadowrocket --- Env.js | 3 +-- Env.min.js | 2 +- box/chavy.boxjs.js | 4 ++-- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 4 ++-- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Env.js b/Env.js index 9bc72a97a..e82eac84e 100644 --- a/Env.js +++ b/Env.js @@ -522,8 +522,7 @@ function Env(name, opts) { if (typeof rawopts === 'string') { if (this.isLoon() || this.isShadowrocket()) return rawopts else if (this.isQuanX()) return { 'open-url': rawopts } - else if (this.isSurge() || this.isStash()) - return { url: rawopts } + else if (this.isSurge() || this.isStash()) return { url: rawopts } else return undefined } else if (typeof rawopts === 'object') { if (this.isLoon()) { diff --git a/Env.min.js b/Env.min.js index 84e9e557f..92de60d94 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index cea994ae4..31d1a8a29 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.5' +$.version = '0.12.6' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -906,4 +906,4 @@ function GistBox(e){const t=function(e,t={}){const{isQX:s,isLoon:n,isSurge:o}=fu * EnvJs */ // prettier-ignore -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} diff --git a/box/release/box.release.json b/box/release/box.release.json index 44faad7ac..3f329b6df 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.6", + "tags": ["beta"], + "author": "@VirgilClyne", + "msg": "fix(boxjs): msg() on Shadowrocket", + "notes": [ + { + "name": "修复", + "descs": ["小火箭环境下消息提示问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne PR"] + } + ] + }, { "version": "0.12.5", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 092e0a17f..56fef44c7 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.6", + "tags": ["beta"], + "author": "@VirgilClyne", + "msg": "fix(boxjs): msg() on Shadowrocket", + "notes": [ + { + "name": "修复", + "descs": ["小火箭环境下消息提示问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne PR"] + } + ] + }, { "version": "0.12.5", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index cea994ae4..31d1a8a29 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.5' +$.version = '0.12.6' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -906,4 +906,4 @@ function GistBox(e){const t=function(e,t={}){const{isQX:s,isLoon:n,isSurge:o}=fu * EnvJs */ // prettier-ignore -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isShadowrocket()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} +function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} From 4af62b2760dae49f43be730395f4078654e0c027 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 22 Mar 2023 15:10:55 +0800 Subject: [PATCH 183/311] feat: add surge calc --- box/chavy.boxjs.html | 57 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index f4cb655c3..b3c2c7c79 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1226,6 +1226,17 @@

{{curbak.name}}

+ + +

Surge 费用计算器(open AI 编写)

+
仅供参考,最终价格以实际为准
+
+ + + 计算费用 +

费用:{{ cost.toFixed(2) }}

+
+
@@ -1281,6 +1292,9 @@

{{curbak.name}}

mdi-new-box + + mdi-calculator-variant-outline + {{box.usercfgs.isLeftBoxIcon ? 'mdi-format-horizontal-align-right' : 'mdi-format-horizontal-align-left'}} @@ -1751,7 +1765,10 @@

v{{ver.versio ] }, boxServerData: null, - box: null + box: null, + purchaseDate: null, + cost: 0, + licenseTypes: ["1 Device License", "3 Devices License", "5 Devices License"], } }, computed: { @@ -2941,7 +2958,43 @@

v{{ver.versio axios.defaults.baseURL = '' } } - } + }, + calculateUpgradePrice(purchaseDate, licenseType) { + const licensePrices = { + '1 Device License': 34.99, + '3 Devices License': 48.99, + '5 Devices License': 69.99, + } + + const upgradePrice = licensePrices[licenseType] + if (!upgradePrice) { + throw new Error(`Invalid license type: ${licenseType}`) + } + + const discountEndDate = dayjs('2022-04-15') + const freeDate = dayjs('2022-10-15') + + if (dayjs(purchaseDate).isBefore(discountEndDate)) { + return licensePrices[licenseType] + } + + const equivalentPurchaseDate = dayjs(purchaseDate) + + const diffDays = freeDate.diff(discountEndDate, 'day') + const daysFromDiscountEndDate = equivalentPurchaseDate.diff(discountEndDate, 'day') + + if (daysFromDiscountEndDate >= diffDays) { + // After free upgrade date + return 0 + } else { + const ratio = 1 - daysFromDiscountEndDate / diffDays + const price = Math.ceil(ratio * upgradePrice * 100) / 100 - 0.01 + return price < 1.99 ? 1.99 : price + } + }, + calculateCost() { + this.cost = this.calculateUpgradePrice(this.purchaseDate, this.licenseType) + }, } }) From 61ce18fae3d04e6176b2275079656466471d279f Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 22 Mar 2023 15:23:56 +0800 Subject: [PATCH 184/311] feat: v0.12.7 --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 31d1a8a29..e2fd88cc5 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.6' +$.version = '0.12.7' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 3f329b6df..d1aeb8430 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.7", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "让 openAI 写了个 Surge 费用计算器", + "notes": [ + { + "name": "实验", + "descs": ["Surge 费用计算器"] + } + ] + }, { "version": "0.12.6", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 56fef44c7..28e5a673e 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.7", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "让 openAI 写了个 Surge 费用计算器", + "notes": [ + { + "name": "实验", + "descs": ["Surge 费用计算器"] + } + ] + }, { "version": "0.12.6", "tags": ["beta"], From 08a7d6193251ab8eb72da7a05bd0098f99803619 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 15:37:13 +0800 Subject: [PATCH 185/311] chore(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#425) Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/kornelski/http-cache-semantics/releases) - [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: http-cache-semantics dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index dfb5e6e98..f4d521acc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -176,9 +176,9 @@ he@^1.1.1: integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== http-cache-semantics@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz#49e91c5cbf36c9b94bcfcd71c23d5249ec74e390" - integrity sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ== + version "4.1.1" + resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a" + integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ== http-proxy@^1.18.0: version "1.18.1" From 6050b86760896f2cba187fc56cc02a2d233ea0d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 15:37:34 +0800 Subject: [PATCH 186/311] chore(deps): bump qs from 6.9.4 to 6.11.0 (#422) Bumps [qs](https://github.com/ljharb/qs) from 6.9.4 to 6.11.0. - [Release notes](https://github.com/ljharb/qs/releases) - [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md) - [Commits](https://github.com/ljharb/qs/compare/v6.9.4...v6.11.0) --- updated-dependencies: - dependency-name: qs dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index f4d521acc..ca43766c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -78,6 +78,14 @@ cacheable-request@^7.0.2: normalize-url "^6.0.1" responselike "^2.0.0" +call-bind@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== + dependencies: + function-bind "^1.1.1" + get-intrinsic "^1.0.2" + clone-response@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b" @@ -146,6 +154,20 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +get-intrinsic@^1.0.2: + version "1.1.3" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.3.tgz#063c84329ad93e83893c7f4f243ef63ffa351385" + integrity sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.3" + get-stream@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" @@ -170,6 +192,18 @@ got@^11.8.5: p-cancelable "^2.0.0" responselike "^2.0.0" +has-symbols@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" + integrity sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A== + +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + he@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" @@ -279,6 +313,11 @@ normalize-url@^6.0.1: resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a" integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== +object-inspect@^1.9.0: + version "1.12.2" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.2.tgz#c0641f26394532f28ab8d796ab954e43c009a8ea" + integrity sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ== + once@^1.3.1, once@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -324,9 +363,11 @@ punycode@^2.1.1: integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== qs@^6.4.0: - version "6.9.4" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687" - integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ== + version "6.11.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a" + integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q== + dependencies: + side-channel "^1.0.4" quick-lru@^5.1.1: version "5.1.1" @@ -360,6 +401,15 @@ secure-compare@3.0.1: resolved "https://registry.yarnpkg.com/secure-compare/-/secure-compare-3.0.1.tgz#f1a0329b308b221fae37b9974f3d578d0ca999e3" integrity sha1-8aAymzCLIh+uN7mXTz1XjQypmeM= +side-channel@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" + integrity sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw== + dependencies: + call-bind "^1.0.0" + get-intrinsic "^1.0.2" + object-inspect "^1.9.0" + tough-cookie@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.0.0.tgz#d822234eeca882f991f0f908824ad2622ddbece4" From e3629c6ec86ee55fc62ccfc501632ffe91ba9ba9 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 22 Mar 2023 16:57:25 +0800 Subject: [PATCH 187/311] feat: add surge calc --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 2 +- box/release/box.release.tf.json | 2 +- chavy.box.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index e2fd88cc5..06dc79fe4 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.7' +$.version = '0.12.8' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index d1aeb8430..0474ddcfc 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,7 +1,7 @@ { "releases": [ { - "version": "0.12.7", + "version": "0.12.8", "tags": ["beta"], "author": "@GideonSenku", "msg": "让 openAI 写了个 Surge 费用计算器", diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 28e5a673e..b8d5201cf 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,7 +1,7 @@ { "releases": [ { - "version": "0.12.7", + "version": "0.12.8", "tags": ["beta"], "author": "@GideonSenku", "msg": "让 openAI 写了个 Surge 费用计算器", diff --git a/chavy.box.js b/chavy.box.js index 31d1a8a29..06dc79fe4 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.6' +$.version = '0.12.8' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 8ef2f5087deb62752ae071954322fbe79c6427a4 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Wed, 22 Mar 2023 20:59:55 +0800 Subject: [PATCH 188/311] fix: licenseType --- box/chavy.boxjs.html | 1 + box/chavy.boxjs.js | 2 +- box/release/box.release.json | 2 +- box/release/box.release.tf.json | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index b3c2c7c79..7e66f6c86 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1769,6 +1769,7 @@

v{{ver.versio purchaseDate: null, cost: 0, licenseTypes: ["1 Device License", "3 Devices License", "5 Devices License"], + licenseType: '' } }, computed: { diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 06dc79fe4..8bb390836 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.8' +$.version = '0.12.9' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 0474ddcfc..dc45cbc26 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,7 +1,7 @@ { "releases": [ { - "version": "0.12.8", + "version": "0.12.9", "tags": ["beta"], "author": "@GideonSenku", "msg": "让 openAI 写了个 Surge 费用计算器", diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index b8d5201cf..cc84fd9c3 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,7 +1,7 @@ { "releases": [ { - "version": "0.12.8", + "version": "0.12.9", "tags": ["beta"], "author": "@GideonSenku", "msg": "让 openAI 写了个 Surge 费用计算器", From c6831b76f808eb43b607bd05a0b325a0e1e532df Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 23 Apr 2023 09:15:38 +0800 Subject: [PATCH 189/311] =?UTF-8?q?fix(env.js):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=A1=A5=E5=85=A8=20Content-Type=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 50 ++++++++++++++++++++++++++++++++++++-------------- Env.min.js | 2 +- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Env.js b/Env.js index e82eac84e..1c2801e0c 100644 --- a/Env.js +++ b/Env.js @@ -43,32 +43,39 @@ function Env(name, opts) { this.log('', `🔔${this.name}, 开始!`) } + getEnv() { + if ('undefined' !== typeof $environment && $environment['surge-version']) + return 'Surge' + if ('undefined' !== typeof $environment && $environment['stash-version']) + return 'Stash' + if ('undefined' !== typeof module && !!module.exports) return 'Node.js' + if ('undefined' !== typeof $task) return 'Quantumult X' + if ('undefined' !== typeof $loon) return 'Loon' + if ('undefined' !== typeof $rocket) return 'Shadowrocket' + } + isNode() { - return 'undefined' !== typeof module && !!module.exports + return 'Node.js' === this.getEnv() } isQuanX() { - return 'undefined' !== typeof $task + return 'Quantumult X' === this.getEnv() } isSurge() { - return ( - 'undefined' !== typeof $environment && $environment['surge-version'] - ) + return 'Surge' === this.getEnv() } isLoon() { - return 'undefined' !== typeof $loon + return 'Loon' === this.getEnv() } isShadowrocket() { - return 'undefined' !== typeof $rocket + return 'Shadowrocket' === this.getEnv() } isStash() { - return ( - 'undefined' !== typeof $environment && $environment['stash-version'] - ) + return 'Stash' === this.getEnv() } toObj(str, defaultValue = null) { @@ -309,6 +316,10 @@ function Env(name, opts) { if (opts.headers) { delete opts.headers['Content-Type'] delete opts.headers['Content-Length'] + + // HTTP/2 全是小写 + delete opts.headers['content-type'] + delete opts.headers['content-length'] } if ( this.isSurge() || @@ -384,11 +395,22 @@ function Env(name, opts) { post(opts, callback = () => {}) { const method = opts.method ? opts.method.toLocaleLowerCase() : 'post' - // 如果指定了请求体, 但没指定`Content-Type`, 则自动生成 - if (opts.body && opts.headers && !opts.headers['Content-Type']) { - opts.headers['Content-Type'] = 'application/x-www-form-urlencoded' + + // 如果指定了请求体, 但没指定 `Content-Type`、`content-type`, 则自动生成。 + if ( + opts.body && + opts.headers && + !opts.headers['Content-Type'] && + !opts.headers['content-type'] + ) { + // HTTP/1、HTTP/2 都支持小写 headers + opts.headers['content-type'] = 'application/x-www-form-urlencoded' + } + // 为避免指定错误 `content-length` 这里删除该属性,由工具端 (HttpClient) 负责重新计算并赋值 + if (opts.headers) { + delete opts.headers['Content-Length'] + delete opts.headers['content-length'] } - if (opts.headers) delete opts.headers['Content-Length'] if ( this.isSurge() || this.isShadowrocket() || diff --git a/Env.min.js b/Env.min.js index 92de60d94..a16551cdb 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,s){class e{constructor(t){this.env=t}send(t,s="GET"){t="string"==typeof t?{url:t}:t;let e=this.get;return"POST"===s&&(e=this.post),new Promise((s,i)=>{e.call(this,t,(t,e,r)=>{t?i(t):s(e)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,s){this.name=t,this.http=new e(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $environment&&$environment["surge-version"]}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,s=null){try{return JSON.parse(t)}catch{return s}}toStr(t,s=null){try{return JSON.stringify(t)}catch{return s}}getjson(t,s){let e=s;const i=this.getdata(t);if(i)try{e=JSON.parse(this.getdata(t))}catch{}return e}setjson(t,s){try{return this.setdata(JSON.stringify(t),s)}catch{return!1}}getScript(t){return new Promise(s=>{this.get({url:t},(t,e,i)=>s(i))})}runScript(t,s){return new Promise(e=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=s&&s.timeout?s.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"},timeout:r};this.post(a,(t,s,i)=>e(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),r=JSON.stringify(this.data);e?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(s,r):this.fs.writeFileSync(t,r)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return e;return r}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),r=e?this.getval(e):"";if(r)try{const t=JSON.parse(r);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(s),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const s=JSON.parse(h);this.lodash_set(s,r,t),e=this.setval(JSON.stringify(s),i)}catch(s){const o={};this.lodash_set(o,r,t),e=this.setval(JSON.stringify(o),i)}}else e=this.setval(t,s);return e}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let e=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{if(t.headers["set-cookie"]){const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();e&&this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:h}=t,a=e.decode(h,this.encoding);s(null,{status:i,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:i,response:r}=t;s(i,r,r&&e.decode(r.rawBody,this.encoding))})}}post(t,s=(()=>{})){const e=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[e](t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status?e.status:e.statusCode,e.status=e.statusCode),s(t,e,i)});else if(this.isQuanX())t.method=e,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:r,body:o}=t;s(null,{status:e,statusCode:i,headers:r,body:o},o)},t=>s(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[e](r,o).then(t=>{const{statusCode:e,statusCode:r,headers:o,rawBody:h}=t,a=i.decode(h,this.encoding);s(null,{status:e,statusCode:r,headers:o,rawBody:h,body:a},a)},t=>{const{message:e,response:r}=t;s(e,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,s=null){const e=s?new Date(s):new Date;let i={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in i)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[s]:("00"+i[s]).substr((""+i[s]).length)));return t}queryStr(t){let s="";for(const e in t){let i=t[e];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),s+=`${e}=${i}&`)}return s=s.substring(0,s.length-1),s}msg(s=t,e="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let s=t.openUrl||t.url||t["open-url"],e=t.mediaUrl||t["media-url"];return{openUrl:s,mediaUrl:e}}if(this.isQuanX()){let s=t["open-url"]||t.url||t.openUrl,e=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":s,"media-url":e,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let s=t.url||t.openUrl||t["open-url"];return{url:s}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(s,e,i,o(r)):this.isQuanX()&&$notify(s,e,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(s),e&&t.push(e),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,s){const e=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());e?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t={}){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,s)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),h=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:h}=t,n=s.decode(h,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:h,body:n},n)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:h}=t,n=i.decode(h,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:h,body:n},n)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(e,s,i,r(o)):this.isQuanX()&&$notify(e,s,i,r(o))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file From 18053e95f25c2f92401a2d681c25f45e39c65a2a Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Sun, 23 Apr 2023 17:25:03 +0800 Subject: [PATCH 190/311] fix(env.js): $task.fetch() bodyBytes (#440) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(env.js): $task.fetch() bodyBytes Update Env.js * style(env.js): switch…case… Update Env.js * chore: gen Env.min.js --------- Co-authored-by: Chavy --- Env.js | 459 ++++++++++++++++++++++++++++------------------------- Env.min.js | 2 +- 2 files changed, 244 insertions(+), 217 deletions(-) diff --git a/Env.js b/Env.js index 1c2801e0c..173ab6a59 100644 --- a/Env.js +++ b/Env.js @@ -263,40 +263,38 @@ function Env(name, opts) { } getval(key) { - if ( - this.isSurge() || - this.isShadowrocket() || - this.isLoon() || - this.isStash() - ) { - return $persistentStore.read(key) - } else if (this.isQuanX()) { - return $prefs.valueForKey(key) - } else if (this.isNode()) { - this.data = this.loaddata() - return this.data[key] - } else { - return (this.data && this.data[key]) || null + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.read(key) + case 'Quantumult X': + return $prefs.valueForKey(key) + case 'Node.js': + this.data = this.loaddata() + return this.data[key] + default: + return (this.data && this.data[key]) || null } } setval(val, key) { - if ( - this.isSurge() || - this.isShadowrocket() || - this.isLoon() || - this.isStash() - ) { - return $persistentStore.write(val, key) - } else if (this.isQuanX()) { - return $prefs.setValueForKey(val, key) - } else if (this.isNode()) { - this.data = this.loaddata() - this.data[key] = val - this.writedata() - return true - } else { - return (this.data && this.data[key]) || null + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.write(val, key) + case 'Quantumult X': + return $prefs.setValueForKey(val, key) + case 'Node.js': + this.data = this.loaddata() + this.data[key] = val + this.writedata() + return true + default: + return (this.data && this.data[key]) || null } } @@ -312,155 +310,161 @@ function Env(name, opts) { } } - get(opts, callback = () => {}) { - if (opts.headers) { - delete opts.headers['Content-Type'] - delete opts.headers['Content-Length'] + get(request, callback = () => {}) { + if (request.headers) { + delete request.headers['Content-Type'] + delete request.headers['Content-Length'] // HTTP/2 全是小写 - delete opts.headers['content-type'] - delete opts.headers['content-length'] + delete request.headers['content-type'] + delete request.headers['content-length'] } - if ( - this.isSurge() || - this.isShadowrocket() || - this.isLoon() || - this.isStash() - ) { - if (this.isSurge() && this.isNeedRewrite) { - opts.headers = opts.headers || {} - Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) - } - $httpClient.get(opts, (err, resp, body) => { - if (!err && resp) { - resp.body = body - resp.statusCode = resp.status ? resp.status : resp.statusCode - resp.status = resp.statusCode + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + if (this.isSurge() && this.isNeedRewrite) { + request.headers = request.headers || {} + Object.assign(request.headers, { 'X-Surge-Skip-Scripting': false }) } - callback(err, resp, body) - }) - } else if (this.isQuanX()) { - if (this.isNeedRewrite) { - opts.opts = opts.opts || {} - Object.assign(opts.opts, { hints: false }) - } - $task.fetch(opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) - }, - (err) => callback((err && err.error) || 'UndefinedError') - ) - } else if (this.isNode()) { - let iconv = require('iconv-lite') - this.initGotEnv(opts) - this.got(opts) - .on('redirect', (resp, nextOpts) => { - try { - if (resp.headers['set-cookie']) { - const ck = resp.headers['set-cookie'] - .map(this.cktough.Cookie.parse) - .toString() - if (ck) { - this.ckjar.setCookieSync(ck, null) - } - nextOpts.cookieJar = this.ckjar - } - } catch (e) { - this.logErr(e) + $httpClient.get(request, (err, resp, body) => { + if (!err && resp) { + resp.body = body + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode } - // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) + callback(err, resp, body) }) - .then( + break; + case 'Quantumult X': + if (this.isNeedRewrite) { + request.opts = request.opts || {} + Object.assign(request.opts, { hints: false }) + } + $task.fetch(request).then( (resp) => { - const { statusCode: status, statusCode, headers, rawBody } = resp - const body = iconv.decode(rawBody, this.encoding) - callback( - null, - { status, statusCode, headers, rawBody, body }, - body - ) + const { statusCode: status, statusCode, headers, body, bodyBytes } = resp + callback(null, { status, statusCode, headers, body, bodyBytes }, body, bodyBytes) }, - (err) => { - const { message: error, response: resp } = err - callback( - error, - resp, - resp && iconv.decode(resp.rawBody, this.encoding) - ) - } + (err) => callback((err && err.error) || 'UndefinedError') ) + break; + case 'Node.js': + let iconv = require('iconv-lite') + this.initGotEnv(request) + this.got(request) + .on('redirect', (resp, nextOpts) => { + try { + if (resp.headers['set-cookie']) { + const ck = resp.headers['set-cookie'] + .map(this.cktough.Cookie.parse) + .toString() + if (ck) { + this.ckjar.setCookieSync(ck, null) + } + nextOpts.cookieJar = this.ckjar + } + } catch (e) { + this.logErr(e) + } + // this.ckjar.setCookieSync(resp.headers['set-cookie'].map(Cookie.parse).toString()) + }) + .then( + (resp) => { + const { statusCode: status, statusCode, headers, rawBody } = resp + const body = iconv.decode(rawBody, this.encoding) + callback( + null, + { status, statusCode, headers, rawBody, body }, + body + ) + }, + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } + ) + break; } } - post(opts, callback = () => {}) { - const method = opts.method ? opts.method.toLocaleLowerCase() : 'post' + post(request, callback = () => {}) { + const method = request.method ? request.method.toLocaleLowerCase() : 'post' // 如果指定了请求体, 但没指定 `Content-Type`、`content-type`, 则自动生成。 if ( - opts.body && - opts.headers && - !opts.headers['Content-Type'] && - !opts.headers['content-type'] + request.body && + request.headers && + !request.headers['Content-Type'] && + !request.headers['content-type'] ) { // HTTP/1、HTTP/2 都支持小写 headers - opts.headers['content-type'] = 'application/x-www-form-urlencoded' + request.headers['content-type'] = 'application/x-www-form-urlencoded' } // 为避免指定错误 `content-length` 这里删除该属性,由工具端 (HttpClient) 负责重新计算并赋值 - if (opts.headers) { - delete opts.headers['Content-Length'] - delete opts.headers['content-length'] + if (request.headers) { + delete request.headers['Content-Length'] + delete request.headers['content-length'] } - if ( - this.isSurge() || - this.isShadowrocket() || - this.isLoon() || - this.isStash() - ) { - if (this.isSurge() && this.isNeedRewrite) { - opts.headers = opts.headers || {} - Object.assign(opts.headers, { 'X-Surge-Skip-Scripting': false }) - } - $httpClient[method](opts, (err, resp, body) => { - if (!err && resp) { - resp.body = body - resp.statusCode = resp.status ? resp.status : resp.statusCode - resp.status = resp.statusCode + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + if (this.isSurge() && this.isNeedRewrite) { + request.headers = request.headers || {} + Object.assign(request.headers, { 'X-Surge-Skip-Scripting': false }) } - callback(err, resp, body) - }) - } else if (this.isQuanX()) { - opts.method = method - if (this.isNeedRewrite) { - opts.opts = opts.opts || {} - Object.assign(opts.opts, { hints: false }) - } - $task.fetch(opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, body } = resp - callback(null, { status, statusCode, headers, body }, body) - }, - (err) => callback((err && err.error) || 'UndefinedError') - ) - } else if (this.isNode()) { - let iconv = require('iconv-lite') - this.initGotEnv(opts) - const { url, ..._opts } = opts - this.got[method](url, _opts).then( - (resp) => { - const { statusCode: status, statusCode, headers, rawBody } = resp - const body = iconv.decode(rawBody, this.encoding) - callback(null, { status, statusCode, headers, rawBody, body }, body) - }, - (err) => { - const { message: error, response: resp } = err - callback( - error, - resp, - resp && iconv.decode(resp.rawBody, this.encoding) - ) + $httpClient[method](request, (err, resp, body) => { + if (!err && resp) { + resp.body = body + resp.statusCode = resp.status ? resp.status : resp.statusCode + resp.status = resp.statusCode + } + callback(err, resp, body) + }) + break; + case 'Quantumult X': + request.method = method + if (this.isNeedRewrite) { + request.opts = request.opts || {} + Object.assign(request.opts, { hints: false }) } - ) + $task.fetch(request).then( + (resp) => { + const { statusCode: status, statusCode, headers, body, bodyBytes } = resp + callback(null, { status, statusCode, headers, body, bodyBytes }, body, bodyBytes) + }, + (err) => callback((err && err.error) || 'UndefinedError') + ) + break; + case 'Node.js': + let iconv = require('iconv-lite') + this.initGotEnv(request) + const { url, ..._request } = request + this.got[method](url, _request).then( + (resp) => { + const { statusCode: status, statusCode, headers, rawBody } = resp + const body = iconv.decode(rawBody, this.encoding) + callback(null, { status, statusCode, headers, rawBody, body }, body) + }, + (err) => { + const { message: error, response: resp } = err + callback( + error, + resp, + resp && iconv.decode(resp.rawBody, this.encoding) + ) + } + ) + break; } } /** @@ -540,49 +544,68 @@ function Env(name, opts) { */ msg(title = name, subt = '', desc = '', opts) { const toEnvOpts = (rawopts) => { - if (!rawopts) return rawopts - if (typeof rawopts === 'string') { - if (this.isLoon() || this.isShadowrocket()) return rawopts - else if (this.isQuanX()) return { 'open-url': rawopts } - else if (this.isSurge() || this.isStash()) return { url: rawopts } - else return undefined - } else if (typeof rawopts === 'object') { - if (this.isLoon()) { - let openUrl = rawopts.openUrl || rawopts.url || rawopts['open-url'] - let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] - return { openUrl, mediaUrl } - } else if (this.isQuanX()) { - let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl - let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl - let updatePasteboard = - rawopts['update-pasteboard'] || rawopts.updatePasteboard - return { - 'open-url': openUrl, - 'media-url': mediaUrl, - 'update-pasteboard': updatePasteboard + switch (typeof rawopts) { + case undefined: + return rawopts + case 'string': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + default: + return { url: rawopts } + case 'Loon': + case 'Shadowrocket': + return rawopts + case 'Quantumult X': + return { 'open-url': rawopts } + case 'Node.js': + return undefined } - } else if ( - this.isSurge() || - this.isShadowrocket() || - this.isStash() - ) { - let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] - return { url: openUrl } - } - } else { - return undefined + case 'object': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + case 'Shadowrocket': + default: { + let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] + return { url: openUrl } + } + case 'Loon': { + let openUrl = rawopts.openUrl || rawopts.url || rawopts['open-url'] + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] + return { openUrl, mediaUrl } + } + case 'Quantumult X': { + let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl + let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl + let updatePasteboard = + rawopts['update-pasteboard'] || rawopts.updatePasteboard + return { + 'open-url': openUrl, + 'media-url': mediaUrl, + 'update-pasteboard': updatePasteboard + } + } + case 'Node.js': + return undefined + } + default: + return undefined } } if (!this.isMute) { - if ( - this.isSurge() || - this.isShadowrocket() || - this.isLoon() || - this.isStash() - ) { - $notification.post(title, subt, desc, toEnvOpts(opts)) - } else if (this.isQuanX()) { - $notify(title, subt, desc, toEnvOpts(opts)) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + $notification.post(title, subt, desc, toEnvOpts(opts)) + case 'Quantumult X': + $notify(title, subt, desc, toEnvOpts(opts)) + break; + case 'Node.js': + break; } } if (!this.isMuteLog) { @@ -603,16 +626,18 @@ function Env(name, opts) { } logErr(err, msg) { - const isPrintSack = - !this.isSurge() && - !this.isShadowrocket() && - !this.isQuanX() && - !this.isLoon() && - !this.isStash() - if (!isPrintSack) { - this.log('', `❗️${this.name}, 错误!`, err) - } else { - this.log('', `❗️${this.name}, 错误!`, err.stack) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + this.log('', `❗️${this.name}, 错误!`, err) + break; + case 'Node.js': + this.log('', `❗️${this.name}, 错误!`, err.stack) + break; } } @@ -625,16 +650,18 @@ function Env(name, opts) { const costTime = (endTime - this.startTime) / 1000 this.log('', `🔔${this.name}, 结束! 🕛 ${costTime} 秒`) this.log() - if ( - this.isSurge() || - this.isShadowrocket() || - this.isQuanX() || - this.isLoon() || - this.isStash() - ) { - $done(val) - } else if (this.isNode()) { - process.exit(1) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + $done(val) + break; + case 'Node.js': + process.exit(1) + break; } } })(name, opts) diff --git a/Env.min.js b/Env.min.js index a16551cdb..99b599f9a 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,h]=i.split("@"),n={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),h=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:h}=t,n=s.decode(h,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:h,body:n},n)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r}=t;e(null,{status:s,statusCode:i,headers:o,body:r},r)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:h}=t,n=i.decode(h,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:h,body:n},n)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()||this.isShadowrocket()?t:this.isQuanX()?{"open-url":t}:this.isSurge()||this.isStash()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()||this.isShadowrocket()||this.isStash()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isShadowrocket()||this.isLoon()||this.isStash()?$notification.post(e,s,i,r(o)):this.isQuanX()&&$notify(e,s,i,r(o))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!(this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash());s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.isSurge()||this.isShadowrocket()||this.isQuanX()||this.isLoon()||this.isStash()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 867af0dab292cc9f7f2febf514253c62500ffe36 Mon Sep 17 00:00:00 2001 From: Chavy Date: Tue, 25 Apr 2023 08:26:54 +0800 Subject: [PATCH 191/311] fix(env.js): $.msg error --- Env.js | 81 +++++++++++++++++++++++++++++++++++++++--------------- Env.min.js | 2 +- 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/Env.js b/Env.js index 173ab6a59..c75382835 100644 --- a/Env.js +++ b/Env.js @@ -337,7 +337,7 @@ function Env(name, opts) { } callback(err, resp, body) }) - break; + break case 'Quantumult X': if (this.isNeedRewrite) { request.opts = request.opts || {} @@ -345,12 +345,23 @@ function Env(name, opts) { } $task.fetch(request).then( (resp) => { - const { statusCode: status, statusCode, headers, body, bodyBytes } = resp - callback(null, { status, statusCode, headers, body, bodyBytes }, body, bodyBytes) + const { + statusCode: status, + statusCode, + headers, + body, + bodyBytes + } = resp + callback( + null, + { status, statusCode, headers, body, bodyBytes }, + body, + bodyBytes + ) }, (err) => callback((err && err.error) || 'UndefinedError') ) - break; + break case 'Node.js': let iconv = require('iconv-lite') this.initGotEnv(request) @@ -373,7 +384,12 @@ function Env(name, opts) { }) .then( (resp) => { - const { statusCode: status, statusCode, headers, rawBody } = resp + const { + statusCode: status, + statusCode, + headers, + rawBody + } = resp const body = iconv.decode(rawBody, this.encoding) callback( null, @@ -390,12 +406,14 @@ function Env(name, opts) { ) } ) - break; + break } } post(request, callback = () => {}) { - const method = request.method ? request.method.toLocaleLowerCase() : 'post' + const method = request.method + ? request.method.toLocaleLowerCase() + : 'post' // 如果指定了请求体, 但没指定 `Content-Type`、`content-type`, 则自动生成。 if ( @@ -430,7 +448,7 @@ function Env(name, opts) { } callback(err, resp, body) }) - break; + break case 'Quantumult X': request.method = method if (this.isNeedRewrite) { @@ -439,12 +457,23 @@ function Env(name, opts) { } $task.fetch(request).then( (resp) => { - const { statusCode: status, statusCode, headers, body, bodyBytes } = resp - callback(null, { status, statusCode, headers, body, bodyBytes }, body, bodyBytes) + const { + statusCode: status, + statusCode, + headers, + body, + bodyBytes + } = resp + callback( + null, + { status, statusCode, headers, body, bodyBytes }, + body, + bodyBytes + ) }, (err) => callback((err && err.error) || 'UndefinedError') ) - break; + break case 'Node.js': let iconv = require('iconv-lite') this.initGotEnv(request) @@ -453,7 +482,11 @@ function Env(name, opts) { (resp) => { const { statusCode: status, statusCode, headers, rawBody } = resp const body = iconv.decode(rawBody, this.encoding) - callback(null, { status, statusCode, headers, rawBody, body }, body) + callback( + null, + { status, statusCode, headers, rawBody, body }, + body + ) }, (err) => { const { message: error, response: resp } = err @@ -464,7 +497,7 @@ function Env(name, opts) { ) } ) - break; + break } } /** @@ -567,16 +600,19 @@ function Env(name, opts) { case 'Stash': case 'Shadowrocket': default: { - let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] + let openUrl = + rawopts.url || rawopts.openUrl || rawopts['open-url'] return { url: openUrl } } case 'Loon': { - let openUrl = rawopts.openUrl || rawopts.url || rawopts['open-url'] + let openUrl = + rawopts.openUrl || rawopts.url || rawopts['open-url'] let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] return { openUrl, mediaUrl } } case 'Quantumult X': { - let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl + let openUrl = + rawopts['open-url'] || rawopts.url || rawopts.openUrl let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl let updatePasteboard = rawopts['update-pasteboard'] || rawopts.updatePasteboard @@ -601,11 +637,12 @@ function Env(name, opts) { case 'Shadowrocket': default: $notification.post(title, subt, desc, toEnvOpts(opts)) + break case 'Quantumult X': $notify(title, subt, desc, toEnvOpts(opts)) - break; + break case 'Node.js': - break; + break } } if (!this.isMuteLog) { @@ -634,10 +671,10 @@ function Env(name, opts) { case 'Quantumult X': default: this.log('', `❗️${this.name}, 错误!`, err) - break; + break case 'Node.js': this.log('', `❗️${this.name}, 错误!`, err.stack) - break; + break } } @@ -658,10 +695,10 @@ function Env(name, opts) { case 'Quantumult X': default: $done(val) - break; + break case 'Node.js': process.exit(1) - break; + break } } })(name, opts) diff --git a/Env.min.js b/Env.min.js index 99b599f9a..11ea60c06 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));break;case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 473d1882a840ec18cd5fa3e4162851e006b0d115 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 26 May 2023 16:04:47 +0800 Subject: [PATCH 192/311] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8dacc0580..0cea240e6 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ A SPA Appliction be used for scripts utils * 便于阅读:[Env.js](./Env.js?raw=true "Env.js") --- + +# 赞助 + +1. [CloudFlare](https://www.cloudflare.com/) # 📃LICENSE Copyright © 2019-present chavyleung. This project is [GPL](https://github.com/chavyleung/scripts/blob/master/LICENSE) licensed. From 5dfc4fed790b84ad1a5399e5d566410ffc2b6984 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:25:13 +0800 Subject: [PATCH 193/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]:=E4=BF=AE=E5=A4=8D=E6=9C=88=E5=BA=95?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E5=AE=9D=E7=AE=B1=E9=A2=86=E5=8F=96=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84bug=EF=BC=8C=E4=BF=AE=E6=94=B9README.md?= =?UTF-8?q?=E6=95=99=E7=A8=8B=20(#442)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 36 +++++++++++++----------------------- zsfc/zsfc.js | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/zsfc/README.md b/zsfc/README.md index 41486a129..3e14b9e66 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -2,38 +2,31 @@ > 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 > 感谢[@danchaw](https://github.com/danchaw) PR +> 感谢[@chiupam](https://github.com/chiupam) 修改 +> ## 配置 (Surge) ```properties [MITM] -mwegame.qq.com +hostname = %APPEDN% mwegame.qq.com [Script] -http-request ^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js -cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +# 掌上飞车 +掌上飞车Cookie = type=http-request, pattern=^https?://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, script-update-interval=0, timeout=15 +掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, script-update-interval=0, timeout=30 ``` ## 配置 (QuanX) ```properties [MITM] -mwegame.qq.com +hostname = mwegame.qq.com [rewrite_local] - -# [商店版] -^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month url script-request-header zsfc.js - -# [TestFlight] ^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js [task_local] - -# [商店版] -1 0 * * * zsfc.js - -# [TestFlight] -1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js ``` ## 说明 @@ -41,14 +34,9 @@ mwegame.qq.com 1. 先把`mwegame.qq.com`加到`[MITM]` 2. 再配置重写规则: - Surge: 把两条远程脚本放到`[Script]` - - QuanX: 把`nio.cookie.js`和`nio.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) -3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后手动签到 1 次, 系统提示: `首次写入xxxUrl成功🎉,首次写入xxxCookie成功🎉` -4. 最后就可以把第 1 条脚本注释掉了 -5. 运行一次脚本, 如果提示重复签到, 那就算成功了! - -> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. - -> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次. + - QuanX: 把`zsfc.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) +3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后手动签到 1 次, 系统提示: `✅ 获取签到数据成功!` +4. 运行一次脚本, 如果提示重复签到, 那就算成功了! ## 常见问题 @@ -101,3 +89,5 @@ mwegame.qq.com [@ConnersHua](https://github.com/ConnersHua) [@danchaw](https://github.com/danchaw) + +[@chiupam](https://github.com/chiupam) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 9560c9f59..68f9c7051 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,8 +1,37 @@ +/** + * + * 使用方法:打开掌上飞车APP, 点击下方发现, 点击每日签到, 点击签到即可。 + * + * hostname: mwegame.qq.com + * + * type: http-request + * regex: ^https://mwegame\.qq\.com/ams/sign/doSign/month + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * requests-body: 1 + * + * type: cron + * cron: 0 10 0 * * * + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * + * =============== Surge =============== + * 掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * + * =============== Loon =============== + * http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie + * cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车Cookie + * + * =============== Quan X =============== + * ^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * 0 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车Cookie, enabled=true + * +*/ + const $ = new Env(`🏎️ 掌上飞车`) const date = new Date() const illustrate = `掌上飞车APP => 发现 => 每日签到 => 点击签到` typeof $request !== `undefined` ? start() : main() - + function start () { if ($request.url && $request.headers) { try {userId = $request.url.match(/userId=([^&]+)/)[1]} catch {userId = ``} @@ -43,7 +72,7 @@ async function main () { function index() { return new Promise(resolve => { const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?` + + url: `https://mwegame.qq.com/ams/sign/month/speed?` + `${$.read(`zsfc_query`)}`, headers: $.toObj($.read(`zsfc_headers`)) } @@ -94,14 +123,14 @@ function sign (_id) { function speed() { return new Promise(resolve => { const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?` + + url: `https://mwegame.qq.com/ams/sign/month/speed?` + `${$.read(`zsfc_query`)}`, headers: $.toObj($.read(`zsfc_headers`)) } $.log(`🧑‍💻 开始获取累计签到天数`) $.get(options, (error, response, data) => { if (data) { - let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16,0,0,0,0,0] + let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16,0,0,0,0,0,0] $.day_award = data.match(/(\d+)<\/span> 天/)[1] * 1 $.log(`✅ 当前 ${date.getMonth() + 1} 月累计签到 ${$.day_award} 天`) if (arr[$.day_award] != 0) { From 1cc6fe663634572c73c0e5e89c6a0cca20746bac Mon Sep 17 00:00:00 2001 From: 2YA <374779789@qq.com> Date: Mon, 10 Jul 2023 16:24:25 +0800 Subject: [PATCH 194/311] =?UTF-8?q?fix(chavy.boxjs)=20=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BC=9A=E8=AF=9D=20JSON=20=E8=BF=87?= =?UTF-8?q?=E5=A4=A7=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=89=80=E6=9C=89=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E6=93=8D=E4=BD=9C=E5=A4=B1=E6=95=88=20(#441)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 临时优化会话 JSON 过大,导致所有会话操作失效 * 增加 开放 surge 的 api 接口访问 * api:增加 /surge api 暴露 surge 的 api 接口 * chore: 格式化代码 * fix(chavy.box.js): 临时优化会话 JSON 过大,导致所有会话操作失效 --------- Co-authored-by: Chavy --- box/chavy.boxjs.js | 57 +++++++++++++++++++++++++++++++-- box/release/box.release.json | 12 +++++++ box/release/box.release.tf.json | 12 +++++++ chavy.box.js | 57 +++++++++++++++++++++++++++++++-- 4 files changed, 132 insertions(+), 6 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 8bb390836..0e482a662 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.9' +$.version = '0.12.10' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -253,6 +253,8 @@ async function handleApi() { await apiRunScript() } else if (api === '/saveData') { await apiSaveData() + } else if (api === '/surge') { + await apiSurge() } } @@ -293,6 +295,7 @@ function getBoxData() { appSubCaches, globalbaks } + return box } @@ -558,12 +561,34 @@ function getAppDatas(app) { return datas } +function dealKey(str) { + const [rootKey, delIndex] = str.split('.') + if (rootKey && rootKey.indexOf('@') > -1 && delIndex !== undefined) { + const key = rootKey.replace('@', '') + const datas = JSON.parse($.getdata(key)) + if (Array.isArray(datas) && delIndex <= datas.length - 1) { + datas.splice(delIndex, 1) + $.setdata(JSON.stringify(datas), key) + } + } +} + async function apiSave() { const data = $.toObj($request.body) if (Array.isArray(data)) { - data.forEach((dat) => $.setdata(dat.val, dat.key)) + data.forEach((dat) => { + if (dat.val === null) { + dealKey(dat.key) + } else { + $.setdata(dat.val, dat.key) + } + }) } else { - $.setdata(data.val, data.key) + if (data.val === null) { + dealKey(data.key) + } else { + $.setdata(data.val, data.key) + } } $.json = getBoxData() } @@ -725,6 +750,32 @@ async function apiRunScript() { } } +async function apiSurge() { + const opts = $.toObj($request.body) + const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi') + const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi) + if ( + $.isSurge() && + !$.isLoon() && + !$.isShadowrocket() && + !$.isStash() && + ishttpapi + ) { + const [key, prefix] = httpapi.split('@') + opts.url = `http://${prefix}/${opts.url}` + opts.headers = { + 'X-Key': key, + 'Accept': 'application/json, text/plain, */*' + } + await new Promise((resolve) => { + $[opts.method.toLowerCase()](opts, (_, __, resp) => { + $.json = JSON.parse(resp) + resolve($.json) + }) + }) + } +} + async function apiSaveData() { const { key: dataKey, val: dataVal } = $.toObj($request.body) $.setdata(dataVal, dataKey) diff --git a/box/release/box.release.json b/box/release/box.release.json index dc45cbc26..47a53fec8 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.10", + "tags": ["beta"], + "author": "@dompling", + "msg": "临时优化会话 JSON 过大,导致所有会话操作失效", + "notes": [ + { + "name": "修复", + "descs": ["临时优化会话 JSON 过大,导致所有会话操作失效"] + } + ] + }, { "version": "0.12.9", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index cc84fd9c3..a8f8cea71 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.10", + "tags": ["beta"], + "author": "@dompling", + "msg": "fix(chavy.box.js): 临时优化会话 JSON 过大,导致所有会话操作失效", + "notes": [ + { + "name": "修复", + "descs": ["临时优化会话 JSON 过大,导致所有会话操作失效"] + } + ] + }, { "version": "0.12.9", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 06dc79fe4..0e482a662 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.8' +$.version = '0.12.10' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -253,6 +253,8 @@ async function handleApi() { await apiRunScript() } else if (api === '/saveData') { await apiSaveData() + } else if (api === '/surge') { + await apiSurge() } } @@ -293,6 +295,7 @@ function getBoxData() { appSubCaches, globalbaks } + return box } @@ -558,12 +561,34 @@ function getAppDatas(app) { return datas } +function dealKey(str) { + const [rootKey, delIndex] = str.split('.') + if (rootKey && rootKey.indexOf('@') > -1 && delIndex !== undefined) { + const key = rootKey.replace('@', '') + const datas = JSON.parse($.getdata(key)) + if (Array.isArray(datas) && delIndex <= datas.length - 1) { + datas.splice(delIndex, 1) + $.setdata(JSON.stringify(datas), key) + } + } +} + async function apiSave() { const data = $.toObj($request.body) if (Array.isArray(data)) { - data.forEach((dat) => $.setdata(dat.val, dat.key)) + data.forEach((dat) => { + if (dat.val === null) { + dealKey(dat.key) + } else { + $.setdata(dat.val, dat.key) + } + }) } else { - $.setdata(data.val, data.key) + if (data.val === null) { + dealKey(data.key) + } else { + $.setdata(data.val, data.key) + } } $.json = getBoxData() } @@ -725,6 +750,32 @@ async function apiRunScript() { } } +async function apiSurge() { + const opts = $.toObj($request.body) + const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi') + const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi) + if ( + $.isSurge() && + !$.isLoon() && + !$.isShadowrocket() && + !$.isStash() && + ishttpapi + ) { + const [key, prefix] = httpapi.split('@') + opts.url = `http://${prefix}/${opts.url}` + opts.headers = { + 'X-Key': key, + 'Accept': 'application/json, text/plain, */*' + } + await new Promise((resolve) => { + $[opts.method.toLowerCase()](opts, (_, __, resp) => { + $.json = JSON.parse(resp) + resolve($.json) + }) + }) + } +} + async function apiSaveData() { const { key: dataKey, val: dataVal } = $.toObj($request.body) $.setdata(dataVal, dataKey) From f3938850d9cd618d7cfbe42e0a3cc4262b9902ad Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:26:26 +0800 Subject: [PATCH 195/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]:=E4=BC=98=E5=8C=96=E5=A4=A7=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81,=E5=87=BD=E6=95=B0=E5=86=85?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A,=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=99=88=E6=97=A7=E7=9A=84README.md=E6=96=87=E6=A1=A3=20(#444)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 56 ++---- zsfc/zsfc.js | 461 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 328 insertions(+), 189 deletions(-) diff --git a/zsfc/README.md b/zsfc/README.md index 3e14b9e66..6247abe7d 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -11,9 +11,19 @@ hostname = %APPEDN% mwegame.qq.com [Script] -# 掌上飞车 -掌上飞车Cookie = type=http-request, pattern=^https?://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, script-update-interval=0, timeout=15 -掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, script-update-interval=0, timeout=30 +掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=10 +掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=10 +``` + +## 配置 (Loon) + +```properties +[Mitm] +hostname = mwegame.qq.com + +[Script] +http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie +cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, tag=掌上飞车 ``` ## 配置 (QuanX) @@ -23,10 +33,10 @@ hostname = %APPEDN% mwegame.qq.com hostname = mwegame.qq.com [rewrite_local] -^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js [task_local] -10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +0 10 0 * * * https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, tag=掌上飞车, enabled=true ``` ## 说明 @@ -34,7 +44,8 @@ hostname = mwegame.qq.com 1. 先把`mwegame.qq.com`加到`[MITM]` 2. 再配置重写规则: - Surge: 把两条远程脚本放到`[Script]` - - QuanX: 把`zsfc.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) + - Loon: 把两条远程脚本放到`[Script]` + - QuanX: 把远程重写脚本放到`[rewrite_local]`,再把远程定时任务放到`[task_local]` 3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后手动签到 1 次, 系统提示: `✅ 获取签到数据成功!` 4. 运行一次脚本, 如果提示重复签到, 那就算成功了! @@ -42,44 +53,13 @@ hostname = mwegame.qq.com 1. 无法写入 Cookie - - 检查 Surge 系统通知权限放开了没 - - 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴) + - 检查系统通知权限放开了没 2. 写入 Cookie 成功, 但签到不成功 - 看看是不是在登录前就写入 Cookie 了 - 如果是,请确保在登录成功后,再尝试写入 Cookie -3. 为什么有时成功有时失败 - - - 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败) - - 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学): - - - `Surge`配置: - - ```properties - # 没有什么是一顿饭解决不了的: - cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次 - # 如果有,那就两顿: - cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次 - # 实在不行,三顿也能接受: - cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次 - - # 再粗暴点,直接: - cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次 - ``` - - - `QuanX`配置: - - ```properties - [task_local] - 1 0 * * * xxx.js # 每天00:01执行一次 - 2 0 * * * xxx.js # 每天00:02执行一次 - 3 0 * * * xxx.js # 每天00:03执行一次 - - */60 * * * * xxx.js # 每60分执行一次 - ``` - ## 感谢 [@NobyDa](https://github.com/NobyDa) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 68f9c7051..21659548c 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,210 +1,369 @@ /** - * + * * 使用方法:打开掌上飞车APP, 点击下方发现, 点击每日签到, 点击签到即可。 - * + * * hostname: mwegame.qq.com - * + * * type: http-request * regex: ^https://mwegame\.qq\.com/ams/sign/doSign/month * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * requests-body: 1 - * + * * type: cron * cron: 0 10 0 * * * * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js - * + * * =============== Surge =============== * 掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 * 掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 - * + * * =============== Loon =============== * http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie - * cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车Cookie - * + * cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 + * * =============== Quan X =============== * ^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js - * 0 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车Cookie, enabled=true - * + * 0 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true + * */ + +/** + * 创建一个名为 $ 的环境变量实例,用于处理掌上飞车相关操作 + */ const $ = new Env(`🏎️ 掌上飞车`) -const date = new Date() -const illustrate = `掌上飞车APP => 发现 => 每日签到 => 点击签到` -typeof $request !== `undefined` ? start() : main() - -function start () { - if ($request.url && $request.headers) { - try {userId = $request.url.match(/userId=([^&]+)/)[1]} catch {userId = ``} - try {areaId = $request.url.match(/areaId=([^&]+)/)[1]} catch {areaId = ``} - try {roleId = $request.url.match(/roleId=([^&]+)/)[1]} catch {roleId = ``} - try {token = $request.url.match(/token=([^&]+)/)[1]} catch {token = ``} - try {uin = $request.url.match(/uin=([^&]+)/)[1]} catch {uin = ``} - $.write($request.url.replace(/&gift_id=\d+/, ""), `zsfc_url`) - $.write($.toStr($request.headers), `zsfc_headers`) - $.write(`userId=${userId}&areaId=${areaId}&roleId=${roleId}&token=${token}&uin=${uin}`, `zsfc_query`) - $.notice($.name, `✅ 获取签到数据成功!`, `请不要再次打开掌上飞车APP, 否则 Cookie 将失效!`) - } else { - $.notice($.name, ``, `⭕ 无法读取请求头, 请检查配置`) - } - $.done() -} -async function main () { - if (!$.read(`zsfc_url`)) { - $.log(`❌ 当前 Cookie 为空, 请先获取`) - $.notice($.name, `❌ 当前 Cookie 为空, 请先获取`, illustrate) - } else if ($.read(`zsfc_query`).indexOf(`&token=&`) != -1) { - $.log(`❌ 当前 Cookie 错误, 请重新获取`) - $.notice($.name, `❌ 当前 Cookie 错误, 请重新获取`, illustrate) +/** + * 检查是否为请求阶段 + */ +const isreq = typeof $request !== 'undefined'; + +/** + * 主函数,用于执行打卡操作或设置请求数据 + */ +(async () => { + if (isreq) { + // 请求阶段,设置请求数据 + if (!$request.url || !$request.headers) { + // 无法读取请求头,显示配置错误通知 + $.notice($.name, '', '⭕ 无法读取请求头, 请检查配置'); + return; + } + + // 提取请求数据 + const url = $request.url.replace(/&gift_id=\d+/, ''); + const headers = $.toStr($request.headers); + const query = [ + `userId=${matchParam(url, 'userId')}`, + `areaId=${matchParam(url, 'areaId')}`, + `roleId=${matchParam(url, 'roleId')}`, + `token=${matchParam(url, 'token')}`, + `uin=${matchParam(url, 'uin')}`, + ].join('&'); + + // 将请求数据写入内存 + $.write(url, 'zsfc_url'); + $.write(headers, 'zsfc_headers'); + $.write(query, 'zsfc_query'); + + $.notice($.name, '✅ 获取签到数据成功!', '请不要再次打开掌上飞车APP, 否则 Cookie 将失效!'); } else { - await sign(await index()) - if ($.expired != 0) { - await speed() - if ($.giftid) await handle($.giftid, `第 ${$.day_award } 天奖励`) - if ($.giftdays) await handle($.giftdays, ` ${$.day_welfare} 特别福利`) - } else { - $.notice($.name, `❌ 当前Cookie 已失效, 请重新获取`, illustrate) + // 执行打卡操作阶段 + const url = $.read('zsfc_url'); + const query = $.read('zsfc_query'); + const illustrate = `掌上飞车APP => 发现 => 每日签到 => 点击签到`; + + if (!url) { + // Cookie 为空,显示获取Cookie错误通知 + $.notice($.name, '❌ 当前 Cookie 为空, 请先获取', illustrate); + return; + } + + if (query.indexOf('&areaId=&') !== -1) { + // Cookie 错误,显示重新获取Cookie错误通知 + $.notice($.name, '❌ 当前 Cookie 错误, 请重新获取', illustrate); + return; + } + + // 获取连续签到的礼物ID + const successiveGiftId = await getSuccessiveGiftId(); + // 进行连续签到 + const isSuccessiveCheckin = await dailyCheckin(successiveGiftId); + + if (!isSuccessiveCheckin) { + // Cookie 失效,显示重新获取Cookie错误通知 + $.notice($.name, '❌ 当前 Cookie 已失效, 请重新获取', illustrate); + return; } + + // 获取签到信息数组 + signInInfoArray = await getSignInInfo(); + + // 遍历签到信息数组,领取每日礼物 + for (let signInInfo of signInInfoArray) { + let { code, title } = signInInfo; + await claimGift(code, title); + } + + // 显示签到结果通知 + $.notice(`${$.name}(${$.subtitle})`, ``, $.message, ``) + } - $.done() +})() + .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) + .finally(() => $.done()); + +/** + * 匹配 URL 参数 + * @param {string} url - URL 字符串 + * @param {string} key - 参数名 + * @returns {string} + */ +function matchParam(url, key) { + const match = url.match(new RegExp(`${key}=([^&]+)`)); + return match ? match[1] : ''; } -function index() { +/** + * 获取连续签到的礼物 ID + * @returns {Promise} 返回连续签到的礼物 ID + */ +async function getSuccessiveGiftId() { + // 用于保存连续签到的礼物 ID + let giftid; + + // 构造请求参数 + const options = { + url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + headers: $.toObj($.read(`zsfc_headers`)) + }; + + // 发送 GET 请求,获取签到页面信息 return new Promise(resolve => { - const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?` + - `${$.read(`zsfc_query`)}`, - headers: $.toObj($.read(`zsfc_headers`)) - } - $.get(options, (error, response, data) => { + $.get(options, (err, resp, data) => { if (data) { - successive = data.match(/giftid="([^"]+)"/g)[0].match(/(\d+)/)[1] - } else { - $.log(`❌ 获取签到页面信息时发生错误`) - $.log($.toStr(error)) + // 解析响应数据,提取礼物 ID + giftid = data.match(/giftid="([^"]+)"/g)[0].match(/(\d+)/)[1]; } - resolve(successive) - }) - }) + resolve(giftid); + }); + }); } -function sign (_id) { +/** + * 每日签到函数 + * @param {string} giftId 礼物 ID + * @returns {Promise} 返回签到结果,true 表示签到成功,false 表示签到失败 + */ +async function dailyCheckin(giftId) { + // 初始化签到结果为 false + let result = false; + + // 构造请求参数 + const options = { + url: `${$.read("zsfc_url")}&gift_id=${giftId}`, + headers: $.toObj($.read(`zsfc_headers`)) + }; + + // 输出日志,开始每日签到 + $.log(`🧑‍💻 开始每日签到`); + + // 发送 GET 请求,进行签到 return new Promise(resolve => { - const options = { - url: `${$.read("zsfc_url")}&gift_id=${_id}`, - headers: $.toObj($.read(`zsfc_headers`)) - } - $.log(`🧑‍💻 开始检查 Cookie 并进行每日签到`) - $.get(options, (error, response, data) => { + $.get(options, (err, resp, data) => { if (data) { - let result = $.toObj(data.replace(/\r|\n/ig, ``)) - let message = result.message + // 解析响应数据 + let body = $.toObj(data.replace(/\r|\n/ig, ``)); + let message = body.message; + if (message.indexOf(`重试`) > -1) { - $.expired = 0 - $.log(`❌ 当前 Cookie 已失效, 请重新获取`) + // Cookie 失效,签到失败 + $.log(`❌ 当前 Cookie 已失效, 请重新获取`); + $.message = ``; } else if (message.indexOf(`已经`) > -1) { - $.log(`✅ 检查结果: 当前 Cookie 有效`) - $.log(`⭕ 签到结果: ${message}`) + // Cookie 有效,再次签到 + result = true; + $.log(`⭕ 签到结果: ${message}`); + $.message = `签到结果: ${message}`; } else { - sMsg = result.send_result.sMsg - $.log(`✅ 检查结果: 当前 Cookie 有效`) - $.log(`✅ ${sMsg}`) - $.notice($.name, `✅ ${message}`, sMsg, ``) + // Cookie 有效,签到成功 + result = true; + $.log(`✅ ${body.send_result.sMsg.replace(":", ":")}`); + $.message = body.send_result.sMsg.replace(":", ":"); } } else { - $.log(`❌ 无法完成每日签到`) - $.log(error) + // 发生错误,签到失败 + $.log(`❌ 进行每日签到时发生错误`); + $.log($.toStr(err)); } - resolve() - }) - }) + resolve(result); + }); + }); } -function speed() { +/** + * @description 获取签到信息,并返回签到礼物列表 + * @returns {Promise} 一个返回包含签到礼物的数组的 Promise。 + */ +async function getSignInInfo() { + // 获取当前时间 + const date = new Date(); + + // 设置请求参数 + const options = { + url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, + headers: $.toObj($.read(`zsfc_headers`)) + } + + // 输出日志,开始获取累计签到天数 + $.log(`🧑‍💻 开始获取累计签到天数`); + + // 初始化 signInGifts 为空列表 + let signInGifts = []; + + // 发送 GET 请求,获取签到信息 return new Promise(resolve => { - const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?` + - `${$.read(`zsfc_query`)}`, - headers: $.toObj($.read(`zsfc_headers`)) - } - $.log(`🧑‍💻 开始获取累计签到天数`) - $.get(options, (error, response, data) => { + $.get(options, (err, resp, data) => { if (data) { - let arr = [0,1,2,3,0,4,0,5,0,6,7,8,0,9,0,10,11,0,12,13,0,14,15,0,0,16,0,0,0,0,0,0] - $.day_award = data.match(/(\d+)<\/span> 天/)[1] * 1 - $.log(`✅ 当前 ${date.getMonth() + 1} 月累计签到 ${$.day_award} 天`) - if (arr[$.day_award] != 0) { - $.giftid = data.match(/giftid="([^"]+)"/g)[arr[$.day_award]].match(/(\d+)/)[1] + // 定义一个数组,用于将累计签到天数映射到礼物编号 + const giftIndexByDay = [ + 0, // 占位,第一个元素不是第一天 + 1, 2, 3, 0, 4, 0, 5, 0, 6, 7, + 8, 0, 9, 0, 10, 11, 0, 12, 13, 0, + 14, 15, 0, 0, 16, 0, 0, 0, 0, 0, 0 + ]; + + // 使用正则表达式获取累计签到天数 + const totalSignInDays = Number(data.match(/(\d+)<\/span>/)?.[1]); + $.subtitle = `累计签到 ${totalSignInDays} 天`; + $.log(`✅ ${$.subtitle}`); + + // 根据累计签到天数获取礼物编号,并将其添加到 signInGifts 中 + const giftIndex = giftIndexByDay[totalSignInDays]; + const giftCode = giftIndex ? data.match(/giftid="([^"]+)"/g)[giftIndex].match(/(\d+)/)[1] : null; + if (giftIndex && giftCode) signInGifts.push({ code: giftCode, title: `第 ${giftIndexByDay.indexOf(giftIndex)} 天奖励` }); + + // 获取当前日期的日数,并检查是否为每月的第 X 天,如果是则将礼物编号添加到 signInGifts 中 + const [matchMonthDay] = data.match(/月(\d+)日/g) || []; + const [, day] = matchMonthDay?.match(/(\d+)/) || []; + if (day && Number(day) === date.getDate()) { + const giftDays = data.match(/"giftdays([^"]+)"/g)[0].match(/(\d+)/)[1]; + const dayWelfare = `${date.getMonth() + 1}月${date.getDate()}日`; + signInGifts.push({ code: giftDays, title: ` ${dayWelfare} 特别福利` }); } - try { - if (data.match(/月(\d+)日/g)[0].match(/(\d+)/)[1] * 1 == date.getDate()) { - $.day_welfare = `${date.getMonth() + 1}月${date.getDate()}日` - $.giftdays = data.match(/"giftdays([^"]+)"/g)[0].match(/(\d+)/)[1] - } - } catch {} + } else { - $.log(`❌ 获取累计签到天数时发生错误`) - $.log($.toStr(error)) + // 发生错误,输出错误日志 + $.log(`❌ 获取累计签到天数时发生错误`); + $.log($.toStr(err)); } - resolve() - }) - }) + // 将 signInGifts 作为 Promise 的返回值,以便在调用方使用 + resolve(signInGifts); + }); + }); } -function handle (_id, _award) { +/** + * 领取礼物函数 + * @param {string} giftId 礼物 ID + * @param {string} giftName 礼物名称 + */ +async function claimGift(giftId, giftName) { + // 设置请求参数 + const options = { + url: `https://mwegame.qq.com/ams/send/handle`, + headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_query`)}&gift_id=${giftId}` + }; + + // 输出日志,开始领取礼物 + $.log(`🧑‍💻 开始领取${giftName}`); + + // 发送 POST 请求,领取礼物 return new Promise(resolve => { - const options = { - url: `https://mwegame.qq.com/ams/send/handle`, - headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_query`)}&gift_id=${_id}` - } - $.log(`🧑‍💻 开始领取${_award}`) - $.post(options, (error, response, data) => { + $.post(options, (err, resp, data) => { if (data) { - let result = $.toObj(data.replace(/\r|\n/ig, ``)) + let result = $.toObj(data.replace(/\r|\n/ig, ``)); if (result.data.indexOf(`成功`) != -1) { - sPackageName = result.send_result.sPackageName - $.log(`✅ 领取结果: 获得${sPackageName}`) + // 领取成功,获取礼物名称并记录日志 + const sPackageName = result.send_result.sPackageName; + $.log(`✅ 领取结果: 获得${sPackageName}`); + $.message += `, ${sPackageName}`; } else { - $.log(`⭕ 领取结果: ${result.message}`) + // 领取失败,记录错误信息日志 + $.log(`⭕ 领取结果: ${result.message}`); } } else { - $.log(`❌ 领取${_award}时发生错误`) - $.log($.toStr(error)) + // 发生错误,输出错误日志 + $.log(`❌ 开始领取${giftName}时发生错误`); + $.log($.toStr(err)); } - resolve() - }) + resolve(); + }); }) } - + +/** + * 创建一个名为 Env 的构造函数,用于处理环境相关操作。 + * @param {string} name - 环境名称 + */ function Env(name) { - LN = typeof $loon != `undefined` - SG = typeof $httpClient != `undefined` && !LN - QX = typeof $task != `undefined` - read = (key) => { - if (LN || SG) return $persistentStore.read(key) - if (QX) return $prefs.valueForKey(key) - } - write = (key, val) => { - if (LN || SG) return $persistentStore.write(key, val); - if (QX) return $prefs.setValueForKey(key, val) - } - notice = (title, subtitle, message, url) => { - if (LN) $notification.post(title, subtitle, message, url) - if (SG) $notification.post(title, subtitle, message, { url: url }) - if (QX) $notify(title, subtitle, message, { 'open-url': url }) - } - get = (url, cb) => { - if (LN || SG) {$httpClient.get(url, cb)} - if (QX) {url.method = `GET`; $task.fetch(url).then((resp) => cb(null, {}, resp.body))} - } - post = (url, cb) => { - if (LN || SG) {$httpClient.post(url, cb)} - if (QX) {url.method = `POST`; $task.fetch(url).then((resp) => cb(null, {}, resp.body))} - } - toObj = (str) => JSON.parse(str) - toStr = (obj) => JSON.stringify(obj) - log = (message) => console.log(message) - done = (value = {}) => {$done(value)} - return { name, read, write, notice, get, post, toObj, toStr, log, done } + // 判断当前环境是否为 Loon + const isLoon = typeof $loon !== "undefined"; + // 判断当前环境是否为 Surge + const isSurge = typeof $httpClient !== "undefined" && !isLoon; + // 判断当前环境是否为 QuantumultX + const isQX = typeof $task !== "undefined"; + + // 定义 read 方法,用于读取数据 + const read = (key) => { + if (isLoon || isSurge) return $persistentStore.read(key); + if (isQX) return $prefs.valueForKey(key); + }; + + // 定义 write 方法,用于写入数据 + const write = (key, value) => { + if (isLoon || isSurge) return $persistentStore.write(key, value); + if (isQX) return $prefs.setValueForKey(key, value); + }; + + // 定义 notice 方法,用于发送通知 + const notice = (title, subtitle, message, url) => { + if (isLoon) $notification.post(title, subtitle, message, url); + if (isSurge) $notification.post(title, subtitle, message, { url }); + if (isQX) $notify(title, subtitle, message, { "open-url": url }); + }; + + // 定义 get 方法,用于发送 GET 请求 + const get = (url, callback) => { + if (isLoon || isSurge) $httpClient.get(url, callback); + if (isQX) {url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + + // 定义 post 方法,用于发送 POST 请求 + const post = (url, callback) => { + if (isLoon || isSurge) $httpClient.post(url, callback); + if (isQX) {url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + + // 定义 put 方法,用于发送 PUT 请求 + const put = (url, callback) => { + if (isLoon || isSurge) $httpClient.put(url, callback) + if (isQX) {url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + + // 定义 toObj 方法,用于将字符串转为对象 + const toObj = (str) => JSON.parse(str); + + // 定义 toStr 方法,用于将对象转为字符串 + const toStr = (obj) => JSON.stringify(obj); + + // 定义 log 方法,用于输出日志 + const log = (message) => console.log(message); + + // 定义 done 方法,用于结束任务 + const done = (value = {}) => $done(value); + + // 返回包含所有方法的对象 + return { name, read, write, notice, get, post, put, toObj, toStr, log, done }; } From 02d54ff0c83dfe9070daf91e6c10a576786c14c5 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Sat, 22 Jul 2023 22:46:50 +0800 Subject: [PATCH 196/311] feat: support paramas on GET method --- Env.js | 4 +- Env.min.js | 2 +- yarn.lock | 134 ++++++++++++++++++++++++++--------------------------- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/Env.js b/Env.js index c75382835..48a3f2bb8 100644 --- a/Env.js +++ b/Env.js @@ -319,6 +319,9 @@ function Env(name, opts) { delete request.headers['content-type'] delete request.headers['content-length'] } + if (request.params) { + request.url += '?' + this.queryStr(request.params) + } switch (this.getEnv()) { case 'Surge': case 'Loon': @@ -698,7 +701,6 @@ function Env(name, opts) { break case 'Node.js': process.exit(1) - break } } })(name, opts) diff --git a/Env.min.js b/Env.min.js index 11ea60c06..700daba1b 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));break;case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));break;case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ca43766c0..e0113f3a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4,19 +4,19 @@ "@sindresorhus/is@^4.0.0": version "4.0.0" - resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.0.0.tgz#2ff674e9611b45b528896d820d3d7a812de2f0e4" + resolved "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz" integrity sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ== "@szmarczak/http-timer@^4.0.5": version "4.0.5" - resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.5.tgz#bfbd50211e9dfa51ba07da58a14cdfd333205152" + resolved "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz" integrity sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ== dependencies: defer-to-connect "^2.0.0" "@types/cacheable-request@^6.0.1": version "6.0.1" - resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.1.tgz#5d22f3dded1fd3a84c0bbeb5039a7419c2c91976" + resolved "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz" integrity sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ== dependencies: "@types/http-cache-semantics" "*" @@ -26,48 +26,48 @@ "@types/http-cache-semantics@*": version "4.0.0" - resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz#9140779736aa2655635ee756e2467d787cfe8a2a" + resolved "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz" integrity sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A== "@types/keyv@*": version "3.1.1" - resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.1.tgz#e45a45324fca9dab716ab1230ee249c9fb52cfa7" + resolved "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz" integrity sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw== dependencies: "@types/node" "*" "@types/node@*": version "14.14.20" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.20.tgz#f7974863edd21d1f8a494a73e8e2b3658615c340" + resolved "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz" integrity sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A== "@types/responselike@*", "@types/responselike@^1.0.0": version "1.0.0" - resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29" + resolved "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz" integrity sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA== dependencies: "@types/node" "*" async@^2.6.2: version "2.6.4" - resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221" + resolved "https://registry.npmjs.org/async/-/async-2.6.4.tgz" integrity sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA== dependencies: lodash "^4.17.14" basic-auth@^1.0.3: version "1.1.0" - resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-1.1.0.tgz#45221ee429f7ee1e5035be3f51533f1cdfd29884" + resolved "https://registry.npmjs.org/basic-auth/-/basic-auth-1.1.0.tgz" integrity sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ= cacheable-lookup@^5.0.3: version "5.0.4" - resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz#5a6b865b2c44357be3d5ebc2a467b032719a7005" + resolved "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz" integrity sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA== cacheable-request@^7.0.2: version "7.0.2" - resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.2.tgz#ea0d0b889364a25854757301ca12b2da77f91d27" + resolved "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz" integrity sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew== dependencies: clone-response "^1.0.2" @@ -80,7 +80,7 @@ cacheable-request@^7.0.2: call-bind@^1.0.0: version "1.0.2" - resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + resolved "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz" integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== dependencies: function-bind "^1.1.1" @@ -88,48 +88,48 @@ call-bind@^1.0.0: clone-response@^1.0.2: version "1.0.2" - resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b" + resolved "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz" integrity sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws= dependencies: mimic-response "^1.0.0" colors@^1.4.0: version "1.4.0" - resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" + resolved "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz" integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== corser@^2.0.1: version "2.0.1" - resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87" + resolved "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz" integrity sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c= crypto-js@^4.0.0: version "4.0.0" - resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc" + resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz" integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg== debug@^3.1.1: version "3.2.7" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" + resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz" integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ== dependencies: ms "^2.1.1" decompress-response@^6.0.0: version "6.0.0" - resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-6.0.0.tgz#ca387612ddb7e104bd16d85aab00d5ecf09c66fc" + resolved "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz" integrity sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ== dependencies: mimic-response "^3.1.0" defer-to-connect@^2.0.0: version "2.0.0" - resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.0.tgz#83d6b199db041593ac84d781b5222308ccf4c2c1" + resolved "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz" integrity sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg== ecstatic@^3.3.2: version "3.3.2" - resolved "https://registry.yarnpkg.com/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48" + resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz" integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog== dependencies: he "^1.1.1" @@ -139,29 +139,29 @@ ecstatic@^3.3.2: end-of-stream@^1.1.0: version "1.4.4" - resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" + resolved "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz" integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== dependencies: once "^1.4.0" eventemitter3@^4.0.0: version "4.0.7" - resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" + resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== follow-redirects@^1.0.0: version "1.14.8" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" + resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz" integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== function-bind@^1.1.1: version "1.1.1" - resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== get-intrinsic@^1.0.2: version "1.1.3" - resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.3.tgz#063c84329ad93e83893c7f4f243ef63ffa351385" + resolved "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz" integrity sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A== dependencies: function-bind "^1.1.1" @@ -170,14 +170,14 @@ get-intrinsic@^1.0.2: get-stream@^5.1.0: version "5.2.0" - resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" + resolved "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz" integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== dependencies: pump "^3.0.0" got@^11.8.5: version "11.8.5" - resolved "https://registry.yarnpkg.com/got/-/got-11.8.5.tgz#ce77d045136de56e8f024bebb82ea349bc730046" + resolved "https://registry.npmjs.org/got/-/got-11.8.5.tgz" integrity sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ== dependencies: "@sindresorhus/is" "^4.0.0" @@ -194,29 +194,29 @@ got@^11.8.5: has-symbols@^1.0.3: version "1.0.3" - resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" + resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz" integrity sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A== has@^1.0.3: version "1.0.3" - resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + resolved "https://registry.npmjs.org/has/-/has-1.0.3.tgz" integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== dependencies: function-bind "^1.1.1" he@^1.1.1: version "1.2.0" - resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" + resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== http-cache-semantics@^4.0.0: version "4.1.1" - resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a" + resolved "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz" integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ== http-proxy@^1.18.0: version "1.18.1" - resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549" + resolved "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz" integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ== dependencies: eventemitter3 "^4.0.0" @@ -225,7 +225,7 @@ http-proxy@^1.18.0: http-server@^0.12.3: version "0.12.3" - resolved "https://registry.yarnpkg.com/http-server/-/http-server-0.12.3.tgz#ba0471d0ecc425886616cb35c4faf279140a0d37" + resolved "https://registry.npmjs.org/http-server/-/http-server-0.12.3.tgz" integrity sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA== dependencies: basic-auth "^1.0.3" @@ -241,7 +241,7 @@ http-server@^0.12.3: http2-wrapper@^1.0.0-beta.5.2: version "1.0.0-beta.5.2" - resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.0-beta.5.2.tgz#8b923deb90144aea65cf834b016a340fc98556f3" + resolved "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.0-beta.5.2.tgz" integrity sha512-xYz9goEyBnC8XwXDTuC/MZ6t+MrKVQZOk4s7+PaDkwIsQd8IwqvM+0M6bA/2lvG8GHXcPdf+MejTUeO2LCPCeQ== dependencies: quick-lru "^5.1.1" @@ -249,95 +249,95 @@ http2-wrapper@^1.0.0-beta.5.2: iconv-lite@0.6.3: version "0.6.3" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" + resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz" integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== dependencies: safer-buffer ">= 2.1.2 < 3.0.0" json-buffer@3.0.1: version "3.0.1" - resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" + resolved "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz" integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ== keyv@^4.0.0: version "4.0.3" - resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.0.3.tgz#4f3aa98de254803cafcd2896734108daa35e4254" + resolved "https://registry.npmjs.org/keyv/-/keyv-4.0.3.tgz" integrity sha512-zdGa2TOpSZPq5mU6iowDARnMBZgtCqJ11dJROFi6tg6kTn4nuUdU09lFyLFSaHrWqpIJ+EBq4E8/Dc0Vx5vLdA== dependencies: json-buffer "3.0.1" lodash@^4.17.14: version "4.17.21" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== lowercase-keys@^2.0.0: version "2.0.0" - resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" + resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== mime@^1.6.0: version "1.6.0" - resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== mimic-response@^1.0.0: version "1.0.1" - resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" + resolved "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz" integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ== mimic-response@^3.1.0: version "3.1.0" - resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9" + resolved "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz" integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ== minimist@^1.1.0, minimist@^1.2.5: version "1.2.6" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" + resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz" integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== mkdirp@^0.5.5: version "0.5.5" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" + resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz" integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== dependencies: minimist "^1.2.5" ms@^2.1.1: version "2.1.3" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== normalize-url@^6.0.1: version "6.1.0" - resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a" + resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz" integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== object-inspect@^1.9.0: version "1.12.2" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.2.tgz#c0641f26394532f28ab8d796ab954e43c009a8ea" + resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz" integrity sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ== once@^1.3.1, once@^1.4.0: version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz" integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= dependencies: wrappy "1" opener@^1.5.1: version "1.5.2" - resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598" + resolved "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz" integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A== p-cancelable@^2.0.0: version "2.0.0" - resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.0.0.tgz#4a3740f5bdaf5ed5d7c3e34882c6fb5d6b266a6e" + resolved "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz" integrity sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg== portfinder@^1.0.25: version "1.0.28" - resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.28.tgz#67c4622852bd5374dd1dd900f779f53462fac778" + resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz" integrity sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA== dependencies: async "^2.6.2" @@ -346,12 +346,12 @@ portfinder@^1.0.25: psl@^1.1.33: version "1.8.0" - resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24" + resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz" integrity sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ== pump@^3.0.0: version "3.0.0" - resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64" + resolved "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz" integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== dependencies: end-of-stream "^1.1.0" @@ -359,51 +359,51 @@ pump@^3.0.0: punycode@^2.1.1: version "2.1.1" - resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" + resolved "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== qs@^6.4.0: version "6.11.0" - resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a" + resolved "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz" integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q== dependencies: side-channel "^1.0.4" quick-lru@^5.1.1: version "5.1.1" - resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" + resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz" integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA== requires-port@^1.0.0: version "1.0.0" - resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz" integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= resolve-alpn@^1.0.0: version "1.0.0" - resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.0.0.tgz#745ad60b3d6aff4b4a48e01b8c0bdc70959e0e8c" + resolved "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz" integrity sha512-rTuiIEqFmGxne4IovivKSDzld2lWW9QCjqv80SYjPgf+gS35eaCAjaP54CCwGAwBtnCsvNLYtqxe1Nw+i6JEmA== responselike@^2.0.0: version "2.0.0" - resolved "https://registry.yarnpkg.com/responselike/-/responselike-2.0.0.tgz#26391bcc3174f750f9a79eacc40a12a5c42d7723" + resolved "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz" integrity sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw== dependencies: lowercase-keys "^2.0.0" "safer-buffer@>= 2.1.2 < 3.0.0": version "2.1.2" - resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== secure-compare@3.0.1: version "3.0.1" - resolved "https://registry.yarnpkg.com/secure-compare/-/secure-compare-3.0.1.tgz#f1a0329b308b221fae37b9974f3d578d0ca999e3" + resolved "https://registry.npmjs.org/secure-compare/-/secure-compare-3.0.1.tgz" integrity sha1-8aAymzCLIh+uN7mXTz1XjQypmeM= side-channel@^1.0.4: version "1.0.4" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" + resolved "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz" integrity sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw== dependencies: call-bind "^1.0.0" @@ -412,7 +412,7 @@ side-channel@^1.0.4: tough-cookie@^4.0.0: version "4.0.0" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.0.0.tgz#d822234eeca882f991f0f908824ad2622ddbece4" + resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz" integrity sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg== dependencies: psl "^1.1.33" @@ -421,22 +421,22 @@ tough-cookie@^4.0.0: union@~0.5.0: version "0.5.0" - resolved "https://registry.yarnpkg.com/union/-/union-0.5.0.tgz#b2c11be84f60538537b846edb9ba266ba0090075" + resolved "https://registry.npmjs.org/union/-/union-0.5.0.tgz" integrity sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA== dependencies: qs "^6.4.0" universalify@^0.1.2: version "0.1.2" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" + resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== url-join@^2.0.5: version "2.0.5" - resolved "https://registry.yarnpkg.com/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728" + resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz" integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg= wrappy@1: version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= From 0f180ee37919d3134e2d8a38d40397a3396806ee Mon Sep 17 00:00:00 2001 From: morooi <19279567+morooi@users.noreply.github.com> Date: Sat, 22 Jul 2023 23:49:43 +0800 Subject: [PATCH 197/311] =?UTF-8?q?fix(v2ex):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=20Cookie=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#448)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2ex/quanx/v2ex.cookie.js | 2 +- v2ex/v2ex.cookie.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/v2ex/quanx/v2ex.cookie.js b/v2ex/quanx/v2ex.cookie.js index 5119d086c..057214fa9 100644 --- a/v2ex/quanx/v2ex.cookie.js +++ b/v2ex/quanx/v2ex.cookie.js @@ -1,6 +1,6 @@ const cookieName = 'V2EX' const cookieKey = 'chavy_cookie_v2ex' -const cookieVal = $request.headers['Cookie'] +const cookieVal = $request.headers['Cookie'] || $request.headers['cookie'] if (cookieVal) { let cookie = $prefs.setValueForKey(cookieVal, cookieKey) diff --git a/v2ex/v2ex.cookie.js b/v2ex/v2ex.cookie.js index 39c1bb7fd..2b7ce6ac8 100644 --- a/v2ex/v2ex.cookie.js +++ b/v2ex/v2ex.cookie.js @@ -1,6 +1,6 @@ const cookieName = 'V2EX' const cookieKey = 'chavy_cookie_v2ex' -const cookieVal = $request.headers['Cookie'] +const cookieVal = $request.headers['Cookie'] || $request.headers['cookie'] if (cookieVal) { let cookie = $persistentStore.write(cookieVal, cookieKey) From 0e09a2b5f584779e197ded7d9ce08e3358d22351 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Sun, 23 Jul 2023 11:23:23 +0800 Subject: [PATCH 198/311] chore: achived [10086] [bcz] [dbsj] [fenqile] --- Loon.cookie.conf | 9 +++------ Loon.task.conf | 8 +++----- QuantumultX_AppStore_Local_Cookie.conf | 13 +++++-------- QuantumultX_Local_Cookie.conf | 13 +++---------- QuantumultX_Local_Task.conf | 14 +++----------- QuantumultX_Remote_Task.conf | 15 --------------- {10086 => achived/10086}/10086.cookie.js | 0 {10086 => achived/10086}/10086.fee.cookie.js | 0 {10086 => achived/10086}/10086.fee.js | 0 {10086 => achived/10086}/10086.js | 0 {10086 => achived/10086}/README.md | 0 {bcz => achived/bcz}/README.md | 0 {bcz => achived/bcz}/bcz.cookie.js | 0 {bcz => achived/bcz}/bcz.js | 0 {dbsj => achived/dbsj}/README.md | 0 {dbsj => achived/dbsj}/dbsj.cookie.js | 0 {dbsj => achived/dbsj}/dbsj.js | 0 {fenqile => achived/fenqile}/README.md | 0 {fenqile => achived/fenqile}/fenqile.cookie.js | 0 {fenqile => achived/fenqile}/fenqile.js | 0 surge.cookies.sgmodule | 6 ------ 21 files changed, 17 insertions(+), 61 deletions(-) rename {10086 => achived/10086}/10086.cookie.js (100%) rename {10086 => achived/10086}/10086.fee.cookie.js (100%) rename {10086 => achived/10086}/10086.fee.js (100%) rename {10086 => achived/10086}/10086.js (100%) rename {10086 => achived/10086}/README.md (100%) rename {bcz => achived/bcz}/README.md (100%) rename {bcz => achived/bcz}/bcz.cookie.js (100%) rename {bcz => achived/bcz}/bcz.js (100%) rename {dbsj => achived/dbsj}/README.md (100%) rename {dbsj => achived/dbsj}/dbsj.cookie.js (100%) rename {dbsj => achived/dbsj}/dbsj.js (100%) rename {fenqile => achived/fenqile}/README.md (100%) rename {fenqile => achived/fenqile}/fenqile.cookie.js (100%) rename {fenqile => achived/fenqile}/fenqile.js (100%) diff --git a/Loon.cookie.conf b/Loon.cookie.conf index 6f276c45b..db5ef4628 100644 --- a/Loon.cookie.conf +++ b/Loon.cookie.conf @@ -24,8 +24,8 @@ http-request ^https:\/\/gw.csdn.net\/mini-app\/v2\/lucky_draw\/login\/sign_in\? http-request ^https:\/\/credits.bz.mgtv.com\/user\/creditsTake script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mgtv/mgtv.cookie.js, tag=芒果tv http-request ^https:\/\/m.gdoil.cn\/webapi\/usersign\/addusersign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/gdoil/gdoil.cookie.js, tag=加油广东 http-request https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.cookie.js, tag=猫咪音乐 -http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 -http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 +# http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 +# http-request ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js, requires-body=true, tag=10086 http-request ^https?:\/\/act.10010.com\/SigninApp\/signin\/querySigninActivity.htm script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 http-request ^https?:\/\/act.10010.com\/SigninApp(.*?)\/signin\/daySign script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 http-request ^https?:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js, tag=中国联通 @@ -34,10 +34,8 @@ http-request ^https:\/\/promotion.waimai.meituan.com\/playcenter\/signIn\/doacti http-request ^https:\/\/(.*?)c\.m\.163\.com\/uc\/api\/sign\/v3\/commit script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasenews/neteasenews.cookie.js, requires-body=true, tag=网易新闻 http-request ^https:\/\/i.meituan.com\/evolve\/signin\/signpost\/ script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/meituan/meituan.cookie.js, requires-body=true, tag=美团 http-request ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.cookie.js, tag=时光相册 -http-request ^https://group\.baicizhan\.com/group/rewards? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js, tag=百词斩 +# http-request ^https://group\.baicizhan\.com/group/rewards? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js, tag=百词斩 http-request ^https:\/\/maicai.api.ddxq.mobi\/point\/home script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.cookie.js, tag=叮咚买菜 -http-request ^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js, requires-body=true, tag=分期乐 -http-request ^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js, requires-body=true, tag=分期乐 http-request ^https://api\.dushu\.io/CheckIn script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js, requires-body=true, tag=樊登读书 http-request ^https://node\.kg\.qq\.com/webapp/proxy? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.cookie.js, requires-body=true, tag=全民K歌 http-request ^https:\/\/app\.nio\.com\/api\/1\/app\/daily_checkin script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/nio/nio.cookie.js, tag=蔚来 @@ -52,7 +50,6 @@ http-request ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do http-request ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js, tag=苏宁易购 http-request ^https:\/\/iphone\.myzaker\.com\/zaker\/sign_in\/\/api\/sign_in\.php script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zaker/zaker.js, tag=Zaker http-request ^https:\/\/sapi\.beingfine\.cn\/v3\/bb\/reward\/by-sign-in script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js, tag=不背单词 -http-request ^https:\/\/frodo\.douban\.com\/api\/v2\/niffler\/check_in\/status script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.cookie.js, tag=豆瓣时间 http-request ^https:\/\/gameapi\.hellobike\.com\/api script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hellobike/hellobike.js, requires-body=true, tag=哈啰出行 http-request ^https:\/\/mwegame\.qq\.com\/ams\/sign\/doSign\/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 http-request ^https:\/\/apiwz\.midukanshu\.com script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/midu/midu.cookie.js, requires-body=true, tag=米读 diff --git a/Loon.task.conf b/Loon.task.conf index 495eebb6b..8fad48658 100644 --- a/Loon.task.conf +++ b/Loon.task.conf @@ -27,13 +27,12 @@ cron "40 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr cron "50 4 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mihoyo/mihoyo.js,tag=米游社 cron "0 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.js,tag=中国联通 cron "10 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.js,tag=猫咪音乐 -cron "20 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js,tag=中国移动 +# cron "20 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js,tag=中国移动 cron "30 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.js,tag= 美团外卖 cron "40 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/meituan/meituan.js,tag=美团 cron "50 5 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js,tag=时光相册 -cron "0 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js,tag=百词斩 +# cron "0 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js,tag=百词斩 cron "10 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.js,tag=叮咚买菜 -cron "20 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.js,tag=分期乐 cron "30 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js,tag=樊登读书 cron "40 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/qmkg/qmkg.js,tag=全民K歌 cron "50 6 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hycan/hycan.js,tag=合创 @@ -46,13 +45,12 @@ cron "50 7 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr cron "0 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js,tag=苏宁易购 cron "10 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zaker/zaker.js,tag=Zaker cron "20 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js,tag=不背单词 -cron "30 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.js,tag=豆瓣时间 cron "40 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hellobike/hellobike.js,tag=哈啰出行 cron "50 8 8 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js,tag=掌上飞车 cron "0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/duokan/duokan.js,tag=多看 cron "3 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/noteyoudao/noteyoudao.js, tag=有道云笔记 cron "0 12 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/box/switcher/box.switcher.js, tag=切换会话 -cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=中国移动-查话费 +# cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.fee.js, tag=中国移动-查话费 cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/wanda/wanda.js, tag=万达电影 cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/pagoda/pagoda.js, tag=百果园 cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/ithome/ithome.js, tag=IT之家 diff --git a/QuantumultX_AppStore_Local_Cookie.conf b/QuantumultX_AppStore_Local_Cookie.conf index 5e2457b6f..e45108b50 100644 --- a/QuantumultX_AppStore_Local_Cookie.conf +++ b/QuantumultX_AppStore_Local_Cookie.conf @@ -82,8 +82,8 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) url script-request-header chavyleung/10010/10010.cookie.js # 中国移动 -^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header chavyleung/10086/10086.cookie.js -^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header chavyleung/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header chavyleung/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header chavyleung/10086/10086.cookie.js # 猫咪音乐网 https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url script-request-header chavyleung/maomicd/maomicd.cookie.js @@ -96,7 +96,7 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 url script-request-header chavyleung/everphoto/everphoto.cookie.js # 百词斩 -^https://group\.baicizhan\.com/group/rewards? url script-request-header chavyleung/bcz/bcz.cookie.js +# ^https://group\.baicizhan\.com/group/rewards? url script-request-header chavyleung/bcz/bcz.cookie.js # 叮咚买菜 ^https:\/\/maicai.api.ddxq.mobi\/point\/home url script-request-header chavyleung/mcdd/mcdd.cookie.js @@ -117,8 +117,8 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https://api\.dushu\.io/CheckIn url script-request-body chavyleung/fandeng/fandeng.cookie.js # 分期乐 -^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body chavyleung/fenqile/fenqile.cookie.js -^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body chavyleung/fenqile/fenqile.cookie.js +# ^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body chavyleung/fenqile/fenqile.cookie.js +# ^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body chavyleung/fenqile/fenqile.cookie.js # 美团 ^https:\/\/i.meituan.com\/evolve\/signin\/signpost\/ url script-request-body chavyleung/meituan/meituan.cookie.js @@ -140,6 +140,3 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/luckman.suning.com\/luck-web\/sign\/api\/clock_sign.do url script-request-header chavyleung/suning/suning.cookie.js ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do url script-request-header chavyleung/suning/suning.cookie.js ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) url script-request-header chavyleung/suning/suning.cookie.js - -# 豆瓣时间 -^https:\/\/fro\.douban\.com\/api\/v2\/niffler\/check_in\/status url script-request-header chavyleung/dbsj/dbsj.cookie.js diff --git a/QuantumultX_Local_Cookie.conf b/QuantumultX_Local_Cookie.conf index 9890969be..69a5ef0d2 100644 --- a/QuantumultX_Local_Cookie.conf +++ b/QuantumultX_Local_Cookie.conf @@ -81,8 +81,8 @@ hostname = apiwz.midukanshu.com, api.1sapp.com, frodo.douban.com, luckman.suning ^https:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo) url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js # 中国移动 -^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js -^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/index\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js +# ^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js # 猫咪音乐网 https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.cookie.js @@ -98,15 +98,11 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/api.everphoto.cn\/users\/self\/checkin\/v2 url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.cookie.js # 百词斩 -^https://group\.baicizhan\.com/group/rewards? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js +# ^https://group\.baicizhan\.com/group/rewards? url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js # 叮咚买菜 ^https:\/\/maicai.api.ddxq.mobi\/point\/home url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.cookie.js -# 分期乐 -^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js -^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js - #樊登读书 ^https://api\.dushu\.io/CheckIn url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js @@ -136,6 +132,3 @@ https:\/\/www.maomicd.com\/plugin.php\?id=k_misign:sign&operation=qiandao url sc ^https:\/\/luckman.suning.com\/luck-web\/sign\/api\/clock_sign.do url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js ^https:\/\/sign.suning.com\/sign-web\/m\/promotion\/sign\/doSign.do url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js ^https:\/\/gameapi.suning.com\/sngame-web\/(api\/signin\/private\/customerSignOperation.do|gateway\/api\/queryPrize.do) url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.cookie.js - -# 豆瓣时间 -^https:\/\/fro\.douban\.com\/api\/v2\/niffler\/check_in\/status url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.cookie.js diff --git a/QuantumultX_Local_Task.conf b/QuantumultX_Local_Task.conf index a1db1922c..ceb023f13 100644 --- a/QuantumultX_Local_Task.conf +++ b/QuantumultX_Local_Task.conf @@ -55,20 +55,16 @@ 9 0 * * * chavyleung/10010/10010.js # 猫咪音乐网 2 0 * * * chavyleung/maomicd/maomicd.js -# 中国移动 -7 0 * * * chavyleung/10086/10086.js +# # 中国移动 +# 7 0 * * * chavyleung/10086/10086.js # 美团外卖 8 0 * * * chavyleung/wmmeituan/wmmeituan.js # 美团 7 0 * * * chavyleung/meituan/meituan.js # 时光相册 7 0 * * * chavyleung/everphoto/everphoto.js -# 百词斩 -50 23 * * * chavyleung/bcz/bcz.js # 叮咚买菜 7 0 * * * chavyleung/mcdd/mcdd.js -# 分期乐 -1 0 * * * chavyleung/fenqile/fenqile.js #樊登读书 1 0 * * * chavyleung/fandeng/fandeng.js #全民K歌 @@ -79,13 +75,9 @@ 1 0 * * * chavyleung/nio/nio.js #京东到家 1 0 * * * chavyleung/jddj/jddj.js -#网易考拉 -1 0 * * * chavyleung/wykl/wykl.js # WPS 0 9 * * * chavyleung/wps/wps.js #智行火车 1 0 * * * chavyleung/zxhc/zxhc.js # 苏宁易购 -7 0 * * * chavyleung/suning/suning.js -# 豆瓣时间 -1 0 * * * chavyleung/dbsj/dbsj.js \ No newline at end of file +7 0 * * * chavyleung/suning/suning.js \ No newline at end of file diff --git a/QuantumultX_Remote_Task.conf b/QuantumultX_Remote_Task.conf index ec8a8eba0..20e326307 100644 --- a/QuantumultX_Remote_Task.conf +++ b/QuantumultX_Remote_Task.conf @@ -106,10 +106,6 @@ #打开 网站 `https://www.maomicd.com` 然后手动签到 1 次 9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/maomicd/maomicd.js -# 中国移动 -#打开 APP , 进入签到页面, 系统提示: `获取刷新链接: 成功`,然后手动签到 1 次 -9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.js - # 美团外卖 #打开 APP , 进入签到页面, 系统提示: `获取刷新链接: 成功`,然后手动签到 1 次 9 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/wmmeituan/wmmeituan.js @@ -122,18 +118,10 @@ #打开 APP 然后手动签到 1 次 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/everphoto/everphoto.js -# 百词斩 -#打开 APP 手动签到一次: 访问下右下角 `我` > `我的铜板` > `加入百词斩小班` > `去查看` > `我的小班进去 领铜板` -0 8-20/4 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.js - # 叮咚买菜 #打开 APP, 访问下`我的`>`积分` 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.js -# 分期乐 -#打开 APP 手动签到一次: 访问下右下角 `我的` > `乐星` > `签到` -10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.js - # 樊登读书 #打开 APP 手动签到一次: 访问下右下角 `我的` > `签到` 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.js @@ -175,6 +163,3 @@ # 首页 > 签到有礼 # 首页 > 领取红包 7 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js - -# 豆瓣时间 -1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.js diff --git a/10086/10086.cookie.js b/achived/10086/10086.cookie.js similarity index 100% rename from 10086/10086.cookie.js rename to achived/10086/10086.cookie.js diff --git a/10086/10086.fee.cookie.js b/achived/10086/10086.fee.cookie.js similarity index 100% rename from 10086/10086.fee.cookie.js rename to achived/10086/10086.fee.cookie.js diff --git a/10086/10086.fee.js b/achived/10086/10086.fee.js similarity index 100% rename from 10086/10086.fee.js rename to achived/10086/10086.fee.js diff --git a/10086/10086.js b/achived/10086/10086.js similarity index 100% rename from 10086/10086.js rename to achived/10086/10086.js diff --git a/10086/README.md b/achived/10086/README.md similarity index 100% rename from 10086/README.md rename to achived/10086/README.md diff --git a/bcz/README.md b/achived/bcz/README.md similarity index 100% rename from bcz/README.md rename to achived/bcz/README.md diff --git a/bcz/bcz.cookie.js b/achived/bcz/bcz.cookie.js similarity index 100% rename from bcz/bcz.cookie.js rename to achived/bcz/bcz.cookie.js diff --git a/bcz/bcz.js b/achived/bcz/bcz.js similarity index 100% rename from bcz/bcz.js rename to achived/bcz/bcz.js diff --git a/dbsj/README.md b/achived/dbsj/README.md similarity index 100% rename from dbsj/README.md rename to achived/dbsj/README.md diff --git a/dbsj/dbsj.cookie.js b/achived/dbsj/dbsj.cookie.js similarity index 100% rename from dbsj/dbsj.cookie.js rename to achived/dbsj/dbsj.cookie.js diff --git a/dbsj/dbsj.js b/achived/dbsj/dbsj.js similarity index 100% rename from dbsj/dbsj.js rename to achived/dbsj/dbsj.js diff --git a/fenqile/README.md b/achived/fenqile/README.md similarity index 100% rename from fenqile/README.md rename to achived/fenqile/README.md diff --git a/fenqile/fenqile.cookie.js b/achived/fenqile/fenqile.cookie.js similarity index 100% rename from fenqile/fenqile.cookie.js rename to achived/fenqile/fenqile.cookie.js diff --git a/fenqile/fenqile.js b/achived/fenqile/fenqile.js similarity index 100% rename from fenqile/fenqile.js rename to achived/fenqile/fenqile.js diff --git a/surge.cookies.sgmodule b/surge.cookies.sgmodule index 91fec1960..4260de509 100644 --- a/surge.cookies.sgmodule +++ b/surge.cookies.sgmodule @@ -6,8 +6,6 @@ Rewrite: 10010 = type=http-request,pattern=^https:\/\/act.10010.com\/SigninApp(.*?)\/signin\/daySign,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js Rewrite: 10010 = type=http-request,pattern=^https:\/\/act.10010.com\/SigninApp\/signin\/querySigninActivity.htm,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js Rewrite: 10010 = type=http-request,pattern=^https:\/\/m.client.10010.com\/dailylottery\/static\/(textdl\/userLogin|active\/findActivityInfo),script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10010/10010.cookie.js -Rewrite: 10086 = type=http-request,pattern=^http:\/\/wx.10086.cn\/website\/taskCenter\/index\?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js -Rewrite: 10086 = type=http-request,pattern=^http:\/\/wx.10086.cn\/website\/taskCenter\/sign\?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/10086/10086.cookie.js Rewrite: AcFun = type=http-request,pattern=^https:\/\/api\-new\.app\.acfun\.cn\/rest\/app\/user\/personalInfo,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/acfun/acfun.cookie.js Rewrite: ApkTw = type=http-request,pattern=^https://apk.tw\/member.php(.*?)action=login,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/apktw/apktw.cookie.js,requires-body=true Rewrite: BiliBili = type=http-request,pattern=^https:\/\/(www|live)\.bilibili\.com\/?.?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js @@ -20,11 +18,7 @@ Rewrite: 电信营业厅 = type=http-request,pattern=^https:\/\/wapside.189.cn:9 Rewrite: 飞客茶馆 = type=http-request,pattern=^https:\/\/www\.flyertea\.com\/source\/plugin\/mobile\/mobile\.php\?module=getdata&.*,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/flyertea/flyertea.cookie.js Rewrite: 网易云音乐 = type=http-request,pattern=^https:\/\/music.163.com\/weapi\/user\/level,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/neteasemusic/quanx/neteasemusic.cookie.js,requires-body=true Rewrite: 百度签到 = type=http-request,pattern=^https?:\/\/tieba\.baidu\.com\/?.?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/tieba/tieba.cookie.js -Rewrite: 百词斩 = type=http-request,pattern=^https://group\.baicizhan\.com/group/rewards?,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bcz/bcz.cookie.js Rewrite: 叮咚买菜 = type=http-request,pattern=^https:\/\/maicai.api.ddxq.mobi\/point\/home,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/mcdd/mcdd.cookie.js -Rewrite: 豆瓣时间 = type=http-request,pattern=^https:\/\/fro\.douban\.com\/api\/v2\/niffler\/check_in\/status,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/dbsj/dbsj.cookie.js -Rewrite: 分期乐 = type=http-request,pattern=^https://pm\.m\.fenqile\.com/route0014/star/sign/sign.json,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js,requires-body=true -Rewrite: 分期乐 = type=http-request,pattern=^https:\/\/pm\.m\.fenqile\.com/route0014\/app\/tab\/privilege\/convertTaskReward.json url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/fenqile/fenqile.cookie.js,requires-body=true Rewrite: 樊登读书 = type=http-request,pattern=^https://api\.dushu\.io/CheckIn,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/fandeng/fandeng.cookie.js,requires-body=true Rewrite: 合创 = type=http-request,pattern=^https:\/\/wxprdapplet\.gac-nio\.com\/community\/userSignIn\/simpleAuth\/front\/v3\.1\.3\.5\/signV2$,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/hycan/hycan.cookie.js Rewrite: 京东到家 = type=http-request,pattern=^https:\/\/daojia.jd.com/client(.*?)functionId=signin(.*?)userSigninNew,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/jddj/jddj.cookie.js From 1e85329e05c93829ced3f402b9f0f35a9b3b3c4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 23 Jul 2023 11:29:58 +0800 Subject: [PATCH 199/311] chore(deps): bump tough-cookie from 4.0.0 to 4.1.3 (#446) Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.0.0 to 4.1.3. - [Release notes](https://github.com/salesforce/tough-cookie/releases) - [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md) - [Commits](https://github.com/salesforce/tough-cookie/compare/v4.0.0...v4.1.3) --- updated-dependencies: - dependency-name: tough-cookie dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index b32cfe07f..9f2bfaf85 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,6 @@ "got": "^11.8.5", "http-server": "^0.12.3", "iconv-lite": "0.6.3", - "tough-cookie": "^4.0.0" + "tough-cookie": "^4.1.3" } } diff --git a/yarn.lock b/yarn.lock index e0113f3a8..48fed4876 100644 --- a/yarn.lock +++ b/yarn.lock @@ -369,6 +369,11 @@ qs@^6.4.0: dependencies: side-channel "^1.0.4" +querystringify@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" + integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ== + quick-lru@^5.1.1: version "5.1.1" resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz" @@ -410,14 +415,15 @@ side-channel@^1.0.4: get-intrinsic "^1.0.2" object-inspect "^1.9.0" -tough-cookie@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz" - integrity sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg== +tough-cookie@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.3.tgz#97b9adb0728b42280aa3d814b6b999b2ff0318bf" + integrity sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw== dependencies: psl "^1.1.33" punycode "^2.1.1" - universalify "^0.1.2" + universalify "^0.2.0" + url-parse "^1.5.3" union@~0.5.0: version "0.5.0" @@ -426,16 +432,24 @@ union@~0.5.0: dependencies: qs "^6.4.0" -universalify@^0.1.2: - version "0.1.2" - resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz" - integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0" + integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg== url-join@^2.0.5: version "2.0.5" resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz" integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg= +url-parse@^1.5.3: + version "1.5.10" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1" + integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ== + dependencies: + querystringify "^2.1.1" + requires-port "^1.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" From 39e876625d48f5ab1103b91745d306ce95f72c64 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Sun, 20 Aug 2023 15:53:13 +0800 Subject: [PATCH 200/311] feat: add citybox draw --- citybox/citybox.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/citybox/citybox.js b/citybox/citybox.js index dc973bb8a..99a3a8443 100644 --- a/citybox/citybox.js +++ b/citybox/citybox.js @@ -1,12 +1,16 @@ const $ = new Env('魔盒') +const hostApi = 'https://api.icitybox.cn/index.php/api' +const drawRes = [] !(async () => { const KEY_har = 'boxapp_citybox_har' const har = $.getjson(KEY_har) const headers = har?.headers await sign(headers) + await draw(headers) + await draw(headers) if ($.sign?.signnum) { - $.msg($.name, `第${$.sign.signnum}天 签到成功`) + $.msg($.name, `第${$.sign.signnum}天 签到成功`, drawRes.join('\n')) } else if ($.sign?.message) { $.msg($.name, $.sign?.message) } else { @@ -19,7 +23,7 @@ const $ = new Env('魔盒') function sign(headers) { return new Promise((resolve) => { const url = { - url: 'https://api.icitybox.cn/index.php/api/user/up_sign', + url: hostApi + '/user/up_sign', headers, } $.get(url, (err, resp, data) => { @@ -33,5 +37,24 @@ function sign(headers) { }) }) } + +function draw(headers) { + return new Promise((resolve) => { + const url = { + url: hostApi + '/roulette_draw/draw_results', + headers, + } + $.post(url, (err, resp, data) => { + try { + const data = JSON.parse(data) + drawRes.push(data.winning_desc) + } catch (e) { + $.logErr(e, resp) + } finally { + resolve() + } + }) + }) +} // prettier-ignore function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} From 71a65c4d944d1af111ef3111659f9858ea1f1ebd Mon Sep 17 00:00:00 2001 From: lowking <33308659+lowking@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:23:32 +0800 Subject: [PATCH 201/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=97=B6=E6=9B=B4=E6=96=B0boxjs=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=AD=98=E5=82=A8=20(#451)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(boxjs): 保存设置时更新boxjs会话存储 * chore: 把 updateBoxjsSessions 相关逻辑迁移到 chavy.boxjs.js * release: 0.12.11 --------- Co-authored-by: Chavy --- box/chavy.boxjs.html | 2 +- box/chavy.boxjs.js | 48 +++++++++++++++++++++++++++++++-- box/release/box.release.json | 16 +++++++++++ box/release/box.release.tf.json | 16 +++++++++++ chavy.box.js | 48 +++++++++++++++++++++++++++++++-- 5 files changed, 125 insertions(+), 5 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 7e66f6c86..c43f41bbd 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2664,7 +2664,7 @@

v{{ver.versio const val = !isNilVal ? _.toString(setting.val) : '' datas.push({ key, val }) }) - axios.post('/api/save', datas).then((resp) => { + axios.post(`/api/save?appid=${this.curapp.id}`, datas).then((resp) => { if (this.curapp.id === 'BoxSetting') { this.isSaveUserCfgs = false } else { diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 0e482a662..268158900 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.10' +$.version = '0.12.11' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -57,6 +57,16 @@ $.ver = `https://raw.githubusercontent.com/chavyleung/scripts/master/box/release // 请求路径 $.path = getPath($request.url) + // 请求参数 /api/save?id=xx&name=xx => {id: 'xx', name: 'xx'} + const [, query] = $.path.split('?') + $.queries = query + ? query.split('&').reduce((obj, cur) => { + const [key, val] = cur.split('=') + obj[key] = val + return obj + }, {}) + : {} + // 请求类型: GET $.isGet = $request.method === 'GET' // 请求类型: POST @@ -233,7 +243,7 @@ async function handleQuery() { async function handleApi() { const [, api] = $.path.split('/api') - if (api === '/save') { + if (api === '/save' || api.startsWith('/save')) { await apiSave() } else if (api === '/addAppSub') { await apiAddAppSub() @@ -590,6 +600,12 @@ async function apiSave() { $.setdata(data.val, data.key) } } + + const appId = $.queries['appid'] + if (appId) { + updateCurSesssions(appId, data) + } + $.json = getBoxData() } @@ -883,6 +899,34 @@ function upgradeGlobalBaks() { $.setdata('', $.KEY_globalBaks) } +function updateCurSesssions(appId, data) { + if (!appId) { + console.log(`[updateCurSesssions] 跳过! 没有指定 appId!`) + return + } + + const curSessions = getCurSessions() + const curSessionId = curSessions[appId] + if (!curSessionId) { + console.log( + `[updateCurSesssions] 跳过! 应用 [${appId}] 找不到当前会话, 请先应用会话!` + ) + return + } + + const sessions = getAppSessions() + const session = sessions.find((session) => session.id === curSessionId) + if (!session) { + console.log( + `[updateCurSesssions] 跳过! 应用 [${appId}] 找不到当前会话, 请先应用会话!` + ) + return + } + + session.datas = data + $.setjson(sessions, $.KEY_sessions) +} + /** * =================================== * 结束类函数 diff --git a/box/release/box.release.json b/box/release/box.release.json index 47a53fec8..bf578a865 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.11", + "tags": ["beta"], + "author": "@lowking", + "msg": "修复保存设置时,没有自动同步到当前会话问题", + "notes": [ + { + "name": "修复", + "descs": ["保存设置时,没有自动同步到当前会话问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.12.10", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index a8f8cea71..7d6759c55 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.11", + "tags": ["beta"], + "author": "@lowking", + "msg": "修复保存设置时,没有自动同步到当前会话问题", + "notes": [ + { + "name": "修复", + "descs": ["保存设置时,没有自动同步到当前会话问题"] + }, + { + "name": "感谢", + "descs": ["@lowking PR"] + } + ] + }, { "version": "0.12.10", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 0e482a662..268158900 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.10' +$.version = '0.12.11' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -57,6 +57,16 @@ $.ver = `https://raw.githubusercontent.com/chavyleung/scripts/master/box/release // 请求路径 $.path = getPath($request.url) + // 请求参数 /api/save?id=xx&name=xx => {id: 'xx', name: 'xx'} + const [, query] = $.path.split('?') + $.queries = query + ? query.split('&').reduce((obj, cur) => { + const [key, val] = cur.split('=') + obj[key] = val + return obj + }, {}) + : {} + // 请求类型: GET $.isGet = $request.method === 'GET' // 请求类型: POST @@ -233,7 +243,7 @@ async function handleQuery() { async function handleApi() { const [, api] = $.path.split('/api') - if (api === '/save') { + if (api === '/save' || api.startsWith('/save')) { await apiSave() } else if (api === '/addAppSub') { await apiAddAppSub() @@ -590,6 +600,12 @@ async function apiSave() { $.setdata(data.val, data.key) } } + + const appId = $.queries['appid'] + if (appId) { + updateCurSesssions(appId, data) + } + $.json = getBoxData() } @@ -883,6 +899,34 @@ function upgradeGlobalBaks() { $.setdata('', $.KEY_globalBaks) } +function updateCurSesssions(appId, data) { + if (!appId) { + console.log(`[updateCurSesssions] 跳过! 没有指定 appId!`) + return + } + + const curSessions = getCurSessions() + const curSessionId = curSessions[appId] + if (!curSessionId) { + console.log( + `[updateCurSesssions] 跳过! 应用 [${appId}] 找不到当前会话, 请先应用会话!` + ) + return + } + + const sessions = getAppSessions() + const session = sessions.find((session) => session.id === curSessionId) + if (!session) { + console.log( + `[updateCurSesssions] 跳过! 应用 [${appId}] 找不到当前会话, 请先应用会话!` + ) + return + } + + session.datas = data + $.setjson(sessions, $.KEY_sessions) +} + /** * =================================== * 结束类函数 From 9a205535e0427d1bfe62016ee46e4deb1d7c0045 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 25 Aug 2023 14:35:30 +0800 Subject: [PATCH 202/311] =?UTF-8?q?fix(boxjs):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=A4=87=E4=BB=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 4 ++-- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ chavy.box.js | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 268158900..511e687a6 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.11' +$.version = '0.12.12' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -243,7 +243,7 @@ async function handleQuery() { async function handleApi() { const [, api] = $.path.split('/api') - if (api === '/save' || api.startsWith('/save')) { + if (api === '/save' || api.startsWith('/save?')) { await apiSave() } else if (api === '/addAppSub') { await apiAddAppSub() diff --git a/box/release/box.release.json b/box/release/box.release.json index bf578a865..f0b58baeb 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.12", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "修复无法备份问题", + "notes": [ + { + "name": "修复", + "descs": ["无法备份问题"] + } + ] + }, { "version": "0.12.11", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 7d6759c55..d8b54b778 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.12.12", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "修复无法备份问题", + "notes": [ + { + "name": "修复", + "descs": ["无法备份问题"] + } + ] + }, { "version": "0.12.11", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 268158900..511e687a6 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.11' +$.version = '0.12.12' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -243,7 +243,7 @@ async function handleQuery() { async function handleApi() { const [, api] = $.path.split('/api') - if (api === '/save' || api.startsWith('/save')) { + if (api === '/save' || api.startsWith('/save?')) { await apiSave() } else if (api === '/addAppSub') { await apiAddAppSub() From 3ddf5290414a0b8741efadf4c4c4e12b1862ba88 Mon Sep 17 00:00:00 2001 From: Chavy Date: Sat, 23 Sep 2023 00:38:56 +0800 Subject: [PATCH 203/311] =?UTF-8?q?fix(sfexpress):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A1=BA=E4=B8=B0=E7=AD=BE=E5=88=B0=E8=84=9A=E6=9C=AC;=20?= =?UTF-8?q?=E6=84=9F=E8=B0=A2=20"Zero=20Ma"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sfexpress/sfexpress.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sfexpress/sfexpress.js b/sfexpress/sfexpress.js index 890deb768..6a54f8a35 100644 --- a/sfexpress/sfexpress.js +++ b/sfexpress/sfexpress.js @@ -82,18 +82,21 @@ async function signDailyTasks() { } function doTask(task) { - return $.http.get({ - url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/task/finishTask?id=${task.taskCode}`, - body: ``, + return $.http.post({ + url: `https://mcs-mimp-web.sf-express.com/mcs-mimp/commonRoutePost/memberEs/taskRecord/finishTask`, + body: `{"taskCode":"${task.taskCode}"}`, headers: {} }) } + + + function getPoint(task) { return $.http .post({ url: 'https://mcs-mimp-web.sf-express.com/mcs-mimp/commonPost/~memberNonactivity~integralTaskStrategyService~fetchIntegral', - body: `{"strategyId":${task.strategyId},"taskId":"${task.taskId}","taskCode":"${task.taskCode}"}`, + body: `{"strategyId":${task.strategyId},"taskId":"${task.taskId}","taskCode":"${task.taskCode}","channelType":"1"}`, headers: { 'Content-Type': 'application/json' } From 30a36303cabf49b5f63af94564d482b43e3b5b0d Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 27 Sep 2023 20:36:11 +0800 Subject: [PATCH 204/311] =?UTF-8?q?fix(tieba):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=20cookie=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=20=E6=84=9F=E8=B0=A2=20"Zero=20Ma"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tieba/tieba.cookie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tieba/tieba.cookie.js b/tieba/tieba.cookie.js index fbe454c63..44b13cd59 100644 --- a/tieba/tieba.cookie.js +++ b/tieba/tieba.cookie.js @@ -1,7 +1,7 @@ const cookieName = '百度贴吧' const cookieKey = 'chavy_cookie_tieba' const chavy = init() -const cookieVal = $request.headers['Cookie'] +const cookieVal = $request.headers['Cookie'] || $request.headers['cookie'] if (cookieVal.indexOf('BDUSS') > 0) { let cookie = chavy.setdata(cookieVal, cookieKey) From c9f1464c309576453312a6e538ad855cf00cbdf7 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:09:08 +0800 Subject: [PATCH 205/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=8F=8A=E8=AF=B4=E6=98=8E=20(#458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 41 +++--- zsfc/zsfc.js | 337 +++++++++++++++++++++++-------------------------- 2 files changed, 177 insertions(+), 201 deletions(-) diff --git a/zsfc/README.md b/zsfc/README.md index 6247abe7d..027d2db8b 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -1,64 +1,63 @@ # 掌上飞车 > 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 + > 感谢[@danchaw](https://github.com/danchaw) PR + > 感谢[@chiupam](https://github.com/chiupam) 修改 -> + +> 代码已适配最新版掌上飞车APP,旧版本APP无法继续签到 + ## 配置 (Surge) ```properties [MITM] -hostname = %APPEDN% mwegame.qq.com +hostname = %APPEDN% comm.ams.game.qq.com [Script] -掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=10 -掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=10 +掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 +掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 ``` ## 配置 (Loon) ```properties [Mitm] -hostname = mwegame.qq.com +hostname = comm.ams.game.qq.com [Script] -http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie -cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, tag=掌上飞车 +http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie +cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 ``` ## 配置 (QuanX) ```properties [MITM] -hostname = mwegame.qq.com +hostname = comm.ams.game.qq.com [rewrite_local] -^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js +^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js [task_local] -0 10 0 * * * https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.js, tag=掌上飞车, enabled=true +0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true ``` ## 说明 -1. 先把`mwegame.qq.com`加到`[MITM]` +1. 先把`comm.ams.game.qq.com`加到`[MITM]` + 2. 再配置重写规则: - Surge: 把两条远程脚本放到`[Script]` - Loon: 把两条远程脚本放到`[Script]` - QuanX: 把远程重写脚本放到`[rewrite_local]`,再把远程定时任务放到`[task_local]` -3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后手动签到 1 次, 系统提示: `✅ 获取签到数据成功!` -4. 运行一次脚本, 如果提示重复签到, 那就算成功了! - -## 常见问题 +3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后进入签到页面, 系统提示: `✅ 获取签到数据成功!` -1. 无法写入 Cookie - - - 检查系统通知权限放开了没 +4. 运行一次脚本, 如果提示重复签到, 那就算成功了! -2. 写入 Cookie 成功, 但签到不成功 +## 反馈bug - - 看看是不是在登录前就写入 Cookie 了 - - 如果是,请确保在登录成功后,再尝试写入 Cookie +如果出现签到失败,请提交issue到[chiupam仓库](https://github.com/chiupam/surge/issues/new) ## 感谢 diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 21659548c..3c3da115d 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,33 +1,33 @@ /** * - * 使用方法:打开掌上飞车APP, 点击下方发现, 点击每日签到, 点击签到即可。 - * - * hostname: mwegame.qq.com - * + * 使用方法:打开掌上飞车APP, 点击咨询栏的签到(每日福利)即可,无需点击签到,否则脚本无法正确运行。 + * 注意事项:每月需手动打开一次掌上飞车APP并进入签到页面,以重新抓包更新礼包数据,为此需要每日运行两次脚本 + * + * hostname: comm.ams.game.qq.com + * * type: http-request - * regex: ^https://mwegame\.qq\.com/ams/sign/doSign/month + * regex: ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * requests-body: 1 - * + * * type: cron - * cron: 0 10 0 * * * - * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * cron: 0 10 0,21 * * * + * script-path: https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.v3.js * * =============== Surge =============== * 掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 - * 掌上飞车 =type=cron, cronexp="0 10 0 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 * * =============== Loon =============== * http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie - * cron "0 10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 + * cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 * * =============== Quan X =============== * ^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js - * 0 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true + * 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true * */ - /** * 创建一个名为 $ 的环境变量实例,用于处理掌上飞车相关操作 */ @@ -43,268 +43,245 @@ const isreq = typeof $request !== 'undefined'; */ (async () => { if (isreq) { - // 请求阶段,设置请求数据 - if (!$request.url || !$request.headers) { - // 无法读取请求头,显示配置错误通知 - $.notice($.name, '', '⭕ 无法读取请求头, 请检查配置'); + /** + * 以下获取签到数据 + */ + + // 设置触发脚本的间隔时间, 单位为秒 + const interval = 120; + // 不能触发 requests 脚本,程序终止 + if (Date.now() - $.read(`zsfc_timestamp`) <= interval * 1000) return; + + // 配置错误,弹窗警告并程序终止 + if (!$request.url || !$request.headers || !$request.body) { + $.notice($.name, '⭕ 无法读取数据', '无法读取掌上飞车请求数据,请检查配置是否正确'); return; } // 提取请求数据 - const url = $request.url.replace(/&gift_id=\d+/, ''); + const url = $.toStr($request.url); const headers = $.toStr($request.headers); - const query = [ - `userId=${matchParam(url, 'userId')}`, - `areaId=${matchParam(url, 'areaId')}`, - `roleId=${matchParam(url, 'roleId')}`, - `token=${matchParam(url, 'token')}`, - `uin=${matchParam(url, 'uin')}`, - ].join('&'); - + const body = $.toStr($request.body); + + // 定义 params 数组 + const params = ['appid', 'iActivityId', 'g_tk', 'e_code', 'g_code', 'eas_url', 'eas_refer', 'sServiceDepartment', 'sServiceType']; + // 数组有空返回则程序终止 + if (params.find(param => !matchParam(body, param))) return; + // 用 & 将键值对拼接成一个长字符串 + const param = params.map(param => `${param}=${matchParam(body, param)}`).join('&'); + + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_url': url.replace(/^"|"$/g, ''), + 'zsfc_headers': headers.replace(/^"|"$/g, ''), + 'zsfc_param': param.replace(/^"|"$/g, ''), + 'zsfc_iFlowId': (matchParam(body, 'iFlowId') - 1).toString(), + 'zsfc_timestamp': Date.now().toString(), + 'zsfc_time': new Date().toLocaleString().toString(), + 'zsfc_month': (new Date().getMonth() + 1).toString() + }; // 将请求数据写入内存 - $.write(url, 'zsfc_url'); - $.write(headers, 'zsfc_headers'); - $.write(query, 'zsfc_query'); + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + + // 显示签到结果通知 + $.notice($.name, '✅ 获取签到数据成功!', `${interval}秒后请不要再点击本页面中的任何按钮,否则脚本会失效!`); - $.notice($.name, '✅ 获取签到数据成功!', '请不要再次打开掌上飞车APP, 否则 Cookie 将失效!'); } else { - // 执行打卡操作阶段 - const url = $.read('zsfc_url'); - const query = $.read('zsfc_query'); - const illustrate = `掌上飞车APP => 发现 => 每日签到 => 点击签到`; - - if (!url) { - // Cookie 为空,显示获取Cookie错误通知 - $.notice($.name, '❌ 当前 Cookie 为空, 请先获取', illustrate); + /** + * 以下进行签到阶段,但是没有做 cookie 有效性验证 + */ + + // 检查用户本月是否打开过签到页面 + const month = (new Date().getMonth() + 1).toString(); + if (!$.read(`zsfc_month`)) $.write(month, `zsfc_month`); + if (month != $.read(`zsfc_month`)) { + $.notice($.name, `❌ 本月未打开过掌上飞车APP`, `每月需打开一次掌上飞车APP并进到签到页面`); return; } - if (query.indexOf('&areaId=&') !== -1) { - // Cookie 错误,显示重新获取Cookie错误通知 - $.notice($.name, '❌ 当前 Cookie 错误, 请重新获取', illustrate); - return; - } + // 获取本月签到礼物列表 + const signInGifts = await getSignInGifts() - // 获取连续签到的礼物ID - const successiveGiftId = await getSuccessiveGiftId(); - // 进行连续签到 - const isSuccessiveCheckin = await dailyCheckin(successiveGiftId); + // 进行每日签到 + await dailyCheckin(signInGifts['每日签到']) - if (!isSuccessiveCheckin) { - // Cookie 失效,显示重新获取Cookie错误通知 - $.notice($.name, '❌ 当前 Cookie 已失效, 请重新获取', illustrate); - return; + // 获取本月累签天数 + const totalSignInDay = await getTotalSignInDays() + + // 初始化 signInInfoArray 数组 + let signInInfoArray = []; + + // 判断当前累签天数是否有礼包 + if (signInGifts[`${totalSignInDay}天`]) { + signInInfoArray.push({ code: signInGifts[`${totalSignInDay}天`], title: `累签奖励` }); + } + + // 判断当前日期是否有特别福利礼包 + const today = `${new Date().getMonth() + 1}月${new Date().getDate()}日`; + if (signInGifts[today]) { + signInInfoArray.push({ code: signInGifts[today], title: `特别福利` }); } - // 获取签到信息数组 - signInInfoArray = await getSignInInfo(); + if (signInInfoArray.length) { + $.log(`🎉 共有 ${signInInfoArray.length} 个礼包待领取`) + } - // 遍历签到信息数组,领取每日礼物 + // 遍历礼包数组,领取奖励 for (let signInInfo of signInInfoArray) { let { code, title } = signInInfo; await claimGift(code, title); } // 显示签到结果通知 - $.notice(`${$.name}(${$.subtitle})`, ``, $.message, ``) - + if ($.message) $.notice($.name, $.subtitle, $.message, ``); + $.write(month, `zsfc_month`); } })() .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) .finally(() => $.done()); /** - * 匹配 URL 参数 - * @param {string} url - URL 字符串 + * @description 匹配 BODY 参数 + * @param {string} body - BODY 字符串 * @param {string} key - 参数名 * @returns {string} */ -function matchParam(url, key) { - const match = url.match(new RegExp(`${key}=([^&]+)`)); +function matchParam(body, key) { + const match = body.match(new RegExp(`${key}=([^&]+)`)); return match ? match[1] : ''; } /** - * 获取连续签到的礼物 ID - * @returns {Promise} 返回连续签到的礼物 ID + * @description 获取签到信息,并返回签到礼物列表 + * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ -async function getSuccessiveGiftId() { - // 用于保存连续签到的礼物 ID - let giftid; - - // 构造请求参数 +async function getSignInGifts() { const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, - headers: $.toObj($.read(`zsfc_headers`)) + url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_param`)}&iFlowId=${$.read(`zsfc_iFlowId`)}` }; - - // 发送 GET 请求,获取签到页面信息 + $.log(`🧑‍💻 开始获取本月礼物列表`); + let giftsDictionary = {}; return new Promise(resolve => { - $.get(options, (err, resp, data) => { + $.post(options, (err, resp, data) => { if (data) { - // 解析响应数据,提取礼物 ID - giftid = data.match(/giftid="([^"]+)"/g)[0].match(/(\d+)/)[1]; + const body = $.toObj(data); + const flowRegex = /#(\d+)#:{#flow_id#:(\d+),#flow_name#:#([^#]+)#/g; + let match; + while ((match = flowRegex.exec($.toStr(body))) !== null) { + const flowId = match[2]; + const flowName = match[3].replace(/累计签到|领取/g, ''); + giftsDictionary[flowName] = flowId; + } + $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`) + } else { + $.log(`❌ 获取本月礼物列表时发生错误`); + $.log($.toStr(err)); } - resolve(giftid); + resolve(giftsDictionary); }); }); } /** - * 每日签到函数 - * @param {string} giftId 礼物 ID - * @returns {Promise} 返回签到结果,true 表示签到成功,false 表示签到失败 + * @description 每日签到函数 + * @param {string} iFlowId - 每日签到礼包的 iFlowId + * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ -async function dailyCheckin(giftId) { - // 初始化签到结果为 false - let result = false; - - // 构造请求参数 +async function dailyCheckin(iFlowId) { const options = { - url: `${$.read("zsfc_url")}&gift_id=${giftId}`, - headers: $.toObj($.read(`zsfc_headers`)) + url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_param`)}&iFlowId=${iFlowId}` }; - - // 输出日志,开始每日签到 - $.log(`🧑‍💻 开始每日签到`); - - // 发送 GET 请求,进行签到 + $.log(`🧑‍💻 开始进行每日签到`); return new Promise(resolve => { - $.get(options, (err, resp, data) => { + $.post(options, (err, resp, data) => { if (data) { - // 解析响应数据 let body = $.toObj(data.replace(/\r|\n/ig, ``)); - let message = body.message; - - if (message.indexOf(`重试`) > -1) { - // Cookie 失效,签到失败 - $.log(`❌ 当前 Cookie 已失效, 请重新获取`); - $.message = ``; - } else if (message.indexOf(`已经`) > -1) { - // Cookie 有效,再次签到 - result = true; - $.log(`⭕ 签到结果: ${message}`); - $.message = `签到结果: ${message}`; + if (body.msg.includes(`已经`)) { + const sMsg = body.flowRet.sMsg; + $.log(`⭕ 领取结果: ${sMsg}`); + // $.message = `签到结果: ${sMsg}` } else { - // Cookie 有效,签到成功 - result = true; - $.log(`✅ ${body.send_result.sMsg.replace(":", ":")}`); - $.message = body.send_result.sMsg.replace(":", ":"); + const sPackageName = body.modRet.sPackageName; + $.log(`✅ 领取结果: 获得${sPackageName}`); + $.message = `恭喜获得:${sPackageName}` } } else { - // 发生错误,签到失败 $.log(`❌ 进行每日签到时发生错误`); $.log($.toStr(err)); } - resolve(result); + resolve(); }); }); } /** - * @description 获取签到信息,并返回签到礼物列表 - * @returns {Promise} 一个返回包含签到礼物的数组的 Promise。 + * @description 获取累签天数的情况 + * @returns {Promise} 返回累签天数 */ -async function getSignInInfo() { - // 获取当前时间 - const date = new Date(); - - // 设置请求参数 +async function getTotalSignInDays() { + let totalSignInDays; const options = { - url: `https://mwegame.qq.com/ams/sign/month/speed?${$.read(`zsfc_query`)}`, - headers: $.toObj($.read(`zsfc_headers`)) - } - - // 输出日志,开始获取累计签到天数 - $.log(`🧑‍💻 开始获取累计签到天数`); - - // 初始化 signInGifts 为空列表 - let signInGifts = []; - - // 发送 GET 请求,获取签到信息 + url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_param`)}&iFlowId=${$.read(`zsfc_iFlowId`) * 1 +1}` + }; + $.log(`🧑‍💻 开始获取累签天数`); return new Promise(resolve => { - $.get(options, (err, resp, data) => { + $.post(options, (err, resp, data) => { if (data) { - // 定义一个数组,用于将累计签到天数映射到礼物编号 - const giftIndexByDay = [ - 0, // 占位,第一个元素不是第一天 - 1, 2, 3, 0, 4, 0, 5, 0, 6, 7, - 8, 0, 9, 0, 10, 11, 0, 12, 13, 0, - 14, 15, 0, 0, 16, 0, 0, 0, 0, 0, 0 - ]; - - // 使用正则表达式获取累计签到天数 - const totalSignInDays = Number(data.match(/(\d+)<\/span>/)?.[1]); - $.subtitle = `累计签到 ${totalSignInDays} 天`; - $.log(`✅ ${$.subtitle}`); - - // 根据累计签到天数获取礼物编号,并将其添加到 signInGifts 中 - const giftIndex = giftIndexByDay[totalSignInDays]; - const giftCode = giftIndex ? data.match(/giftid="([^"]+)"/g)[giftIndex].match(/(\d+)/)[1] : null; - if (giftIndex && giftCode) signInGifts.push({ code: giftCode, title: `第 ${giftIndexByDay.indexOf(giftIndex)} 天奖励` }); - - // 获取当前日期的日数,并检查是否为每月的第 X 天,如果是则将礼物编号添加到 signInGifts 中 - const [matchMonthDay] = data.match(/月(\d+)日/g) || []; - const [, day] = matchMonthDay?.match(/(\d+)/) || []; - if (day && Number(day) === date.getDate()) { - const giftDays = data.match(/"giftdays([^"]+)"/g)[0].match(/(\d+)/)[1]; - const dayWelfare = `${date.getMonth() + 1}月${date.getDate()}日`; - signInGifts.push({ code: giftDays, title: ` ${dayWelfare} 特别福利` }); - } - + totalSignInDays = $.toObj(data).modRet.sOutValue1.split(":")[1]; + const missedDays = new Date().getDate() - totalSignInDays; + const missedDaysText = missedDays !== 0 ? `(漏签 ${missedDays} 天)` : ``; + $.subtitle = `✅ 累计签到 ${totalSignInDays} 天${missedDaysText}`; + $.log($.subtitle); } else { - // 发生错误,输出错误日志 - $.log(`❌ 获取累计签到天数时发生错误`); + $.log(`❌ 获取累签天数时发生错误`); $.log($.toStr(err)); } - // 将 signInGifts 作为 Promise 的返回值,以便在调用方使用 - resolve(signInGifts); + resolve(totalSignInDays); }); }); } /** - * 领取礼物函数 + * @description 领取礼物函数 * @param {string} giftId 礼物 ID * @param {string} giftName 礼物名称 */ async function claimGift(giftId, giftName) { - // 设置请求参数 const options = { - url: `https://mwegame.qq.com/ams/send/handle`, - headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_query`)}&gift_id=${giftId}` + url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), + body: `${$.read(`zsfc_param`)}&iFlowId=${giftId}` }; - - // 输出日志,开始领取礼物 - $.log(`🧑‍💻 开始领取${giftName}`); - - // 发送 POST 请求,领取礼物 + $.log(`🧑‍💻 开始领取 ${giftName}`); return new Promise(resolve => { $.post(options, (err, resp, data) => { if (data) { - let result = $.toObj(data.replace(/\r|\n/ig, ``)); - if (result.data.indexOf(`成功`) != -1) { - // 领取成功,获取礼物名称并记录日志 - const sPackageName = result.send_result.sPackageName; - $.log(`✅ 领取结果: 获得${sPackageName}`); - $.message += `, ${sPackageName}`; + let body = $.toObj(data.replace(/\r|\n/ig, ``)); + if (body.msg.includes(`已经`)) { + $.log(`⭕ 领取结果: 已经领取`); + // $.message += `, ${giftName}`; } else { - // 领取失败,记录错误信息日志 - $.log(`⭕ 领取结果: ${result.message}`); + const sPackageName = body.modRet.sPackageName; + $.log(`✅ 领取结果: 获得${sPackageName}`); + if ($.message) { + $.message += `, ${sPackageName}`; + } else { + $.message = `领取结果: 获得${sPackageName}` + } } } else { - // 发生错误,输出错误日志 - $.log(`❌ 开始领取${giftName}时发生错误`); + $.log(`❌ 领取 ${giftName} 时发生错误`); $.log($.toStr(err)); } resolve(); }); - }) + }); } /** - * 创建一个名为 Env 的构造函数,用于处理环境相关操作。 + * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 * @param {string} name - 环境名称 */ function Env(name) { From bb6bc1f258be46f9272724724d2e504d8e5ae19a Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:59:52 +0800 Subject: [PATCH 206/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=8F=8A=E8=AF=B4=E6=98=8E=20(#459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更新[掌上飞车]每日签到脚本及说明 * 更新[掌上飞车]每日签到脚本及说明 --------- Co-authored-by: Chavy --- zsfc/README.md | 6 +++--- zsfc/zsfc.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zsfc/README.md b/zsfc/README.md index 027d2db8b..fc72f7f1c 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -15,7 +15,7 @@ hostname = %APPEDN% comm.ams.game.qq.com [Script] -掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 +掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 ``` @@ -26,7 +26,7 @@ hostname = %APPEDN% comm.ams.game.qq.com hostname = comm.ams.game.qq.com [Script] -http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie +http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 ``` @@ -37,7 +37,7 @@ cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/ hostname = comm.ams.game.qq.com [rewrite_local] -^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js [task_local] 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 3c3da115d..ed6a79fe0 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -15,15 +15,15 @@ * script-path: https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.v3.js * * =============== Surge =============== - * 掌上飞车Cookie = type=http-request, pattern=^https://mwegame\.qq\.com/ams/sign/doSign/month, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 * 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 * * =============== Loon =============== - * http-request ^https://mwegame\.qq\.com/ams/sign/doSign/month script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie + * http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie * cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 * * =============== Quan X =============== - * ^https://mwegame\.qq\.com/ams/sign/doSign/month url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true * */ From a87284e1c2285ac878067e32b9884a572c14d8bb Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:52:07 +0800 Subject: [PATCH 207/311] =?UTF-8?q?=E6=B7=BB=E5=8A=A0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]=E6=8E=8C=E9=A3=9E=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=84=9A=E6=9C=AC=20(#460)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 38 ++-- zsfc/zsfc.js | 6 +- zsfc/zsfc.shop.js | 476 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 495 insertions(+), 25 deletions(-) create mode 100644 zsfc/zsfc.shop.js diff --git a/zsfc/README.md b/zsfc/README.md index fc72f7f1c..0058fec32 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -2,71 +2,65 @@ > 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 -> 感谢[@danchaw](https://github.com/danchaw) PR +> 感谢[@danchaw](https://github.com/danchaw) PR、[@chiupam](https://github.com/chiupam) 修改签到脚本,感谢[@chiupam](https://github.com/chiupam) PR购物脚本 -> 感谢[@chiupam](https://github.com/chiupam) 修改 - -> 代码已适配最新版掌上飞车APP,旧版本APP无法继续签到 +> 代码已适配最新版掌上飞车APP,旧版本APP无法继续签到,请及时更新 ## 配置 (Surge) - ```properties [MITM] -hostname = %APPEDN% comm.ams.game.qq.com +hostname = %APPEDN% comm.ams.game.qq.com, bang.qq.com [Script] 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 +掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=5 +掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 ``` ## 配置 (Loon) - ```properties [Mitm] -hostname = comm.ams.game.qq.com +hostname = comm.ams.game.qq.com, bang.qq.com [Script] http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 +http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=10, tag=掌飞购物Cookie +cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 ``` ## 配置 (QuanX) - ```properties [MITM] -hostname = comm.ams.game.qq.com +hostname = comm.ams.game.qq.com, bang.qq.com [rewrite_local] ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +^https?://bang\.qq\.com/app/speed/mall/main2\?* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js [task_local] 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true +0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true ``` ## 说明 -1. 先把`comm.ams.game.qq.com`加到`[MITM]` - +1. 先把`comm.ams.game.qq.com, bang.qq.com`加到`[MITM]` 2. 再配置重写规则: - Surge: 把两条远程脚本放到`[Script]` - Loon: 把两条远程脚本放到`[Script]` - QuanX: 把远程重写脚本放到`[rewrite_local]`,再把远程定时任务放到`[task_local]` -3. 打开 APP[掌上飞车](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233) 然后进入签到页面, 系统提示: `✅ 获取签到数据成功!` - -4. 运行一次脚本, 如果提示重复签到, 那就算成功了! +3. 打开[掌上飞车APP](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233),点击咨询栏的签到(每日福利),系统提示`✅ 获取签到数据成功!`即可 +4. 打开[掌上飞车APP](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233),点击下方游戏栏,然后点击掌飞商城,系统提示`✅ 获取商城数据成功!`即可 +5. 订阅[chiupam boxjs仓库](https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json)并在应用中设置掌飞商城所需购买的游戏道具名称 ## 反馈bug - -如果出现签到失败,请提交issue到[chiupam仓库](https://github.com/chiupam/surge/issues/new) +如果出现bug,请提交issue到[chiupam仓库](https://github.com/chiupam/surge/issues/new) ## 感谢 - [@NobyDa](https://github.com/NobyDa) - [@lhie1](https://github.com/lhie1) - [@ConnersHua](https://github.com/ConnersHua) - [@danchaw](https://github.com/danchaw) - [@chiupam](https://github.com/chiupam) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index ed6a79fe0..e60a8fcaa 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -12,7 +12,7 @@ * * type: cron * cron: 0 10 0,21 * * * - * script-path: https://raw.githubusercontent.com/chiupam/surge/main/scripts/javascripts/zsfc.v3.js + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * * =============== Surge =============== * 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 @@ -254,7 +254,7 @@ async function claimGift(giftId, giftName) { url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), body: `${$.read(`zsfc_param`)}&iFlowId=${giftId}` }; - $.log(`🧑‍💻 开始领取 ${giftName}`); + $.log(`🧑‍💻 开始领取${giftName}`); return new Promise(resolve => { $.post(options, (err, resp, data) => { if (data) { @@ -266,7 +266,7 @@ async function claimGift(giftId, giftName) { const sPackageName = body.modRet.sPackageName; $.log(`✅ 领取结果: 获得${sPackageName}`); if ($.message) { - $.message += `, ${sPackageName}`; + $.message += `,${sPackageName}`; } else { $.message = `领取结果: 获得${sPackageName}` } diff --git a/zsfc/zsfc.shop.js b/zsfc/zsfc.shop.js new file mode 100644 index 000000000..82926399f --- /dev/null +++ b/zsfc/zsfc.shop.js @@ -0,0 +1,476 @@ +/** + * + * 使用方法:打开掌上飞车APP, 点击下方游戏栏,然后点击掌飞商城即可获取所需数据。 + * + * boxjs订阅地址:https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json + * + * 关于boxjs应用中的道具名称,只能填写以下道具中的其中一个,但我推荐购买改装道具,因为这样可以尽量用光点券 + * 雷诺、进气系统、燃料系统、点火系统、引擎系统、防护装置、普通粒子推进、普通阿尔法离合、重生宝珠LV1、效率宝珠LV1、效率宝珠LV2 + * + * hostname: bang.qq.com + * + * type: http-request + * regex: ^https?://bang\.qq\.com/app/speed/mall/main2\?* + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js + * requests-body: 1 + * + * type: cron + * cron: 0 11 0,21 * * * + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js + * + * =============== Surge =============== + * 掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=5 + * 掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 + * + * =============== Loon =============== + * http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=5, tag=掌飞购物Cookie + * cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 + * + * =============== Quan X =============== + * ^https?://bang\.qq\.com/app/speed/mall/main2\?* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js + * 0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true + * + */ + +const $ = new Env(`🏎️ 掌飞购物`); // 创建名为 $ 的环境实例 + +const isreq = typeof $request !== 'undefined'; // 检查是否存在请求对象 + +(async () => { + if (isreq) { + // 处理请求阶段 + + const url = $.toStr($request.url).replace(/^"|"$/g, ''); // 提取请求的URL并去除引号 + + // 定义需要提取的请求参数 + const paramValue = [ + "roleName", "roleLevel", "roleId", "uin", "nickname", "areaName", + "serverName", "serverId", "areaId", "isMainRole", "isapp", + "userId", "token", "appOpenid", "uniqueRoleId", "gameId", "subGameId", + "cGameId", "roleJob", "secret", "env", "openid", "toOpenid" + ]; + + // 需要添加的附加参数 + const extraParams = { + steamid: '0', openType: '1', isother: '0', platid: 'false', + cleId: 'false', from: 'false', pay_type: '1', isapp: '1' + }; + + // 提取请求中的参数 + const filteredParams = extractParams(url, paramValue); + const data = generateQueryString({ ...filteredParams, ...extraParams }); + + // 提取请求中的引用参数 + const refererValue = [ + "serverName", "appid", "areaName", "roleName", "gameName", + "nickname", "isMainRole", "appOpenid", "roleId", "areaId", + "toUin", "roleJob", "serverId", "accessToken", "gameId", "subGameId", + "token", "cGameId", "uniqueRoleId", "acctype", "accType", "uin", + "roleLevel", "userId" + ]; + + const filteredReferer = extractParams(url, refererValue); + const referer = generateQueryString(filteredReferer); + + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_bang_url': url, + 'zsfc_bang_referer': referer, + 'zsfc_bang_data': data + }; + + // 将请求数据写入内存 + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + + // 发送通知 + $.notice($.name, `✅ 获取商城数据成功!`, ``); + + } else { + // 执行购物阶段 + + // 定义商品信息(目前只支持买着下面的东西,因为我懒得爬取了) + const shopIdArray = { + "雷诺": {"itemId": "12720", "price_idx": {"180天": {"index": "0", "price": 12200}, "30天": {"index": "1", "price": 8500}}}, // 雷诺不购买30天的,有点浪费点券和消费券 + "进气系统": {"itemId": "12377", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + "燃料系统": {"itemId": "12378", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + "点火系统": {"itemId": "12376", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + "引擎系统": {"itemId": "12380", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + "防护装置": {"itemId": "96597", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + + "普通粒子推进": {"itemId": "64025", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + "普通阿尔法离合": {"itemId": "65028", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, + + "重生宝珠LV1": {"itemId": "21983", "price_idx": {"3个": {"index": "0", "price": 2600}, "2个": {"index": "1", "price": 1800}, "1个": {"index": "2", "price": 990}, "4个": {"index": "3", "price": 3390}}}, + "效率宝珠LV1": {"itemId": "21977", "price_idx": {"3个": {"index": "0", "price": 2600}, "2个": {"index": "1", "price": 1800}, "1个": {"index": "2", "price": 990}, "4个": {"index": "3", "price": 3390}}}, + "效率宝珠LV2": {"itemId": "21978", "price_idx": {"3个": {"index": "0", "price": 13000}, "2个": {"index": "1", "price": 9000}, "1个": {"index": "2", "price": 4900}, "4个": {"index": "3", "price": 16990}}} + } + + // 获取当前点券和消费券 + const packBefore = await getPackInfo(`before`); + + // Cookie 已过期,程序终止 + if (!packBefore) { + $.log(`❌ Cookie 已过期,请重新获取`) + $.notice($.name, `❌ Cookie 已过期`, `请打开掌上飞车,点击游戏,最后点击掌上商城即可`); + return; + } + + // 获取当前余额 + const moneyBefore = packBefore.money * 1; + const couponsBefore = packBefore.coupons * 1; + const beforeLog = `✅ 当前共有${moneyBefore}点券,${couponsBefore}消费券`; + $.log(beforeLog); + $.subtitle = beforeLog; + + // 读取要购买的商品名称 + const shopName = $.read(`zsfc_bang_shopname`); + + // 获取购物包 + const [shopArray, totalCount] = getShopItems(shopName, shopIdArray[shopName], + isLastDays(3) ? moneyBefore + couponsBefore : couponsBefore + ); + + // 开始购物循环 + if (shopArray.length) { + $.log(`✅ 共计可购买${totalCount}个${shopName}`); + let successBuyCounts = 0; + let failedBuyCounts = 0; + + // 开始购物 + $.log(`✅ 开始购买${totalCount}个${shopName}`); + for (let buyInfo of shopArray) { + let { name, count, id, idx } = buyInfo; + successBuyCounts += await purchaseItem(name, count, id, idx); + } + failedBuyCounts = totalCount - successBuyCounts; + + if (successBuyCounts > 0) { + $.message = `🎉 成功购买${successBuyCounts}个${shopName}`; + if (failedBuyCounts > 0) { + $.message += `(未成功购买${failedBuyCounts}个)`; + } + } else { + $.message = `❌ 全部购买失败,共计${totalCount}个`; + } + $.log($.message) + + // 获取剩余余额 + const packAfter = await getPackInfo(`after`); + const moneyAfter = packAfter.money * 1; + const couponsAfter = packAfter.coupons * 1; + const afterLog = `✅ 现在剩余${moneyAfter}点券,${couponsAfter}消费券`; + $.log(afterLog); + $.subtitle = afterLog; + + } else { + $.log(`⭕ 余额不足以购买${shopName}`); + } + + // 显示购物结果通知 + if ($.message) $.notice($.name, $.subtitle, $.message, ``); + + } +})() + .catch((e) => $.notice($.name, '❌ 未知错误无法进行购物', e, '')) + .finally(() => $.done()); + +/** + * @description 从字符串中提取参数并返回指定键名的参数值 + * @param {string} str - 包含参数的字符串 + * @param {Array} argument - 需要提取的参数键名 + * @returns {object} 包含提取的参数键值对的对象 + */ +function extractParams(str, argument) { + // 创建正则表达式,用于匹配参数键值对 + const regex = /([^&=]+)=([^&]+)/g; + + // 创建一个空对象,用于存储提取的参数键值对 + const extractedParams = {}; + + // 用于迭代匹配参数的正则表达式结果 + let match; + + // 遍历字符串以匹配参数,并将它们存储在 extractedParams 对象中 + while ((match = regex.exec(str))) { + // 提取参数名 + const paramName = match[1]; + + // 提取参数值 + let paramValue = match[2]; + + // 将参数键值对存储在 extractedParams 对象中 + extractedParams[paramName] = paramValue; + } + + // 创建一个空对象,用于存储筛选后的参数键值对 + const filteredParams = {}; + + // 遍历需要提取的参数键名 + for (const paramName of argument) { + // 将符合参数键名的键值对存储在 filteredParams 对象中 + filteredParams[paramName] = extractedParams[paramName]; + } + + // 返回包含筛选后的参数键值对的对象 + return filteredParams; +} + + +/** + * @description 生成查询字符串 + * @param {object} argument - 包含键值对的对象 + * @returns {string} 包含 key=value 键值对的查询字符串 + */ +function generateQueryString(argument) { + return Object.entries(argument) + .map(([key, value]) => `${key}=${value}`) + .join('&') + .replace(/undefined|"/g, ''); +} + +/** + * @description 检查今天是否是当月的最后几天 + * @param {number} N - 要检查的倒数第N天 + * @returns {boolean} true 表示今天是当月的倒数第N天,false 表示反之 + */ +function isLastDays(N) { + // 获取当前日期的 Date 对象 + const today = new Date(); + + // 迭代从1到N的整数,用于检查倒数第N天 + for (let i = 1; i <= N; i++) { + // 创建一个新的 Date 对象,表示明天的日期 + const nextDay = new Date(today); + nextDay.setDate(today.getDate() + i); + + // 检查如果明天的月份不等于今天的月份,则表示今天是当月的倒数第N天 + if (today.getMonth() !== nextDay.getMonth()) { + return true; + } + } + + // 如果没有在循环中返回 true,表示今天不是当月的倒数第N天 + return false; +} + +/** + * @description 获取当前月份对应的游戏道具。 + * @returns {string} 返回当前月份对应的游戏道具名称。 + */ +function autoGetGameItem() { + // 定义游戏道具的列表,包括普通改装道具和进阶改装道具 + const gameItems = [ + "进气系统", "燃料系统", "点火系统", "引擎系统", // 普通改装道具 + "普通粒子推进", "普通阿尔法离合" // 进阶改装道具 + ]; + + // 获取当前月份(加1是因为月份从0开始) + const currentMonth = new Date().getMonth() + 1; + + // 计算当前月份对应的游戏道具的索引 + const index = (currentMonth - 1) % gameItems.length; + + // 返回当前月份对应的游戏道具名称 + return gameItems[index]; +} + +/** + * @description 根据当前余额和道具价格生成购物列表 + * @param {string} name - 道具名称 + * @param {object} item - 包含道具价格信息的对象 + * @param {number} money - 当前可用余额 + * @returns {[array, number]} - 一个包含待购物对象和总购物数量的数组 + */ +function getShopItems(name, item, money) { + // 获取道具价格的所有可购买数量,并由高到低排序 + const itemCounts = Object.keys(item.price_idx) + .map((key) => parseInt(key.match(/\d+/))) + .filter((num) => !isNaN(num)) + .sort((a, b) => b - a); + + // 获取道具价格的所有价格,并由高到低排序 + const itemPrices = Object.values(item.price_idx) + .map((priceData) => priceData.price) + .sort((a, b) => b - a); + + // 初始化总购物数量和购物列表 + let totalCounts = 0; + let shopArray = []; + + for (let i = 0; i < itemPrices.length; i++) { + // 计算当前余额可以购买的最大道具数量 + const maxItems = Math.floor(money / itemPrices[i]); // 这是一个计算出的整数,表示根据当前余额和道具价格,最多可以购买的道具数量。 + totalCounts += maxItems * itemCounts[i]; // 这是一个累加的变量,用于跟踪购买的总道具数量。 + money -= maxItems * itemPrices[i]; // 这是当前可用的余额。在每次购买道具后,余额会根据购买的道具数量和价格进行更新,以反映购买后的余额。 + + if (maxItems) { + // 获取当前道具的索引 + const index = item.price_idx[`${itemCounts[i]}天`] || item.price_idx[`${itemCounts[i]}个`]; + + // 将可购买的道具添加到购物列表 + for (let m = 0; m < maxItems; m++) { + shopArray.push({"name": name, "count": itemCounts[i].toString(), "id": item.itemId, "idx": index.index}); + } + } + + // 如果当前余额不足以购买最便宜的道具,跳出循环 + if (money < itemPrices[itemPrices.length - 1]) { + break; + } + } + + return [shopArray, totalCounts ? totalCounts : 0]; +} + +/** + * @description 获取点券和消费券信息 + * @param {string} argument - 余额状态,可选值为 "before" 或 "after" + * @returns {Promise} - 包含点券和消费券数量的对象,或者在获取失败时返回 false + */ +async function getPackInfo(argument) { + // 创建一个空对象,用于存储点券和消费券信息 + let result = {}; + + // 根据参数值设置状态文本 + const statu = (argument === "before") ? "当前" : "剩余"; + + // 输出日志,表示开始获取点券和消费券 + $.log(`🧑‍💻 开始获取${statu}点券和消费券`); + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 GET 请求,获取点券和消费券信息 + $.get({ url: $.read(`zsfc_bang_url`) }, (err, resp, data) => { + if (data) { + // 将响应数据转换为字符串 + const body = data.toString(); + + // 使用正则表达式匹配点券和消费券数量 + money = body.match(/(\d+)<\/b>/)[1]; + coupons = body.match(/(\d+)<\/b>/)[1]; + + // 将点券和消费券数量存储在结果对象中 + result.money = money; + result.coupons = coupons; + } else { + // 如果获取失败,将结果对象设置为 false + result = false; + } + + // 解析 Promise,将结果对象传递给 resolve 函数 + resolve(result); + }); + }); +} + +/** + * @description 购买道具 + * @param {string} name - 道具名称 + * @param {number} count - 购买数量 + * @param {string} id - 道具的唯一标识符 + * @param {string} idx - 道具的价格索引 + * @returns {Promise} - 返回成功购买的道具数量 + */ +async function purchaseItem(name, count, id, idx) { + // 配置请求选项 + const options = { + url: `https://bang.qq.com/app/speed/mall/getPurchase`, + headers: { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "Referer": `https://bang.qq.com/app/speed/mall/detail2?itemId=${id}&${$.read("zsfc_bang_referer")}` + }, + body: `${$.read(`zsfc_bang_data`)}&commodity_id=${id}&price_idx=${idx}` + }; + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 POST 请求,购买道具 + $.post(options, (err, resp, data) => { + if (data) { + // 将响应数据转换为对象 + const body = $.toObj(data); + + // 提取响应中的消息 + const msg = body.msg; + + // 检查响应结果,如果购买失败,输出错误消息 + if (body.res == -1) { + $.log(`❌ ${msg}`); + } else { + // 如果购买成功,将成功购买的道具数量设置为购买数量 + totalCount = count * 1; + } + } else { + // 如果发生错误,输出错误消息和错误信息 + $.log(`❌ 购买${name}时发生错误`); + $.log($.toStr(err)); + } + + // 解析 Promise,将成功购买的道具数量传递给 resolve 函数 + resolve(totalCount ? totalCount : 0); + }); + }); +} + +/** + * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 + * @param {string} name - 环境名称 + */ +function Env(name) { + // 判断当前环境 + const isLoon = typeof $loon !== "undefined"; + const isSurge = typeof $httpClient !== "undefined" && !isLoon; + const isQX = typeof $task !== "undefined"; + + // 定义 read 方法,用于读取数据 + const read = (key) => { + if (isLoon || isSurge) return $persistentStore.read(key); + if (isQX) return $prefs.valueForKey(key); + }; + + // 定义 write 方法,用于写入数据 + const write = (key, value) => { + if (isLoon || isSurge) return $persistentStore.write(key, value); + if (isQX) return $prefs.setValueForKey(key, value); + }; + + // 定义 notice 方法,用于发送通知 + const notice = (title, subtitle, message, url) => { + if (isLoon) $notification.post(title, subtitle, message, url); + if (isSurge) $notification.post(title, subtitle, message, { url }); + if (isQX) $notify(title, subtitle, message, { "open-url": url }); + }; + + // 定义 get 方法,用于发送 GET 请求 + const get = (url, callback) => { + if (isLoon || isSurge) $httpClient.get(url, callback); + if (isQX) { url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + }; + + // 定义 post 方法,用于发送 POST 请求 + const post = (url, callback) => { + if (isLoon || isSurge) $httpClient.post(url, callback); + if (isQX) { url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + }; + + // 定义 put 方法,用于发送 PUT 请求 + const put = (url, callback) => { + if (isLoon || isSurge) $httpClient.put(url, callback); + if (isQX) { url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + }; + + // 定义 toObj 方法,用于将字符串转为对象 + const toObj = (str) => JSON.parse(str); + + // 定义 toStr 方法,用于将对象转为字符串 + const toStr = (obj) => JSON.stringify(obj); + + // 定义 log 方法,用于输出日志 + const log = (message) => console.log(message); + + // 定义 done 方法,用于结束任务 + const done = (value = {}) => $done(value); + + // 返回包含所有方法的对象 + return { name, read, write, notice, get, post, put, toObj, toStr, log, done }; +} From 51acadef7650e468bef9ede1f4db44037790ac4a Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:16:27 +0800 Subject: [PATCH 208/311] =?UTF-8?q?=E6=B7=BB=E5=8A=A0[=E6=8E=8C=E9=A3=9E?= =?UTF-8?q?=E5=AF=BB=E5=AE=9D]=E8=84=9A=E6=9C=AC=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D[=E6=8E=8C=E9=A3=9E=E8=B4=AD=E7=89=A9]=E5=85=B3?= =?UTF-8?q?=E4=BA=8EQX=E9=85=8D=E7=BD=AE=20(#461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 25 ++-- zsfc/zsfc.js | 14 +- zsfc/zsfc.shop.js | 38 +++-- zsfc/zsfc.treasure.js | 319 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 367 insertions(+), 29 deletions(-) create mode 100644 zsfc/zsfc.treasure.js diff --git a/zsfc/README.md b/zsfc/README.md index 0058fec32..29bcfe088 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -2,7 +2,7 @@ > 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 -> 感谢[@danchaw](https://github.com/danchaw) PR、[@chiupam](https://github.com/chiupam) 修改签到脚本,感谢[@chiupam](https://github.com/chiupam) PR购物脚本 +> 感谢[@danchaw](https://github.com/danchaw) PR、[@chiupam](https://github.com/chiupam) 修改签到脚本,感谢[@chiupam](https://github.com/chiupam) PR购物脚本、寻宝脚本 > 代码已适配最新版掌上飞车APP,旧版本APP无法继续签到,请及时更新 @@ -13,9 +13,12 @@ hostname = %APPEDN% comm.ams.game.qq.com, bang.qq.com [Script] 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 -掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=5 +掌飞寻宝Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/treasure/index\?*, requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=60 + +掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 +掌飞寻宝 =type=cron, cronexp="0 0 11-16/1 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=30 ``` ## 配置 (Loon) @@ -25,9 +28,12 @@ hostname = comm.ams.game.qq.com, bang.qq.com [Script] http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie -cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=10, tag=掌飞购物Cookie +http-request ^https?://bang\.qq\.com/app/speed/treasure/index\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, requires-body=true, timeout=60, tag=掌飞寻宝Cookie + +cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 +cron "0 0 11-16/1 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝 ``` ## 配置 (QuanX) @@ -36,24 +42,27 @@ cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/ hostname = comm.ams.game.qq.com, bang.qq.com [rewrite_local] -^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js -^https?://bang\.qq\.com/app/speed/mall/main2\?* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js +^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js +^https?://bang\.qq\.com/app/speed/mall/main2\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js +^https?://bang\.qq\.com/app/speed/treasure/index\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js [task_local] 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true 0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true +0 0 11-16/1 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝, enabled=true ``` ## 说明 1. 先把`comm.ams.game.qq.com, bang.qq.com`加到`[MITM]` 2. 再配置重写规则: - - Surge: 把两条远程脚本放到`[Script]` - - Loon: 把两条远程脚本放到`[Script]` + - Surge: 把三条远程脚本放到`[Script]` + - Loon: 把三条远程脚本放到`[Script]` - QuanX: 把远程重写脚本放到`[rewrite_local]`,再把远程定时任务放到`[task_local]` 3. 打开[掌上飞车APP](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233),点击咨询栏的签到(每日福利),系统提示`✅ 获取签到数据成功!`即可 4. 打开[掌上飞车APP](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233),点击下方游戏栏,然后点击掌飞商城,系统提示`✅ 获取商城数据成功!`即可 -5. 订阅[chiupam boxjs仓库](https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json)并在应用中设置掌飞商城所需购买的游戏道具名称 +5. 打开[掌上飞车APP](https://apps.apple.com/cn/app/%E6%8E%8C%E4%B8%8A%E9%A3%9E%E8%BD%A6/id1116903233),点击下方游戏栏,然后点击每日寻宝,系统提示`✅ 获取寻宝数据成功!`即可 +6. 如果使用了[掌飞购物](https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js)脚本的,请继续订阅[chiupam boxjs仓库](https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json)并在应用中设置掌飞商城所需购买的游戏道具名称 ## 反馈bug 如果出现bug,请提交issue到[chiupam仓库](https://github.com/chiupam/surge/issues/new) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index e60a8fcaa..1683f1a2c 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,5 +1,5 @@ /** - * + * * 使用方法:打开掌上飞车APP, 点击咨询栏的签到(每日福利)即可,无需点击签到,否则脚本无法正确运行。 * 注意事项:每月需手动打开一次掌上飞车APP并进入签到页面,以重新抓包更新礼包数据,为此需要每日运行两次脚本 * @@ -13,19 +13,19 @@ * type: cron * cron: 0 10 0,21 * * * * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js - * + * * =============== Surge =============== - * 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 * 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 - * + * * =============== Loon =============== * http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie * cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 - * + * * =============== Quan X =============== - * ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true - * + * */ /** diff --git a/zsfc/zsfc.shop.js b/zsfc/zsfc.shop.js index 82926399f..bc3ad7e3b 100644 --- a/zsfc/zsfc.shop.js +++ b/zsfc/zsfc.shop.js @@ -19,23 +19,33 @@ * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js * * =============== Surge =============== - * 掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=5 + * 掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=10 * 掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 * * =============== Loon =============== - * http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=5, tag=掌飞购物Cookie + * http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=10, tag=掌飞购物Cookie * cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 * * =============== Quan X =============== - * ^https?://bang\.qq\.com/app/speed/mall/main2\?* url scripts-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js + * ^https?://bang\.qq\.com/app/speed/mall/main2\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js * 0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true * */ -const $ = new Env(`🏎️ 掌飞购物`); // 创建名为 $ 的环境实例 -const isreq = typeof $request !== 'undefined'; // 检查是否存在请求对象 +/** + * 创建一个名为 $ 的环境变量实例,用于处理掌飞购物相关操作 + */ +const $ = new Env(`🏎️ 掌飞购物`) + +/** + * 检查是否为请求阶段 + */ +const isreq = typeof $request !== 'undefined'; +/** + * 主函数,用于执行打卡操作或设置请求数据 + */ (async () => { if (isreq) { // 处理请求阶段 @@ -90,7 +100,7 @@ const isreq = typeof $request !== 'undefined'; // 检查是否存在请求对 // 定义商品信息(目前只支持买着下面的东西,因为我懒得爬取了) const shopIdArray = { - "雷诺": {"itemId": "12720", "price_idx": {"180天": {"index": "0", "price": 12200}, "30天": {"index": "1", "price": 8500}}}, // 雷诺不购买30天的,有点浪费点券和消费券 + "雷诺": {"itemId": "12720", "price_idx": {"180天": {"index": "0", "price": 12200}}}, // 雷诺不购买30天的,有点浪费点券和消费券 "进气系统": {"itemId": "12377", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, "燃料系统": {"itemId": "12378", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, "点火系统": {"itemId": "12376", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, @@ -123,7 +133,8 @@ const isreq = typeof $request !== 'undefined'; // 检查是否存在请求对 $.subtitle = beforeLog; // 读取要购买的商品名称 - const shopName = $.read(`zsfc_bang_shopname`); + shopName = $.read(`zsfc_bang_shopname`); + if (!shopName) shopName = autoGetGameItem(); // 获取购物包 const [shopArray, totalCount] = getShopItems(shopName, shopIdArray[shopName], @@ -175,11 +186,11 @@ const isreq = typeof $request !== 'undefined'; // 检查是否存在请求对 .finally(() => $.done()); /** - * @description 从字符串中提取参数并返回指定键名的参数值 - * @param {string} str - 包含参数的字符串 - * @param {Array} argument - 需要提取的参数键名 - * @returns {object} 包含提取的参数键值对的对象 - */ + * @description 从字符串中提取参数并返回指定键名的参数值 + * @param {string} str - 包含参数的字符串 + * @param {Array} argument - 需要提取的参数键名 + * @returns {object} 包含提取的参数键值对的对象 + */ function extractParams(str, argument) { // 创建正则表达式,用于匹配参数键值对 const regex = /([^&=]+)=([^&]+)/g; @@ -215,7 +226,6 @@ function extractParams(str, argument) { return filteredParams; } - /** * @description 生成查询字符串 * @param {object} argument - 包含键值对的对象 @@ -261,7 +271,7 @@ function autoGetGameItem() { // 定义游戏道具的列表,包括普通改装道具和进阶改装道具 const gameItems = [ "进气系统", "燃料系统", "点火系统", "引擎系统", // 普通改装道具 - "普通粒子推进", "普通阿尔法离合" // 进阶改装道具 + // "普通粒子推进", "普通阿尔法离合" // 进阶改装道具,我不需要,注释掉了 ]; // 获取当前月份(加1是因为月份从0开始) diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js new file mode 100644 index 000000000..1416e7949 --- /dev/null +++ b/zsfc/zsfc.treasure.js @@ -0,0 +1,319 @@ +/** + * + * 使用方法:打开掌上飞车APP, 点击下方游戏栏,然后点击每日寻宝即可获取所需数据。 + * 注意事项:该脚本未做Cookie失效检测,引测如果运行错误请重新获取所需数据。 + * + * hostname: bang.qq.com + * + * type: http-request + * regex: ^https?://bang\.qq\.com/app/speed/treasure/index\?* + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js + * requests-body: 1 + * + * type: cron + * cron: 0 0 11-16/1 * * * + * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js + * + * =============== Surge =============== + * 掌飞寻宝Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/treasure/index\?*, requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=60 + * 掌飞寻宝 =type=cron, cronexp="0 0 11-16/1 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=30 + * + * =============== Loon =============== + * http-request ^https?://bang\.qq\.com/app/speed/treasure/index\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, requires-body=true, timeout=60, tag=掌飞寻宝Cookie + * cron "0 0 11-16/1 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝 + * + * =============== Quan X =============== + * ^https?://bang\.qq\.com/app/speed/treasure/index\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js + * 0 0 11-16/1 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝, enabled=true + * + */ + +/** + * 创建一个名为 $ 的环境变量实例,用于处理掌飞寻宝相关操作 + */ +const $ = new Env(`🏎️ 掌飞寻宝`) + +/** + * 检查是否为请求阶段 + */ +const isreq = typeof $request !== 'undefined'; + +/** + * 主函数,用于执行打卡操作或设置请求数据 + */ +(async () => { + if (isreq) { + // 处理请求时的逻辑 + + const url = $request.url; + const cookie = $request.headers.cookie; + + // 处理所需的键值 + const data = { + "accessToken": matchStr(cookie, "access_token"), + "openid": matchStr(cookie, "openid"), + "token": matchStr(url, "token"), + "roleId": matchStr(url, "roleId"), + "userId": matchStr(url, "userId"), + "areaId": matchStr(url, "areaId") + }; + + // 将数据写入内存 + $.write($.toStr(data), `zsfc_treasure_data`); + + // 发送通知 + $.notice($.name, `✅ 获取寻宝数据成功!`, ``, ``); + + } else { + // 处理非请求时的逻辑 + + // 获取内存数据 + $.memoryData = $.toObj($.read(`zsfc_treasure_data`)); + + // 获取地图数据 + $.mapData = await fetchMapData(); + + // 输出最高解锁星级信息和今日大吉地图 + $.log(`✅ 最高解锁星级:${'⭐️'.repeat($.mapData.starId * 1)}`); + $.log(`✅ 今日大吉地图:${$.mapData.mapName}`); + + // 开始查询目前的寻宝状态 + const treasureData = await performTreasureAction(`start`); + + if (treasureData.ending) { + // 寻宝完成,先结束寻宝再领取奖励 + $.log(`🧑‍💻 结束在${$.mapData.mapName}中寻宝`); + await performTreasureAction(`end`); + + // 循环领取两个寻宝奖励 + for (let iFlowId of $.mapData.iFlowId) { + $.log(`✅ 恭喜你获得:${await claimTreasureReward(iFlowId)}`); + } + + // 今天还能寻宝,继续寻宝 + if (treasureData.todaycanTimes) { + $.log(`还剩余${treasureData.todaycanTimes}次寻宝机会,继续寻宝`); + await performTreasureAction(`start`); + } + } else if (!treasureData.todaycanTimes) { + $.log(`⭕ 当天的寻宝次数已用完`); + } else if (treasureData.timeLeft > 596) { + $.log(`✅ 开始寻宝,将在${treasureData.timeLeft}秒后结束`); + } else { + $.log(`⭕ 正在寻宝中,将在${treasureData.timeLeft}秒后结束`); + } + + // 这个脚本不发送通知,静默运行 + // $.notice($.name, ``, ``, ``) + } +})() + .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) + .finally(() => $.done()); + +/** + * 从输入字符串中提取指定关键字的值。 + * + * @param {string} input - 输入字符串,要从中提取关键字的值。 + * @param {string} key - 要提取的关键字。 + * @returns {string} - 返回匹配到的关键字值,如果没有匹配到则返回空字符串。 + */ +function matchStr(input, key) { + const inputStr = input.toString(); + const separator = inputStr.includes("&") ? "&" : ";"; + const pattern = new RegExp(`${key}=([^${separator}]+)`); + const match = inputStr.match(pattern); + return match ? match[1] : ''; +} + +/** + * @description 异步获取地图数据操作。 + * @returns {Promise} 包含地图数据的 Promise 对象。 + */ +async function fetchMapData() { + const url = `https://bang.qq.com/app/speed/treasure/index?roleId=${$.memoryData.roleId}&uin=${$.memoryData.roleId}&areaId=${$.memoryData.areaId}`; + $.log(`🧑‍💻 正在获取地图数据`); + let mapData = {}; + + return new Promise(resolve => { + $.get(url, (error, response, rawData) => { + if (rawData) { + // 提取userInfo和mapInfo的数据 + const userInfoMatch = rawData.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/); + const mapInfoMatch = rawData.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/); + + if (userInfoMatch && mapInfoMatch) { + const userInfoData = eval('(' + userInfoMatch[1] + ')'); + const mapInfoData = eval('(' + mapInfoMatch[1] + ')'); + + const unlockedStars = Object.keys(userInfoData.starInfo) + .filter(starId => userInfoData.starInfo[starId] === 1); + const highestUnlockedStarId = Math.max(...unlockedStars); + const luckyMap = mapInfoData[highestUnlockedStarId] + .find(map => map.isdaji === 1); + + const mapArrRegex = new RegExp(`${highestUnlockedStarId} == i \\? \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\) :`, 'g'); + const mapArrMatch = mapArrRegex.exec(rawData); + const mapArr = mapArrMatch ? [parseInt(mapArrMatch[1]), parseInt(mapArrMatch[2])] : []; + + mapData = { + starId: highestUnlockedStarId, + mapId: luckyMap.id, + mapName: luckyMap.name, + iFlowId: mapArr + }; + } + } else { + $.log(`❌ 获取地图数据时发生错误`); + $.log($.toStr(error)); + } + + resolve(mapData); + }); + }); +} + +/** + * @description 异步执行寻宝操作。 + * @param {string} action - 操作动作,可以是 "start" 或 "end"。 + * @returns {Promise} - 包含操作结果的相关信息的 Promise 对象。 + */ +async function performTreasureAction(action) { + let isEnding = 0; + let timeRemaining = 0; + let remainingTreasureAttempts = 0; + + const options = { + url:`https://bang.qq.com/app/speed/treasure/ajax/${action}DigTreasure`, + headers: { + "Referer": "https://bang.qq.com/app/speed/treasure/index", + "Cookie": `access_token=${$.memoryData.accessToken}; acctype=qc; appid=1105330667; openid=${$.memoryData.openid}` + }, + body: $.queryStr({ + "mapId": $.mapData.mapId, + "starId": $.mapData.starId, + "areaId": $.memoryData.areaId, + "roleId": $.memoryData.roleId, + "userId": $.memoryData.userId, + "uin": $.memoryData.roleId, + "token": $.memoryData.token + }) + }; + + return new Promise(resolve => { + $.post(options, (error, response, data) => { + if (data) { + const treasureResponse = $.toObj(data); + if (action === "start") { + if (treasureResponse.msg.includes(`用完`)) { + remainingTreasureAttempts = 0; + } else { + const targetTimestamp = new Date(treasureResponse.data.time).getTime(); + const tenMinutesLaterTimestamp = targetTimestamp + 10 * 60 * 1000; + if (Date.now() > tenMinutesLaterTimestamp) { + isEnding = 1; + } else { + timeRemaining = parseInt((tenMinutesLaterTimestamp - Date.now()) / 1000); + } + } + } else { + remainingTreasureAttempts = treasureResponse.data.todaycanTimes - treasureResponse.data.todayTimes; + } + } else { + $.log(`❌ 寻宝时发生错误`); + $.log($.toStr(error)); + } + + resolve({ + "ending": isEnding, + "timeLeft": timeRemaining, + "todaycanTimes": remainingTreasureAttempts + }); + }); + }); +} + +/** + * @description 异步执行领取寻宝奖励操作。 + * @param {number} flowId - 寻宝流水ID,用于标识领取的奖励。 + * @returns {Promise} - 包含领取的奖励包名的 Promise 对象。 + */ +async function claimTreasureReward(flowId) { + let sPackageName; + + const options = { + url: `https://act.game.qq.com/ams/ame/amesvr?ameVersion=0.3&iActivityId=468228`, + headers: { + "Cookie": `access_token=${$.memoryData.accessToken}; acctype=qc; appid=1105330667; openid=${$.memoryData.openid}` + }, + body: $.queryStr({ + 'appid': '1105330667', + 'sArea': $.memoryData.areaId, + 'sRoleId': $.memoryData.roleId, + 'accessToken': $.memoryData.accessToken, + 'iActivityId': "468228", + 'iFlowId': flowId, + 'g_tk': '1842395457', + 'sServiceType': 'bb' + }) + } + + return new Promise(resolve => { + $.post(options, (error, response, data) => { + if (data) { + sPackageName = $.toObj(data).modRet.sPackageName; + } else { + $.log(`❌ 领取寻宝奖励时发生错误`); + $.log($.toStr(error)); + } + resolve(sPackageName); + }); + }); +} + +function Env(name) { + const isLoon = typeof $loon !== "undefined"; + const isSurge = typeof $httpClient !== "undefined" && !isLoon; + const isQX = typeof $task !== "undefined"; + const read = (key) => { + if (isLoon || isSurge) return $persistentStore.read(key); + if (isQX) return $prefs.valueForKey(key); + }; + const write = (key, value) => { + if (isLoon || isSurge) return $persistentStore.write(key, value); + if (isQX) return $prefs.setValueForKey(key, value); + }; + const notice = (title, subtitle, message, url) => { + if (isLoon) $notification.post(title, subtitle, message, url); + if (isSurge) $notification.post(title, subtitle, message, { url }); + if (isQX) $notify(title, subtitle, message, { "open-url": url }); + }; + const get = (url, callback) => { + if (isLoon || isSurge) $httpClient.get(url, callback); + if (isQX) {url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + const post = (url, callback) => { + if (isLoon || isSurge) $httpClient.post(url, callback); + if (isQX) {url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + const put = (url, callback) => { + if (isLoon || isSurge) $httpClient.put(url, callback) + if (isQX) {url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; + }; + const toObj = (str) => JSON.parse(str); + const toStr = (obj) => JSON.stringify(obj); + const queryStr = (obj) => { + const keyValuePairs = []; + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + const value = obj[key]; + const encodedKey = encodeURIComponent(key); + const encodedValue = encodeURIComponent(value); + keyValuePairs.push(`${encodedKey}=${encodedValue}`); + } + } + return keyValuePairs.join('&'); + }; + const log = (message) => console.log(message); + const done = (value = {}) => $done(value); + return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; +} From 51c740c56f96553afc12898c3d588e3b0b79a27a Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:28:22 +0800 Subject: [PATCH 209/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D[=E6=8E=8C=E9=A3=9E?= =?UTF-8?q?=E5=AF=BB=E5=AE=9D]BUG=20(#463)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.treasure.js | 51 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index 1416e7949..1e05839df 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -78,12 +78,12 @@ const isreq = typeof $request !== 'undefined'; $.log(`✅ 今日大吉地图:${$.mapData.mapName}`); // 开始查询目前的寻宝状态 - const treasureData = await performTreasureAction(`start`); + treasureData = await performTreasureAction(`start`); if (treasureData.ending) { // 寻宝完成,先结束寻宝再领取奖励 $.log(`🧑‍💻 结束在${$.mapData.mapName}中寻宝`); - await performTreasureAction(`end`); + treasureData = await performTreasureAction(`end`); // 循环领取两个寻宝奖励 for (let iFlowId of $.mapData.iFlowId) { @@ -92,7 +92,7 @@ const isreq = typeof $request !== 'undefined'; // 今天还能寻宝,继续寻宝 if (treasureData.todaycanTimes) { - $.log(`还剩余${treasureData.todaycanTimes}次寻宝机会,继续寻宝`); + $.log(`💨 还剩余${treasureData.todaycanTimes}次寻宝机会,继续寻宝`); await performTreasureAction(`start`); } } else if (!treasureData.todaycanTimes) { @@ -135,15 +135,15 @@ async function fetchMapData() { let mapData = {}; return new Promise(resolve => { - $.get(url, (error, response, rawData) => { - if (rawData) { + $.get(url, (error, response, data) => { + if (data) { // 提取userInfo和mapInfo的数据 - const userInfoMatch = rawData.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/); - const mapInfoMatch = rawData.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/); + const userInfoMatch = data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/); + const mapInfoMatch = data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/); if (userInfoMatch && mapInfoMatch) { - const userInfoData = eval('(' + userInfoMatch[1] + ')'); - const mapInfoData = eval('(' + mapInfoMatch[1] + ')'); + const userInfoData = eval(`(${userInfoMatch[1]})`); + const mapInfoData = eval(`(${mapInfoMatch[1]})`); const unlockedStars = Object.keys(userInfoData.starInfo) .filter(starId => userInfoData.starInfo[starId] === 1); @@ -151,15 +151,15 @@ async function fetchMapData() { const luckyMap = mapInfoData[highestUnlockedStarId] .find(map => map.isdaji === 1); - const mapArrRegex = new RegExp(`${highestUnlockedStarId} == i \\? \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\) :`, 'g'); - const mapArrMatch = mapArrRegex.exec(rawData); - const mapArr = mapArrMatch ? [parseInt(mapArrMatch[1]), parseInt(mapArrMatch[2])] : []; + const iFlowIdArrRegex = new RegExp(`${highestUnlockedStarId} == i \\? \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\) :`, 'g'); + const iFlowIdArrMatch = iFlowIdArrRegex.exec(data); + const iFlowIdArr = iFlowIdArrMatch ? [parseInt(iFlowIdArrMatch[1]), parseInt(iFlowIdArrMatch[2])] : []; mapData = { starId: highestUnlockedStarId, mapId: luckyMap.id, mapName: luckyMap.name, - iFlowId: mapArr + iFlowId: iFlowIdArr }; } } else { @@ -180,7 +180,8 @@ async function fetchMapData() { async function performTreasureAction(action) { let isEnding = 0; let timeRemaining = 0; - let remainingTreasureAttempts = 0; + let remainingTimes = 1; + let digTreasureData = {}; const options = { url:`https://bang.qq.com/app/speed/treasure/ajax/${action}DigTreasure`, @@ -202,12 +203,12 @@ async function performTreasureAction(action) { return new Promise(resolve => { $.post(options, (error, response, data) => { if (data) { - const treasureResponse = $.toObj(data); + const body = $.toObj(data); if (action === "start") { - if (treasureResponse.msg.includes(`用完`)) { - remainingTreasureAttempts = 0; + if (body.msg.includes(`用完`)) { + remainingTimes = 0; } else { - const targetTimestamp = new Date(treasureResponse.data.time).getTime(); + const targetTimestamp = new Date(body.data.time).getTime(); const tenMinutesLaterTimestamp = targetTimestamp + 10 * 60 * 1000; if (Date.now() > tenMinutesLaterTimestamp) { isEnding = 1; @@ -216,18 +217,20 @@ async function performTreasureAction(action) { } } } else { - remainingTreasureAttempts = treasureResponse.data.todaycanTimes - treasureResponse.data.todayTimes; + remainingTimes = body.data.todaycanTimes - body.data.todayTimes } + + digTreasureData = { + ending: isEnding, + timeLeft: timeRemaining, + todaycanTimes: remainingTimes + }; } else { $.log(`❌ 寻宝时发生错误`); $.log($.toStr(error)); } - resolve({ - "ending": isEnding, - "timeLeft": timeRemaining, - "todaycanTimes": remainingTreasureAttempts - }); + resolve(digTreasureData); }); }); } From 82fbbc7877655d14967527aed175aee9712e601f Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:12:09 +0800 Subject: [PATCH 210/311] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=8C=E9=A3=9E?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=AD=BE=E5=88=B0=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#466)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.js | 94 +++++++++++++---------- zsfc/zsfc.shop.js | 162 +++++++++++++++++---------------------- zsfc/zsfc.treasure.js | 174 +++++++++++++++++++++++++++--------------- 3 files changed, 235 insertions(+), 195 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 1683f1a2c..7cc82d9d4 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -59,23 +59,20 @@ const isreq = typeof $request !== 'undefined'; } // 提取请求数据 - const url = $.toStr($request.url); - const headers = $.toStr($request.headers); - const body = $.toStr($request.body); + const cookie = $request.headers.cookie; + const body = $request.body; // 定义 params 数组 const params = ['appid', 'iActivityId', 'g_tk', 'e_code', 'g_code', 'eas_url', 'eas_refer', 'sServiceDepartment', 'sServiceType']; // 数组有空返回则程序终止 if (params.find(param => !matchParam(body, param))) return; - // 用 & 将键值对拼接成一个长字符串 - const param = params.map(param => `${param}=${matchParam(body, param)}`).join('&'); // 初始化 dataToWrite 词典,填充待写入内存的键值对 const dataToWrite = { - 'zsfc_url': url.replace(/^"|"$/g, ''), - 'zsfc_headers': headers.replace(/^"|"$/g, ''), - 'zsfc_param': param.replace(/^"|"$/g, ''), + 'zsfc_iActivityId': (matchParam(body, 'iActivityId')).toString(), 'zsfc_iFlowId': (matchParam(body, 'iFlowId') - 1).toString(), + 'zsfc_accessToken': matchParam(cookie, 'accessToken'), + 'zsfc_openid': matchParam(cookie, 'openId'), 'zsfc_timestamp': Date.now().toString(), 'zsfc_time': new Date().toLocaleString().toString(), 'zsfc_month': (new Date().getMonth() + 1).toString() @@ -83,8 +80,13 @@ const isreq = typeof $request !== 'undefined'; // 将请求数据写入内存 Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + // 输出到日志只输出特定的键值对 + // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; + // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); + $.log(dataToWrite) + // 显示签到结果通知 - $.notice($.name, '✅ 获取签到数据成功!', `${interval}秒后请不要再点击本页面中的任何按钮,否则脚本会失效!`); + $.notice($.name, `✅ 获取签到数据成功(${dataToWrite.zsfc_iFlowId}/${dataToWrite.zsfc_iActivityId})`, `${interval}秒后请不要再点击本页面中的任何按钮,否则脚本会失效!`); } else { /** @@ -99,14 +101,26 @@ const isreq = typeof $request !== 'undefined'; return; } + const option = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + }, + body: $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed" + }) + }; + // 获取本月签到礼物列表 - const signInGifts = await getSignInGifts() + const signInGifts = await getSignInGifts(option); // 进行每日签到 - await dailyCheckin(signInGifts['每日签到']) + await dailyCheckin(option, signInGifts['每日签到']); // 获取本月累签天数 - const totalSignInDay = await getTotalSignInDays() + const totalSignInDay = await getTotalSignInDays(option); // 初始化 signInInfoArray 数组 let signInInfoArray = []; @@ -123,13 +137,13 @@ const isreq = typeof $request !== 'undefined'; } if (signInInfoArray.length) { - $.log(`🎉 共有 ${signInInfoArray.length} 个礼包待领取`) + $.log(`🎉 共有 ${signInInfoArray.length} 个礼包待领取`); } // 遍历礼包数组,领取奖励 for (let signInInfo of signInInfoArray) { let { code, title } = signInInfo; - await claimGift(code, title); + await claimGift(option, code, title); } // 显示签到结果通知 @@ -146,8 +160,10 @@ const isreq = typeof $request !== 'undefined'; * @param {string} key - 参数名 * @returns {string} */ -function matchParam(body, key) { - const match = body.match(new RegExp(`${key}=([^&]+)`)); +function matchParam(input, key) { + const separator = input.includes("&") ? "&" : ";"; + const pattern = new RegExp(`${key}=([^${separator}]+)`); + const match = input.match(pattern); return match ? match[1] : ''; } @@ -155,11 +171,9 @@ function matchParam(body, key) { * @description 获取签到信息,并返回签到礼物列表 * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ -async function getSignInGifts() { - const options = { - url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_param`)}&iFlowId=${$.read(`zsfc_iFlowId`)}` - }; +async function getSignInGifts(option) { + const options = option; + options.body += `&iFlowId=${$.read(`zsfc_iFlowId`)}`; $.log(`🧑‍💻 开始获取本月礼物列表`); let giftsDictionary = {}; return new Promise(resolve => { @@ -173,7 +187,7 @@ async function getSignInGifts() { const flowName = match[3].replace(/累计签到|领取/g, ''); giftsDictionary[flowName] = flowId; } - $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`) + $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`); } else { $.log(`❌ 获取本月礼物列表时发生错误`); $.log($.toStr(err)); @@ -188,11 +202,9 @@ async function getSignInGifts() { * @param {string} iFlowId - 每日签到礼包的 iFlowId * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ -async function dailyCheckin(iFlowId) { - const options = { - url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_param`)}&iFlowId=${iFlowId}` - }; +async function dailyCheckin(option, iFlowId) { + const options = option; + options.body += `&iFlowId=${iFlowId}`; $.log(`🧑‍💻 开始进行每日签到`); return new Promise(resolve => { $.post(options, (err, resp, data) => { @@ -205,7 +217,7 @@ async function dailyCheckin(iFlowId) { } else { const sPackageName = body.modRet.sPackageName; $.log(`✅ 领取结果: 获得${sPackageName}`); - $.message = `恭喜获得:${sPackageName}` + $.message = `恭喜获得:${sPackageName}`; } } else { $.log(`❌ 进行每日签到时发生错误`); @@ -220,12 +232,10 @@ async function dailyCheckin(iFlowId) { * @description 获取累签天数的情况 * @returns {Promise} 返回累签天数 */ -async function getTotalSignInDays() { +async function getTotalSignInDays(option) { + const options = option; + options.body += `&iFlowId=${$.read(`zsfc_iFlowId`) * 1 + 1}`; let totalSignInDays; - const options = { - url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_param`)}&iFlowId=${$.read(`zsfc_iFlowId`) * 1 +1}` - }; $.log(`🧑‍💻 开始获取累签天数`); return new Promise(resolve => { $.post(options, (err, resp, data) => { @@ -249,12 +259,9 @@ async function getTotalSignInDays() { * @param {string} giftId 礼物 ID * @param {string} giftName 礼物名称 */ -async function claimGift(giftId, giftName) { - const options = { - url: $.read(`zsfc_url`), headers: $.toObj($.read(`zsfc_headers`)), - body: `${$.read(`zsfc_param`)}&iFlowId=${giftId}` - }; - $.log(`🧑‍💻 开始领取${giftName}`); +async function claimGift(option, giftId, giftName) { + const options = option; + options.body += `&iFlowId=${giftId}`; return new Promise(resolve => { $.post(options, (err, resp, data) => { if (data) { @@ -335,6 +342,13 @@ function Env(name) { // 定义 toStr 方法,用于将对象转为字符串 const toStr = (obj) => JSON.stringify(obj); + // 定义 queryStr 方法,用于将对象转为可以请求的字符串 + const queryStr = (obj) => { + return Object.keys(obj) + .map(key => `${key}=${obj[key]}`) + .join('&'); + }; + // 定义 log 方法,用于输出日志 const log = (message) => console.log(message); @@ -342,5 +356,5 @@ function Env(name) { const done = (value = {}) => $done(value); // 返回包含所有方法的对象 - return { name, read, write, notice, get, post, put, toObj, toStr, log, done }; + return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; } diff --git a/zsfc/zsfc.shop.js b/zsfc/zsfc.shop.js index bc3ad7e3b..2a2ce4572 100644 --- a/zsfc/zsfc.shop.js +++ b/zsfc/zsfc.shop.js @@ -50,50 +50,35 @@ const isreq = typeof $request !== 'undefined'; if (isreq) { // 处理请求阶段 - const url = $.toStr($request.url).replace(/^"|"$/g, ''); // 提取请求的URL并去除引号 - - // 定义需要提取的请求参数 - const paramValue = [ - "roleName", "roleLevel", "roleId", "uin", "nickname", "areaName", - "serverName", "serverId", "areaId", "isMainRole", "isapp", - "userId", "token", "appOpenid", "uniqueRoleId", "gameId", "subGameId", - "cGameId", "roleJob", "secret", "env", "openid", "toOpenid" - ]; - - // 需要添加的附加参数 - const extraParams = { - steamid: '0', openType: '1', isother: '0', platid: 'false', - cleId: 'false', from: 'false', pay_type: '1', isapp: '1' - }; - - // 提取请求中的参数 - const filteredParams = extractParams(url, paramValue); - const data = generateQueryString({ ...filteredParams, ...extraParams }); - - // 提取请求中的引用参数 - const refererValue = [ - "serverName", "appid", "areaName", "roleName", "gameName", - "nickname", "isMainRole", "appOpenid", "roleId", "areaId", - "toUin", "roleJob", "serverId", "accessToken", "gameId", "subGameId", - "token", "cGameId", "uniqueRoleId", "acctype", "accType", "uin", - "roleLevel", "userId" - ]; + // 提取请求的URL并去除引号 + const url = $.toStr($request.url).replace(/^"|"$/g, ''); + const cookie = $request.headers.cookie; - const filteredReferer = extractParams(url, refererValue); - const referer = generateQueryString(filteredReferer); + // 对比 token 是否发生变化 + if ($.read(`zsfc_token`) == matchStr(url, "token")) return; // 初始化 dataToWrite 词典,填充待写入内存的键值对 const dataToWrite = { - 'zsfc_bang_url': url, - 'zsfc_bang_referer': referer, - 'zsfc_bang_data': data + 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞商城无法抓取,只能读取签到页面的脚本获取情况 + "zsfc_accessToken": matchStr(url, "accessToken"), + "zsfc_openid": matchStr(cookie, "openid"), + "zsfc_token": matchStr(url, "token"), + "zsfc_roleId": matchStr(url, "roleId"), + "zsfc_userId": matchStr(url, "userId"), + "zsfc_areaId": matchStr(url, "areaId"), + 'zsfc_uin': matchStr(url, "uin"), }; // 将请求数据写入内存 Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + // 输出到日志只输出特定的键值对 + // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; + // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); + $.log(dataToWrite) + // 发送通知 - $.notice($.name, `✅ 获取商城数据成功!`, ``); + $.notice($.name, `✅ 获取商城数据成功!`, `请不要再次打开掌上飞车APP, 否则 Cookie 将失效!`); } else { // 执行购物阶段 @@ -186,56 +171,17 @@ const isreq = typeof $request !== 'undefined'; .finally(() => $.done()); /** - * @description 从字符串中提取参数并返回指定键名的参数值 - * @param {string} str - 包含参数的字符串 - * @param {Array} argument - 需要提取的参数键名 - * @returns {object} 包含提取的参数键值对的对象 - */ -function extractParams(str, argument) { - // 创建正则表达式,用于匹配参数键值对 - const regex = /([^&=]+)=([^&]+)/g; - - // 创建一个空对象,用于存储提取的参数键值对 - const extractedParams = {}; - - // 用于迭代匹配参数的正则表达式结果 - let match; - - // 遍历字符串以匹配参数,并将它们存储在 extractedParams 对象中 - while ((match = regex.exec(str))) { - // 提取参数名 - const paramName = match[1]; - - // 提取参数值 - let paramValue = match[2]; - - // 将参数键值对存储在 extractedParams 对象中 - extractedParams[paramName] = paramValue; - } - - // 创建一个空对象,用于存储筛选后的参数键值对 - const filteredParams = {}; - - // 遍历需要提取的参数键名 - for (const paramName of argument) { - // 将符合参数键名的键值对存储在 filteredParams 对象中 - filteredParams[paramName] = extractedParams[paramName]; - } - - // 返回包含筛选后的参数键值对的对象 - return filteredParams; -} - -/** - * @description 生成查询字符串 - * @param {object} argument - 包含键值对的对象 - * @returns {string} 包含 key=value 键值对的查询字符串 + * 从输入字符串中提取指定关键字的值。 + * + * @param {string} input - 输入字符串,要从中提取关键字的值。 + * @param {string} key - 要提取的关键字。 + * @returns {string} - 返回匹配到的关键字值,如果没有匹配到则返回空字符串。 */ -function generateQueryString(argument) { - return Object.entries(argument) - .map(([key, value]) => `${key}=${value}`) - .join('&') - .replace(/undefined|"/g, ''); +function matchStr(input, key) { + const separator = input.includes("&") ? "&" : ";"; + const pattern = new RegExp(`${key}=([^${separator}]+)`); + const match = input.match(pattern); + return match ? match[1] : ''; } /** @@ -344,13 +290,27 @@ async function getPackInfo(argument) { // 根据参数值设置状态文本 const statu = (argument === "before") ? "当前" : "剩余"; + // 获取 URL 中的查询参数 + const params = { + 'areaId': $.read(`zsfc_areaId`), + 'accessToken': $.read(`zsfc_accessToken`), + 'token': $.read(`zsfc_token`), + 'uin': $.read(`zsfc_uin`), + 'userId': $.read(`zsfc_userId`), + }; + + // 配置请求选项 + const options = { + url: `https://bang.qq.com/app/speed/mall/main2?${$.queryStr(params)}` + }; + // 输出日志,表示开始获取点券和消费券 $.log(`🧑‍💻 开始获取${statu}点券和消费券`); // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { // 发送 GET 请求,获取点券和消费券信息 - $.get({ url: $.read(`zsfc_bang_url`) }, (err, resp, data) => { + $.get(options, (err, resp, data) => { if (data) { // 将响应数据转换为字符串 const body = data.toString(); @@ -386,10 +346,17 @@ async function purchaseItem(name, count, id, idx) { const options = { url: `https://bang.qq.com/app/speed/mall/getPurchase`, headers: { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - "Referer": `https://bang.qq.com/app/speed/mall/detail2?itemId=${id}&${$.read("zsfc_bang_referer")}` + "Referer": `https://bang.qq.com/app/speed/mall/detail2` }, - body: `${$.read(`zsfc_bang_data`)}&commodity_id=${id}&price_idx=${idx}` + body: $.queryStr({ + 'areaId': $.read(`zsfc_areaId`), + 'token': $.read(`zsfc_token`), + 'userId': $.read(`zsfc_userId`), + 'uin': $.read(`zsfc_uin`), + 'pay_type': "1", + 'commodity_id': id, + 'price_idx': idx + }) }; // 返回一个 Promise 对象,用于异步操作 @@ -427,9 +394,11 @@ async function purchaseItem(name, count, id, idx) { * @param {string} name - 环境名称 */ function Env(name) { - // 判断当前环境 + // 判断当前环境是否为 Loon const isLoon = typeof $loon !== "undefined"; + // 判断当前环境是否为 Surge const isSurge = typeof $httpClient !== "undefined" && !isLoon; + // 判断当前环境是否为 QuantumultX const isQX = typeof $task !== "undefined"; // 定义 read 方法,用于读取数据 @@ -454,19 +423,19 @@ function Env(name) { // 定义 get 方法,用于发送 GET 请求 const get = (url, callback) => { if (isLoon || isSurge) $httpClient.get(url, callback); - if (isQX) { url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + if (isQX) {url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; // 定义 post 方法,用于发送 POST 请求 const post = (url, callback) => { if (isLoon || isSurge) $httpClient.post(url, callback); - if (isQX) { url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + if (isQX) {url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; // 定义 put 方法,用于发送 PUT 请求 const put = (url, callback) => { - if (isLoon || isSurge) $httpClient.put(url, callback); - if (isQX) { url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body)) }; + if (isLoon || isSurge) $httpClient.put(url, callback) + if (isQX) {url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; // 定义 toObj 方法,用于将字符串转为对象 @@ -475,6 +444,13 @@ function Env(name) { // 定义 toStr 方法,用于将对象转为字符串 const toStr = (obj) => JSON.stringify(obj); + // 定义 queryStr 方法,用于将对象转为可以请求的字符串 + const queryStr = (obj) => { + return Object.keys(obj) + .map(key => `${key}=${obj[key]}`) + .join('&'); + }; + // 定义 log 方法,用于输出日志 const log = (message) => console.log(message); @@ -482,5 +458,5 @@ function Env(name) { const done = (value = {}) => $done(value); // 返回包含所有方法的对象 - return { name, read, write, notice, get, post, put, toObj, toStr, log, done }; + return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; } diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index 1e05839df..58b23e6a0 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -39,40 +39,60 @@ const $ = new Env(`🏎️ 掌飞寻宝`) const isreq = typeof $request !== 'undefined'; /** - * 主函数,用于执行打卡操作或设置请求数据 + * 主函数,用于执行寻宝操作或设置请求数据 */ (async () => { if (isreq) { // 处理请求时的逻辑 + // 提取请求的URL和其他数据 const url = $request.url; const cookie = $request.headers.cookie; - // 处理所需的键值 - const data = { - "accessToken": matchStr(cookie, "access_token"), - "openid": matchStr(cookie, "openid"), - "token": matchStr(url, "token"), - "roleId": matchStr(url, "roleId"), - "userId": matchStr(url, "userId"), - "areaId": matchStr(url, "areaId") + // 对比 token 是否发生变化 + if ($.read(`zsfc_token`) == matchStr(url, "token")) return; + + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞商城无法抓取,只能读取签到页面的脚本获取情况 + "zsfc_accessToken": matchStr(url, "accessToken"), + "zsfc_openid": matchStr(cookie, "openid"), + "zsfc_token": matchStr(url, "token"), + "zsfc_roleId": matchStr(url, "roleId"), + "zsfc_userId": matchStr(url, "userId"), + "zsfc_areaId": matchStr(url, "areaId"), + 'zsfc_uin': matchStr(url, "uin"), + 'zsfc_treasure_day': (new Date().getDate()).toString() }; - // 将数据写入内存 - $.write($.toStr(data), `zsfc_treasure_data`); + // 将请求数据写入内存 + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + + // 输出到日志只输出特定的键值对 + // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; + // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); + $.log(dataToWrite) // 发送通知 - $.notice($.name, `✅ 获取寻宝数据成功!`, ``, ``); + $.notice($.name, `✅ 获取寻宝数据成功!`, `此脚本需每天打开掌上飞车APP并进入一次寻宝页面`, ``); } else { // 处理非请求时的逻辑 - // 获取内存数据 - $.memoryData = $.toObj($.read(`zsfc_treasure_data`)); + // 检查用户今天是否打开过寻宝页面 + const date = (new Date().getDate()).toString(); + if (!$.read(`zsfc_treasure_day`)) $.write(date, `zsfc_treasure_day`); + if (date != $.read(`zsfc_treasure_day`)) { + $.log(`❌ 今天未进过寻宝页面`); + return; + } // 获取地图数据 $.mapData = await fetchMapData(); + // 尊贵的紫钻用户 + if ($.mapData.isVip) $.log(`💎 尊贵的紫钻用户`); + // 输出最高解锁星级信息和今日大吉地图 $.log(`✅ 最高解锁星级:${'⭐️'.repeat($.mapData.starId * 1)}`); $.log(`✅ 今日大吉地图:${$.mapData.mapName}`); @@ -97,17 +117,18 @@ const isreq = typeof $request !== 'undefined'; } } else if (!treasureData.todaycanTimes) { $.log(`⭕ 当天的寻宝次数已用完`); - } else if (treasureData.timeLeft > 596) { + } else if (treasureData.timeLeft > 597) { $.log(`✅ 开始寻宝,将在${treasureData.timeLeft}秒后结束`); } else { $.log(`⭕ 正在寻宝中,将在${treasureData.timeLeft}秒后结束`); } // 这个脚本不发送通知,静默运行 - // $.notice($.name, ``, ``, ``) + // $.notice($.name, ``, ``, ``); + $.write(date, `zsfc_treasure_day`); } })() - .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) + .catch((e) => $.notice($.name, '❌ 未知错误无法寻宝', e, '')) .finally(() => $.done()); /** @@ -118,10 +139,9 @@ const isreq = typeof $request !== 'undefined'; * @returns {string} - 返回匹配到的关键字值,如果没有匹配到则返回空字符串。 */ function matchStr(input, key) { - const inputStr = input.toString(); - const separator = inputStr.includes("&") ? "&" : ";"; + const separator = input.includes("&") ? "&" : ";"; const pattern = new RegExp(`${key}=([^${separator}]+)`); - const match = inputStr.match(pattern); + const match = input.match(pattern); return match ? match[1] : ''; } @@ -130,7 +150,12 @@ function matchStr(input, key) { * @returns {Promise} 包含地图数据的 Promise 对象。 */ async function fetchMapData() { - const url = `https://bang.qq.com/app/speed/treasure/index?roleId=${$.memoryData.roleId}&uin=${$.memoryData.roleId}&areaId=${$.memoryData.areaId}`; + const params = { + 'roleId': $.read(`zsfc_roleId`), + 'uin': $.read(`zsfc_uin`), + 'areaId': $.read(`zsfc_areaId`), + }; + const url = `https://bang.qq.com/app/speed/treasure/index?${$.queryStr(params)}`; $.log(`🧑‍💻 正在获取地图数据`); let mapData = {}; @@ -141,27 +166,25 @@ async function fetchMapData() { const userInfoMatch = data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/); const mapInfoMatch = data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/); - if (userInfoMatch && mapInfoMatch) { - const userInfoData = eval(`(${userInfoMatch[1]})`); - const mapInfoData = eval(`(${mapInfoMatch[1]})`); - - const unlockedStars = Object.keys(userInfoData.starInfo) - .filter(starId => userInfoData.starInfo[starId] === 1); - const highestUnlockedStarId = Math.max(...unlockedStars); - const luckyMap = mapInfoData[highestUnlockedStarId] - .find(map => map.isdaji === 1); - - const iFlowIdArrRegex = new RegExp(`${highestUnlockedStarId} == i \\? \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\) :`, 'g'); - const iFlowIdArrMatch = iFlowIdArrRegex.exec(data); - const iFlowIdArr = iFlowIdArrMatch ? [parseInt(iFlowIdArrMatch[1]), parseInt(iFlowIdArrMatch[2])] : []; - - mapData = { - starId: highestUnlockedStarId, - mapId: luckyMap.id, - mapName: luckyMap.name, - iFlowId: iFlowIdArr - }; - } + const userInfoData = eval(`(${userInfoMatch[1]})`); + const mapInfoData = eval(`(${mapInfoMatch[1]})`); + + const unlockedStars = Object.keys(userInfoData.starInfo).filter(starId => userInfoData.starInfo[starId] === 1); + const highestUnlockedStarId = Math.max(...unlockedStars); + const luckyMap = mapInfoData[highestUnlockedStarId].find(map => map.isdaji === 1); + const iFlowIdRegex = `${highestUnlockedStarId} == i ${highestUnlockedStarId == 6 ? "&&" : "\\?"} \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\)`; + + const iFlowIdArrRegex = new RegExp(iFlowIdRegex, 'g'); + const iFlowIdArrMatch = iFlowIdArrRegex.exec(data); + const iFlowIdArr = iFlowIdArrMatch ? [parseInt(iFlowIdArrMatch[1]), parseInt(iFlowIdArrMatch[2])] : []; + + mapData = { + starId: highestUnlockedStarId, + mapId: luckyMap.id, + isVip: userInfoData.vip_flag, + mapName: luckyMap.name, + iFlowId: iFlowIdArr + }; } else { $.log(`❌ 获取地图数据时发生错误`); $.log($.toStr(error)); @@ -187,16 +210,19 @@ async function performTreasureAction(action) { url:`https://bang.qq.com/app/speed/treasure/ajax/${action}DigTreasure`, headers: { "Referer": "https://bang.qq.com/app/speed/treasure/index", - "Cookie": `access_token=${$.memoryData.accessToken}; acctype=qc; appid=1105330667; openid=${$.memoryData.openid}` + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` }, body: $.queryStr({ "mapId": $.mapData.mapId, "starId": $.mapData.starId, - "areaId": $.memoryData.areaId, - "roleId": $.memoryData.roleId, - "userId": $.memoryData.userId, - "uin": $.memoryData.roleId, - "token": $.memoryData.token + // 普通寻宝1 600s -- 快捷寻宝2 10s + // "type": $.mapData.isVip + 1, + "type": "1", // 懒得检查是否为紫钻了,统统使用普通寻宝 + "areaId": $.read(`zsfc_areaId`), + "roleId": $.read(`zsfc_roleId`), + "userId": $.read(`zsfc_userId`), + "uin": $.read(`zsfc_roleId`), + "token": $.read(`zsfc_token`) }) }; @@ -246,13 +272,13 @@ async function claimTreasureReward(flowId) { const options = { url: `https://act.game.qq.com/ams/ame/amesvr?ameVersion=0.3&iActivityId=468228`, headers: { - "Cookie": `access_token=${$.memoryData.accessToken}; acctype=qc; appid=1105330667; openid=${$.memoryData.openid}` + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` }, body: $.queryStr({ 'appid': '1105330667', - 'sArea': $.memoryData.areaId, - 'sRoleId': $.memoryData.roleId, - 'accessToken': $.memoryData.accessToken, + 'sArea': $.read(`zsfc_areaId`), + 'sRoleId': $.read(`zsfc_roleId`), + 'accessToken': $.read(`zsfc_accessToken`), 'iActivityId': "468228", 'iFlowId': flowId, 'g_tk': '1842395457', @@ -273,50 +299,74 @@ async function claimTreasureReward(flowId) { }); } +/** + * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 + * @param {string} name - 环境名称 + */ function Env(name) { + // 判断当前环境是否为 Loon const isLoon = typeof $loon !== "undefined"; + // 判断当前环境是否为 Surge const isSurge = typeof $httpClient !== "undefined" && !isLoon; + // 判断当前环境是否为 QuantumultX const isQX = typeof $task !== "undefined"; + + // 定义 read 方法,用于读取数据 const read = (key) => { if (isLoon || isSurge) return $persistentStore.read(key); if (isQX) return $prefs.valueForKey(key); }; + + // 定义 write 方法,用于写入数据 const write = (key, value) => { if (isLoon || isSurge) return $persistentStore.write(key, value); if (isQX) return $prefs.setValueForKey(key, value); }; + + // 定义 notice 方法,用于发送通知 const notice = (title, subtitle, message, url) => { if (isLoon) $notification.post(title, subtitle, message, url); if (isSurge) $notification.post(title, subtitle, message, { url }); if (isQX) $notify(title, subtitle, message, { "open-url": url }); }; + + // 定义 get 方法,用于发送 GET 请求 const get = (url, callback) => { if (isLoon || isSurge) $httpClient.get(url, callback); if (isQX) {url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; + + // 定义 post 方法,用于发送 POST 请求 const post = (url, callback) => { if (isLoon || isSurge) $httpClient.post(url, callback); if (isQX) {url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; + + // 定义 put 方法,用于发送 PUT 请求 const put = (url, callback) => { if (isLoon || isSurge) $httpClient.put(url, callback) if (isQX) {url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; }; + + // 定义 toObj 方法,用于将字符串转为对象 const toObj = (str) => JSON.parse(str); + + // 定义 toStr 方法,用于将对象转为字符串 const toStr = (obj) => JSON.stringify(obj); + + // 定义 queryStr 方法,用于将对象转为可以请求的字符串 const queryStr = (obj) => { - const keyValuePairs = []; - for (const key in obj) { - if (obj.hasOwnProperty(key)) { - const value = obj[key]; - const encodedKey = encodeURIComponent(key); - const encodedValue = encodeURIComponent(value); - keyValuePairs.push(`${encodedKey}=${encodedValue}`); - } - } - return keyValuePairs.join('&'); + return Object.keys(obj) + .map(key => `${key}=${obj[key]}`) + .join('&'); }; + + // 定义 log 方法,用于输出日志 const log = (message) => console.log(message); + + // 定义 done 方法,用于结束任务 const done = (value = {}) => $done(value); + + // 返回包含所有方法的对象 return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; } From 6992ffb71fcbe8ee47b054cab119487a7ef86525 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:01:39 +0800 Subject: [PATCH 211/311] =?UTF-8?q?=E6=9B=B4=E6=96=B0[=E6=8E=8C=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E8=BD=A6]=E7=B3=BB=E5=88=97=E8=84=9A=E6=9C=AC=20(#468?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更新[掌飞寻宝]考虑弃坑 * 更新[掌飞签到]优化抓取并添加青龙相关接口 * 更新[掌飞购物]支持购买商城所有在售物品 --- zsfc/zsfc.js | 253 ++++++++++++++++++++++++++++++++---------- zsfc/zsfc.shop.js | 153 +++++++++++++++++++------ zsfc/zsfc.treasure.js | 2 +- 3 files changed, 313 insertions(+), 95 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 7cc82d9d4..7e2780c57 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -27,7 +27,6 @@ * 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true * */ - /** * 创建一个名为 $ 的环境变量实例,用于处理掌上飞车相关操作 */ @@ -36,58 +35,92 @@ const $ = new Env(`🏎️ 掌上飞车`) /** * 检查是否为请求阶段 */ -const isreq = typeof $request !== 'undefined'; +const isRequest = typeof $request !== 'undefined'; + +/** + * 构建请求的部分参数 + */ +const option = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + } +}; /** - * 主函数,用于执行打卡操作或设置请求数据 + * 主函数,用于执行签到操作或设置请求数据 */ (async () => { - if (isreq) { + if (isRequest) { /** * 以下获取签到数据 */ - // 设置触发脚本的间隔时间, 单位为秒 - const interval = 120; - // 不能触发 requests 脚本,程序终止 - if (Date.now() - $.read(`zsfc_timestamp`) <= interval * 1000) return; - - // 配置错误,弹窗警告并程序终止 - if (!$request.url || !$request.headers || !$request.body) { - $.notice($.name, '⭕ 无法读取数据', '无法读取掌上飞车请求数据,请检查配置是否正确'); - return; - } - // 提取请求数据 const cookie = $request.headers.cookie; const body = $request.body; - // 定义 params 数组 - const params = ['appid', 'iActivityId', 'g_tk', 'e_code', 'g_code', 'eas_url', 'eas_refer', 'sServiceDepartment', 'sServiceType']; - // 数组有空返回则程序终止 - if (params.find(param => !matchParam(body, param))) return; + // 提取请求体中的 iActivityId 和 iFlowId 作为检验使用 + $.iActivityId = matchParam(body, 'iActivityId'); + $.iFlowId = matchParam(body, 'iFlowId') - 1; - // 初始化 dataToWrite 词典,填充待写入内存的键值对 - const dataToWrite = { - 'zsfc_iActivityId': (matchParam(body, 'iActivityId')).toString(), - 'zsfc_iFlowId': (matchParam(body, 'iFlowId') - 1).toString(), + // 初始化 cookieToWrite 词典,填充待写入内存的键值对 + const cookieToWrite = { 'zsfc_accessToken': matchParam(cookie, 'accessToken'), - 'zsfc_openid': matchParam(cookie, 'openId'), - 'zsfc_timestamp': Date.now().toString(), - 'zsfc_time': new Date().toLocaleString().toString(), - 'zsfc_month': (new Date().getMonth() + 1).toString() + 'zsfc_openid': matchParam(cookie, 'openId') }; + // 将请求数据写入内存 - Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + Object.entries(cookieToWrite).forEach(([key, value]) => $.write(value, key)); - // 输出到日志只输出特定的键值对 - // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; - // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); - $.log(dataToWrite) + // 发起请求检验 iActivityId 和 iFlowId 是否为需要的值,如果返回的对象中不存在任何一个键值对则立即终止程序 + if (!Object.keys(await getSignInGifts()).length) return; - // 显示签到结果通知 - $.notice($.name, `✅ 获取签到数据成功(${dataToWrite.zsfc_iFlowId}/${dataToWrite.zsfc_iActivityId})`, `${interval}秒后请不要再点击本页面中的任何按钮,否则脚本会失效!`); + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_iActivityId': ($.iActivityId).toString(), + 'zsfc_iFlowId': ($.iFlowId).toString(), + 'zsfc_month': (new Date().getMonth() + 1).toString() + } + + // 如果所有键值都与内存中的值相同,则立即终止程序 + if (Object.keys(dataToWrite).every(key => dataToWrite[key] === $.read(key))) return; + + // 将请求数据写入内存,并输出到日志中 + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + $.log(dataToWrite) + // 显示获取结果通知 + $.notice($.name, `✅ 获取签到数据成功`, `流水ID:${$.iFlowId},活动ID:${$.iActivityId}`); + + // 检查并设置青龙相关变量 + if ($.read(`ql_url`) && $.read(`ql_client_id`) && $.read(`ql_client_secret`) && $.toObj($.read(`zsfc_upload_id`))) { + const qlUrlCache = $.read(`ql_url`); + $.qlUrl = qlUrlCache.charAt(qlUrlCache.length - 1) === '/' ? qlUrlCache.slice(0, -1) : qlUrlCache; + $.qlId = $.read(`ql_client_id`); + $.qlSecret = $.read(`ql_client_secret`); + $.qlToken = await qlToken(); + + const qlEnvsName = `ZSFC_iFlowdId`; + const qlEnvsValue = `${$.iFlowId}/${$.iActivityId}`; + const qlEnvsRemarks = `掌飞签到`; + + // 获取青龙面板令牌,若成功则执行后续操作 + if ($.qlToken) { + const qlEnvsNewBody = await qlEnvsSearch(qlEnvsName, qlEnvsValue, qlEnvsRemarks); + if (!qlEnvsNewBody) return; // 环境变量的值没有发生变化,不需要进行操作 + + // 检查并处理环境变量的返回值类型 + if (Array.isArray(qlEnvsNewBody)) { + // 暂时无法完成新增操作,后续再修改 + $.log(`⭕ 手动添加名为 ${qlEnvsName} 变量`); + } else { + await qlEnvsEdit(qlEnvsNewBody); + } + } else { + $.log("❌ 无法获取 token,请检查青龙相关配置"); + } + } } else { /** * 以下进行签到阶段,但是没有做 cookie 有效性验证 @@ -95,26 +128,13 @@ const isreq = typeof $request !== 'undefined'; // 检查用户本月是否打开过签到页面 const month = (new Date().getMonth() + 1).toString(); - if (!$.read(`zsfc_month`)) $.write(month, `zsfc_month`); if (month != $.read(`zsfc_month`)) { $.notice($.name, `❌ 本月未打开过掌上飞车APP`, `每月需打开一次掌上飞车APP并进到签到页面`); return; } - const option = { - url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, - headers: { - "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` - }, - body: $.queryStr({ - "iActivityId": $.read(`zsfc_iActivityId`), - "g_tk": "1842395457", - "sServiceType": "speed" - }) - }; - // 获取本月签到礼物列表 - const signInGifts = await getSignInGifts(option); + const signInGifts = await getSignInGifts(); // 进行每日签到 await dailyCheckin(option, signInGifts['每日签到']); @@ -148,7 +168,6 @@ const isreq = typeof $request !== 'undefined'; // 显示签到结果通知 if ($.message) $.notice($.name, $.subtitle, $.message, ``); - $.write(month, `zsfc_month`); } })() .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) @@ -158,7 +177,7 @@ const isreq = typeof $request !== 'undefined'; * @description 匹配 BODY 参数 * @param {string} body - BODY 字符串 * @param {string} key - 参数名 - * @returns {string} + * @returns {string} 返回匹配到的字符串或空值 */ function matchParam(input, key) { const separator = input.includes("&") ? "&" : ";"; @@ -171,10 +190,20 @@ function matchParam(input, key) { * @description 获取签到信息,并返回签到礼物列表 * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ -async function getSignInGifts(option) { - const options = option; - options.body += `&iFlowId=${$.read(`zsfc_iFlowId`)}`; - $.log(`🧑‍💻 开始获取本月礼物列表`); +async function getSignInGifts() { + const options = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + }, + body: $.queryStr({ + "iActivityId": isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": isRequest ? $.iFlowId : $.read(`zsfc_iFlowId`) + }) + }; + if (!isRequest) $.log(`🧑‍💻 开始获取本月礼物列表`) let giftsDictionary = {}; return new Promise(resolve => { $.post(options, (err, resp, data) => { @@ -187,7 +216,9 @@ async function getSignInGifts(option) { const flowName = match[3].replace(/累计签到|领取/g, ''); giftsDictionary[flowName] = flowId; } - $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`); + if (!isRequest) { + $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`); + } } else { $.log(`❌ 获取本月礼物列表时发生错误`); $.log($.toStr(err)); @@ -199,12 +230,17 @@ async function getSignInGifts(option) { /** * @description 每日签到函数 + * @param {object} option - 部分请求对象 * @param {string} iFlowId - 每日签到礼包的 iFlowId - * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ async function dailyCheckin(option, iFlowId) { const options = option; - options.body += `&iFlowId=${iFlowId}`; + options.body = $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": iFlowId + }); $.log(`🧑‍💻 开始进行每日签到`); return new Promise(resolve => { $.post(options, (err, resp, data) => { @@ -230,11 +266,17 @@ async function dailyCheckin(option, iFlowId) { /** * @description 获取累签天数的情况 + * @param {object} option - 部分请求对象 * @returns {Promise} 返回累签天数 */ async function getTotalSignInDays(option) { const options = option; - options.body += `&iFlowId=${$.read(`zsfc_iFlowId`) * 1 + 1}`; + options.body = $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": $.read(`zsfc_iFlowId`) * 1 + 1 + }); let totalSignInDays; $.log(`🧑‍💻 开始获取累签天数`); return new Promise(resolve => { @@ -256,6 +298,7 @@ async function getTotalSignInDays(option) { /** * @description 领取礼物函数 + * @param {object} option - 部分请求对象 * @param {string} giftId 礼物 ID * @param {string} giftName 礼物名称 */ @@ -287,6 +330,100 @@ async function claimGift(option, giftId, giftName) { }); } +/** + * @description 获取青龙面板令牌 + * @returns {Promise} 返回一个包含青龙面板令牌或布尔值的 Promise。 + */ +async function qlToken() { + let accessToken; // 更具体的变量名,表示访问令牌 + const options = { + url: `${$.qlUrl}/open/auth/token?client_id=${$.qlId}&client_secret=${$.qlSecret}` + }; + return new Promise(resolve => { + $.get(options, (err, resp, data) => { + if (data) { + const responseBody = $.toObj(data); + if (responseBody.code === 200) { + accessToken = responseBody.data.token; + } else { + accessToken = false; + } + } + resolve(accessToken); + }); + }); +} + +/** + * @description 搜索环境变量并生成新的请求体部分参数 + * @param {string} envsName - 新环境变量的名称 + * @param {string} envsValue - 新环境变量的具体值 + * @param {string} envsRemarks - 新环境变量的备注名 + * @returns {Promise} 返回一个请求体对象或列表或布尔值的 Promise。 + */ +async function qlEnvsSearch(envsName, envsValue, envsRemarks) { + let requestPayload; // 代表请求体的变量名更具体 + const options = { + url: `${$.qlUrl}/open/envs?searchValue=${envsName}`, + headers: { "Authorization": `Bearer ${$.qlToken}` } + }; + return new Promise(resolve => { + $.get(options, (err, resp, data) => { + if (data) { + const responseBody = $.toObj(data).data; + if (responseBody.length === 1) { + // 找到匹配的环境变量,生成单个请求体对象 + const matchingEnv = responseBody[0]; + if (matchingEnv.value === envsValue) { + requestPayload = false; + } else { + requestPayload = { + 'id': matchingEnv.id, + 'name': envsName, + 'value': envsValue, + 'remarks': envsRemarks + }; + } + } else { + // 未找到匹配的环境变量,生成包含一个对象的数组 + requestPayload = [{ + 'name': envsName, + 'value': envsValue, + 'remarks': envsRemarks + }]; + } + } + resolve(requestPayload); + }); + }); +} + +/** + * @description 编辑青龙面板的环境变量 + * @param {object} data - 请求参数 + */ +async function qlEnvsEdit(data) { + const options = { + url: `${$.qlUrl}/open/envs`, + headers: { "Authorization": `Bearer ${$.qlToken}` }, + body: data + }; + return new Promise(resolve => { + // 判断请求方法(post还是put) + const requestMethod = Array.isArray(data) ? $.post : $.put; + requestMethod(options, (err, resp, responseData) => { + if (responseData) { + let body = $.toObj(responseData); + // 根据返回的状态码处理结果 + if (body.code !== 200) { + $.log(`❌ 上传青龙面板失败`); + } + } + resolve(); // 完成Promise + }); + }); +} + /** * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 * @param {string} name - 环境名称 diff --git a/zsfc/zsfc.shop.js b/zsfc/zsfc.shop.js index 2a2ce4572..7a72c8a51 100644 --- a/zsfc/zsfc.shop.js +++ b/zsfc/zsfc.shop.js @@ -1,12 +1,10 @@ /** * * 使用方法:打开掌上飞车APP, 点击下方游戏栏,然后点击掌飞商城即可获取所需数据。 + * 注意事项:如需购买掌飞商店中的指定商品,请订阅boxjs链接,并在掌上飞车应用中填写在售商品的完整名称 * * boxjs订阅地址:https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json * - * 关于boxjs应用中的道具名称,只能填写以下道具中的其中一个,但我推荐购买改装道具,因为这样可以尽量用光点券 - * 雷诺、进气系统、燃料系统、点火系统、引擎系统、防护装置、普通粒子推进、普通阿尔法离合、重生宝珠LV1、效率宝珠LV1、效率宝珠LV2 - * * hostname: bang.qq.com * * type: http-request @@ -76,6 +74,7 @@ const isreq = typeof $request !== 'undefined'; // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); $.log(dataToWrite) + $.log(`token: ${dataToWrite.zsfc_token}`) // 发送通知 $.notice($.name, `✅ 获取商城数据成功!`, `请不要再次打开掌上飞车APP, 否则 Cookie 将失效!`); @@ -83,21 +82,15 @@ const isreq = typeof $request !== 'undefined'; } else { // 执行购物阶段 - // 定义商品信息(目前只支持买着下面的东西,因为我懒得爬取了) - const shopIdArray = { - "雷诺": {"itemId": "12720", "price_idx": {"180天": {"index": "0", "price": 12200}}}, // 雷诺不购买30天的,有点浪费点券和消费券 - "进气系统": {"itemId": "12377", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - "燃料系统": {"itemId": "12378", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - "点火系统": {"itemId": "12376", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - "引擎系统": {"itemId": "12380", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - "防护装置": {"itemId": "96597", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - - "普通粒子推进": {"itemId": "64025", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - "普通阿尔法离合": {"itemId": "65028", "price_idx": {"10个": {"index": "0", "price": 3500}, "5个": {"index": "1", "price": 2000}, "1个": {"index": "2", "price": 500}, "50个": {"index": "3", "price": 17500}}}, - - "重生宝珠LV1": {"itemId": "21983", "price_idx": {"3个": {"index": "0", "price": 2600}, "2个": {"index": "1", "price": 1800}, "1个": {"index": "2", "price": 990}, "4个": {"index": "3", "price": 3390}}}, - "效率宝珠LV1": {"itemId": "21977", "price_idx": {"3个": {"index": "0", "price": 2600}, "2个": {"index": "1", "price": 1800}, "1个": {"index": "2", "price": 990}, "4个": {"index": "3", "price": 3390}}}, - "效率宝珠LV2": {"itemId": "21978", "price_idx": {"3个": {"index": "0", "price": 13000}, "2个": {"index": "1", "price": 9000}, "1个": {"index": "2", "price": 4900}, "4个": {"index": "3", "price": 16990}}} + // 读取要购买的商品名称并生成商品列表 + shopName = $.read(`zsfc_bang_shopname`); + if (!shopName) shopName = autoGetGameItem(); + const shopIdArray = await searchShop(shopName); + + // 无法在掌上商城中搜索到相关商品时终止程序 + if (!Object.keys(shopIdArray).length) { + $.notice($.name, `❌ ${shopName} 未在商店中售卖`, `请在掌上商城中认真核对商品名称`); + return; } // 获取当前点券和消费券 @@ -117,36 +110,32 @@ const isreq = typeof $request !== 'undefined'; $.log(beforeLog); $.subtitle = beforeLog; - // 读取要购买的商品名称 - shopName = $.read(`zsfc_bang_shopname`); - if (!shopName) shopName = autoGetGameItem(); - // 获取购物包 - const [shopArray, totalCount] = getShopItems(shopName, shopIdArray[shopName], + const [shopArray, totalCount, unit] = getShopItems(shopName, shopIdArray[shopName], isLastDays(3) ? moneyBefore + couponsBefore : couponsBefore ); // 开始购物循环 if (shopArray.length) { - $.log(`✅ 共计可购买${totalCount}个${shopName}`); + $.log(`✅ 预计可购买${totalCount ? totalCount : ""}${unit}${shopName}`); let successBuyCounts = 0; let failedBuyCounts = 0; // 开始购物 - $.log(`✅ 开始购买${totalCount}个${shopName}`); for (let buyInfo of shopArray) { let { name, count, id, idx } = buyInfo; successBuyCounts += await purchaseItem(name, count, id, idx); } - failedBuyCounts = totalCount - successBuyCounts; + failedBuyCounts = totalCount - (successBuyCounts === 999 ? 1 : successBuyCounts); if (successBuyCounts > 0) { - $.message = `🎉 成功购买${successBuyCounts}个${shopName}`; + successBuyCounts === 999 ? successBuyCounts = "" : successBuyCounts; + $.message = `🎉 成功购买${successBuyCounts}${unit}${shopName}`; if (failedBuyCounts > 0) { - $.message += `(未成功购买${failedBuyCounts}个)`; + $.message += `(未成功购买${failedBuyCounts}${unit})`; } } else { - $.message = `❌ 全部购买失败,共计${totalCount}个`; + $.message = `❌ 全部购买失败,共计${totalCount ? totalCount : ""}${unit}`; } $.log($.message) @@ -184,6 +173,47 @@ function matchStr(input, key) { return match ? match[1] : ''; } +/** + * @description 处理输入对象,转换成输出对象 + * @param {Object} shopInfo - 输入对象 + * @returns {Object} 处理后的输出对象 + */ +function processInput(shopInfo) { + // 初始化一些变量 + let resultObject = {}; + let price_idx = {}; + let item = shopInfo.szItems[0]; + + // 准备工作:去除可能的逗号结尾 + if (item.ItemNum) { + item.ItemNum = item.ItemNum.slice(0, -1); + } else { + item.ItemAvailPeriod = item.ItemAvailPeriod.slice(0, -1); + } + + // 对每个项目数量或可用期限和价格执行逻辑 + let itemArray = (item.ItemNum ? item.ItemNum : item.ItemAvailPeriod).split(','); + + // 构建 price_idx 词典信息 + itemArray.forEach((value, index) => { + let key = item.ItemNum ? value : (value === "-1" ? "999" : (Number(value) / 24).toString()); + let itemPrice = shopInfo.szPrices[index].SuperMoneyPrice; + price_idx[key] = { + index: index.toString(), // 价格索引 + price: itemPrice + }; + }); + + // 构建最终结果对象,包括单位信息 + resultObject[shopInfo.szName] = { + price_idx: price_idx, + itemId: shopInfo.iId, + unit: item.ItemNum ? "个" : "天" // 根据 ItemNum 存在与否确定单位 + }; + + return resultObject; +} + /** * @description 检查今天是否是当月的最后几天 * @param {number} N - 要检查的倒数第N天 @@ -216,7 +246,7 @@ function isLastDays(N) { function autoGetGameItem() { // 定义游戏道具的列表,包括普通改装道具和进阶改装道具 const gameItems = [ - "进气系统", "燃料系统", "点火系统", "引擎系统", // 普通改装道具 + "进气系统+1", "燃料系统+1", "点火装置+1", "引擎装置+1", // 普通改装道具 // "普通粒子推进", "普通阿尔法离合" // 进阶改装道具,我不需要,注释掉了 ]; @@ -254,18 +284,25 @@ function getShopItems(name, item, money) { let shopArray = []; for (let i = 0; i < itemPrices.length; i++) { + // 商品数量索引 + let shopIdx = item.price_idx[itemCounts[i]].index; + + // 如果购买的商品可以购买永久且当前余额可以购买永久 + if (itemCounts[i] === 999 && money > itemPrices[i]) { + shopArray.push({"name": name, "count": "999", "id": item.itemId, "idx": shopIdx}); + item.unit = "永久" + break; + } + // 计算当前余额可以购买的最大道具数量 const maxItems = Math.floor(money / itemPrices[i]); // 这是一个计算出的整数,表示根据当前余额和道具价格,最多可以购买的道具数量。 totalCounts += maxItems * itemCounts[i]; // 这是一个累加的变量,用于跟踪购买的总道具数量。 money -= maxItems * itemPrices[i]; // 这是当前可用的余额。在每次购买道具后,余额会根据购买的道具数量和价格进行更新,以反映购买后的余额。 if (maxItems) { - // 获取当前道具的索引 - const index = item.price_idx[`${itemCounts[i]}天`] || item.price_idx[`${itemCounts[i]}个`]; - // 将可购买的道具添加到购物列表 for (let m = 0; m < maxItems; m++) { - shopArray.push({"name": name, "count": itemCounts[i].toString(), "id": item.itemId, "idx": index.index}); + shopArray.push({"name": name, "count": itemCounts[i].toString(), "id": item.itemId, "idx": shopIdx}); } } @@ -275,7 +312,51 @@ function getShopItems(name, item, money) { } } - return [shopArray, totalCounts ? totalCounts : 0]; + return [shopArray, totalCounts ? totalCounts : 0, item.unit]; +} + +/** + * @description 根据商品名称搜索商品信息 + * @param {string} shopName - 要搜索的商品名称 + * @returns {Promise} 包含商品信息的 Promise 对象 + */ +async function searchShop(shopName) { + // 初始化目标商品对象 + let targetShopObject = {}; + + // 获取 URL 中的查询参数 + const params = { + 'uin': $.read(`zsfc_uin`), + 'userId': $.read(`zsfc_userId`), + 'token': $.read(`zsfc_token`), + 'start': '0', + 'paytype': '1', // 按点券筛选 + 'order': '2', // 按点券筛选 + 'text': encodeURIComponent(shopName) + }; + + // 构建请求选项 + const options = { + url: `https://bang.qq.com/app/speed/mall/search?${$.queryStr(params)}`, + headers: { Referer: `https://bang.qq.com/app/speed/mall/main2` }, + }; + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 POST 请求,获取商品信息 + $.post(options, (err, resp, data) => { + if (data) { + const body = $.toObj(data); + const targetObject = body.data.find(item => item.szName === shopName); + if (targetObject) { + // 处理商品信息,将结果赋给目标商品对象 + targetShopObject = processInput(targetObject); + } + } + // 解析 Promise,将结果对象传递给 resolve 函数 + resolve(targetShopObject); + }); + }); } /** @@ -305,7 +386,7 @@ async function getPackInfo(argument) { }; // 输出日志,表示开始获取点券和消费券 - $.log(`🧑‍💻 开始获取${statu}点券和消费券`); + if (statu === "before") $.log(`🧑‍💻 开始获取${statu}点券和消费券`); // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index 58b23e6a0..fcc699f78 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -1,7 +1,7 @@ /** * * 使用方法:打开掌上飞车APP, 点击下方游戏栏,然后点击每日寻宝即可获取所需数据。 - * 注意事项:该脚本未做Cookie失效检测,引测如果运行错误请重新获取所需数据。 + * 注意事项:目前只能每天打开掌飞并进入寻宝页面进行寻宝,非常麻烦,准备弃坑~ * * hostname: bang.qq.com * From 4e564a745e4b80ea155e297be9e0a0bf482e774d Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Sun, 3 Dec 2023 21:12:47 +0800 Subject: [PATCH 212/311] =?UTF-8?q?=E7=AD=BE=E5=88=B0=E5=92=8C=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=84=9A=E6=9C=AC=E5=90=88=E5=B9=B6=EF=BC=8C=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E6=94=AF=E6=8C=81=E4=BB=BB=E4=BD=95=E5=9C=A8=E5=94=AE?= =?UTF-8?q?=E5=95=86=E5=93=81=EF=BC=8C=E9=9D=9E=E6=9C=88=E5=B0=BE=E5=8F=AF?= =?UTF-8?q?=E8=B6=85=E8=B4=AD=E9=81=93=E5=85=B7=EF=BC=88=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E6=96=B9=E5=BC=8F=E5=9C=A8boxjs=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=89=EF=BC=8C=E4=BC=98=E5=8C=96=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E6=96=B9=E5=BC=8F=20(#471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/README.md | 21 +- zsfc/zsfc.js | 689 +++++++++++++++++++++++++++++++++--------- zsfc/zsfc.shop.js | 543 --------------------------------- zsfc/zsfc.treasure.js | 203 +++++++++++-- 4 files changed, 732 insertions(+), 724 deletions(-) delete mode 100644 zsfc/zsfc.shop.js diff --git a/zsfc/README.md b/zsfc/README.md index 29bcfe088..cf91f7a4b 100644 --- a/zsfc/README.md +++ b/zsfc/README.md @@ -12,13 +12,10 @@ hostname = %APPEDN% comm.ams.game.qq.com, bang.qq.com [Script] -掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 -掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=5 +掌上飞车Cookie = type=http-request, pattern=^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*), requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 掌飞寻宝Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/treasure/index\?*, requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=60 - -掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 -掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 -掌飞寻宝 =type=cron, cronexp="0 0 11-16/1 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=30 +掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=60 +掌飞寻宝 =type=cron, cronexp="0 */11 17 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, script-update-interval=0, timeout=60 ``` ## 配置 (Loon) @@ -27,13 +24,11 @@ hostname = %APPEDN% comm.ams.game.qq.com, bang.qq.com hostname = comm.ams.game.qq.com, bang.qq.com [Script] -http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie -http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=10, tag=掌飞购物Cookie +http-request ^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie http-request ^https?://bang\.qq\.com/app/speed/treasure/index\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, requires-body=true, timeout=60, tag=掌飞寻宝Cookie cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 -cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 -cron "0 0 11-16/1 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝 +cron "0 */11 17 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝 ``` ## 配置 (QuanX) @@ -42,14 +37,12 @@ cron "0 0 11-16/1 * * *" script-path=https://raw.githubusercontent.com/chavyleun hostname = comm.ams.game.qq.com, bang.qq.com [rewrite_local] -^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js -^https?://bang\.qq\.com/app/speed/mall/main2\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js +^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*) url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js ^https?://bang\.qq\.com/app/speed/treasure/index\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js [task_local] 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true -0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true -0 0 11-16/1 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝, enabled=true +0 */11 17 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.treasure.js, tag=掌飞寻宝, enabled=true ``` ## 说明 diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 7e2780c57..01663b737 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -1,12 +1,15 @@ /** * - * 使用方法:打开掌上飞车APP, 点击咨询栏的签到(每日福利)即可,无需点击签到,否则脚本无法正确运行。 - * 注意事项:每月需手动打开一次掌上飞车APP并进入签到页面,以重新抓包更新礼包数据,为此需要每日运行两次脚本 + * 使用方法:打开掌上飞车APP, 点击咨询栏的签到(每日福利)即可,无需点击签到,然后点击下方游戏栏,最后点击掌飞商城即可获取所需商城数据。 + * 注意事项:1、每月需手动打开一次掌上飞车APP并进入签到页面,以重新抓包更新礼包数据,为此需要每日运行两次脚本;2、如果账号信息没有发生根本性变化的话,抓取 Cookie 等信息的脚本就不会被执行;3、如需购买掌飞商店中的指定商品,请订阅boxjs链接,并在掌上飞车应用中填写在售商品的完整名称 * + * boxjs订阅地址:https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json + * + * * hostname: comm.ams.game.qq.com * * type: http-request - * regex: ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* + * regex: ^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*) * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * requests-body: 1 * @@ -15,132 +18,159 @@ * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * * =============== Surge =============== - * 掌上飞车Cookie = type=http-request, pattern=^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr*, requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 - * 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车Cookie = type=http-request, pattern=^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*), requires-body=true, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=5 + * 掌上飞车 =type=cron, cronexp="0 10 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, script-update-interval=0, timeout=60 * * =============== Loon =============== - * http-request ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=10, tag=掌上飞车Cookie + * http-request ^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*) script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, requires-body=true, timeout=60, tag=掌上飞车Cookie * cron "0 10 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车 * * =============== Quan X =============== - * ^https?://comm\.ams\.game\.qq\.com/ams/ame/amesvr* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js + * ^https?://(comm\.ams\.game\.qq\.com/ams/ame/amesvr*|bang\.qq\.com/app/speed/mall/main2\?*) url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js * 0 10 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.js, tag=掌上飞车, enabled=true * */ + /** * 创建一个名为 $ 的环境变量实例,用于处理掌上飞车相关操作 */ -const $ = new Env(`🏎️ 掌上飞车`) +const $ = new Env() /** * 检查是否为请求阶段 */ const isRequest = typeof $request !== 'undefined'; -/** - * 构建请求的部分参数 - */ -const option = { - url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, - headers: { - "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` - } -}; - /** * 主函数,用于执行签到操作或设置请求数据 */ (async () => { if (isRequest) { - /** - * 以下获取签到数据 - */ - // 提取请求数据 - const cookie = $request.headers.cookie; - const body = $request.body; + if ($request.url.includes(`amesvr`)) { + /** + * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 以下获取签到数据 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ + */ - // 提取请求体中的 iActivityId 和 iFlowId 作为检验使用 - $.iActivityId = matchParam(body, 'iActivityId'); - $.iFlowId = matchParam(body, 'iFlowId') - 1; + // 提取请求数据 + const cookie = $request.headers.cookie; + const body = $request.body; - // 初始化 cookieToWrite 词典,填充待写入内存的键值对 - const cookieToWrite = { - 'zsfc_accessToken': matchParam(cookie, 'accessToken'), - 'zsfc_openid': matchParam(cookie, 'openId') - }; + // 提取请求体中的 iActivityId 和 iFlowId 作为检验使用 + $.iActivityId = matchParam(body, 'iActivityId'); + $.iFlowId = matchParam(body, 'iFlowId') - 1; - // 将请求数据写入内存 - Object.entries(cookieToWrite).forEach(([key, value]) => $.write(value, key)); + // 初始化 cookieToWrite 词典,填充待写入内存的键值对 + const cookieToWrite = { + 'zsfc_accessToken': matchParam(cookie, 'accessToken'), + 'zsfc_openid': matchParam(cookie, 'openId') + }; - // 发起请求检验 iActivityId 和 iFlowId 是否为需要的值,如果返回的对象中不存在任何一个键值对则立即终止程序 - if (!Object.keys(await getSignInGifts()).length) return; + // 将请求数据写入内存 + Object.entries(cookieToWrite).forEach(([key, value]) => $.write(value, key)); - // 初始化 dataToWrite 词典,填充待写入内存的键值对 - const dataToWrite = { - 'zsfc_iActivityId': ($.iActivityId).toString(), - 'zsfc_iFlowId': ($.iFlowId).toString(), - 'zsfc_month': (new Date().getMonth() + 1).toString() - } + // 发起请求检验 iActivityId 和 iFlowId 是否为需要的值 + if (!Object.keys(await getSignInGifts()).length || !(await getTotalSignInDays())) return; - // 如果所有键值都与内存中的值相同,则立即终止程序 - if (Object.keys(dataToWrite).every(key => dataToWrite[key] === $.read(key))) return; - - // 将请求数据写入内存,并输出到日志中 - Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); - $.log(dataToWrite) - - // 显示获取结果通知 - $.notice($.name, `✅ 获取签到数据成功`, `流水ID:${$.iFlowId},活动ID:${$.iActivityId}`); - - // 检查并设置青龙相关变量 - if ($.read(`ql_url`) && $.read(`ql_client_id`) && $.read(`ql_client_secret`) && $.toObj($.read(`zsfc_upload_id`))) { - const qlUrlCache = $.read(`ql_url`); - $.qlUrl = qlUrlCache.charAt(qlUrlCache.length - 1) === '/' ? qlUrlCache.slice(0, -1) : qlUrlCache; - $.qlId = $.read(`ql_client_id`); - $.qlSecret = $.read(`ql_client_secret`); - $.qlToken = await qlToken(); - - const qlEnvsName = `ZSFC_iFlowdId`; - const qlEnvsValue = `${$.iFlowId}/${$.iActivityId}`; - const qlEnvsRemarks = `掌飞签到`; - - // 获取青龙面板令牌,若成功则执行后续操作 - if ($.qlToken) { - const qlEnvsNewBody = await qlEnvsSearch(qlEnvsName, qlEnvsValue, qlEnvsRemarks); - if (!qlEnvsNewBody) return; // 环境变量的值没有发生变化,不需要进行操作 - - // 检查并处理环境变量的返回值类型 - if (Array.isArray(qlEnvsNewBody)) { - // 暂时无法完成新增操作,后续再修改 - $.log(`⭕ 手动添加名为 ${qlEnvsName} 变量`); + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_iActivityId': ($.iActivityId).toString(), + 'zsfc_iFlowId': ($.iFlowId).toString(), + 'zsfc_month': (new Date().getMonth() + 1).toString() + } + + // 如果所有键值都与内存中的值相同,则立即终止程序 + if (Object.keys(dataToWrite).every(key => dataToWrite[key] === $.read(key))) return; + + // 将请求数据写入内存,并输出到日志中 + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + $.log(dataToWrite) + + // 显示获取结果通知 + $.notice(`🏎️ 掌上飞车`, `✅ 获取签到数据成功!`, `流水ID:${$.iFlowId},活动ID:${$.iActivityId}`); + + // 检查并设置青龙相关变量 + if ($.read(`ql_url`) && $.read(`ql_client_id`) && $.read(`ql_client_secret`) && $.toObj($.read(`zsfc_upload_id`))) { + const qlUrlCache = $.read(`ql_url`); + $.qlUrl = qlUrlCache.charAt(qlUrlCache.length - 1) === '/' ? qlUrlCache.slice(0, -1) : qlUrlCache; + $.qlId = $.read(`ql_client_id`); + $.qlSecret = $.read(`ql_client_secret`); + $.qlToken = await qlToken(); + + const qlEnvsName = `ZSFC_iFlowdId`; + const qlEnvsValue = `${$.iFlowId}/${$.iActivityId}`; + const qlEnvsRemarks = `掌飞签到`; + + // 获取青龙面板令牌,若成功则执行后续操作 + if ($.qlToken) { + const qlEnvsNewBody = await qlEnvsSearch(qlEnvsName, qlEnvsValue, qlEnvsRemarks); + if (!qlEnvsNewBody) return; // 环境变量的值没有发生变化,不需要进行操作 + + // 检查并处理环境变量的返回值类型 + if (Array.isArray(qlEnvsNewBody)) { + // 暂时无法完成新增操作,后续再修改 + $.log(`⭕ 手动添加名为 ${qlEnvsName} 变量`); + } else { + await qlEnvsEdit(qlEnvsNewBody); + } } else { - await qlEnvsEdit(qlEnvsNewBody); + $.log("❌ 无法获取 token,请检查青龙相关配置"); } - } else { - $.log("❌ 无法获取 token,请检查青龙相关配置"); } + } else { + /** + * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 以下获取商城数据 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ + */ + + // 提取请求的URL并去除引号 + const url = $.toStr($request.url).replace(/^"|"$/g, ''); + const cookie = $request.headers.cookie; + + // 对比 token 是否发生变化 + if ($.read(`zsfc_token`) == matchParam(url, "token")) return; + + // 初始化 dataToWrite 词典,填充待写入内存的键值对 + const dataToWrite = { + 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞商城无法抓取,只能读取签到页面的脚本获取情况 + "zsfc_accessToken": matchParam(url, "accessToken"), + "zsfc_openid": matchParam(cookie, "openid"), + "zsfc_token": matchParam(url, "token"), + "zsfc_roleId": matchParam(url, "roleId"), + "zsfc_userId": matchParam(url, "userId"), + "zsfc_areaId": matchParam(url, "areaId"), + 'zsfc_uin': matchParam(url, "uin"), + }; + + // 将请求数据写入内存 + Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); + + // 输出到日志只输出特定的键值对 + // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; + // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); + $.log(dataToWrite) + + // 发送通知 + $.notice(`🏎️ 掌飞购物`, `✅ 获取商城数据成功!`, `请不要再次打开掌上飞车APP, 否则商城 Cookie 将失效!`); + } + } else { /** - * 以下进行签到阶段,但是没有做 cookie 有效性验证 + * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 以下进行签到阶段 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */ // 检查用户本月是否打开过签到页面 const month = (new Date().getMonth() + 1).toString(); - if (month != $.read(`zsfc_month`)) { - $.notice($.name, `❌ 本月未打开过掌上飞车APP`, `每月需打开一次掌上飞车APP并进到签到页面`); - return; - } + if (month != $.read(`zsfc_month`)) return $.notice(`🏎️ 掌上飞车`, `❌ 本月未打开过掌上飞车APP`, `每月需打开一次掌上飞车APP并进到签到页面`); // 获取本月签到礼物列表 const signInGifts = await getSignInGifts(); // 进行每日签到 - await dailyCheckin(option, signInGifts['每日签到']); + await dailyCheckin(signInGifts['每日签到']); - // 获取本月累签天数 - const totalSignInDay = await getTotalSignInDays(option); + // // 获取本月累签天数 + const totalSignInDay = await getTotalSignInDays(); // 初始化 signInInfoArray 数组 let signInInfoArray = []; @@ -163,21 +193,98 @@ const option = { // 遍历礼包数组,领取奖励 for (let signInInfo of signInInfoArray) { let { code, title } = signInInfo; - await claimGift(option, code, title); + await claimGift(code, title); } // 显示签到结果通知 - if ($.message) $.notice($.name, $.subtitle, $.message, ``); + if ($.checkInMsg) $.notice(`🏎️ 掌上飞车`, $.subtitle, $.checkInMsg, ``); + + + /** + * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 以下进行购物阶段 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ + */ + + // 读取到设置不进行购物 + if (!$.toObj($.read(`zsfc_shop`))) return $.log(`⭕ 设置为不执行购物`); + + // 读取到没有获取过商城数据 + if (!$.read(`zsfc_token`)) return $.notice(`🏎️ 掌飞购物`, `❌ 请先获取商城数据`, `打开掌上飞车,点击游戏并进入掌上商城`); + + // 获取当前点券和消费券 + const packBefore = await getPackInfo(`before`); + + // Cookie 已过期,程序终止 + if (!packBefore) return $.log(`❌ Cookie 已过期,请重新获取`), $.notice(`🏎️ 掌飞购物`, `❌ Cookie 已过期`, `打开掌上飞车,点击游戏并进入掌上商城`); + + // 读取要购买的商品名称并生成商品列表 + const shopName = $.read(`zsfc_bang_shopname`) || autoGetGameItem(); + const shopIdArray = await searchShop(shopName); + + // 无法在掌上商城中搜索到相关商品时终止程序 + if (!Object.keys(shopIdArray).length) return $.notice(`🏎️ 掌飞购物`, `❌ ${shopName} 未在商店中售卖`, `请在掌上商城中认真核对商品名称`); + + // 获取当前余额 + const beforeLog = `✅ 当前共有${packBefore.money}点券,${packBefore.coupons}消费券`; + $.log(beforeLog); + $.subtitle = beforeLog; + + // 获取购物包 + const [shopArray, totalCount, unit] = getShopItems(shopIdArray, packBefore); + + // 开始购物循环 + if (shopArray.length) { + let successBuyCounts = 0; + let failedBuyCounts = 0; + + const estimatedBydCounts = totalCount === 999 ? "1个" : totalCount; + const caption = totalCount === 999 ? "永久" : unit; + + $.log(`✅ 预计可购买${estimatedBydCounts}${caption}${shopName}`); + + // 开始购物 + for (let buyInfo of shopArray) { + let { count, id, idx } = buyInfo; + successBuyCounts += await purchaseItem(shopName, count, id, idx); + } + + if (successBuyCounts > 0) { + // 购买永久道具后为避免重复购买自动禁用购买脚本并重置道具名称 + if (totalCount === 999) $.write(`false`, `zsfc_shop`), $.write(``, `zsfc_bang_shopname`); + + $.shopMsg = `🎉 成功购买${estimatedBydCounts}${caption}${shopName}`; + failedBuyCounts = estimatedBydCounts - successBuyCounts; + if (failedBuyCounts > 0) { + $.shopMsg += `(未成功购买${failedBuyCounts}${caption})`; + } + } else { + $.shopMsg = `❌ 全部购买失败,共计${estimatedBydCounts}${caption}${shopName}`; + } + $.log($.shopMsg) + + // 获取剩余余额 + const packAfter = await getPackInfo(`after`); + const afterLog = `✅ 现在剩余${packAfter.money}点券,${packAfter.coupons}消费券`; + $.log(afterLog); + $.subtitle = afterLog; + + } else { + $.log(`⭕ 余额不足以购买${shopName}`); + } + + // 显示购物结果通知 + if ($.shopMsg) $.notice(`🏎️ 掌飞购物`, $.subtitle, $.shopMsg, ``); + } })() - .catch((e) => $.notice($.name, '❌ 未知错误无法打卡', e, '')) + .catch((e) => $.notice(`🏎️ 掌上飞车`, '❌ 未知错误无法执行', e, '')) .finally(() => $.done()); /** - * @description 匹配 BODY 参数 - * @param {string} body - BODY 字符串 - * @param {string} key - 参数名 - * @returns {string} 返回匹配到的字符串或空值 + * 从输入字符串中提取指定关键字的值。 + * + * @param {string} input - 输入字符串,要从中提取关键字的值。 + * @param {string} key - 要提取的关键字。 + * @returns {string} - 返回匹配到的关键字值,如果没有匹配到则返回空字符串。 */ function matchParam(input, key) { const separator = input.includes("&") ? "&" : ";"; @@ -187,10 +294,112 @@ function matchParam(input, key) { } /** - * @description 获取签到信息,并返回签到礼物列表 + * @description 掌飞购物相关函数,获取当前月份对应的游戏道具。 + * @returns {string} 返回当前月份对应的游戏道具名称。 + */ +function autoGetGameItem() { + // 定义游戏道具的列表,包括普通改装道具和进阶改装道具 + const gameItems = [ + "进气系统+1", "燃料系统+1", "点火装置+1", "引擎装置+1", // 普通改装道具 + // "普通粒子推进", "普通阿尔法离合" // 进阶改装道具,我不需要,注释掉了 + ]; + + // 计算当前月份对应的游戏道具的索引 + const index = new Date().getMonth() % gameItems.length; + + // 返回当前月份对应的游戏道具名称 + return gameItems[index]; +} + +/** + * @description 掌飞购物相关函数,获取商店物品信息。 + * @param {object} shopInfo - 商店信息对象 + * @param {object} overage - 用户余额对象 + * @returns {[array, number, str]} - 返回购买的物品数组、总数和单位信息的数组 + */ +function getShopItems(shopInfo, overage) { + // 获取今天的日期和本月剩余天数是否小于等于3天 + const today = new Date(); + const day = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate(); + const lastDay = (day - today.getDate()) <= 3; + + // 创建一个包含商店信息和物品数据的对象 + const info = {"Id": shopInfo.iId, "data": []}; + + // 判断商店类型并获取相应的物品数值 + const shopType = shopInfo.szItems[0].ItemNum !== ""; + const values = shopType ? shopInfo.szItems[0].ItemNum : shopInfo.szItems[0].ItemAvailPeriod; + + // 将物品数值转换成数组 + const numArray = values.split(',').filter(item => item !== '').map((item) => { + if (item === "-1") return 999; + return shopType ? parseInt(item) : parseInt(item) / 24; + }); + + // 根据价格排序物品数据 + const sortedData = shopInfo.szPrices.map((price, index) => ({ + price: parseInt(price.SuperMoneyPrice), count: numArray[index], idx: index + })).sort((a, b) => b.count - a.count); + + // 将排序后的数据存入 info 对象 + sortedData.forEach(({ price, count, idx }) => { + info.data.push({ count, price, idx }); + }); + + // 初始化总数、物品数组和剩余金钱 + let totalCount = 0; + let items = []; + let remMoney = lastDay ? overage.money + overage.coupons : overage.coupons; + + const data = info.data; + const amount = data.length - 1; + + for (let m = 0; m < data.length; m++) { + let itemIndex = data[m].idx; + + // 判断是否购买永久物品 + if (data[m].count === 999 && remMoney > data[m].price) { + items.push({"count": 999, "id": info.Id, "idx": itemIndex}); + totalCount = data[m].count; + info.unit = "永久"; + break; + } + + // 计算最大可购买的物品数量并更新总数和剩余金钱 + const maxPurchasableItems = Math.floor(remMoney / data[m].price); // 这是一个计算出的整数,表示根据当前余额和道具价格,最多可以购买的道具数量。 + totalCount += maxPurchasableItems * data[m].count; // 这是一个累加的变量,用于跟踪购买的总道具数量。 + remMoney -= maxPurchasableItems * data[m].price; // 这是当前可用的余额。在每次购买道具后,余额会根据购买的道具数量和价格进行更新,以反映购买后的余额。 + + // 将购买的物品加入数组 + for (let n = 0; n < maxPurchasableItems; n++) { + items.push({"count": data[m].count, "id": info.Id, "idx": itemIndex}); + } + + // 非月尾判断是否可以购买最后一个物品 + if (remMoney < data[amount].price && !lastDay) { + const meetsThreshold = remMoney > data[amount].price / Number($.read(`zsfc_shop_threshold`)); + const canAffordLastItem = remMoney + overage.money >= data[amount].price; + + if (meetsThreshold && canAffordLastItem) { + items.push({"count": data[amount].count, "id": info.Id, "idx": data[amount].idx}); + totalCount += data[amount].count; + } + break; + } + } + + return [items, totalCount, shopType ? "个" : "天"]; +} + +/** + * @description 掌飞签到相关函数,获取签到信息,并返回签到礼物列表 * @returns {Promise} 返回一个包含本月礼物的数组的 Promise。 */ async function getSignInGifts() { + // 初始化礼包词典 + let giftsDictionary = {}; + + // 构建请求体 const options = { url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`)}`, headers: { @@ -203,19 +412,21 @@ async function getSignInGifts() { "iFlowId": isRequest ? $.iFlowId : $.read(`zsfc_iFlowId`) }) }; - if (!isRequest) $.log(`🧑‍💻 开始获取本月礼物列表`) - let giftsDictionary = {}; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 POST 请求,获取本月所有礼包情况 $.post(options, (err, resp, data) => { if (data) { const body = $.toObj(data); const flowRegex = /#(\d+)#:{#flow_id#:(\d+),#flow_name#:#([^#]+)#/g; - let match; + while ((match = flowRegex.exec($.toStr(body))) !== null) { const flowId = match[2]; const flowName = match[3].replace(/累计签到|领取/g, ''); giftsDictionary[flowName] = flowId; } + if (!isRequest) { $.log(`✅ 本月共有 ${Object.keys(giftsDictionary).length} 个礼包`); } @@ -229,31 +440,39 @@ async function getSignInGifts() { } /** - * @description 每日签到函数 - * @param {object} option - 部分请求对象 + * @description 掌飞签到相关函数,每日签到函数 * @param {string} iFlowId - 每日签到礼包的 iFlowId */ -async function dailyCheckin(option, iFlowId) { - const options = option; - options.body = $.queryStr({ - "iActivityId": $.read(`zsfc_iActivityId`), - "g_tk": "1842395457", - "sServiceType": "speed", - "iFlowId": iFlowId - }); - $.log(`🧑‍💻 开始进行每日签到`); +async function dailyCheckin(iFlowId) { + // 构建请求体 + const options = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + }, + body: $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": iFlowId + }) + }; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 POST 请求,获取今日签到结果 $.post(options, (err, resp, data) => { if (data) { - let body = $.toObj(data.replace(/\r|\n/ig, ``)); + const body = $.toObj(data.replace(/\r|\n/ig, ``)); + if (body.msg.includes(`已经`)) { const sMsg = body.flowRet.sMsg; $.log(`⭕ 领取结果: ${sMsg}`); - // $.message = `签到结果: ${sMsg}` + // $.checkInMsg = `签到结果: ${sMsg}` } else { const sPackageName = body.modRet.sPackageName; $.log(`✅ 领取结果: 获得${sPackageName}`); - $.message = `恭喜获得:${sPackageName}`; + $.checkInMsg = `恭喜获得:${sPackageName}`; } } else { $.log(`❌ 进行每日签到时发生错误`); @@ -265,60 +484,88 @@ async function dailyCheckin(option, iFlowId) { } /** - * @description 获取累签天数的情况 - * @param {object} option - 部分请求对象 + * @description 掌飞签到相关函数,获取累签天数的情况 * @returns {Promise} 返回累签天数 */ -async function getTotalSignInDays(option) { - const options = option; - options.body = $.queryStr({ - "iActivityId": $.read(`zsfc_iActivityId`), - "g_tk": "1842395457", - "sServiceType": "speed", - "iFlowId": $.read(`zsfc_iFlowId`) * 1 + 1 - }); +async function getTotalSignInDays() { + // 初始化总签到天数 let totalSignInDays; - $.log(`🧑‍💻 开始获取累签天数`); + + // 根据请求方式获取 iFlowId 具体值 + let iFlowId = Number(isRequest ? $.iFlowId : $.read(`zsfc_iFlowId`)); + + // 构建请求体 + const options = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + }, + body: $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": iFlowId + 1 + }) + }; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 POST 请求,获取累签天数 $.post(options, (err, resp, data) => { if (data) { - totalSignInDays = $.toObj(data).modRet.sOutValue1.split(":")[1]; - const missedDays = new Date().getDate() - totalSignInDays; - const missedDaysText = missedDays !== 0 ? `(漏签 ${missedDays} 天)` : ``; - $.subtitle = `✅ 累计签到 ${totalSignInDays} 天${missedDaysText}`; - $.log($.subtitle); + try { + totalSignInDays = $.toObj(data).modRet.sOutValue1.split(":")[1]; + const missedDays = new Date().getDate() - totalSignInDays; + const missedDaysText = missedDays !== 0 ? `(漏签 ${missedDays} 天)` : ``; + + $.subtitle = `✅ 累计签到 ${totalSignInDays} 天${missedDaysText}`; + $.log($.subtitle); + } catch {} } else { $.log(`❌ 获取累签天数时发生错误`); $.log($.toStr(err)); } - resolve(totalSignInDays); + resolve(!isNaN(totalSignInDays) ? totalSignInDays : false); }); }); } /** - * @description 领取礼物函数 - * @param {object} option - 部分请求对象 + * @description 掌飞签到相关函数,领取礼物函数 * @param {string} giftId 礼物 ID * @param {string} giftName 礼物名称 */ -async function claimGift(option, giftId, giftName) { - const options = option; - options.body += `&iFlowId=${giftId}`; +async function claimGift(giftId, giftName) { + // 构建请求体 + const options = { + url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${$.read(`zsfc_iActivityId`)}`, + headers: { + "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` + }, + body: $.queryStr({ + "iActivityId": $.read(`zsfc_iActivityId`), + "g_tk": "1842395457", + "sServiceType": "speed", + "iFlowId": giftId + }) + }; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 POST 请求,获取领取结果 $.post(options, (err, resp, data) => { if (data) { let body = $.toObj(data.replace(/\r|\n/ig, ``)); if (body.msg.includes(`已经`)) { $.log(`⭕ 领取结果: 已经领取`); - // $.message += `, ${giftName}`; + // $.checkInMsg += `, ${giftName}`; } else { const sPackageName = body.modRet.sPackageName; $.log(`✅ 领取结果: 获得${sPackageName}`); - if ($.message) { - $.message += `,${sPackageName}`; + if ($.checkInMsg) { + $.checkInMsg += `,${sPackageName}`; } else { - $.message = `领取结果: 获得${sPackageName}` + $.checkInMsg = `领取结果: 获得${sPackageName}` } } } else { @@ -330,20 +577,177 @@ async function claimGift(option, giftId, giftName) { }); } +/** + * @description 掌飞购物相关函数,根据商品名称搜索商品信息 + * @param {string} shopName - 要搜索的商品名称 + * @returns {Promise} 包含商品信息的 Promise 对象 + */ +async function searchShop(shopName) { + // 初始化目标商品对象 + let targetShopObject = {}; + + // 获取 URL 中的查询参数 + const params = { + 'uin': $.read(`zsfc_uin`), + 'userId': $.read(`zsfc_userId`), + 'token': $.read(`zsfc_token`), + 'start': '0', + 'paytype': '1', // 按点券筛选 + 'order': '2', // 按点券筛选 + 'text': encodeURIComponent(shopName) + }; + + // 构建请求体 + const options = { + url: `https://bang.qq.com/app/speed/mall/search?${$.queryStr(params)}`, + headers: { Referer: `https://bang.qq.com/app/speed/mall/main2` }, + }; + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 POST 请求,获取商品信息 + $.post(options, (err, resp, data) => { + if (data) { + const body = $.toObj(data); + targetShopObject = body.data.find(item => item.szName === shopName); + } + // 解析 Promise,将结果对象传递给 resolve 函数 + resolve(targetShopObject); + }); + }); +} + +/** + * @description 掌飞购物相关函数,获取点券和消费券信息 + * @param {string} argument - 余额状态,可选值为 "before" 或 "after" + * @returns {Promise} - 包含点券和消费券数量的对象,或者在获取失败时返回 false + */ +async function getPackInfo(argument) { + // 创建一个空对象,用于存储点券和消费券信息 + let result = {}; + + // 根据参数值设置状态文本 + const statu = (argument === "before") ? "当前" : "剩余"; + + // 获取 URL 中的查询参数 + const params = { + 'areaId': $.read(`zsfc_areaId`), + 'accessToken': $.read(`zsfc_accessToken`), + 'token': $.read(`zsfc_token`), + 'uin': $.read(`zsfc_uin`), + 'userId': $.read(`zsfc_userId`), + }; + + // 构建请求体 + const options = { + url: `https://bang.qq.com/app/speed/mall/main2?${$.queryStr(params)}` + }; + + // 输出日志,表示开始获取点券和消费券 + if (statu === "before") $.log(`🧑‍💻 开始获取${statu}点券和消费券`); + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 GET 请求,获取点券和消费券信息 + $.get(options, (err, resp, data) => { + if (data) { + // 将响应数据转换为字符串 + const body = data.toString(); + + // 使用正则表达式匹配点券和消费券数量 + money = body.match(/(\d+)<\/b>/)[1]; + coupons = body.match(/(\d+)<\/b>/)[1]; + + // 将点券和消费券数量存储在结果对象中 + result.money = Number(money); + result.coupons = Number(coupons); + } else { + // 如果获取失败,将结果对象设置为 false + result = false; + } + + // 解析 Promise,将结果对象传递给 resolve 函数 + resolve(result); + }); + }); +} + +/** + * @description 掌飞购物相关函数,购买道具 + * @param {string} name - 道具名称 + * @param {number} count - 购买数量 + * @param {string} id - 道具的唯一标识符 + * @param {string} idx - 道具的价格索引 + * @returns {Promise} - 返回成功购买的道具数量 + */ +async function purchaseItem(name, count, id, idx) { + // 构建请求体 + const options = { + url: `https://bang.qq.com/app/speed/mall/getPurchase`, + headers: { + "Referer": `https://bang.qq.com/app/speed/mall/detail2` + }, + body: $.queryStr({ + 'areaId': $.read(`zsfc_areaId`), + 'token': $.read(`zsfc_token`), + 'userId': $.read(`zsfc_userId`), + 'uin': $.read(`zsfc_uin`), + 'pay_type': "1", + 'commodity_id': id, + 'price_idx': idx + }) + }; + + // 返回一个 Promise 对象,用于异步操作 + return new Promise(resolve => { + // 发送 POST 请求,购买道具 + $.post(options, (err, resp, data) => { + if (data) { + // 将响应数据转换为对象 + const body = $.toObj(data); + + // 提取响应中的消息 + const msg = body.msg; + + // 检查响应结果,如果购买失败,输出错误消息 + if (body.res == -1) { + $.log(`❌ ${msg}`); + } else { + // 如果购买成功,将成功购买的道具数量设置为购买数量 + totalCount = count; + } + } else { + // 如果发生错误,输出错误消息和错误信息 + $.log(`❌ 购买${name}时发生错误`); + $.log($.toStr(err)); + } + + // 解析 Promise,将成功购买的道具数量传递给 resolve 函数 + resolve(totalCount ? totalCount : 0); + }); + }); +} + /** * @description 获取青龙面板令牌 * @returns {Promise} 返回一个包含青龙面板令牌或布尔值的 Promise。 */ async function qlToken() { - let accessToken; // 更具体的变量名,表示访问令牌 + // 初始化访问令牌 + let accessToken; + + // 构建请求体 const options = { url: `${$.qlUrl}/open/auth/token?client_id=${$.qlId}&client_secret=${$.qlSecret}` }; + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 GET 请求,获取token令牌 $.get(options, (err, resp, data) => { if (data) { const responseBody = $.toObj(data); if (responseBody.code === 200) { + // 获取成功 accessToken = responseBody.data.token; } else { accessToken = false; @@ -362,12 +766,18 @@ async function qlToken() { * @returns {Promise} 返回一个请求体对象或列表或布尔值的 Promise。 */ async function qlEnvsSearch(envsName, envsValue, envsRemarks) { - let requestPayload; // 代表请求体的变量名更具体 + // 初始化请求体的变量名 + let requestPayload; + + // 构建请求体 const options = { url: `${$.qlUrl}/open/envs?searchValue=${envsName}`, headers: { "Authorization": `Bearer ${$.qlToken}` } }; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { + // 发送 GET 请求,搜索指定变量 $.get(options, (err, resp, data) => { if (data) { const responseBody = $.toObj(data).data; @@ -403,11 +813,14 @@ async function qlEnvsSearch(envsName, envsValue, envsRemarks) { * @param {object} data - 请求参数 */ async function qlEnvsEdit(data) { + // 构建请求体 const options = { url: `${$.qlUrl}/open/envs`, headers: { "Authorization": `Bearer ${$.qlToken}` }, body: data }; + + // 返回一个 Promise 对象,用于异步操作 return new Promise(resolve => { // 判断请求方法(post还是put) const requestMethod = Array.isArray(data) ? $.post : $.put; @@ -494,4 +907,4 @@ function Env(name) { // 返回包含所有方法的对象 return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; -} +} \ No newline at end of file diff --git a/zsfc/zsfc.shop.js b/zsfc/zsfc.shop.js deleted file mode 100644 index 7a72c8a51..000000000 --- a/zsfc/zsfc.shop.js +++ /dev/null @@ -1,543 +0,0 @@ -/** - * - * 使用方法:打开掌上飞车APP, 点击下方游戏栏,然后点击掌飞商城即可获取所需数据。 - * 注意事项:如需购买掌飞商店中的指定商品,请订阅boxjs链接,并在掌上飞车应用中填写在售商品的完整名称 - * - * boxjs订阅地址:https://raw.githubusercontent.com/chiupam/surge/main/boxjs/chiupam.boxjs.json - * - * hostname: bang.qq.com - * - * type: http-request - * regex: ^https?://bang\.qq\.com/app/speed/mall/main2\?* - * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js - * requests-body: 1 - * - * type: cron - * cron: 0 11 0,21 * * * - * script-path: https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js - * - * =============== Surge =============== - * 掌飞购物Cookie = type=http-request, pattern=^https?://bang\.qq\.com/app/speed/mall/main2\?*, requires-body=1, max-size=-1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=10 - * 掌飞购物 =type=cron, cronexp="0 11 0,21 * * *", wake-system=1, script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, script-update-interval=0, timeout=60 - * - * =============== Loon =============== - * http-request ^https?://bang\.qq\.com/app/speed/mall/main2\?* script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, requires-body=true, timeout=10, tag=掌飞购物Cookie - * cron "0 11 0,21 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物 - * - * =============== Quan X =============== - * ^https?://bang\.qq\.com/app/speed/mall/main2\?* url script-request-body https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js - * 0 11 0,21 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/zsfc/zsfc.shop.js, tag=掌飞购物, enabled=true - * - */ - - -/** - * 创建一个名为 $ 的环境变量实例,用于处理掌飞购物相关操作 - */ -const $ = new Env(`🏎️ 掌飞购物`) - -/** - * 检查是否为请求阶段 - */ -const isreq = typeof $request !== 'undefined'; - -/** - * 主函数,用于执行打卡操作或设置请求数据 - */ -(async () => { - if (isreq) { - // 处理请求阶段 - - // 提取请求的URL并去除引号 - const url = $.toStr($request.url).replace(/^"|"$/g, ''); - const cookie = $request.headers.cookie; - - // 对比 token 是否发生变化 - if ($.read(`zsfc_token`) == matchStr(url, "token")) return; - - // 初始化 dataToWrite 词典,填充待写入内存的键值对 - const dataToWrite = { - 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞商城无法抓取,只能读取签到页面的脚本获取情况 - "zsfc_accessToken": matchStr(url, "accessToken"), - "zsfc_openid": matchStr(cookie, "openid"), - "zsfc_token": matchStr(url, "token"), - "zsfc_roleId": matchStr(url, "roleId"), - "zsfc_userId": matchStr(url, "userId"), - "zsfc_areaId": matchStr(url, "areaId"), - 'zsfc_uin': matchStr(url, "uin"), - }; - - // 将请求数据写入内存 - Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); - - // 输出到日志只输出特定的键值对 - // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; - // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); - $.log(dataToWrite) - $.log(`token: ${dataToWrite.zsfc_token}`) - - // 发送通知 - $.notice($.name, `✅ 获取商城数据成功!`, `请不要再次打开掌上飞车APP, 否则 Cookie 将失效!`); - - } else { - // 执行购物阶段 - - // 读取要购买的商品名称并生成商品列表 - shopName = $.read(`zsfc_bang_shopname`); - if (!shopName) shopName = autoGetGameItem(); - const shopIdArray = await searchShop(shopName); - - // 无法在掌上商城中搜索到相关商品时终止程序 - if (!Object.keys(shopIdArray).length) { - $.notice($.name, `❌ ${shopName} 未在商店中售卖`, `请在掌上商城中认真核对商品名称`); - return; - } - - // 获取当前点券和消费券 - const packBefore = await getPackInfo(`before`); - - // Cookie 已过期,程序终止 - if (!packBefore) { - $.log(`❌ Cookie 已过期,请重新获取`) - $.notice($.name, `❌ Cookie 已过期`, `请打开掌上飞车,点击游戏,最后点击掌上商城即可`); - return; - } - - // 获取当前余额 - const moneyBefore = packBefore.money * 1; - const couponsBefore = packBefore.coupons * 1; - const beforeLog = `✅ 当前共有${moneyBefore}点券,${couponsBefore}消费券`; - $.log(beforeLog); - $.subtitle = beforeLog; - - // 获取购物包 - const [shopArray, totalCount, unit] = getShopItems(shopName, shopIdArray[shopName], - isLastDays(3) ? moneyBefore + couponsBefore : couponsBefore - ); - - // 开始购物循环 - if (shopArray.length) { - $.log(`✅ 预计可购买${totalCount ? totalCount : ""}${unit}${shopName}`); - let successBuyCounts = 0; - let failedBuyCounts = 0; - - // 开始购物 - for (let buyInfo of shopArray) { - let { name, count, id, idx } = buyInfo; - successBuyCounts += await purchaseItem(name, count, id, idx); - } - failedBuyCounts = totalCount - (successBuyCounts === 999 ? 1 : successBuyCounts); - - if (successBuyCounts > 0) { - successBuyCounts === 999 ? successBuyCounts = "" : successBuyCounts; - $.message = `🎉 成功购买${successBuyCounts}${unit}${shopName}`; - if (failedBuyCounts > 0) { - $.message += `(未成功购买${failedBuyCounts}${unit})`; - } - } else { - $.message = `❌ 全部购买失败,共计${totalCount ? totalCount : ""}${unit}`; - } - $.log($.message) - - // 获取剩余余额 - const packAfter = await getPackInfo(`after`); - const moneyAfter = packAfter.money * 1; - const couponsAfter = packAfter.coupons * 1; - const afterLog = `✅ 现在剩余${moneyAfter}点券,${couponsAfter}消费券`; - $.log(afterLog); - $.subtitle = afterLog; - - } else { - $.log(`⭕ 余额不足以购买${shopName}`); - } - - // 显示购物结果通知 - if ($.message) $.notice($.name, $.subtitle, $.message, ``); - - } -})() - .catch((e) => $.notice($.name, '❌ 未知错误无法进行购物', e, '')) - .finally(() => $.done()); - -/** - * 从输入字符串中提取指定关键字的值。 - * - * @param {string} input - 输入字符串,要从中提取关键字的值。 - * @param {string} key - 要提取的关键字。 - * @returns {string} - 返回匹配到的关键字值,如果没有匹配到则返回空字符串。 - */ -function matchStr(input, key) { - const separator = input.includes("&") ? "&" : ";"; - const pattern = new RegExp(`${key}=([^${separator}]+)`); - const match = input.match(pattern); - return match ? match[1] : ''; -} - -/** - * @description 处理输入对象,转换成输出对象 - * @param {Object} shopInfo - 输入对象 - * @returns {Object} 处理后的输出对象 - */ -function processInput(shopInfo) { - // 初始化一些变量 - let resultObject = {}; - let price_idx = {}; - let item = shopInfo.szItems[0]; - - // 准备工作:去除可能的逗号结尾 - if (item.ItemNum) { - item.ItemNum = item.ItemNum.slice(0, -1); - } else { - item.ItemAvailPeriod = item.ItemAvailPeriod.slice(0, -1); - } - - // 对每个项目数量或可用期限和价格执行逻辑 - let itemArray = (item.ItemNum ? item.ItemNum : item.ItemAvailPeriod).split(','); - - // 构建 price_idx 词典信息 - itemArray.forEach((value, index) => { - let key = item.ItemNum ? value : (value === "-1" ? "999" : (Number(value) / 24).toString()); - let itemPrice = shopInfo.szPrices[index].SuperMoneyPrice; - price_idx[key] = { - index: index.toString(), // 价格索引 - price: itemPrice - }; - }); - - // 构建最终结果对象,包括单位信息 - resultObject[shopInfo.szName] = { - price_idx: price_idx, - itemId: shopInfo.iId, - unit: item.ItemNum ? "个" : "天" // 根据 ItemNum 存在与否确定单位 - }; - - return resultObject; -} - -/** - * @description 检查今天是否是当月的最后几天 - * @param {number} N - 要检查的倒数第N天 - * @returns {boolean} true 表示今天是当月的倒数第N天,false 表示反之 - */ -function isLastDays(N) { - // 获取当前日期的 Date 对象 - const today = new Date(); - - // 迭代从1到N的整数,用于检查倒数第N天 - for (let i = 1; i <= N; i++) { - // 创建一个新的 Date 对象,表示明天的日期 - const nextDay = new Date(today); - nextDay.setDate(today.getDate() + i); - - // 检查如果明天的月份不等于今天的月份,则表示今天是当月的倒数第N天 - if (today.getMonth() !== nextDay.getMonth()) { - return true; - } - } - - // 如果没有在循环中返回 true,表示今天不是当月的倒数第N天 - return false; -} - -/** - * @description 获取当前月份对应的游戏道具。 - * @returns {string} 返回当前月份对应的游戏道具名称。 - */ -function autoGetGameItem() { - // 定义游戏道具的列表,包括普通改装道具和进阶改装道具 - const gameItems = [ - "进气系统+1", "燃料系统+1", "点火装置+1", "引擎装置+1", // 普通改装道具 - // "普通粒子推进", "普通阿尔法离合" // 进阶改装道具,我不需要,注释掉了 - ]; - - // 获取当前月份(加1是因为月份从0开始) - const currentMonth = new Date().getMonth() + 1; - - // 计算当前月份对应的游戏道具的索引 - const index = (currentMonth - 1) % gameItems.length; - - // 返回当前月份对应的游戏道具名称 - return gameItems[index]; -} - -/** - * @description 根据当前余额和道具价格生成购物列表 - * @param {string} name - 道具名称 - * @param {object} item - 包含道具价格信息的对象 - * @param {number} money - 当前可用余额 - * @returns {[array, number]} - 一个包含待购物对象和总购物数量的数组 - */ -function getShopItems(name, item, money) { - // 获取道具价格的所有可购买数量,并由高到低排序 - const itemCounts = Object.keys(item.price_idx) - .map((key) => parseInt(key.match(/\d+/))) - .filter((num) => !isNaN(num)) - .sort((a, b) => b - a); - - // 获取道具价格的所有价格,并由高到低排序 - const itemPrices = Object.values(item.price_idx) - .map((priceData) => priceData.price) - .sort((a, b) => b - a); - - // 初始化总购物数量和购物列表 - let totalCounts = 0; - let shopArray = []; - - for (let i = 0; i < itemPrices.length; i++) { - // 商品数量索引 - let shopIdx = item.price_idx[itemCounts[i]].index; - - // 如果购买的商品可以购买永久且当前余额可以购买永久 - if (itemCounts[i] === 999 && money > itemPrices[i]) { - shopArray.push({"name": name, "count": "999", "id": item.itemId, "idx": shopIdx}); - item.unit = "永久" - break; - } - - // 计算当前余额可以购买的最大道具数量 - const maxItems = Math.floor(money / itemPrices[i]); // 这是一个计算出的整数,表示根据当前余额和道具价格,最多可以购买的道具数量。 - totalCounts += maxItems * itemCounts[i]; // 这是一个累加的变量,用于跟踪购买的总道具数量。 - money -= maxItems * itemPrices[i]; // 这是当前可用的余额。在每次购买道具后,余额会根据购买的道具数量和价格进行更新,以反映购买后的余额。 - - if (maxItems) { - // 将可购买的道具添加到购物列表 - for (let m = 0; m < maxItems; m++) { - shopArray.push({"name": name, "count": itemCounts[i].toString(), "id": item.itemId, "idx": shopIdx}); - } - } - - // 如果当前余额不足以购买最便宜的道具,跳出循环 - if (money < itemPrices[itemPrices.length - 1]) { - break; - } - } - - return [shopArray, totalCounts ? totalCounts : 0, item.unit]; -} - -/** - * @description 根据商品名称搜索商品信息 - * @param {string} shopName - 要搜索的商品名称 - * @returns {Promise} 包含商品信息的 Promise 对象 - */ -async function searchShop(shopName) { - // 初始化目标商品对象 - let targetShopObject = {}; - - // 获取 URL 中的查询参数 - const params = { - 'uin': $.read(`zsfc_uin`), - 'userId': $.read(`zsfc_userId`), - 'token': $.read(`zsfc_token`), - 'start': '0', - 'paytype': '1', // 按点券筛选 - 'order': '2', // 按点券筛选 - 'text': encodeURIComponent(shopName) - }; - - // 构建请求选项 - const options = { - url: `https://bang.qq.com/app/speed/mall/search?${$.queryStr(params)}`, - headers: { Referer: `https://bang.qq.com/app/speed/mall/main2` }, - }; - - // 返回一个 Promise 对象,用于异步操作 - return new Promise(resolve => { - // 发送 POST 请求,获取商品信息 - $.post(options, (err, resp, data) => { - if (data) { - const body = $.toObj(data); - const targetObject = body.data.find(item => item.szName === shopName); - if (targetObject) { - // 处理商品信息,将结果赋给目标商品对象 - targetShopObject = processInput(targetObject); - } - } - // 解析 Promise,将结果对象传递给 resolve 函数 - resolve(targetShopObject); - }); - }); -} - -/** - * @description 获取点券和消费券信息 - * @param {string} argument - 余额状态,可选值为 "before" 或 "after" - * @returns {Promise} - 包含点券和消费券数量的对象,或者在获取失败时返回 false - */ -async function getPackInfo(argument) { - // 创建一个空对象,用于存储点券和消费券信息 - let result = {}; - - // 根据参数值设置状态文本 - const statu = (argument === "before") ? "当前" : "剩余"; - - // 获取 URL 中的查询参数 - const params = { - 'areaId': $.read(`zsfc_areaId`), - 'accessToken': $.read(`zsfc_accessToken`), - 'token': $.read(`zsfc_token`), - 'uin': $.read(`zsfc_uin`), - 'userId': $.read(`zsfc_userId`), - }; - - // 配置请求选项 - const options = { - url: `https://bang.qq.com/app/speed/mall/main2?${$.queryStr(params)}` - }; - - // 输出日志,表示开始获取点券和消费券 - if (statu === "before") $.log(`🧑‍💻 开始获取${statu}点券和消费券`); - - // 返回一个 Promise 对象,用于异步操作 - return new Promise(resolve => { - // 发送 GET 请求,获取点券和消费券信息 - $.get(options, (err, resp, data) => { - if (data) { - // 将响应数据转换为字符串 - const body = data.toString(); - - // 使用正则表达式匹配点券和消费券数量 - money = body.match(/(\d+)<\/b>/)[1]; - coupons = body.match(/(\d+)<\/b>/)[1]; - - // 将点券和消费券数量存储在结果对象中 - result.money = money; - result.coupons = coupons; - } else { - // 如果获取失败,将结果对象设置为 false - result = false; - } - - // 解析 Promise,将结果对象传递给 resolve 函数 - resolve(result); - }); - }); -} - -/** - * @description 购买道具 - * @param {string} name - 道具名称 - * @param {number} count - 购买数量 - * @param {string} id - 道具的唯一标识符 - * @param {string} idx - 道具的价格索引 - * @returns {Promise} - 返回成功购买的道具数量 - */ -async function purchaseItem(name, count, id, idx) { - // 配置请求选项 - const options = { - url: `https://bang.qq.com/app/speed/mall/getPurchase`, - headers: { - "Referer": `https://bang.qq.com/app/speed/mall/detail2` - }, - body: $.queryStr({ - 'areaId': $.read(`zsfc_areaId`), - 'token': $.read(`zsfc_token`), - 'userId': $.read(`zsfc_userId`), - 'uin': $.read(`zsfc_uin`), - 'pay_type': "1", - 'commodity_id': id, - 'price_idx': idx - }) - }; - - // 返回一个 Promise 对象,用于异步操作 - return new Promise(resolve => { - // 发送 POST 请求,购买道具 - $.post(options, (err, resp, data) => { - if (data) { - // 将响应数据转换为对象 - const body = $.toObj(data); - - // 提取响应中的消息 - const msg = body.msg; - - // 检查响应结果,如果购买失败,输出错误消息 - if (body.res == -1) { - $.log(`❌ ${msg}`); - } else { - // 如果购买成功,将成功购买的道具数量设置为购买数量 - totalCount = count * 1; - } - } else { - // 如果发生错误,输出错误消息和错误信息 - $.log(`❌ 购买${name}时发生错误`); - $.log($.toStr(err)); - } - - // 解析 Promise,将成功购买的道具数量传递给 resolve 函数 - resolve(totalCount ? totalCount : 0); - }); - }); -} - -/** - * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 - * @param {string} name - 环境名称 - */ -function Env(name) { - // 判断当前环境是否为 Loon - const isLoon = typeof $loon !== "undefined"; - // 判断当前环境是否为 Surge - const isSurge = typeof $httpClient !== "undefined" && !isLoon; - // 判断当前环境是否为 QuantumultX - const isQX = typeof $task !== "undefined"; - - // 定义 read 方法,用于读取数据 - const read = (key) => { - if (isLoon || isSurge) return $persistentStore.read(key); - if (isQX) return $prefs.valueForKey(key); - }; - - // 定义 write 方法,用于写入数据 - const write = (key, value) => { - if (isLoon || isSurge) return $persistentStore.write(key, value); - if (isQX) return $prefs.setValueForKey(key, value); - }; - - // 定义 notice 方法,用于发送通知 - const notice = (title, subtitle, message, url) => { - if (isLoon) $notification.post(title, subtitle, message, url); - if (isSurge) $notification.post(title, subtitle, message, { url }); - if (isQX) $notify(title, subtitle, message, { "open-url": url }); - }; - - // 定义 get 方法,用于发送 GET 请求 - const get = (url, callback) => { - if (isLoon || isSurge) $httpClient.get(url, callback); - if (isQX) {url.method = `GET`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; - }; - - // 定义 post 方法,用于发送 POST 请求 - const post = (url, callback) => { - if (isLoon || isSurge) $httpClient.post(url, callback); - if (isQX) {url.method = `POST`; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; - }; - - // 定义 put 方法,用于发送 PUT 请求 - const put = (url, callback) => { - if (isLoon || isSurge) $httpClient.put(url, callback) - if (isQX) {url.method = 'PUT'; $task.fetch(url).then((resp) => callback(null, {}, resp.body))}; - }; - - // 定义 toObj 方法,用于将字符串转为对象 - const toObj = (str) => JSON.parse(str); - - // 定义 toStr 方法,用于将对象转为字符串 - const toStr = (obj) => JSON.stringify(obj); - - // 定义 queryStr 方法,用于将对象转为可以请求的字符串 - const queryStr = (obj) => { - return Object.keys(obj) - .map(key => `${key}=${obj[key]}`) - .join('&'); - }; - - // 定义 log 方法,用于输出日志 - const log = (message) => console.log(message); - - // 定义 done 方法,用于结束任务 - const done = (value = {}) => $done(value); - - // 返回包含所有方法的对象 - return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; -} diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index fcc699f78..042005b33 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -54,7 +54,7 @@ const isreq = typeof $request !== 'undefined'; // 初始化 dataToWrite 词典,填充待写入内存的键值对 const dataToWrite = { - 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞商城无法抓取,只能读取签到页面的脚本获取情况 + 'zsfc_iActivityId': $.read(`zsfc_iActivityId`), // 掌飞寻宝无法抓取,只能读取签到页面的脚本获取情况 "zsfc_accessToken": matchStr(url, "accessToken"), "zsfc_openid": matchStr(cookie, "openid"), "zsfc_token": matchStr(url, "token"), @@ -62,33 +62,57 @@ const isreq = typeof $request !== 'undefined'; "zsfc_userId": matchStr(url, "userId"), "zsfc_areaId": matchStr(url, "areaId"), 'zsfc_uin': matchStr(url, "uin"), - 'zsfc_treasure_day': (new Date().getDate()).toString() + 'zsfc_day': (new Date().getDate()).toString() }; // 将请求数据写入内存 Object.entries(dataToWrite).forEach(([key, value]) => $.write(value, key)); - // 输出到日志只输出特定的键值对 - // const { zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid } = dataToWrite; - // $.log({ zsfc_iActivityId, zsfc_iFlowId, zsfc_accessToken, zsfc_openid }); - $.log(dataToWrite) + // 写入日志并发送通知 + if ($.toObj($.read(`zsfc_treasure_log`) || `true`)) { + $.log(dataToWrite); + $.notice($.name, `✅ 获取寻宝数据成功!`, `此脚本需每天打开掌上飞车APP并进入一次寻宝页面`, ``); + } - // 发送通知 - $.notice($.name, `✅ 获取寻宝数据成功!`, `此脚本需每天打开掌上飞车APP并进入一次寻宝页面`, ``); + // 检查并设置青龙相关变量 + if ($.read(`ql_url`) && $.read(`ql_client_id`) && $.read(`ql_client_secret`) && $.toObj($.read(`zsfc_upload_config`))) { + const qlUrlCache = $.read(`ql_url`); + $.qlUrl = qlUrlCache.charAt(qlUrlCache.length - 1) === '/' ? qlUrlCache.slice(0, -1) : qlUrlCache; + $.qlId = $.read(`ql_client_id`); + $.qlSecret = $.read(`ql_client_secret`); + $.qlToken = await qlToken(); + + const qlEnvsName = `ZSFC_CONFIG`; + const qlEnvsValue = $.toStr(dataToWrite); + const qlEnvsRemarks = `掌飞商城`; + + // 获取青龙面板令牌,若成功则执行后续操作 + if ($.qlToken) { + const qlEnvsNewBody = await qlEnvsSearch(qlEnvsName, qlEnvsValue, qlEnvsRemarks); + if (!qlEnvsNewBody) return; // 环境变量的值没有发生变化,不需要进行操作 + + // 检查并处理环境变量的返回值类型 + if (Array.isArray(qlEnvsNewBody)) { + // 暂时无法完成新增操作,后续再修改 + $.log(`⭕ 手动添加名为 ${qlEnvsName} 变量`); + } else { + await qlEnvsEdit(qlEnvsNewBody); + } + } else { + $.log("❌ 无法获取 token,请检查青龙相关配置"); + } + } } else { // 处理非请求时的逻辑 // 检查用户今天是否打开过寻宝页面 const date = (new Date().getDate()).toString(); - if (!$.read(`zsfc_treasure_day`)) $.write(date, `zsfc_treasure_day`); - if (date != $.read(`zsfc_treasure_day`)) { - $.log(`❌ 今天未进过寻宝页面`); - return; - } + if (date != $.read(`zsfc_day`)) return $.log(`❌ 今天未进过寻宝页面`); // 获取地图数据 $.mapData = await fetchMapData(); + if (!Object.keys($.mapData).length) return $.log(`❌ 无法获取地图信息`); // 尊贵的紫钻用户 if ($.mapData.isVip) $.log(`💎 尊贵的紫钻用户`); @@ -97,8 +121,12 @@ const isreq = typeof $request !== 'undefined'; $.log(`✅ 最高解锁星级:${'⭐️'.repeat($.mapData.starId * 1)}`); $.log(`✅ 今日大吉地图:${$.mapData.mapName}`); + // 等待当前分钟数除以5的秒数时间 + // await wait((new Date().getMinutes()) / 5); + // 开始查询目前的寻宝状态 treasureData = await performTreasureAction(`start`); + // if (!treasureData.timeLeft) return $.log(`❌ 无法获取寻宝状态`); if (treasureData.ending) { // 寻宝完成,先结束寻宝再领取奖励 @@ -125,7 +153,6 @@ const isreq = typeof $request !== 'undefined'; // 这个脚本不发送通知,静默运行 // $.notice($.name, ``, ``, ``); - $.write(date, `zsfc_treasure_day`); } })() .catch((e) => $.notice($.name, '❌ 未知错误无法寻宝', e, '')) @@ -145,6 +172,18 @@ function matchStr(input, key) { return match ? match[1] : ''; } +/** + * @description 等待一段时候。 + * @param {number} s - 等待时长。 + * @returns {Promise} Promise + */ + async function wait(s) { + $.log(`💤 程序休眠 ${s}s 后继续...`); + return new Promise((resolve) => { + setTimeout(resolve, s * 1000); + }); +} + /** * @description 异步获取地图数据操作。 * @returns {Promise} 包含地图数据的 Promise 对象。 @@ -163,27 +202,37 @@ async function fetchMapData() { $.get(url, (error, response, data) => { if (data) { // 提取userInfo和mapInfo的数据 - const userInfoMatch = data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/); - const mapInfoMatch = data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/); - - const userInfoData = eval(`(${userInfoMatch[1]})`); - const mapInfoData = eval(`(${mapInfoMatch[1]})`); + const [userInfoData, mapInfoData] = [ + data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/)?.[1], + data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/)?.[1] + ].map(match => match && eval(`(${match})`)); + + // 固定 iFlowId 列表 + const iFlowIdArray = { + "1": ["856152", "856155"], // 1星 + "2": ["856156", "856157"], // 2星,100次 + "3": ["856158", "856159"], // 3星,300次 + "4": ["856160", "856161"], // 4星,500次 + "5": ["856162", "856163"], // 5星,紫钻地图 + "6": ["856164", "856165"] // 6星,皇族地图 + }; - const unlockedStars = Object.keys(userInfoData.starInfo).filter(starId => userInfoData.starInfo[starId] === 1); - const highestUnlockedStarId = Math.max(...unlockedStars); - const luckyMap = mapInfoData[highestUnlockedStarId].find(map => map.isdaji === 1); - const iFlowIdRegex = `${highestUnlockedStarId} == i ${highestUnlockedStarId == 6 ? "&&" : "\\?"} \\(M\\.getLb\\((\\d+), e\\), B\\.getLb\\((\\d+), e\\)\\)`; + // 获取地图最高解锁星级 + const highestUnlockedStarId = Math.max( + ...Object.keys(userInfoData.starInfo) // 转化为数组 + .filter(starId => userInfoData.starInfo[starId] === 1) + ); - const iFlowIdArrRegex = new RegExp(iFlowIdRegex, 'g'); - const iFlowIdArrMatch = iFlowIdArrRegex.exec(data); - const iFlowIdArr = iFlowIdArrMatch ? [parseInt(iFlowIdArrMatch[1]), parseInt(iFlowIdArrMatch[2])] : []; + // 获取大吉地图信息 + const luckyMap = mapInfoData[highestUnlockedStarId] + .find(map => map.isdaji === 1); mapData = { starId: highestUnlockedStarId, mapId: luckyMap.id, isVip: userInfoData.vip_flag, mapName: luckyMap.name, - iFlowId: iFlowIdArr + iFlowId: iFlowIdArray[highestUnlockedStarId] }; } else { $.log(`❌ 获取地图数据时发生错误`); @@ -216,8 +265,7 @@ async function performTreasureAction(action) { "mapId": $.mapData.mapId, "starId": $.mapData.starId, // 普通寻宝1 600s -- 快捷寻宝2 10s - // "type": $.mapData.isVip + 1, - "type": "1", // 懒得检查是否为紫钻了,统统使用普通寻宝 + "type": $.mapData.isVip ? 2 : 1, "areaId": $.read(`zsfc_areaId`), "roleId": $.read(`zsfc_roleId`), "userId": $.read(`zsfc_userId`), @@ -226,6 +274,7 @@ async function performTreasureAction(action) { }) }; + // 发送 POST 异步请求并返回一个 Promise 对象 return new Promise(resolve => { $.post(options, (error, response, data) => { if (data) { @@ -299,6 +348,102 @@ async function claimTreasureReward(flowId) { }); } +/** + * @description 获取青龙面板令牌 + * @returns {Promise} 返回一个包含青龙面板令牌或布尔值的 Promise。 + */ +async function qlToken() { + let accessToken; // 更具体的变量名,表示访问令牌 + const options = { + url: `${$.qlUrl}/open/auth/token?client_id=${$.qlId}&client_secret=${$.qlSecret}` + }; + return new Promise(resolve => { + $.get(options, (err, resp, data) => { + if (data) { + const responseBody = $.toObj(data); + if (responseBody.code === 200) { + accessToken = responseBody.data.token; + } else { + accessToken = false; + } + } + resolve(accessToken); + }); + }); +} + +/** + * @description 搜索环境变量并生成新的请求体部分参数 + * @param {string} envsName - 新环境变量的名称 + * @param {string} envsValue - 新环境变量的具体值 + * @param {string} envsRemarks - 新环境变量的备注名 + * @returns {Promise} 返回一个请求体对象或列表或布尔值的 Promise。 + */ +async function qlEnvsSearch(envsName, envsValue, envsRemarks) { + let requestPayload; // 代表请求体的变量名更具体 + const options = { + url: `${$.qlUrl}/open/envs?searchValue=${envsName}`, + headers: { "Authorization": `Bearer ${$.qlToken}` } + }; + return new Promise(resolve => { + $.get(options, (err, resp, data) => { + if (data) { + const responseBody = $.toObj(data).data; + if (responseBody.length === 1) { + // 找到匹配的环境变量,生成单个请求体对象 + const matchingEnv = responseBody[0]; + if (matchingEnv.value === envsValue) { + requestPayload = false; + } else { + requestPayload = { + 'id': matchingEnv.id, + 'name': envsName, + 'value': envsValue, + 'remarks': envsRemarks + }; + } + } else { + // 未找到匹配的环境变量,生成包含一个对象的数组 + requestPayload = [{ + 'name': envsName, + 'value': envsValue, + 'remarks': envsRemarks + }]; + } + } + resolve(requestPayload); + }); + }); +} + +/** + * @description 编辑青龙面板的环境变量 + * @param {object} data - 请求参数 + */ +async function qlEnvsEdit(data) { + const options = { + url: `${$.qlUrl}/open/envs`, + headers: { "Authorization": `Bearer ${$.qlToken}` }, + body: data + }; + $.log(options.body) + return new Promise(resolve => { + // 判断请求方法(post还是put) + const requestMethod = Array.isArray(data) ? $.post : $.put; + requestMethod(options, (err, resp, responseData) => { + if (responseData) { + let body = $.toObj(responseData); + // 根据返回的状态码处理结果 + if (body.code !== 200) { + $.log(`❌ 上传青龙面板失败`); + $.log(body) + } + } + resolve(); // 完成Promise + }); + }); +} + /** * @description 创建一个名为 Env 的构造函数,用于处理环境相关操作。 * @param {string} name - 环境名称 From 1b42d63988ce7f1e5564373b104028331af0f366 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:42:22 +0800 Subject: [PATCH 213/311] =?UTF-8?q?=E9=80=82=E9=85=8DQX=E3=80=81Loon?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=20(#472)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.js | 17 ++++++++--------- zsfc/zsfc.treasure.js | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 01663b737..59097aef2 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -53,7 +53,7 @@ const isRequest = typeof $request !== 'undefined'; */ // 提取请求数据 - const cookie = $request.headers.cookie; + const cookie = $request.headers.cookie || $request.headers.Cookie; // QX、Loon都是用的Cookie const body = $request.body; // 提取请求体中的 iActivityId 和 iFlowId 作为检验使用 @@ -124,7 +124,7 @@ const isRequest = typeof $request !== 'undefined'; // 提取请求的URL并去除引号 const url = $.toStr($request.url).replace(/^"|"$/g, ''); - const cookie = $request.headers.cookie; + const cookie = $request.headers.cookie || $request.headers.Cookie; // QX、Loon都是用的Cookie // 对比 token 是否发生变化 if ($.read(`zsfc_token`) == matchParam(url, "token")) return; @@ -491,9 +491,6 @@ async function getTotalSignInDays() { // 初始化总签到天数 let totalSignInDays; - // 根据请求方式获取 iFlowId 具体值 - let iFlowId = Number(isRequest ? $.iFlowId : $.read(`zsfc_iFlowId`)); - // 构建请求体 const options = { url: `https://comm.ams.game.qq.com/ams/ame/amesvr?iActivityId=${isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`)}`, @@ -501,10 +498,10 @@ async function getTotalSignInDays() { "Cookie": `access_token=${$.read(`zsfc_accessToken`)}; acctype=qc; appid=1105330667; openid=${$.read(`zsfc_openid`)}` }, body: $.queryStr({ - "iActivityId": $.read(`zsfc_iActivityId`), + "iActivityId": isRequest ? $.iActivityId : $.read(`zsfc_iActivityId`), "g_tk": "1842395457", "sServiceType": "speed", - "iFlowId": iFlowId + 1 + "iFlowId": Number(isRequest ? $.iFlowId : $.read(`zsfc_iFlowId`)) + 1 }) }; @@ -518,8 +515,10 @@ async function getTotalSignInDays() { const missedDays = new Date().getDate() - totalSignInDays; const missedDaysText = missedDays !== 0 ? `(漏签 ${missedDays} 天)` : ``; - $.subtitle = `✅ 累计签到 ${totalSignInDays} 天${missedDaysText}`; - $.log($.subtitle); + if (!isRequest) { + $.subtitle = `✅ 累计签到 ${totalSignInDays} 天${missedDaysText}`; + $.log($.subtitle); + } } catch {} } else { $.log(`❌ 获取累签天数时发生错误`); diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index 042005b33..bfd03b78f 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -47,7 +47,7 @@ const isreq = typeof $request !== 'undefined'; // 提取请求的URL和其他数据 const url = $request.url; - const cookie = $request.headers.cookie; + const cookie = $request.headers.cookie || $request.headers.Cookie; // QX、Loon都是用的Cookie // 对比 token 是否发生变化 if ($.read(`zsfc_token`) == matchStr(url, "token")) return; From 29fadf36829f753ec6b8deab9744a41ce3a0e031 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:10:44 +0800 Subject: [PATCH 214/311] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=AD=E4=B9=B0?= =?UTF-8?q?=E9=81=93=E5=85=B7=E7=9A=84=E6=9C=80=E4=BC=98=E8=B4=AD=E4=B9=B0?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=AF=BB=E5=AE=9D=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=BD=93=E5=A4=A9=E6=98=AF=E5=90=A6=E7=94=A8=E5=AE=8C=E5=AF=BB?= =?UTF-8?q?=E5=AE=9D=E6=AC=A1=E6=95=B0=20(#473)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.js | 59 ++++++++++++++++++++++--------- zsfc/zsfc.treasure.js | 81 +++++++++++++++++++++++++------------------ 2 files changed, 90 insertions(+), 50 deletions(-) diff --git a/zsfc/zsfc.js b/zsfc/zsfc.js index 59097aef2..a35169f8d 100644 --- a/zsfc/zsfc.js +++ b/zsfc/zsfc.js @@ -127,7 +127,7 @@ const isRequest = typeof $request !== 'undefined'; const cookie = $request.headers.cookie || $request.headers.Cookie; // QX、Loon都是用的Cookie // 对比 token 是否发生变化 - if ($.read(`zsfc_token`) == matchParam(url, "token")) return; + if ($.read(`zsfc_token`) === matchParam(url, "token")) return; // 初始化 dataToWrite 词典,填充待写入内存的键值对 const dataToWrite = { @@ -197,7 +197,7 @@ const isRequest = typeof $request !== 'undefined'; } // 显示签到结果通知 - if ($.checkInMsg) $.notice(`🏎️ 掌上飞车`, $.subtitle, $.checkInMsg, ``); + if ($.checkInMsg && $.toObj($.read(`zsfc_treasure_log`) || `true`)) $.notice(`🏎️ 掌上飞车`, $.subtitle, $.checkInMsg, ``); /** @@ -272,7 +272,7 @@ const isRequest = typeof $request !== 'undefined'; } // 显示购物结果通知 - if ($.shopMsg) $.notice(`🏎️ 掌飞购物`, $.subtitle, $.shopMsg, ``); + if ($.shopMsg && $.toObj($.read(`zsfc_treasure_log`) || `true`)) $.notice(`🏎️ 掌飞购物`, $.subtitle, $.shopMsg, ``); } })() @@ -318,16 +318,16 @@ function autoGetGameItem() { * @returns {[array, number, str]} - 返回购买的物品数组、总数和单位信息的数组 */ function getShopItems(shopInfo, overage) { - // 获取今天的日期和本月剩余天数是否小于等于3天 + // 获取今天的日期和本月剩余天数是否小于3天(月底3天的计算方式不可以为小于等于3) const today = new Date(); const day = new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate(); - const lastDay = (day - today.getDate()) <= 3; + const lastDay = (day - today.getDate()) < 3; // 创建一个包含商店信息和物品数据的对象 const info = {"Id": shopInfo.iId, "data": []}; // 判断商店类型并获取相应的物品数值 - const shopType = shopInfo.szItems[0].ItemNum !== ""; + const shopType = shopInfo.szItems[0].ItemNum !== ""; // 表示购买的商品是按数量购买 const values = shopType ? shopInfo.szItems[0].ItemNum : shopInfo.szItems[0].ItemAvailPeriod; // 将物品数值转换成数组 @@ -346,15 +346,16 @@ function getShopItems(shopInfo, overage) { info.data.push({ count, price, idx }); }); - // 初始化总数、物品数组和剩余金钱 + // 初始化购买总数、物品数组和投入金额 let totalCount = 0; let items = []; - let remMoney = lastDay ? overage.money + overage.coupons : overage.coupons; + let remMoney = lastDay ? overage.money + overage.coupons : overage.coupons; const data = info.data; - const amount = data.length - 1; + const lastOne = data.length - 1; for (let m = 0; m < data.length; m++) { + let pushCounts = 0; let itemIndex = data[m].idx; // 判断是否购买永久物品 @@ -367,23 +368,49 @@ function getShopItems(shopInfo, overage) { // 计算最大可购买的物品数量并更新总数和剩余金钱 const maxPurchasableItems = Math.floor(remMoney / data[m].price); // 这是一个计算出的整数,表示根据当前余额和道具价格,最多可以购买的道具数量。 + thisTimeCost = maxPurchasableItems * data[m].price; // 这是一个累加的变量,用于跟踪本轮循环购买道具的总花费。 totalCount += maxPurchasableItems * data[m].count; // 这是一个累加的变量,用于跟踪购买的总道具数量。 remMoney -= maxPurchasableItems * data[m].price; // 这是当前可用的余额。在每次购买道具后,余额会根据购买的道具数量和价格进行更新,以反映购买后的余额。 // 将购买的物品加入数组 for (let n = 0; n < maxPurchasableItems; n++) { - items.push({"count": data[m].count, "id": info.Id, "idx": itemIndex}); + items.push({"count": data[m].count, "id": info.Id, "idx": itemIndex, "cost": data[m].price}); + pushCounts += 1; } - // 非月尾判断是否可以购买最后一个物品 - if (remMoney < data[amount].price && !lastDay) { - const meetsThreshold = remMoney > data[amount].price / Number($.read(`zsfc_shop_threshold`)); - const canAffordLastItem = remMoney + overage.money >= data[amount].price; + // 在购买数量道具情况下,非月尾判断是否可以购买最后一个物品 + if (remMoney < data[lastOne].price && !lastDay && shopType) { + const meetsThreshold = remMoney > data[lastOne].price / Number(`1000000`); + const canAffordLastItem = remMoney + overage.money >= data[lastOne].price; + // 如果满足阈值条件,且消费券加点券的和大于最便宜一个道具的价格 if (meetsThreshold && canAffordLastItem) { - items.push({"count": data[amount].count, "id": info.Id, "idx": data[amount].idx}); - totalCount += data[amount].count; + items.push({"count": data[lastOne].count, "id": info.Id, "idx": data[lastOne].idx, "cost": data[lastOne].price}); + pushCounts += 1; + totalCount += data[lastOne].count; + thisTimeCost += data[lastOne].price; } + + // 本轮花费大于0且本轮消费等于倒数第二阶梯的消费价格时,清空本轮添加的购买包 + if (thisTimeCost !== 0 && thisTimeCost === data[m - 1].price) { + // 计算需要保留的元素数量 + const itemsToKeep = items.length - pushCounts; + + // 计算新的元素序列 + const newIndex = lastOne - 1; + + // 使用 slice 创建一个新数组,仅保留需要的元素 + items = items.slice(0, itemsToKeep); + + // 添加新元素到数组末尾 + items.push({ + "count": data[newIndex].count, + "id": info.Id, + "idx": data[newIndex].idx, + "cost": data[newIndex].price + }); + } + break; } } diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index bfd03b78f..4f4a5252d 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -50,7 +50,7 @@ const isreq = typeof $request !== 'undefined'; const cookie = $request.headers.cookie || $request.headers.Cookie; // QX、Loon都是用的Cookie // 对比 token 是否发生变化 - if ($.read(`zsfc_token`) == matchStr(url, "token")) return; + // if ($.read(`zsfc_token`) === matchStr(url, "token")) return; // 初始化 dataToWrite 词典,填充待写入内存的键值对 const dataToWrite = { @@ -62,7 +62,7 @@ const isreq = typeof $request !== 'undefined'; "zsfc_userId": matchStr(url, "userId"), "zsfc_areaId": matchStr(url, "areaId"), 'zsfc_uin': matchStr(url, "uin"), - 'zsfc_day': (new Date().getDate()).toString() + // 'zsfc_day': (new Date().getDate()).toString() }; // 将请求数据写入内存 @@ -106,13 +106,17 @@ const isreq = typeof $request !== 'undefined'; } else { // 处理非请求时的逻辑 + /** + * 2023.12.15 发现iOS端重开掌飞不会使token过期,因此无需检测 + */ // 检查用户今天是否打开过寻宝页面 - const date = (new Date().getDate()).toString(); - if (date != $.read(`zsfc_day`)) return $.log(`❌ 今天未进过寻宝页面`); + // const date = (new Date().getDate()).toString(); + // if (date != $.read(`zsfc_day`)) return $.log(`❌ 今天未进过寻宝页面`); // 获取地图数据 $.mapData = await fetchMapData(); if (!Object.keys($.mapData).length) return $.log(`❌ 无法获取地图信息`); + if (!$.mapData.remainingTimes) return $.log(`⭕ 当天的寻宝次数已用完`); // 尊贵的紫钻用户 if ($.mapData.isVip) $.log(`💎 尊贵的紫钻用户`); @@ -202,38 +206,47 @@ async function fetchMapData() { $.get(url, (error, response, data) => { if (data) { // 提取userInfo和mapInfo的数据 - const [userInfoData, mapInfoData] = [ + const [userInfoData, mapInfoData, todaycanTimes, todayTimes] = [ data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/)?.[1], - data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/)?.[1] + data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/)?.[1], + data.match(/"todaycanTimes":(\d+)/)?.[1], + data.match(/"todayTimes":"(\d+)"/)?.[1] ].map(match => match && eval(`(${match})`)); - // 固定 iFlowId 列表 - const iFlowIdArray = { - "1": ["856152", "856155"], // 1星 - "2": ["856156", "856157"], // 2星,100次 - "3": ["856158", "856159"], // 3星,300次 - "4": ["856160", "856161"], // 4星,500次 - "5": ["856162", "856163"], // 5星,紫钻地图 - "6": ["856164", "856165"] // 6星,皇族地图 - }; - - // 获取地图最高解锁星级 - const highestUnlockedStarId = Math.max( - ...Object.keys(userInfoData.starInfo) // 转化为数组 - .filter(starId => userInfoData.starInfo[starId] === 1) - ); - - // 获取大吉地图信息 - const luckyMap = mapInfoData[highestUnlockedStarId] - .find(map => map.isdaji === 1); - - mapData = { - starId: highestUnlockedStarId, - mapId: luckyMap.id, - isVip: userInfoData.vip_flag, - mapName: luckyMap.name, - iFlowId: iFlowIdArray[highestUnlockedStarId] - }; + // 判断今日可寻宝次数是否用完 + if ((todaycanTimes - todayTimes)) { + mapData = { + remainingTimes: false + }; + } else { + // 固定 iFlowId 列表 + const iFlowIdArray = { + "1": ["856152", "856155"], // 1星 + "2": ["856156", "856157"], // 2星,100次 + "3": ["856158", "856159"], // 3星,300次 + "4": ["856160", "856161"], // 4星,500次 + "5": ["856162", "856163"], // 5星,紫钻地图 + "6": ["856164", "856165"] // 6星,皇族地图 + }; + + // 获取地图最高解锁星级 + const highestUnlockedStarId = Math.max( + ...Object.keys(userInfoData.starInfo) // 转化为数组 + .filter(starId => userInfoData.starInfo[starId] === 1) + ); + + // 获取大吉地图信息 + const luckyMap = mapInfoData[highestUnlockedStarId] + .find(map => map.isdaji === 1); + + mapData = { + starId: highestUnlockedStarId, + mapId: luckyMap.id, + isVip: userInfoData.vip_flag, + mapName: luckyMap.name, + iFlowId: iFlowIdArray[highestUnlockedStarId] + }; + } } else { $.log(`❌ 获取地图数据时发生错误`); $.log($.toStr(error)); @@ -514,4 +527,4 @@ function Env(name) { // 返回包含所有方法的对象 return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; -} +} \ No newline at end of file From 8c174120cda818dbd0271cdaea0e0e4ba449e698 Mon Sep 17 00:00:00 2001 From: Chiupam <65508083+chiupam@users.noreply.github.com> Date: Sun, 31 Dec 2023 01:57:13 +0800 Subject: [PATCH 215/311] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=94=99=E8=AF=AF=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=A4=E6=96=AD=20(#474)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zsfc/zsfc.treasure.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/zsfc/zsfc.treasure.js b/zsfc/zsfc.treasure.js index 4f4a5252d..5294acccb 100644 --- a/zsfc/zsfc.treasure.js +++ b/zsfc/zsfc.treasure.js @@ -210,15 +210,11 @@ async function fetchMapData() { data.match(/window\.userInfo\s*=\s*eval\('([^']+)'\);/)?.[1], data.match(/window\.mapInfo\s*=\s*eval\('([^']+)'\);/)?.[1], data.match(/"todaycanTimes":(\d+)/)?.[1], - data.match(/"todayTimes":"(\d+)"/)?.[1] + data.match(/"todayTimes":(\d+)/)?.[1] ].map(match => match && eval(`(${match})`)); // 判断今日可寻宝次数是否用完 - if ((todaycanTimes - todayTimes)) { - mapData = { - remainingTimes: false - }; - } else { + if ((todaycanTimes - todayTimes)) { // 次数没有用完 // 固定 iFlowId 列表 const iFlowIdArray = { "1": ["856152", "856155"], // 1星 @@ -240,12 +236,17 @@ async function fetchMapData() { .find(map => map.isdaji === 1); mapData = { + remainingTimes: true, starId: highestUnlockedStarId, mapId: luckyMap.id, isVip: userInfoData.vip_flag, mapName: luckyMap.name, iFlowId: iFlowIdArray[highestUnlockedStarId] }; + } else { // 次数已经用完 + mapData = { + remainingTimes: false + }; } } else { $.log(`❌ 获取地图数据时发生错误`); @@ -527,4 +528,4 @@ function Env(name) { // 返回包含所有方法的对象 return { name, read, write, notice, get, post, put, toObj, toStr, queryStr, log, done }; -} \ No newline at end of file +} From e5ce5e92d38a309711f0b6bf9a4a86785b4573dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:56:08 +0800 Subject: [PATCH 216/311] chore(deps): bump crypto-js from 4.0.0 to 4.2.0 (#464) Bumps [crypto-js](https://github.com/brix/crypto-js) from 4.0.0 to 4.2.0. - [Commits](https://github.com/brix/crypto-js/compare/4.0.0...4.2.0) --- updated-dependencies: - dependency-name: crypto-js dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9f2bfaf85..44abe7ac8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "http-server ." }, "dependencies": { - "crypto-js": "^4.0.0", + "crypto-js": "^4.2.0", "got": "^11.8.5", "http-server": "^0.12.3", "iconv-lite": "0.6.3", diff --git a/yarn.lock b/yarn.lock index 48fed4876..a8e54594f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -103,10 +103,10 @@ corser@^2.0.1: resolved "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz" integrity sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c= -crypto-js@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz" - integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg== +crypto-js@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" + integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== debug@^3.1.1: version "3.2.7" From 3a36a96356e8fe7c259573c3e5ac58ee2286f564 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:56:16 +0800 Subject: [PATCH 217/311] chore(deps): bump follow-redirects from 1.14.8 to 1.15.4 (#476) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.8 to 1.15.4. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.14.8...v1.15.4) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a8e54594f..120f60431 100644 --- a/yarn.lock +++ b/yarn.lock @@ -150,9 +150,9 @@ eventemitter3@^4.0.0: integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== follow-redirects@^1.0.0: - version "1.14.8" - resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz" - integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== + version "1.15.4" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.4.tgz#cdc7d308bf6493126b17ea2191ea0ccf3e535adf" + integrity sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw== function-bind@^1.1.1: version "1.1.1" From 62d65d03e3602295b39f5c8ffd006ac5b11e9301 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 19 Jan 2024 11:07:42 +0800 Subject: [PATCH 218/311] =?UTF-8?q?fix(boxjs):=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E6=97=B6=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=20[object=20Object]=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 17 ++++++++++------- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 2 +- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index c43f41bbd..cc4bbaa98 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1159,12 +1159,14 @@

{{curapp.name}}

- + @@ -2700,7 +2702,8 @@

v{{ver.versio updateAppSession(session) { session.datas.forEach((dat) => { // 如果属性值是 undefined 或 null, 则修改为 ``, 否则转为字符串 - dat.val = !_.isNil(dat.val) ? _.toString(dat.val) : '' + // dat.val 有可能是个 object + dat.val = !_.isNil(dat.val) ? dat.val : '' }) const key = 'chavy_boxjs_sessions' const val = JSON.stringify(this.box.sessions) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 511e687a6..90766776b 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.12' +$.version = '0.12.13' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index f0b58baeb..e6d642e27 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.13", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 编辑会话时数据显示 [object Object] 问题", + "notes": [ + { + "name": "修复", + "descs": ["编辑会话时数据显示 [object Object] 问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne 反馈"] + } + ] + }, { "version": "0.12.12", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index d8b54b778..87b5c99e2 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.13", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 编辑会话时数据显示 [object Object] 问题", + "notes": [ + { + "name": "修复", + "descs": ["编辑会话时数据显示 [object Object] 问题"] + }, + { + "name": "感谢", + "descs": ["@VirgilClyne 反馈"] + } + ] + }, { "version": "0.12.12", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 511e687a6..90766776b 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.12' +$.version = '0.12.13' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 19ee2d5241a2a9bfcb66bc79957f567a1775da44 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 19 Jan 2024 18:33:33 +0800 Subject: [PATCH 219/311] =?UTF-8?q?chore:=20=E9=A6=96=E9=A1=B5=E6=94=B6?= =?UTF-8?q?=E8=97=8F=E5=BA=94=E7=94=A8=E7=9A=84=E5=85=89=E6=A0=87=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 1 + 1 file changed, 1 insertion(+) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index cc4bbaa98..843c054d4 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -94,6 +94,7 @@ .appicon { user-select: none; -webkit-user-select: none; + cursor: pointer; } From b7f7b6f65fe33a4e0084b76b1ef84e06a6e991f3 Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 28 Jan 2024 20:41:26 +0800 Subject: [PATCH 220/311] =?UTF-8?q?fix(boxjs):=20qx=20=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=90=8E=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 2 +- box/chavy.boxjs.js | 8 ++++---- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 8 ++++---- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 843c054d4..c643525cc 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2902,7 +2902,7 @@

v{{ver.versio if (!resp) return resp.data.forEach((contributor) => { const { login: id, login, html_url: repo, avatar_url: icon } = contributor - if ([29748519, 39037656, 9592236].includes(contributor.id)) { + if ([29748519, 39037656, 9592236, 1210282, 65508083].includes(contributor.id)) { this.ui.collaborators.push({ id, login, repo, icon }) } else { this.ui.contributors.push({ id, login, repo, icon }) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 90766776b..80dceb7e5 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.13' +$.version = '0.12.14' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -731,7 +731,7 @@ async function apiRunScript() { (resp) => ($.json = JSON.parse(resp)) ) } else { - await new Promise((resolve) => { + const result = await new Promise((resolve) => { $eval_env.resolve = resolve // 避免被执行脚本误认为是 rewrite 环境 // 所以需要 `$request = undefined` @@ -760,7 +760,7 @@ async function apiRunScript() { $request = $eval_env.request // 返回数据 $.json = { - result: '', + result, output: $eval_env.cached_logs.join('\n') } } @@ -961,7 +961,7 @@ function getHtmlDoneHeaders() { } function getJsonDoneHeaders() { return getBaseDoneHeaders({ - 'Content-Type': 'text/json; charset=utf-8' + 'Content-Type': 'application/json; charset=utf-8' }) } diff --git a/box/release/box.release.json b/box/release/box.release.json index e6d642e27..cdc5b9cb7 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.14", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): qx 执行脚本后无法获取结果问题", + "notes": [ + { + "name": "修复", + "descs": ["qx 执行脚本后无法获取结果问题"] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.12.13", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 87b5c99e2..695d99a77 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.12.14", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): qx 执行脚本后无法获取结果问题", + "notes": [ + { + "name": "修复", + "descs": ["qx 执行脚本后无法获取结果问题"] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.12.13", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 90766776b..80dceb7e5 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.13' +$.version = '0.12.14' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -731,7 +731,7 @@ async function apiRunScript() { (resp) => ($.json = JSON.parse(resp)) ) } else { - await new Promise((resolve) => { + const result = await new Promise((resolve) => { $eval_env.resolve = resolve // 避免被执行脚本误认为是 rewrite 环境 // 所以需要 `$request = undefined` @@ -760,7 +760,7 @@ async function apiRunScript() { $request = $eval_env.request // 返回数据 $.json = { - result: '', + result, output: $eval_env.cached_logs.join('\n') } } @@ -961,7 +961,7 @@ function getHtmlDoneHeaders() { } function getJsonDoneHeaders() { return getBaseDoneHeaders({ - 'Content-Type': 'text/json; charset=utf-8' + 'Content-Type': 'application/json; charset=utf-8' }) } From be98dc5e829ab2319f5cdbb564c86c84e9408113 Mon Sep 17 00:00:00 2001 From: FoKit <44187836+FoKit@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:12:57 +0800 Subject: [PATCH 221/311] =?UTF-8?q?feat:=20add=20followRedirect=20?= =?UTF-8?q?=E7=A6=81=E6=AD=A2=E9=87=8D=E5=AE=9A=E5=90=91=E5=8F=82=E6=95=B0?= =?UTF-8?q?=20(#478)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 10 ++++++++++ Env.min.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 48a3f2bb8..398ab1b81 100644 --- a/Env.js +++ b/Env.js @@ -322,6 +322,11 @@ function Env(name, opts) { if (request.params) { request.url += '?' + this.queryStr(request.params) } + // followRedirect 禁止重定向 + if (typeof request.followRedirect !== 'undefined' && !request['followRedirect']) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) request.opts ? request['opts']['redirection'] = false : request.opts = { redirection: false } // Quantumult X + } switch (this.getEnv()) { case 'Surge': case 'Loon': @@ -433,6 +438,11 @@ function Env(name, opts) { delete request.headers['Content-Length'] delete request.headers['content-length'] } + // followRedirect 禁止重定向 + if (typeof request.followRedirect !== 'undefined' && !request['followRedirect']) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) request.opts ? request['opts']['redirection'] = false : request.opts = { redirection: false } // Quantumult X + } switch (this.getEnv()) { case 'Surge': case 'Loon': diff --git a/Env.min.js b/Env.min.js index 700daba1b..35e13f9eb 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,a)=>{s.call(this,t,(t,s,r)=>{t?a(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const a=this.getdata(t);if(a)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,a)=>e(a))})}runScript(t,e){return new Promise(s=>{let a=this.getdata("@chavy_boxjs_userCfgs.httpapi");a=a?a.replace(/\n/g,"").trim():a;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,o]=a.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,a)=>s(a))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e);if(!s&&!a)return{};{const a=s?t:e;try{return JSON.parse(this.fs.readFileSync(a))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),a=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):a?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const a=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of a)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,a)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[a+1])>>0==+e[a+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,a]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,a,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,a,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(a),o=a?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),a)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),a)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:a,statusCode:r,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:a,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:a,response:r}=t;e(a,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,a)=>{!t&&s&&(s.body=a,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,a)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:a,headers:r,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:a,headers:r,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let a=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:o}=t,n=a.decode(o,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&a.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let a={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in a)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?a[e]:("00"+a[e]).substr((""+a[e]).length)));return t}queryStr(t){let e="";for(const s in t){let a=t[s];null!=a&&""!==a&&("object"==typeof a&&(a=JSON.stringify(a)),e+=`${s}=${a}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",a="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,a=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":a}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,a,i(r));break;case"Quantumult X":$notify(e,s,a,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),a&&t.push(a),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,r)=>{s.call(this,t,((t,s,a)=>{t?r(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,r)=>e(r)))}))}runScript(t,e){return new Promise((s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[i,o]=r.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":i,Accept:"*/*"},timeout:a};this.post(n,((t,e,r)=>s(r)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):r?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s=void 0){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of r)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,a]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(r),o=r?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),r)}catch(e){const i={};this.lodash_set(i,a,t),s=this.setval(JSON.stringify(i),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:r,statusCode:a,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:r,statusCode:a,headers:i,rawBody:o,body:n},n)}),(t=>{const{message:r,response:a}=t;e(r,a,a&&s.decode(a.rawBody,this.encoding))}))}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:a,...i}=t;this.got[s](a,i).then((t=>{const{statusCode:s,statusCode:a,headers:i,rawBody:o}=t,n=r.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:i,rawBody:o,body:n},n)}),(t=>{const{message:s,response:a}=t;e(s,a,a&&r.decode(a.rawBody,this.encoding))}))}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",a){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:return{url:t.url||t.openUrl||t["open-url"]};case"Loon":return{openUrl:t.openUrl||t.url||t["open-url"],mediaUrl:t.mediaUrl||t["media-url"]};case"Quantumult X":return{"open-url":t["open-url"]||t.url||t.openUrl,"media-url":t["media-url"]||t.mediaUrl,"update-pasteboard":t["update-pasteboard"]||t.updatePasteboard};case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,i(a));break;case"Quantumult X":$notify(e,s,r,i(a));case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t.stack)}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 186e29bbf406f041385b03b7d72713fc1ca73e43 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 4 Mar 2024 10:45:52 +0800 Subject: [PATCH 222/311] =?UTF-8?q?feat(boxjs):=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=99=A8=E6=98=BE=E7=A4=BA=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 40 +++++++++++++++++++++++++++------ box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++++++ box/release/box.release.tf.json | 12 ++++++++++ chavy.box.js | 2 +- 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index c643525cc..a7d15b056 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -876,15 +876,20 @@ + - {{ $t('base.dialog.view') }} @@ -896,12 +901,16 @@ {{ $t('base.cmd.cp') }} - + + + - {{ $t('base.dialog.save') }} + {{ + $t('base.dialog.save') }} @@ -1238,7 +1247,7 @@

Surge 费用计算器(open AI 编写)

计算费用

费用:{{ cost.toFixed(2) }}

- + @@ -1550,7 +1559,8 @@

v{{ver.versio dataKey: 'Data Key', dataKeyDesc: 'Input the data key', dataEditor: 'Data Editor', - dataVal: 'Data Value' + dataVal: 'Data Value', + dataEditable: 'This data is not editable', }, reloadDialog: { title: 'Next', @@ -1702,7 +1712,8 @@

v{{ver.versio dataKey: '数据键 (Key)', dataKeyDesc: '输入要查询的数据键, 如: boxjs_host', dataEditor: '数据编辑器', - dataVal: '数据内容' + dataVal: '数据内容', + dataEditable: '该数据不可编辑', }, reloadDialog: { title: '接下来', @@ -2175,6 +2186,9 @@

v{{ver.versio const bak = this.baks.find((bak) => bak.id === bakId) return bak } + }, + viewkeys() { + return Array.from(new Set(this.box.usercfgs.viewkeys)).filter((k) => k) } }, watch: { @@ -2921,13 +2935,25 @@

v{{ver.versio } }) }, + viewkey(key) { + this.ui.viewer.key = key + this.queryData() + }, + + delviewkey(key) { + if (this.ui.viewer.key == key) { + this.ui.viewer.key = '' + } + this.box.usercfgs.viewkeys = this.box.usercfgs.viewkeys.filter((k) => k != key) + }, // 查询数据 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) + const newkeys = [this.ui.viewer.key, ...this.box.usercfgs.viewkeys] + this.box.usercfgs.viewkeys = Array.from(new Set(newkeys)).filter((k) => k) }) }, saveData() { diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 80dceb7e5..78283529f 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.14' +$.version = '0.13.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index cdc5b9cb7..457ca722f 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.13.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 数据查看器显示历史查询记录", + "notes": [ + { + "name": "功能", + "descs": ["数据查看器显示历史查询记录"] + } + ] + }, { "version": "0.12.14", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 695d99a77..7f0fa4433 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.13.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 数据查看器显示历史查询记录", + "notes": [ + { + "name": "功能", + "descs": ["数据查看器显示历史查询记录"] + } + ] + }, { "version": "0.12.14", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 80dceb7e5..78283529f 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.12.14' +$.version = '0.13.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From a2ff94452970a37d30a89b85da5af4b008ac1ca5 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 4 Mar 2024 14:48:07 +0800 Subject: [PATCH 223/311] =?UTF-8?q?fix(boxjs):=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=99=A8=E6=97=A0=E6=B3=95=E5=AF=B9=E7=A9=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=9B=E8=A1=8C=E7=BC=96=E8=BE=91=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 2 +- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 20 ++++++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 2 +- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index a7d15b056..84f329082 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -901,7 +901,7 @@ {{ $t('base.cmd.cp') }} - diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 78283529f..9d09ab73a 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.13.0' +$.version = '0.13.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 457ca722f..a70da2cd3 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.13.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 数据查看器无法对空数据进行编辑问题", + "notes": [ + { + "name": "修复", + "descs": ["数据查看器无法对空数据进行编辑问题"] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.13.0", "tags": ["beta"], @@ -9,6 +25,10 @@ { "name": "功能", "descs": ["数据查看器显示历史查询记录"] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] } ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 7f0fa4433..3fa0238fb 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.13.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 数据查看器无法对空数据进行编辑问题", + "notes": [ + { + "name": "修复", + "descs": ["数据查看器无法对空数据进行编辑问题"] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.13.0", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 78283529f..9d09ab73a 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.13.0' +$.version = '0.13.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 87a211eae88f0826cfcd9670548d40c2f6d2d48f Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 4 Mar 2024 16:31:19 +0800 Subject: [PATCH 224/311] =?UTF-8?q?feat(boxjs):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 19 +++++++++++++++++++ box/chavy.boxjs.js | 30 ++++++++++++++++++++++++++++-- box/release/box.release.json | 19 +++++++++++++++++++ box/release/box.release.tf.json | 19 +++++++++++++++++++ chavy.box.js | 30 ++++++++++++++++++++++++++++-- 5 files changed, 113 insertions(+), 4 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 84f329082..bc860ea25 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -400,6 +400,21 @@ mdi-volume-off + + + + + mdi-volume-off + + v{{ver.versio autoBottomBarDesc: 'Hides when scrolling', muteMode: 'Do Not Disturb', muteModeDesc: 'Disable notifications', + muteQueryAlert: 'Do not display query warnings', + muteQueryAlertDesc: 'Disable notifications', hideHelp: 'Hide Help', hideHelpDesc: 'Hides help button', hideBoxJs: 'Hide BoxJs', @@ -1660,6 +1677,8 @@

v{{ver.versio autoBottomBarDesc: '滚动时自动隐藏', muteMode: '勿扰模式', muteModeDesc: '不发出通知 (仍记日志)', + muteQueryAlert: '不显示查询警告', + muteQueryAlertDesc: '不发出警告 (仍记日志)', hideHelp: '隐藏帮助按钮', hideHelpDesc: '隐藏帮助按钮', hideBoxJs: '隐藏悬浮按钮', diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 9d09ab73a..1b08db984 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.13.1' +$.version = '0.14.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -219,6 +219,33 @@ async function handlePage() { * 处理`查询`请求 */ async function handleQuery() { + if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test($request.headers.referer)) { + const isMuteQueryAlert = [true, 'true'].includes( + $.getdata('@chavy_boxjs_userCfgs.isMuteQueryAlert') + ) + + if (!isMuteQueryAlert) { + $.msg( + $.name, + '❗️发现有脚本或人正在读取你的数据', + [ + '请注意数据安全, 你可以: ', + '1. 在 BoxJs 的脚本日志中查看详情', + '2. 在 BoxJs 的页面 (侧栏) 中 "不显示查询警告"' + ].join('\n') + ) + } + + $.log( + [ + '', + '❗️❗️❗️ 发现有脚本或人正在读取你的数据 ❗️❗️❗️', + JSON.stringify($request), + '' + ].join('\n') + ) + } + const [, query] = $.path.split('/query') if (/^\/boxdata/.test(query)) { $.json = getBoxData() @@ -228,7 +255,6 @@ async function handleQuery() { } 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, diff --git a/box/release/box.release.json b/box/release/box.release.json index a70da2cd3..5e954d4fe 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.14.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 增加数据查询警告", + "notes": [ + { + "name": "数据查询警告", + "descs": [ + "为保护用户数据,当发现不是 boxjs 自身发起的数据查询时,会发出警告 (默认开启)", + "可以在 boxjs 页面侧栏中关闭警告 (但仍会记录日志)" + ] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.13.1", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 3fa0238fb..ba416332b 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.14.0", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "feat(boxjs): 增加数据查询警告", + "notes": [ + { + "name": "数据查询警告", + "descs": [ + "为保护用户数据,当发现不是 boxjs 自身发起的数据查询时,会发出警告 (默认开启)", + "可以在 boxjs 页面侧栏中关闭警告 (但仍会记录日志)" + ] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.13.1", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 9d09ab73a..1b08db984 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.13.1' +$.version = '0.14.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -219,6 +219,33 @@ async function handlePage() { * 处理`查询`请求 */ async function handleQuery() { + if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test($request.headers.referer)) { + const isMuteQueryAlert = [true, 'true'].includes( + $.getdata('@chavy_boxjs_userCfgs.isMuteQueryAlert') + ) + + if (!isMuteQueryAlert) { + $.msg( + $.name, + '❗️发现有脚本或人正在读取你的数据', + [ + '请注意数据安全, 你可以: ', + '1. 在 BoxJs 的脚本日志中查看详情', + '2. 在 BoxJs 的页面 (侧栏) 中 "不显示查询警告"' + ].join('\n') + ) + } + + $.log( + [ + '', + '❗️❗️❗️ 发现有脚本或人正在读取你的数据 ❗️❗️❗️', + JSON.stringify($request), + '' + ].join('\n') + ) + } + const [, query] = $.path.split('/query') if (/^\/boxdata/.test(query)) { $.json = getBoxData() @@ -228,7 +255,6 @@ async function handleQuery() { } 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, From 360cb8962063cd1957b32ce2cef78f7648bf87ea Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 4 Mar 2024 16:33:46 +0800 Subject: [PATCH 225/311] =?UTF-8?q?chore(boxjs):=20=E5=A2=9E=E5=8A=A0=20su?= =?UTF-8?q?rge=20=E6=A8=A1=E5=9D=97=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/rewrite/boxjs.rewrite.surge.sgmodule | 4 ++++ box/rewrite/boxjs.rewrite.surge.tf.sgmodule | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/box/rewrite/boxjs.rewrite.surge.sgmodule b/box/rewrite/boxjs.rewrite.surge.sgmodule index f87d90d82..b4d0c6c98 100644 --- a/box/rewrite/boxjs.rewrite.surge.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.sgmodule @@ -1,5 +1,9 @@ #!name=BoxJs #!desc=http://boxjs.com +#!author=ChavyLeung +#!homepage=https://docs.boxjs.app/ +#!icon=https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png +#!category=BoxJs [General] force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net diff --git a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule index 98a9d8e1d..b4d0c6c98 100644 --- a/box/rewrite/boxjs.rewrite.surge.tf.sgmodule +++ b/box/rewrite/boxjs.rewrite.surge.tf.sgmodule @@ -1,5 +1,9 @@ #!name=BoxJs -#!desc=http://boxjs.net +#!desc=http://boxjs.com +#!author=ChavyLeung +#!homepage=https://docs.boxjs.app/ +#!icon=https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png +#!category=BoxJs [General] force-http-engine-hosts = %APPEND% boxjs.com, boxjs.net, *.boxjs.com, *.boxjs.net From 6ca6128844bebfa0e6f2cf69e78a517df10dc1b3 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 4 Mar 2024 16:55:45 +0800 Subject: [PATCH 226/311] =?UTF-8?q?fix(boxjs):=20boxjs=20=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E7=9A=84=E8=AF=B7=E6=B1=82=E4=BB=8D=E5=8F=91=E5=87=BA?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 5 +++-- box/release/box.release.json | 19 +++++++++++++++++++ box/release/box.release.tf.json | 19 +++++++++++++++++++ chavy.box.js | 5 +++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 1b08db984..e70d513f7 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.0' +$.version = '0.14.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -219,7 +219,8 @@ async function handlePage() { * 处理`查询`请求 */ async function handleQuery() { - if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test($request.headers.referer)) { + const referer = $request.headers.referer || $request.headers.Referer + if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test(referer)) { const isMuteQueryAlert = [true, 'true'].includes( $.getdata('@chavy_boxjs_userCfgs.isMuteQueryAlert') ) diff --git a/box/release/box.release.json b/box/release/box.release.json index 5e954d4fe..904a47091 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.14.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): boxjs 自身的请求仍发出警告问题", + "notes": [ + { + "name": "数据查询警告", + "descs": [ + "为保护用户数据,当发现不是 boxjs 自身发起的数据查询时,会发出警告 (默认开启)", + "可以在 boxjs 页面侧栏中关闭警告 (但仍会记录日志)" + ] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.14.0", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index ba416332b..f5bfdd2be 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.14.1", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): boxjs 自身的请求仍发出警告问题", + "notes": [ + { + "name": "数据查询警告", + "descs": [ + "为保护用户数据,当发现不是 boxjs 自身发起的数据查询时,会发出警告 (默认开启)", + "可以在 boxjs 页面侧栏中关闭警告 (但仍会记录日志)" + ] + }, + { + "name": "感谢", + "descs": ["@xream 反馈"] + } + ] + }, { "version": "0.14.0", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 1b08db984..e70d513f7 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.0' +$.version = '0.14.1' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -219,7 +219,8 @@ async function handlePage() { * 处理`查询`请求 */ async function handleQuery() { - if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test($request.headers.referer)) { + const referer = $request.headers.referer || $request.headers.Referer + if (!/^https?:\/\/(.+\.)?boxjs\.(com|net)\//.test(referer)) { const isMuteQueryAlert = [true, 'true'].includes( $.getdata('@chavy_boxjs_userCfgs.isMuteQueryAlert') ) From eb939372f0a0fb52d2417dd1875ab268f2f02422 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 6 Mar 2024 17:04:50 +0800 Subject: [PATCH 227/311] =?UTF-8?q?fix(boxjs):=20=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E7=8A=B6=E6=80=81=E4=B8=8B=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=8F=91=E5=87=BA=E6=9F=A5=E8=AF=A2=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 9 ++++++++- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 9 ++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index e70d513f7..20284ce6e 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.1' +$.version = '0.14.2' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -226,6 +226,10 @@ async function handleQuery() { ) if (!isMuteQueryAlert) { + // 关闭静默状态 + const _isMute = $.isMute + $.isMute = false + $.msg( $.name, '❗️发现有脚本或人正在读取你的数据', @@ -235,6 +239,9 @@ async function handleQuery() { '2. 在 BoxJs 的页面 (侧栏) 中 "不显示查询警告"' ].join('\n') ) + + // 还原静默状态 + $.isMute = _isMute } $.log( diff --git a/box/release/box.release.json b/box/release/box.release.json index 904a47091..3ad0e6222 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.14.2", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 全局静默状态下没有发出查询警告", + "notes": [ + { + "name": "修复", + "descs": ["全局静默状态下没有发出查询警告"] + }, + { + "name": "感谢", + "descs": ["@MuTu888 反馈"] + } + ] + }, { "version": "0.14.1", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index f5bfdd2be..54460fa7e 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.14.2", + "tags": ["beta"], + "author": "@chavyleung", + "msg": "fix(boxjs): 全局静默状态下没有发出查询警告", + "notes": [ + { + "name": "修复", + "descs": ["全局静默状态下没有发出查询警告"] + }, + { + "name": "感谢", + "descs": ["@MuTu888 反馈"] + } + ] + }, { "version": "0.14.1", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index e70d513f7..20284ce6e 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.1' +$.version = '0.14.2' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -226,6 +226,10 @@ async function handleQuery() { ) if (!isMuteQueryAlert) { + // 关闭静默状态 + const _isMute = $.isMute + $.isMute = false + $.msg( $.name, '❗️发现有脚本或人正在读取你的数据', @@ -235,6 +239,9 @@ async function handleQuery() { '2. 在 BoxJs 的页面 (侧栏) 中 "不显示查询警告"' ].join('\n') ) + + // 还原静默状态 + $.isMute = _isMute } $.log( From 57ca69eb15a3d716346bb08b1f856d87e4222347 Mon Sep 17 00:00:00 2001 From: Chavy Date: Mon, 18 Mar 2024 08:43:07 +0800 Subject: [PATCH 228/311] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20Stash=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/rewrite/boxjs.rewrite.stash.stoverride | 10 ++++++++-- box/rewrite/boxjs.rewrite.stash.tf.stoverride | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/box/rewrite/boxjs.rewrite.stash.stoverride b/box/rewrite/boxjs.rewrite.stash.stoverride index b0506f54c..f974aa92a 100644 --- a/box/rewrite/boxjs.rewrite.stash.stoverride +++ b/box/rewrite/boxjs.rewrite.stash.stoverride @@ -1,5 +1,11 @@ -name: BoxJs -desc: http://boxjs.com +name: "BoxJs" +desc: "http://boxjs.com" +openUrl: "http://boxjs.com" +author: "ChavyLeung" +homepage: "https://docs.boxjs.app/" +manual: "https://docs.boxjs.app/" +icon: "https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png" +category: "BoxJs" http: force-http-engine: diff --git a/box/rewrite/boxjs.rewrite.stash.tf.stoverride b/box/rewrite/boxjs.rewrite.stash.tf.stoverride index 79018947f..f974aa92a 100644 --- a/box/rewrite/boxjs.rewrite.stash.tf.stoverride +++ b/box/rewrite/boxjs.rewrite.stash.tf.stoverride @@ -1,5 +1,11 @@ -name: BoxJs -desc: http://boxjs.net +name: "BoxJs" +desc: "http://boxjs.com" +openUrl: "http://boxjs.com" +author: "ChavyLeung" +homepage: "https://docs.boxjs.app/" +manual: "https://docs.boxjs.app/" +icon: "https://raw.githubusercontent.com/chavyleung/scripts/master/box/icons/BoxJs.png" +category: "BoxJs" http: force-http-engine: From 28bedb52be92f1a36413d4724a9122b433f73ed6 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 27 Mar 2024 09:19:20 +0800 Subject: [PATCH 229/311] =?UTF-8?q?feat(Env.js):=20=E5=AE=8C=E5=96=84=20No?= =?UTF-8?q?de.js=20=E4=B8=8B=E9=94=99=E8=AF=AF=E8=BE=93=E5=87=BA;=20toStr?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E9=A2=9D=E5=A4=96=E5=8F=82=E6=95=B0;=20?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=20logErr=20msg=20=E5=8F=82=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 38 ++++++++++++++++++++++++++++---------- Env.min.js | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Env.js b/Env.js index 398ab1b81..69b317da1 100644 --- a/Env.js +++ b/Env.js @@ -86,9 +86,9 @@ function Env(name, opts) { } } - toStr(obj, defaultValue = null) { + toStr(obj, defaultValue = null, ...args) { try { - return JSON.stringify(obj) + return JSON.stringify(obj, ...args) } catch { return defaultValue } @@ -323,9 +323,15 @@ function Env(name, opts) { request.url += '?' + this.queryStr(request.params) } // followRedirect 禁止重定向 - if (typeof request.followRedirect !== 'undefined' && !request['followRedirect']) { - if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon - if (this.isQuanX()) request.opts ? request['opts']['redirection'] = false : request.opts = { redirection: false } // Quantumult X + if ( + typeof request.followRedirect !== 'undefined' && + !request['followRedirect'] + ) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) + request.opts + ? (request['opts']['redirection'] = false) + : (request.opts = { redirection: false }) // Quantumult X } switch (this.getEnv()) { case 'Surge': @@ -439,9 +445,15 @@ function Env(name, opts) { delete request.headers['content-length'] } // followRedirect 禁止重定向 - if (typeof request.followRedirect !== 'undefined' && !request['followRedirect']) { - if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon - if (this.isQuanX()) request.opts ? request['opts']['redirection'] = false : request.opts = { redirection: false } // Quantumult X + if ( + typeof request.followRedirect !== 'undefined' && + !request['followRedirect'] + ) { + if (this.isSurge() || this.isLoon()) request['auto-redirect'] = false // Surge & Loon + if (this.isQuanX()) + request.opts + ? (request['opts']['redirection'] = false) + : (request.opts = { redirection: false }) // Quantumult X } switch (this.getEnv()) { case 'Surge': @@ -683,10 +695,16 @@ function Env(name, opts) { case 'Shadowrocket': case 'Quantumult X': default: - this.log('', `❗️${this.name}, 错误!`, err) + this.log('', `❗️${this.name}, 错误!`, msg, err) break case 'Node.js': - this.log('', `❗️${this.name}, 错误!`, err.stack) + this.log( + '', + `❗️${this.name}, 错误!`, + msg, + typeof err.message !== 'undefined' ? err.message : err, + err.stack + ) break } } diff --git a/Env.min.js b/Env.min.js index 35e13f9eb..e390d33ed 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,r)=>{s.call(this,t,((t,s,a)=>{t?r(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,r)=>e(r)))}))}runScript(t,e){return new Promise((s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[i,o]=r.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":i,Accept:"*/*"},timeout:a};this.post(n,((t,e,r)=>s(r)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):r?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s=void 0){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of r)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,a]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(r),o=r?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),r)}catch(e){const i={};this.lodash_set(i,a,t),s=this.setval(JSON.stringify(i),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:r,statusCode:a,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:r,statusCode:a,headers:i,rawBody:o,body:n},n)}),(t=>{const{message:r,response:a}=t;e(r,a,a&&s.decode(a.rawBody,this.encoding))}))}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:a,...i}=t;this.got[s](a,i).then((t=>{const{statusCode:s,statusCode:a,headers:i,rawBody:o}=t,n=r.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:i,rawBody:o,body:n},n)}),(t=>{const{message:s,response:a}=t;e(s,a,a&&r.decode(a.rawBody,this.encoding))}))}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",a){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:return{url:t.url||t.openUrl||t["open-url"]};case"Loon":return{openUrl:t.openUrl||t.url||t["open-url"],mediaUrl:t.mediaUrl||t["media-url"]};case"Quantumult X":return{"open-url":t["open-url"]||t.url||t.openUrl,"media-url":t["media-url"]||t.mediaUrl,"update-pasteboard":t["update-pasteboard"]||t.updatePasteboard};case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,i(a));break;case"Quantumult X":$notify(e,s,r,i(a));case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t.stack)}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,r)=>{s.call(this,t,(t,s,a)=>{t?r(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const r=this.getdata(t);if(r)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,r)=>e(r))})}runScript(t,e){return new Promise(s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[i,o]=r.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":i,Accept:"*/*"},timeout:a};this.post(n,(t,e,r)=>s(r))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):r?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of r)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,a]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(r),o=r?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),r)}catch(e){const i={};this.lodash_set(i,a,t),s=this.setval(JSON.stringify(i),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:r,statusCode:a,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:r,statusCode:a,headers:i,rawBody:o,body:n},n)},t=>{const{message:r,response:a}=t;e(r,a,a&&s.decode(a.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:a,...i}=t;this.got[s](a,i).then(t=>{const{statusCode:s,statusCode:a,headers:i,rawBody:o}=t,n=r.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:a}=t;e(s,a,a&&r.decode(a.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",a){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,r=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":r}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,i(a));break;case"Quantumult X":$notify(e,s,r,i(a));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 0850db81128e0f79ea14d9401d8ee77d60c70d82 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 27 Mar 2024 11:12:42 +0800 Subject: [PATCH 230/311] =?UTF-8?q?feat(Env.js):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B9=20logLevel,=20=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?debug=20info=20warn=20error=20=E5=9B=9B=E7=A7=8D=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 26 ++++++++++++++++++++++++++ Env.min.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 69b317da1..5c7566e90 100644 --- a/Env.js +++ b/Env.js @@ -29,6 +29,8 @@ function Env(name, opts) { return new (class { constructor(name, opts) { + this.logLevels = { debug: 0, info: 1, warn: 2, error: 3 } + this.logLevel = 'info' this.name = name this.http = new Http(this) this.data = null @@ -680,6 +682,30 @@ function Env(name, opts) { } } + debug(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.debug) { + this.log('[DEBUG]', ...logs) + } + } + + info(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.info) { + this.log('[INFO]', ...logs) + } + } + + warn(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.warn) { + this.log('[WARN]', ...logs) + } + } + + error(...logs) { + if (this.logLevels[this.logLevel] <= this.logLevels.error) { + this.log('[ERROR]', ...logs) + } + } + log(...logs) { if (logs.length > 0) { this.logs = [...this.logs, ...logs] diff --git a/Env.min.js b/Env.min.js index e390d33ed..bd4b09441 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,r)=>{s.call(this,t,(t,s,a)=>{t?r(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const r=this.getdata(t);if(r)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,r)=>e(r))})}runScript(t,e){return new Promise(s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[i,o]=r.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":i,Accept:"*/*"},timeout:a};this.post(n,(t,e,r)=>s(r))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):r?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of r)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,a]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(r),o=r?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),r)}catch(e){const i={};this.lodash_set(i,a,t),s=this.setval(JSON.stringify(i),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:r,statusCode:a,headers:i,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:r,statusCode:a,headers:i,rawBody:o,body:n},n)},t=>{const{message:r,response:a}=t;e(r,a,a&&s.decode(a.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:a,body:i,bodyBytes:o}=t;e(null,{status:s,statusCode:r,headers:a,body:i,bodyBytes:o},i,o)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:a,...i}=t;this.got[s](a,i).then(t=>{const{statusCode:s,statusCode:a,headers:i,rawBody:o}=t,n=r.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:i,rawBody:o,body:n},n)},t=>{const{message:s,response:a}=t;e(s,a,a&&r.decode(a.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",a){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,r=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":r}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,i(a));break;case"Quantumult X":$notify(e,s,r,i(a));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,r)=>{s.call(this,t,(t,s,i)=>{t?r(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const r=this.getdata(t);if(r)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,r)=>e(r))})}runScript(t,e){return new Promise(s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=e&&e.timeout?e.timeout:i;const[o,a]=r.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:i},headers:{"X-Key":o,Accept:"*/*"},timeout:i};this.post(n,(t,e,r)=>s(r))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),i=JSON.stringify(this.data);s?this.fs.writeFileSync(t,i):r?this.fs.writeFileSync(e,i):this.fs.writeFileSync(t,i)}}lodash_get(t,e,s){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(const t of r)if(i=Object(i)[t],void 0===i)return s;return i}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),i=s?this.getval(s):"";if(i)try{const t=JSON.parse(i);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,i]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(r),a=r?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,i,t),s=this.setval(JSON.stringify(e),r)}catch(e){const o={};this.lodash_set(o,i,t),s=this.setval(JSON.stringify(o),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:i,body:o,bodyBytes:a}=t;e(null,{status:s,statusCode:r,headers:i,body:o,bodyBytes:a},o,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:r,statusCode:i,headers:o,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:r,statusCode:i,headers:o,rawBody:a,body:n},n)},t=>{const{message:r,response:i}=t;e(r,i,i&&s.decode(i.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:i,body:o,bodyBytes:a}=t;e(null,{status:s,statusCode:r,headers:i,body:o,bodyBytes:a},o,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:i,...o}=t;this.got[s](i,o).then(t=>{const{statusCode:s,statusCode:i,headers:o,rawBody:a}=t,n=r.decode(a,this.encoding);e(null,{status:s,statusCode:i,headers:o,rawBody:a,body:n},n)},t=>{const{message:s,response:i}=t;e(s,i,i&&r.decode(i.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",i){const o=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,r=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":r}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,o(i));break;case"Quantumult X":$notify(e,s,r,o(i));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&this.log("[DEBUG]",...t)}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&this.log("[INFO]",...t)}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&this.log("[WARN]",...t)}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&this.log("[ERROR]",...t)}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From c12d6cc2049a4c7721e78f24e581a2353d24e5b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:51:13 +0800 Subject: [PATCH 231/311] chore(deps): bump follow-redirects from 1.15.4 to 1.15.6 (#479) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.4 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 120f60431..7db24c05f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -150,9 +150,9 @@ eventemitter3@^4.0.0: integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== follow-redirects@^1.0.0: - version "1.15.4" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.4.tgz#cdc7d308bf6493126b17ea2191ea0ccf3e535adf" - integrity sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw== + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== function-bind@^1.1.1: version "1.1.1" From ce584e7252e635c812b50636ef94c46b3392be51 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 27 Mar 2024 17:42:50 +0800 Subject: [PATCH 232/311] =?UTF-8?q?feat(Env.js):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B9=20logLevelPrefixs,=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20debug=20info=20warn=20error=20=E5=9B=9B=E7=A7=8D?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=89=8D?= =?UTF-8?q?=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 34 ++++++++++++++++++++++++++++++---- Env.min.js | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Env.js b/Env.js index 5c7566e90..f5ddb94eb 100644 --- a/Env.js +++ b/Env.js @@ -30,6 +30,12 @@ function Env(name, opts) { return new (class { constructor(name, opts) { this.logLevels = { debug: 0, info: 1, warn: 2, error: 3 } + this.logLevelPrefixs = { + debug: '[DEBUG] ', + info: '[INFO] ', + warn: '[WARN] ', + error: '[ERROR] ' + } this.logLevel = 'info' this.name = name this.http = new Http(this) @@ -684,25 +690,45 @@ function Env(name, opts) { debug(...logs) { if (this.logLevels[this.logLevel] <= this.logLevels.debug) { - this.log('[DEBUG]', ...logs) + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.debug}${logs.join(this.logSeparator)}` + ) } } info(...logs) { if (this.logLevels[this.logLevel] <= this.logLevels.info) { - this.log('[INFO]', ...logs) + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.info}${logs.join(this.logSeparator)}` + ) } } warn(...logs) { if (this.logLevels[this.logLevel] <= this.logLevels.warn) { - this.log('[WARN]', ...logs) + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.warn}${logs.join(this.logSeparator)}` + ) } } error(...logs) { if (this.logLevels[this.logLevel] <= this.logLevels.error) { - this.log('[ERROR]', ...logs) + if (logs.length > 0) { + this.logs = [...this.logs, ...logs] + } + console.log( + `${this.logLevelPrefixs.error}${logs.join(this.logSeparator)}` + ) } } diff --git a/Env.min.js b/Env.min.js index bd4b09441..411684b87 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,r)=>{s.call(this,t,(t,s,i)=>{t?r(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const r=this.getdata(t);if(r)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,r)=>e(r))})}runScript(t,e){return new Promise(s=>{let r=this.getdata("@chavy_boxjs_userCfgs.httpapi");r=r?r.replace(/\n/g,"").trim():r;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=e&&e.timeout?e.timeout:i;const[o,a]=r.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:i},headers:{"X-Key":o,Accept:"*/*"},timeout:i};this.post(n,(t,e,r)=>s(r))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e);if(!s&&!r)return{};{const r=s?t:e;try{return JSON.parse(this.fs.readFileSync(r))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),r=!s&&this.fs.existsSync(e),i=JSON.stringify(this.data);s?this.fs.writeFileSync(t,i):r?this.fs.writeFileSync(e,i):this.fs.writeFileSync(t,i)}}lodash_get(t,e,s){const r=e.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(const t of r)if(i=Object(i)[t],void 0===i)return s;return i}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,r)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[r+1])>>0==+e[r+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,r]=/^@(.*?)\.(.*?)$/.exec(t),i=s?this.getval(s):"";if(i)try{const t=JSON.parse(i);e=t?this.lodash_get(t,r,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,r,i]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(r),a=r?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,i,t),s=this.setval(JSON.stringify(e),r)}catch(e){const o={};this.lodash_set(o,i,t),s=this.setval(JSON.stringify(o),r)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:i,body:o,bodyBytes:a}=t;e(null,{status:s,statusCode:r,headers:i,body:o,bodyBytes:a},o,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:r,statusCode:i,headers:o,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:r,statusCode:i,headers:o,rawBody:a,body:n},n)},t=>{const{message:r,response:i}=t;e(r,i,i&&s.decode(i.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,r)=>{!t&&s&&(s.body=r,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,r)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:r,headers:i,body:o,bodyBytes:a}=t;e(null,{status:s,statusCode:r,headers:i,body:o,bodyBytes:a},o,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let r=require("iconv-lite");this.initGotEnv(t);const{url:i,...o}=t;this.got[s](i,o).then(t=>{const{statusCode:s,statusCode:i,headers:o,rawBody:a}=t,n=r.decode(a,this.encoding);e(null,{status:s,statusCode:i,headers:o,rawBody:a,body:n},n)},t=>{const{message:s,response:i}=t;e(s,i,i&&r.decode(i.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let r={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in r)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[e]:("00"+r[e]).substr((""+r[e]).length)));return t}queryStr(t){let e="";for(const s in t){let r=t[s];null!=r&&""!==r&&("object"==typeof r&&(r=JSON.stringify(r)),e+=`${s}=${r}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",r="",i){const o=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,r=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":r}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,r,o(i));break;case"Quantumult X":$notify(e,s,r,o(i));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),r&&t.push(r),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&this.log("[DEBUG]",...t)}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&this.log("[INFO]",...t)}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&this.log("[WARN]",...t)}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&this.log("[ERROR]",...t)}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,r)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):o?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of o)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(o),a=o?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),o)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:r,headers:i,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:o,response:r}=t;e(o,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&o.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,o=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":o}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,i(r));break;case"Quantumult X":$notify(e,s,o,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 9e0012d12046f3dc44195eec4a7f6d8f932bff5c Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 10 Apr 2024 14:12:55 +0800 Subject: [PATCH 233/311] =?UTF-8?q?fix(Env.js):=20h2=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 11 +++++++++-- Env.min.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Env.js b/Env.js index f5ddb94eb..4ca267df3 100644 --- a/Env.js +++ b/Env.js @@ -312,8 +312,15 @@ function Env(name, opts) { this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar() if (opts) { opts.headers = opts.headers ? opts.headers : {} - if (undefined === opts.headers.Cookie && undefined === opts.cookieJar) { - opts.cookieJar = this.ckjar + if (opts) { + opts.headers = opts.headers ? opts.headers : {} + if ( + undefined === opts.headers.cookie && + undefined === opts.headers.Cookie && + undefined === opts.cookieJar + ) { + opts.cookieJar = this.ckjar + } } } } diff --git a/Env.min.js b/Env.min.js index 411684b87..5a422396a 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,r)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):o?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of o)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(o),a=o?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),o)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:r,headers:i,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:o,response:r}=t;e(o,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&o.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,o=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":o}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,i(r));break;case"Quantumult X":$notify(e,s,o,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,r)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):o?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of o)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(o),a=o?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),o)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:r,headers:i,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:o,response:r}=t;e(o,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&o.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,o=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":o}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,i(r));break;case"Quantumult X":$notify(e,s,o,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From c77be0227251cff169073bf1c8ccc659dd3f3d70 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 11 Apr 2024 17:58:14 +0800 Subject: [PATCH 234/311] =?UTF-8?q?feat(Env.js):=20$.msg()=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20surge=20=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84=20?= =?UTF-8?q?=E6=89=93=E5=BC=80=E9=93=BE=E6=8E=A5&=20=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 51 +++++++++++++++++++++++++++++++++++++++------------ Env.min.js | 2 +- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Env.js b/Env.js index 4ca267df3..c9096b5bd 100644 --- a/Env.js +++ b/Env.js @@ -617,6 +617,7 @@ function Env(name, opts) { */ msg(title = name, subt = '', desc = '', opts) { const toEnvOpts = (rawopts) => { + const { $open, $copy } = rawopts switch (typeof rawopts) { case undefined: return rawopts @@ -640,27 +641,53 @@ function Env(name, opts) { case 'Stash': case 'Shadowrocket': default: { + const options = {} + + // 打开URL let openUrl = - rawopts.url || rawopts.openUrl || rawopts['open-url'] - return { url: openUrl } + rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open + if (openUrl) + Object.assign(options, { action: 'open-url', url: openUrl }) + + // 粘贴板 + let copy = + rawopts['update-pasteboard'] || + rawopts.updatePasteboard || + $copy + if (copy) + Object.assign(options, { action: 'clipboard', text: copy }) + + return Object.assign(options, rawopts) } case 'Loon': { + const options = {} + let openUrl = - rawopts.openUrl || rawopts.url || rawopts['open-url'] + rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open + if (openUrl) Object.assign(options, { openUrl }) + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] - return { openUrl, mediaUrl } + if (mediaUrl) Object.assign(options, { mediaUrl }) + + return options } case 'Quantumult X': { + const options = {} + let openUrl = - rawopts['open-url'] || rawopts.url || rawopts.openUrl + rawopts['open-url'] || rawopts.url || rawopts.openUrl || $open + if (openUrl) Object.assign(options, { 'open-url': openUrl }) + let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl - let updatePasteboard = - rawopts['update-pasteboard'] || rawopts.updatePasteboard - return { - 'open-url': openUrl, - 'media-url': mediaUrl, - 'update-pasteboard': updatePasteboard - } + if (mediaUrl) Object.assign(options, { 'media-url': mediaUrl }) + + let copy = + rawopts['update-pasteboard'] || + rawopts.updatePasteboard || + $copy + if (copy) Object.assign(options, { 'update-pasteboard': copy }) + + return options } case 'Node.js': return undefined diff --git a/Env.min.js b/Env.min.js index 5a422396a..ad33136a0 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,r)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[i,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":i,Accept:"*/*"},timeout:r};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):o?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of o)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,r]=/^@(.*?)\.(.*?)$/.exec(e),i=this.getval(o),a=o?"null"===i?null:i||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),o)}catch(e){const i={};this.lodash_set(i,r,t),s=this.setval(JSON.stringify(i),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:r,headers:i,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:o,response:r}=t;e(o,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:r,body:i,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:r,body:i,bodyBytes:a},i,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:r,...i}=t;this.got[s](r,i).then(t=>{const{statusCode:s,statusCode:r,headers:i,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:r,headers:i,rawBody:a,body:n},n)},t=>{const{message:s,response:r}=t;e(s,r,r&&o.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",r){const i=t=>{switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{let e=t.url||t.openUrl||t["open-url"];return{url:e}}case"Loon":{let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}case"Quantumult X":{let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,o=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":o}}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,i(r));break;case"Quantumult X":$notify(e,s,o,i(r));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,i)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=e&&e.timeout?e.timeout:i;const[r,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:i},headers:{"X-Key":r,Accept:"*/*"},timeout:i};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),i=JSON.stringify(this.data);s?this.fs.writeFileSync(t,i):o?this.fs.writeFileSync(e,i):this.fs.writeFileSync(t,i)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(const t of o)if(i=Object(i)[t],void 0===i)return s;return i}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),i=s?this.getval(s):"";if(i)try{const t=JSON.parse(i);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,i]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(o),a=o?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,i,t),s=this.setval(JSON.stringify(e),o)}catch(e){const r={};this.lodash_set(r,i,t),s=this.setval(JSON.stringify(r),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:i,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:i,headers:r,rawBody:a,body:n},n)},t=>{const{message:o,response:i}=t;e(o,i,i&&s.decode(i.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:i,headers:r,rawBody:a,body:n},n)},t=>{const{message:s,response:i}=t;e(s,i,i&&o.decode(i.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",i){const r=t=>{const{$open:e,$copy:s}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const o={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(o,{action:"open-url",url:i});let r=t["update-pasteboard"]||t.updatePasteboard||s;return r&&Object.assign(o,{action:"clipboard",text:r}),Object.assign(o,t)}case"Loon":{const s={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(s,{openUrl:o});let i=t.mediaUrl||t["media-url"];return i&&Object.assign(s,{mediaUrl:i}),s}case"Quantumult X":{const o={};let i=t["open-url"]||t.url||t.openUrl||e;i&&Object.assign(o,{"open-url":i});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(o,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(o,{"update-pasteboard":a}),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,r(i));break;case"Quantumult X":$notify(e,s,o,r(i));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 4fc16b47692572947568aa294e4375d90bfb6f8c Mon Sep 17 00:00:00 2001 From: 2YA Date: Thu, 11 Apr 2024 18:12:06 +0800 Subject: [PATCH 235/311] =?UTF-8?q?add(key):=20=E5=A2=9E=E5=8A=A0=20chavy?= =?UTF-8?q?=5Fboxjs=5FuserCfgs.gist=5Fcache=5Fkey=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E5=AD=98=E5=82=A8=E9=80=9A=E8=BF=87=20boxjs=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E7=9C=8B=E5=99=A8=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=9A=84=20key=EF=BC=8C=E4=BB=A5=E4=BE=BF?= =?UTF-8?q?=E4=BA=8E=20gist=20=E5=A4=87=E4=BB=BD=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=8D=E4=B8=A2=E5=A4=B1=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: dompling <374779789@qq.com> --- box/chavy.boxjs.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 20284ce6e..4943b9f7d 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -312,6 +312,14 @@ async function handleOptions() {} function getBoxData() { const datas = {} + + const extraDatas = + $.getdata(`${$.KEY_usercfgs.replace('#', '@')}.gist_cache_key`) || [] + + extraDatas.forEach((key) => { + datas[key] = $.getdata(key) + }) + const usercfgs = getUserCfgs() const sessions = getAppSessions() const curSessions = getCurSessions() From 0a63e275e1b43001cf6ab0e42cf30cdee083334b Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 11 Apr 2024 23:19:47 +0800 Subject: [PATCH 236/311] =?UTF-8?q?feat(Env.js):=20$.msg:=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20Surge=20=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84`?= =?UTF-8?q?=E6=89=93=E5=BC=80=E9=93=BE=E6=8E=A5`&`=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=96=87=E6=9C=AC`&`=E5=AA=92=E4=BD=93=E5=9B=BE=E7=89=87`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- Env.min.js | 2 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Env.js b/Env.js index c9096b5bd..807def9f3 100644 --- a/Env.js +++ b/Env.js @@ -617,7 +617,7 @@ function Env(name, opts) { */ msg(title = name, subt = '', desc = '', opts) { const toEnvOpts = (rawopts) => { - const { $open, $copy } = rawopts + const { $open, $copy, $media, $mediaMime } = rawopts switch (typeof rawopts) { case undefined: return rawopts @@ -657,7 +657,59 @@ function Env(name, opts) { if (copy) Object.assign(options, { action: 'clipboard', text: copy }) - return Object.assign(options, rawopts) + if ($media) { + let mediaUrl = undefined + let media = undefined + let mime = undefined + // http 开头的网络地址 + if ($media.startsWith('http')) { + mediaUrl = $media + } + // 带标识的 Base64 字符串 + // data:image/png;base64,iVBORw0KGgo... + else if ($media.startsWith('data:')) { + const [data] = $media.split(';') + const [, base64str] = $media.split(',') + media = base64str + mime = data.replace('data:', '') + } + // 没有标识的 Base64 字符串 + // iVBORw0KGgo... + else { + // https://stackoverflow.com/questions/57976898/how-to-get-mime-type-from-base-64-string + const getMimeFromBase64 = (encoded) => { + const signatures = { + 'JVBERi0': 'application/pdf', + 'R0lGODdh': 'image/gif', + 'R0lGODlh': 'image/gif', + 'iVBORw0KGgo': 'image/png', + '/9j/': 'image/jpg' + } + for (var s in signatures) { + if (encoded.indexOf(s) === 0) { + return signatures[s] + } + } + return null + } + media = $media + mime = getMimeFromBase64($media) + } + + Object.assign(options, { + 'media-url': mediaUrl, + 'media-base64': media, + 'media-base64-mime': $mediaMime ?? mime + }) + } + + // 未处理属性, 直接转发 + Object.assign(options, { + 'auto-dismiss': rawopts['auto-dismiss'], + 'sound': rawopts['sound'] + }) + + return options } case 'Loon': { const options = {} diff --git a/Env.min.js b/Env.min.js index ad33136a0..75268b29b 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,o)=>{s.call(this,t,(t,s,i)=>{t?o(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const o=this.getdata(t);if(o)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,o)=>e(o))})}runScript(t,e){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=e&&e.timeout?e.timeout:i;const[r,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:i},headers:{"X-Key":r,Accept:"*/*"},timeout:i};this.post(n,(t,e,o)=>s(o))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e);if(!s&&!o)return{};{const o=s?t:e;try{return JSON.parse(this.fs.readFileSync(o))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),o=!s&&this.fs.existsSync(e),i=JSON.stringify(this.data);s?this.fs.writeFileSync(t,i):o?this.fs.writeFileSync(e,i):this.fs.writeFileSync(t,i)}}lodash_get(t,e,s){const o=e.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(const t of o)if(i=Object(i)[t],void 0===i)return s;return i}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,o)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[o+1])>>0==+e[o+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(t),i=s?this.getval(s):"";if(i)try{const t=JSON.parse(i);e=t?this.lodash_get(t,o,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,o,i]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(o),a=o?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,i,t),s=this.setval(JSON.stringify(e),o)}catch(e){const r={};this.lodash_set(r,i,t),s=this.setval(JSON.stringify(r),o)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:o,statusCode:i,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:o,statusCode:i,headers:r,rawBody:a,body:n},n)},t=>{const{message:o,response:i}=t;e(o,i,i&&s.decode(i.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,o)=>{!t&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,o)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,rawBody:a}=t,n=o.decode(a,this.encoding);e(null,{status:s,statusCode:i,headers:r,rawBody:a,body:n},n)},t=>{const{message:s,response:i}=t;e(s,i,i&&o.decode(i.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in o)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?o[e]:("00"+o[e]).substr((""+o[e]).length)));return t}queryStr(t){let e="";for(const s in t){let o=t[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),e+=`${s}=${o}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",o="",i){const r=t=>{const{$open:e,$copy:s}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const o={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(o,{action:"open-url",url:i});let r=t["update-pasteboard"]||t.updatePasteboard||s;return r&&Object.assign(o,{action:"clipboard",text:r}),Object.assign(o,t)}case"Loon":{const s={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(s,{openUrl:o});let i=t.mediaUrl||t["media-url"];return i&&Object.assign(s,{mediaUrl:i}),s}case"Quantumult X":{const o={};let i=t["open-url"]||t.url||t.openUrl||e;i&&Object.assign(o,{"open-url":i});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(o,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(o,{"update-pasteboard":a}),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,o,r(i));break;case"Quantumult X":$notify(e,s,o,r(i));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),o&&t.push(o),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;return"POST"===t&&(s=this.post),new Promise((t,o)=>{s.call(this,e,(e,s,i)=>{e?o(e):t(s)})})}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;const o=this.getdata(e);if(o)try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise(t=>{this.get({url:e},(e,s,o)=>t(o))})}runScript(e,t){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=t&&t.timeout?t.timeout:i;const[r,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:i},headers:{"X-Key":r,Accept:"*/*"},timeout:i};this.post(n,(e,t,o)=>s(o))}).catch(e=>this.logErr(e))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),o=!s&&this.fs.existsSync(t);if(!s&&!o)return{};{const o=s?e:t;try{return JSON.parse(this.fs.readFileSync(o))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),o=!s&&this.fs.existsSync(t),i=JSON.stringify(this.data);s?this.fs.writeFileSync(e,i):o?this.fs.writeFileSync(t,i):this.fs.writeFileSync(e,i)}}lodash_get(e,t,s){const o=t.replace(/\[(\d+)\]/g,".$1").split(".");let i=e;for(const e of o)if(i=Object(i)[e],void 0===i)return s;return i}lodash_set(e,t,s){return Object(e)!==e?e:(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce((e,s,o)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[o+1])>>0==+t[o+1]?[]:{},e)[t[t.length-1]]=s,e)}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(e),i=s?this.getval(s):"";if(i)try{const e=JSON.parse(i);t=e?this.lodash_get(e,o,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,o,i]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(o),a=o?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,i,e),s=this.setval(JSON.stringify(t),o)}catch(t){const r={};this.lodash_set(r,i,e),s=this.setval(JSON.stringify(r),o)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,(e,s,o)=>{!e&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then(e=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},e=>t(e&&e.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",(e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}}).then(e=>{const{statusCode:o,statusCode:i,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:o,statusCode:i,headers:r,rawBody:a,body:n},n)},e=>{const{message:o,response:i}=e;t(o,i,i&&s.decode(i.rawBody,this.encoding))})}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,(e,s,o)=>{!e&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,o)});break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then(e=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},e=>t(e&&e.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(e);const{url:i,...r}=e;this.got[s](i,r).then(e=>{const{statusCode:s,statusCode:i,headers:r,rawBody:a}=e,n=o.decode(a,this.encoding);t(null,{status:s,statusCode:i,headers:r,rawBody:a,body:n},n)},e=>{const{message:s,response:i}=e;t(s,i,i&&o.decode(i.rawBody,this.encoding))})}}time(e,t=null){const s=t?new Date(t):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in o)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?o[t]:("00"+o[t]).substr((""+o[t]).length)));return e}queryStr(e){let t="";for(const s in e){let o=e[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),t+=`${s}=${o}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",o="",i){const r=e=>{const{$open:t,$copy:s,$media:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const i={};let r=e.openUrl||e.url||e["open-url"]||t;r&&Object.assign(i,{action:"open-url",url:r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(i,{action:"clipboard",text:a}),o&&Object.assign(i,{"media-base64":o,"media-base64-mime":"image"}),Object.assign(i,e)}case"Loon":{const s={};let o=e.openUrl||e.url||e["open-url"]||t;o&&Object.assign(s,{openUrl:o});let i=e.mediaUrl||e["media-url"];return i&&Object.assign(s,{mediaUrl:i}),s}case"Quantumult X":{const o={};let i=e["open-url"]||e.url||e.openUrl||t;i&&Object.assign(o,{"open-url":i});let r=e["media-url"]||e.mediaUrl;r&&Object.assign(o,{"media-url":r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(o,{"update-pasteboard":a}),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,o,r(i));break;case"Quantumult X":$notify(t,s,o,r(i));break;case"Node.js":}if(!this.isMuteLog){let e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];e.push(t),s&&e.push(s),o&&e.push(o),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t,e);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t,void 0!==e.message?e.message:e,e.stack)}}wait(e){return new Promise(t=>setTimeout(t,e))}done(e={}){const t=(new Date).getTime(),s=(t-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file From d9bb37b2223c2aa030622e9c8936bcc03f83c9a8 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 11 Apr 2024 23:28:44 +0800 Subject: [PATCH 237/311] =?UTF-8?q?feat(boxjs):=20=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E7=9C=8B=E5=99=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=BF=87=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=8C=E4=BC=9A=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=85=A8=E5=B1=80=E5=A4=87=E4=BB=BD=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 16 ++++++++++++++++ box/release/box.release.tf.json | 16 ++++++++++++++++ chavy.box.js | 10 +++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 4943b9f7d..35685e595 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.2' +$.version = '0.15.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 3ad0e6222..7f08fcc77 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.15.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 通过数据查看器查询过的数据,会加入全局备份的名单中", + "notes": [ + { + "name": "新增", + "descs": ["通过数据查看器查询过的数据,会加入全局备份的名单中"] + }, + { + "name": "感谢", + "descs": ["@dompling PR"] + } + ] + }, { "version": "0.14.2", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 54460fa7e..ce30ca2f4 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,21 @@ { "releases": [ + { + "version": "0.15.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 通过数据查看器查询过的数据,会加入全局备份的名单中", + "notes": [ + { + "name": "新增", + "descs": ["通过数据查看器查询过的数据,会加入全局备份的名单中"] + }, + { + "name": "感谢", + "descs": ["@dompling PR"] + } + ] + }, { "version": "0.14.2", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 20284ce6e..35685e595 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.14.2' +$.version = '0.15.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -312,6 +312,14 @@ async function handleOptions() {} function getBoxData() { const datas = {} + + const extraDatas = + $.getdata(`${$.KEY_usercfgs.replace('#', '@')}.gist_cache_key`) || [] + + extraDatas.forEach((key) => { + datas[key] = $.getdata(key) + }) + const usercfgs = getUserCfgs() const sessions = getAppSessions() const curSessions = getCurSessions() From 4b6ea54f35fbd555b6776f52584fc3edb16b1e07 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 00:05:23 +0800 Subject: [PATCH 238/311] =?UTF-8?q?fix(Env.js):=20=E4=BF=AE=E5=A4=8D=20$.m?= =?UTF-8?q?sg=20=E7=9A=84=20$media=20=E5=8F=82=E6=95=B0=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 7 +++---- Env.min.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Env.js b/Env.js index 807def9f3..8983b5fd4 100644 --- a/Env.js +++ b/Env.js @@ -654,8 +654,9 @@ function Env(name, opts) { rawopts['update-pasteboard'] || rawopts.updatePasteboard || $copy - if (copy) + if (copy) { Object.assign(options, { action: 'clipboard', text: copy }) + } if ($media) { let mediaUrl = undefined @@ -699,16 +700,14 @@ function Env(name, opts) { Object.assign(options, { 'media-url': mediaUrl, 'media-base64': media, - 'media-base64-mime': $mediaMime ?? mime + 'media-base64-mime': $mediaMime || mime }) } - // 未处理属性, 直接转发 Object.assign(options, { 'auto-dismiss': rawopts['auto-dismiss'], 'sound': rawopts['sound'] }) - return options } case 'Loon': { diff --git a/Env.min.js b/Env.min.js index 75268b29b..733a84fd3 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;return"POST"===t&&(s=this.post),new Promise((t,o)=>{s.call(this,e,(e,s,i)=>{e?o(e):t(s)})})}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;const o=this.getdata(e);if(o)try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise(t=>{this.get({url:e},(e,s,o)=>t(o))})}runScript(e,t){return new Promise(s=>{let o=this.getdata("@chavy_boxjs_userCfgs.httpapi");o=o?o.replace(/\n/g,"").trim():o;let i=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");i=i?1*i:20,i=t&&t.timeout?t.timeout:i;const[r,a]=o.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:i},headers:{"X-Key":r,Accept:"*/*"},timeout:i};this.post(n,(e,t,o)=>s(o))}).catch(e=>this.logErr(e))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),o=!s&&this.fs.existsSync(t);if(!s&&!o)return{};{const o=s?e:t;try{return JSON.parse(this.fs.readFileSync(o))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),o=!s&&this.fs.existsSync(t),i=JSON.stringify(this.data);s?this.fs.writeFileSync(e,i):o?this.fs.writeFileSync(t,i):this.fs.writeFileSync(e,i)}}lodash_get(e,t,s){const o=t.replace(/\[(\d+)\]/g,".$1").split(".");let i=e;for(const e of o)if(i=Object(i)[e],void 0===i)return s;return i}lodash_set(e,t,s){return Object(e)!==e?e:(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce((e,s,o)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[o+1])>>0==+t[o+1]?[]:{},e)[t[t.length-1]]=s,e)}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,o]=/^@(.*?)\.(.*?)$/.exec(e),i=s?this.getval(s):"";if(i)try{const e=JSON.parse(i);t=e?this.lodash_get(e,o,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,o,i]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(o),a=o?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,i,e),s=this.setval(JSON.stringify(t),o)}catch(t){const r={};this.lodash_set(r,i,e),s=this.setval(JSON.stringify(r),o)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,(e,s,o)=>{!e&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,o)});break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then(e=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},e=>t(e&&e.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",(e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}}).then(e=>{const{statusCode:o,statusCode:i,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:o,statusCode:i,headers:r,rawBody:a,body:n},n)},e=>{const{message:o,response:i}=e;t(o,i,i&&s.decode(i.rawBody,this.encoding))})}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,(e,s,o)=>{!e&&s&&(s.body=o,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,o)});break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then(e=>{const{statusCode:s,statusCode:o,headers:i,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:o,headers:i,body:r,bodyBytes:a},r,a)},e=>t(e&&e.error||"UndefinedError"));break;case"Node.js":let o=require("iconv-lite");this.initGotEnv(e);const{url:i,...r}=e;this.got[s](i,r).then(e=>{const{statusCode:s,statusCode:i,headers:r,rawBody:a}=e,n=o.decode(a,this.encoding);t(null,{status:s,statusCode:i,headers:r,rawBody:a,body:n},n)},e=>{const{message:s,response:i}=e;t(s,i,i&&o.decode(i.rawBody,this.encoding))})}}time(e,t=null){const s=t?new Date(t):new Date;let o={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in o)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?o[t]:("00"+o[t]).substr((""+o[t]).length)));return e}queryStr(e){let t="";for(const s in e){let o=e[s];null!=o&&""!==o&&("object"==typeof o&&(o=JSON.stringify(o)),t+=`${s}=${o}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",o="",i){const r=e=>{const{$open:t,$copy:s,$media:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const i={};let r=e.openUrl||e.url||e["open-url"]||t;r&&Object.assign(i,{action:"open-url",url:r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(i,{action:"clipboard",text:a}),o&&Object.assign(i,{"media-base64":o,"media-base64-mime":"image"}),Object.assign(i,e)}case"Loon":{const s={};let o=e.openUrl||e.url||e["open-url"]||t;o&&Object.assign(s,{openUrl:o});let i=e.mediaUrl||e["media-url"];return i&&Object.assign(s,{mediaUrl:i}),s}case"Quantumult X":{const o={};let i=e["open-url"]||e.url||e.openUrl||t;i&&Object.assign(o,{"open-url":i});let r=e["media-url"]||e.mediaUrl;r&&Object.assign(o,{"media-url":r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(o,{"update-pasteboard":a}),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,o,r(i));break;case"Quantumult X":$notify(t,s,o,r(i));break;case"Node.js":}if(!this.isMuteLog){let e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];e.push(t),s&&e.push(s),o&&e.push(o),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t,e);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t,void 0!==e.message?e.message:e,e.stack)}}wait(e){return new Promise(t=>setTimeout(t,e))}done(e={}){const t=(new Date).getTime(),s=(t-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t=void 0,e=void 0,s=void 0;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{const t=t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null};e=i,s=t(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o||s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From f03ba62e84cc1efe36e23e52eef4f04c89bb0d48 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 00:35:29 +0800 Subject: [PATCH 239/311] =?UTF-8?q?chore(Env.js):=20=E4=BD=BF=E7=94=A8=20M?= =?UTF-8?q?inifyAll=20=E9=87=8D=E6=96=B0=E6=89=93=E5=8C=85=20Env.min.js=20?= =?UTF-8?q?(=E4=B8=BA=E4=BA=86=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E8=AF=AD=E6=B3=95=E7=B3=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 2 +- Env.min.js | 2 +- package-lock.json | 749 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +- yarn.lock | 19 +- 5 files changed, 766 insertions(+), 11 deletions(-) create mode 100644 package-lock.json diff --git a/Env.js b/Env.js index 8983b5fd4..92f0112cc 100644 --- a/Env.js +++ b/Env.js @@ -700,7 +700,7 @@ function Env(name, opts) { Object.assign(options, { 'media-url': mediaUrl, 'media-base64': media, - 'media-base64-mime': $mediaMime || mime + 'media-base64-mime': $mediaMime ?? mime }) } diff --git a/Env.min.js b/Env.min.js index 733a84fd3..8248b741e 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,o)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)},t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)},t=>e(t&&t.error||"UndefinedError"));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then(t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)},t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t=void 0,e=void 0,s=void 0;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{const t=t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null};e=i,s=t(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o||s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":}if(!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,t);break;case"Node.js":this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,e,void 0!==t.message?t.message:t,t.stack)}}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;switch(this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,a)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[r,o]=i.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":r,Accept:"*/*"},timeout:a};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):i?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of i)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,a]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),o=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,a,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:a,body:r,bodyBytes:o}=t;e(null,{status:s,statusCode:i,headers:a,body:r,bodyBytes:o},r,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:a,headers:r,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:i,statusCode:a,headers:r,rawBody:o,body:n},n)}),(t=>{const{message:i,response:a}=t;e(i,a,a&&s.decode(a.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:a,body:r,bodyBytes:o}=t;e(null,{status:s,statusCode:i,headers:a,body:r,bodyBytes:o},r,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:a,...r}=t;this.got[s](a,r).then((t=>{const{statusCode:s,statusCode:a,headers:r,rawBody:o}=t,n=i.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:r,rawBody:o,body:n},n)}),(t=>{const{message:s,response:a}=t;e(s,a,a&&i.decode(a.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",a){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:a}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(r,{action:"open-url",url:o});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,a]=i.split(",");e=a,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":a??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let a=t.mediaUrl||t["media-url"];return a&&Object.assign(s,{mediaUrl:a}),s}case"Quantumult X":{const i={};let a=t["open-url"]||t.url||t.openUrl||e;a&&Object.assign(i,{"open-url":a});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let o=t["update-pasteboard"]||t.updatePasteboard||s;return o&&Object.assign(i,{"update-pasteboard":o}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(a));break;case"Quantumult X":$notify(e,s,i,r(a));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&t.length>0&&(this.logs=[...this.logs,...t])}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&t.length>0&&(this.logs=[...this.logs,...t])}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&t.length>0&&(this.logs=[...this.logs,...t])}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&t.length>0&&(this.logs=[...this.logs,...t])}log(...t){t.length>0&&(this.logs=[...this.logs,...t])}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..a6bf4776f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,749 @@ +{ + "name": "chavy_scripts", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "chavy_scripts", + "version": "1.0.0", + "dependencies": { + "crypto-js": "^4.2.0", + "got": "^11.8.5", + "http-server": "^0.12.3", + "iconv-lite": "0.6.3", + "tough-cookie": "^4.1.3" + }, + "devDependencies": { + "prettier": "^3.2.5" + } + }, + "node_modules/@sindresorhus/is": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.0.tgz", + "integrity": "sha512-FyD2meJpDPjyNQejSjvnhpgI/azsQkA4lGbuu5BQZfjvJ9cbRZXzeWL2HceCekW4lixO9JPesIIQkSoLjeJHNQ==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, + "node_modules/@szmarczak/http-timer": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz", + "integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==", + "license": "MIT", + "dependencies": { + "defer-to-connect": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@types/cacheable-request": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz", + "integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==", + "license": "MIT", + "dependencies": { + "@types/http-cache-semantics": "*", + "@types/keyv": "*", + "@types/node": "*", + "@types/responselike": "*" + } + }, + "node_modules/@types/http-cache-semantics": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz", + "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==", + "license": "MIT" + }, + "node_modules/@types/keyv": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz", + "integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "14.14.20", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", + "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==", + "license": "MIT" + }, + "node_modules/@types/responselike": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", + "integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==", + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "license": "MIT", + "dependencies": { + "lodash": "^4.17.14" + } + }, + "node_modules/basic-auth": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-1.1.0.tgz", + "integrity": "sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ=", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cacheable-lookup": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", + "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==", + "license": "MIT", + "engines": { + "node": ">=10.6.0" + } + }, + "node_modules/cacheable-request": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz", + "integrity": "sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==", + "license": "MIT", + "dependencies": { + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^4.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^6.0.1", + "responselike": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/clone-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", + "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", + "license": "MIT", + "dependencies": { + "mimic-response": "^1.0.0" + } + }, + "node_modules/clone-response/node_modules/mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "license": "MIT", + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/corser": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz", + "integrity": "sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c=", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "license": "MIT", + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/defer-to-connect": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz", + "integrity": "sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/ecstatic": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz", + "integrity": "sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==", + "license": "MIT", + "dependencies": { + "he": "^1.1.1", + "mime": "^1.6.0", + "minimist": "^1.1.0", + "url-join": "^2.0.5" + }, + "bin": { + "ecstatic": "lib/ecstatic.js" + } + }, + "node_modules/end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, + "node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "license": "MIT" + }, + "node_modules/follow-redirects": { + "version": "1.15.4", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "license": "MIT" + }, + "node_modules/get-intrinsic": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz", + "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "license": "MIT", + "dependencies": { + "pump": "^3.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/got": { + "version": "11.8.5", + "resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz", + "integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==", + "license": "MIT", + "dependencies": { + "@sindresorhus/is": "^4.0.0", + "@szmarczak/http-timer": "^4.0.5", + "@types/cacheable-request": "^6.0.1", + "@types/responselike": "^1.0.0", + "cacheable-lookup": "^5.0.3", + "cacheable-request": "^7.0.2", + "decompress-response": "^6.0.0", + "http2-wrapper": "^1.0.0-beta.5.2", + "lowercase-keys": "^2.0.0", + "p-cancelable": "^2.0.0", + "responselike": "^2.0.0" + }, + "engines": { + "node": ">=10.19.0" + }, + "funding": { + "url": "https://github.com/sindresorhus/got?sponsor=1" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "license": "MIT", + "bin": { + "he": "bin/he" + } + }, + "node_modules/http-cache-semantics": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", + "license": "BSD-2-Clause" + }, + "node_modules/http-proxy": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", + "license": "MIT", + "dependencies": { + "eventemitter3": "^4.0.0", + "follow-redirects": "^1.0.0", + "requires-port": "^1.0.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/http-server": { + "version": "0.12.3", + "resolved": "https://registry.npmjs.org/http-server/-/http-server-0.12.3.tgz", + "integrity": "sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA==", + "license": "MIT", + "dependencies": { + "basic-auth": "^1.0.3", + "colors": "^1.4.0", + "corser": "^2.0.1", + "ecstatic": "^3.3.2", + "http-proxy": "^1.18.0", + "minimist": "^1.2.5", + "opener": "^1.5.1", + "portfinder": "^1.0.25", + "secure-compare": "3.0.1", + "union": "~0.5.0" + }, + "bin": { + "hs": "bin/http-server", + "http-server": "bin/http-server" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/http2-wrapper": { + "version": "1.0.0-beta.5.2", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.0-beta.5.2.tgz", + "integrity": "sha512-xYz9goEyBnC8XwXDTuC/MZ6t+MrKVQZOk4s7+PaDkwIsQd8IwqvM+0M6bA/2lvG8GHXcPdf+MejTUeO2LCPCeQ==", + "license": "MIT", + "dependencies": { + "quick-lru": "^5.1.1", + "resolve-alpn": "^1.0.0" + }, + "engines": { + "node": ">=10.19.0" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "license": "MIT" + }, + "node_modules/keyv": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.3.tgz", + "integrity": "sha512-zdGa2TOpSZPq5mU6iowDARnMBZgtCqJ11dJROFi6tg6kTn4nuUdU09lFyLFSaHrWqpIJ+EBq4E8/Dc0Vx5vLdA==", + "license": "MIT", + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "license": "MIT" + }, + "node_modules/lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "license": "MIT" + }, + "node_modules/mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.5" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/normalize-url": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", + "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/opener": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", + "integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==", + "license": "(WTFPL OR MIT)", + "bin": { + "opener": "bin/opener-bin.js" + } + }, + "node_modules/p-cancelable": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz", + "integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/portfinder": { + "version": "1.0.28", + "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz", + "integrity": "sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA==", + "license": "MIT", + "dependencies": { + "async": "^2.6.2", + "debug": "^3.1.1", + "mkdirp": "^0.5.5" + }, + "engines": { + "node": ">= 0.12.0" + } + }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/psl": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", + "license": "MIT" + }, + "node_modules/pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "license": "MIT" + }, + "node_modules/quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", + "license": "MIT" + }, + "node_modules/resolve-alpn": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.0.0.tgz", + "integrity": "sha512-rTuiIEqFmGxne4IovivKSDzld2lWW9QCjqv80SYjPgf+gS35eaCAjaP54CCwGAwBtnCsvNLYtqxe1Nw+i6JEmA==", + "license": "MIT" + }, + "node_modules/responselike": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", + "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==", + "license": "MIT", + "dependencies": { + "lowercase-keys": "^2.0.0" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/secure-compare": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/secure-compare/-/secure-compare-3.0.1.tgz", + "integrity": "sha1-8aAymzCLIh+uN7mXTz1XjQypmeM=", + "license": "MIT" + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "license": "MIT", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "license": "BSD-3-Clause", + "dependencies": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/union": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz", + "integrity": "sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==", + "dependencies": { + "qs": "^6.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "license": "MIT", + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/url-join": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz", + "integrity": "sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=", + "license": "MIT" + }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "license": "MIT", + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json index 44abe7ac8..83b4bac0b 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,8 @@ "http-server": "^0.12.3", "iconv-lite": "0.6.3", "tough-cookie": "^4.1.3" + }, + "devDependencies": { + "prettier": "^3.2.5" } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 7db24c05f..c0369ce22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -105,7 +105,7 @@ corser@^2.0.1: crypto-js@^4.2.0: version "4.2.0" - resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" + resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz" integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== debug@^3.1.1: @@ -150,9 +150,7 @@ eventemitter3@^4.0.0: integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== follow-redirects@^1.0.0: - version "1.15.6" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" - integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + version "1.15.4" function-bind@^1.1.1: version "1.1.1" @@ -344,6 +342,11 @@ portfinder@^1.0.25: debug "^3.1.1" mkdirp "^0.5.5" +prettier@^3.2.5: + version "3.2.5" + resolved "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz" + integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A== + psl@^1.1.33: version "1.8.0" resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz" @@ -371,7 +374,7 @@ qs@^6.4.0: querystringify@^2.1.1: version "2.2.0" - resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" + resolved "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz" integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ== quick-lru@^5.1.1: @@ -417,7 +420,7 @@ side-channel@^1.0.4: tough-cookie@^4.1.3: version "4.1.3" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.3.tgz#97b9adb0728b42280aa3d814b6b999b2ff0318bf" + resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz" integrity sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw== dependencies: psl "^1.1.33" @@ -434,7 +437,7 @@ union@~0.5.0: universalify@^0.2.0: version "0.2.0" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0" + resolved "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz" integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg== url-join@^2.0.5: @@ -444,7 +447,7 @@ url-join@^2.0.5: url-parse@^1.5.3: version "1.5.10" - resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1" + resolved "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz" integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ== dependencies: querystringify "^2.1.1" From 56b09b58834ca28df72a39fa363f8d0879f82657 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 00:58:04 +0800 Subject: [PATCH 240/311] =?UTF-8?q?fix(Env.js):=20=E4=BF=AE=E5=A4=8D=20con?= =?UTF-8?q?sole.log=20=E6=89=93=E5=8C=85=E6=97=B6=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=8E=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Env.min.js b/Env.min.js index 8248b741e..8ea4479b0 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,a)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let a=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");a=a?1*a:20,a=e&&e.timeout?e.timeout:a;const[r,o]=i.split("@"),n={url:`http://${o}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:a},headers:{"X-Key":r,Accept:"*/*"},timeout:a};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),a=JSON.stringify(this.data);s?this.fs.writeFileSync(t,a):i?this.fs.writeFileSync(e,a):this.fs.writeFileSync(t,a)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let a=t;for(const t of i)if(a=Object(a)[t],void 0===a)return s;return a}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),a=s?this.getval(s):"";if(a)try{const t=JSON.parse(a);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,a]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),o=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(o);this.lodash_set(e,a,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,a,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:a,body:r,bodyBytes:o}=t;e(null,{status:s,statusCode:i,headers:a,body:r,bodyBytes:o},r,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:a,headers:r,rawBody:o}=t,n=s.decode(o,this.encoding);e(null,{status:i,statusCode:a,headers:r,rawBody:o,body:n},n)}),(t=>{const{message:i,response:a}=t;e(i,a,a&&s.decode(a.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:a,body:r,bodyBytes:o}=t;e(null,{status:s,statusCode:i,headers:a,body:r,bodyBytes:o},r,o)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:a,...r}=t;this.got[s](a,r).then((t=>{const{statusCode:s,statusCode:a,headers:r,rawBody:o}=t,n=i.decode(o,this.encoding);e(null,{status:s,statusCode:a,headers:r,rawBody:o,body:n},n)}),(t=>{const{message:s,response:a}=t;e(s,a,a&&i.decode(a.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",a){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:a}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(r,{action:"open-url",url:o});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,a]=i.split(",");e=a,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":a??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let a=t.mediaUrl||t["media-url"];return a&&Object.assign(s,{mediaUrl:a}),s}case"Quantumult X":{const i={};let a=t["open-url"]||t.url||t.openUrl||e;a&&Object.assign(i,{"open-url":a});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let o=t["update-pasteboard"]||t.updatePasteboard||s;return o&&Object.assign(i,{"update-pasteboard":o}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(a));break;case"Quantumult X":$notify(e,s,i,r(a));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&t.length>0&&(this.logs=[...this.logs,...t])}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&t.length>0&&(this.logs=[...this.logs,...t])}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&t.length>0&&(this.logs=[...this.logs,...t])}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&t.length>0&&(this.logs=[...this.logs,...t])}log(...t){t.length>0&&(this.logs=[...this.logs,...t])}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;return"POST"===t&&(s=this.post),new Promise(((t,i)=>{s.call(this,e,((e,s,o)=>{e?i(e):t(s)}))}))}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;if(this.getdata(e))try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise((t=>{this.get({url:e},((e,s,i)=>t(i)))}))}runScript(e,t){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=t&&t.timeout?t.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((e,t,i)=>s(i)))})).catch((e=>this.logErr(e)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t);if(!s&&!i)return{};{const i=s?e:t;try{return JSON.parse(this.fs.readFileSync(i))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t),o=JSON.stringify(this.data);s?this.fs.writeFileSync(e,o):i?this.fs.writeFileSync(t,o):this.fs.writeFileSync(e,o)}}lodash_get(e,t,s){const i=t.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(const e of i)if(o=Object(o)[e],void 0===o)return s;return o}lodash_set(e,t,s){return Object(e)!==e||(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce(((e,s,i)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[i+1])>>0==+t[i+1]?[]:{}),e)[t[t.length-1]]=s),e}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(e),o=s?this.getval(s):"";if(o)try{const e=JSON.parse(o);t=e?this.lodash_get(e,i,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,o,e),s=this.setval(JSON.stringify(t),i)}catch(t){const r={};this.lodash_set(r,o,e),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",((e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}})).then((e=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:i,response:o}=e;t(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(e);const{url:o,...r}=e;this.got[s](o,r).then((e=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=e,n=i.decode(a,this.encoding);t(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:s,response:o}=e;t(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(e,t=null){const s=t?new Date(t):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in i)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?i[t]:("00"+i[t]).substr((""+i[t]).length)));return e}queryStr(e){let t="";for(const s in e){let i=e[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),t+=`${s}=${i}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",i="",o){const r=e=>{const{$open:t,$copy:s,$media:i,$mediaMime:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=e.openUrl||e.url||e["open-url"]||t;a&&Object.assign(r,{action:"open-url",url:a});let n=e["update-pasteboard"]||e.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let e,t,s;if(i.startsWith("http"))e=i;else if(i.startsWith("data:")){const[e]=i.split(";"),[,o]=i.split(",");t=o,s=e.replace("data:","")}else{t=i,s=(e=>{const t={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in t)if(0===e.indexOf(s))return t[s];return null})(i)}Object.assign(r,{"media-url":e,"media-base64":t,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":e["auto-dismiss"],sound:e.sound}),r}case"Loon":{const s={};let i=e.openUrl||e.url||e["open-url"]||t;i&&Object.assign(s,{openUrl:i});let o=e.mediaUrl||e["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=e["open-url"]||e.url||e.openUrl||t;o&&Object.assign(i,{"open-url":o});let r=e["media-url"]||e.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,i,r(o));break;case"Quantumult X":$notify(t,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let e=["","==============📣系统通知📣=============="];e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t,e);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t,void 0!==e.message?e.message:e,e.stack);break}}wait(e){return new Promise((t=>setTimeout(t,e)))}done(e={}){const t=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${t} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file From 24035eab66fbc548b16666ceb2fc601f251fff8c Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 01:13:11 +0800 Subject: [PATCH 241/311] =?UTF-8?q?fix(Env.js):=20=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=BE=93=E5=85=A5=20undefined=20=E5=92=8C=20?= =?UTF-8?q?null=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 10 +- Env.min.js | 698 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 702 insertions(+), 6 deletions(-) diff --git a/Env.js b/Env.js index 92f0112cc..4fbf18c08 100644 --- a/Env.js +++ b/Env.js @@ -779,7 +779,7 @@ function Env(name, opts) { this.logs = [...this.logs, ...logs] } console.log( - `${this.logLevelPrefixs.debug}${logs.join(this.logSeparator)}` + `${this.logLevelPrefixs.debug}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` ) } } @@ -790,7 +790,7 @@ function Env(name, opts) { this.logs = [...this.logs, ...logs] } console.log( - `${this.logLevelPrefixs.info}${logs.join(this.logSeparator)}` + `${this.logLevelPrefixs.info}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` ) } } @@ -801,7 +801,7 @@ function Env(name, opts) { this.logs = [...this.logs, ...logs] } console.log( - `${this.logLevelPrefixs.warn}${logs.join(this.logSeparator)}` + `${this.logLevelPrefixs.warn}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` ) } } @@ -812,7 +812,7 @@ function Env(name, opts) { this.logs = [...this.logs, ...logs] } console.log( - `${this.logLevelPrefixs.error}${logs.join(this.logSeparator)}` + `${this.logLevelPrefixs.error}${logs.map((l) => l ?? String(l)).join(this.logSeparator)}` ) } } @@ -821,7 +821,7 @@ function Env(name, opts) { if (logs.length > 0) { this.logs = [...this.logs, ...logs] } - console.log(logs.join(this.logSeparator)) + console.log(logs.map((l) => l ?? String(l)).join(this.logSeparator)) } logErr(err, msg) { diff --git a/Env.min.js b/Env.min.js index 8ea4479b0..6112400bc 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1,697 @@ -function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;return"POST"===t&&(s=this.post),new Promise(((t,i)=>{s.call(this,e,((e,s,o)=>{e?i(e):t(s)}))}))}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;if(this.getdata(e))try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise((t=>{this.get({url:e},((e,s,i)=>t(i)))}))}runScript(e,t){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=t&&t.timeout?t.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((e,t,i)=>s(i)))})).catch((e=>this.logErr(e)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t);if(!s&&!i)return{};{const i=s?e:t;try{return JSON.parse(this.fs.readFileSync(i))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t),o=JSON.stringify(this.data);s?this.fs.writeFileSync(e,o):i?this.fs.writeFileSync(t,o):this.fs.writeFileSync(e,o)}}lodash_get(e,t,s){const i=t.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(const e of i)if(o=Object(o)[e],void 0===o)return s;return o}lodash_set(e,t,s){return Object(e)!==e||(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce(((e,s,i)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[i+1])>>0==+t[i+1]?[]:{}),e)[t[t.length-1]]=s),e}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(e),o=s?this.getval(s):"";if(o)try{const e=JSON.parse(o);t=e?this.lodash_get(e,i,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,o,e),s=this.setval(JSON.stringify(t),i)}catch(t){const r={};this.lodash_set(r,o,e),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",((e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}})).then((e=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:i,response:o}=e;t(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(e);const{url:o,...r}=e;this.got[s](o,r).then((e=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=e,n=i.decode(a,this.encoding);t(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:s,response:o}=e;t(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(e,t=null){const s=t?new Date(t):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in i)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?i[t]:("00"+i[t]).substr((""+i[t]).length)));return e}queryStr(e){let t="";for(const s in e){let i=e[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),t+=`${s}=${i}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",i="",o){const r=e=>{const{$open:t,$copy:s,$media:i,$mediaMime:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=e.openUrl||e.url||e["open-url"]||t;a&&Object.assign(r,{action:"open-url",url:a});let n=e["update-pasteboard"]||e.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let e,t,s;if(i.startsWith("http"))e=i;else if(i.startsWith("data:")){const[e]=i.split(";"),[,o]=i.split(",");t=o,s=e.replace("data:","")}else{t=i,s=(e=>{const t={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in t)if(0===e.indexOf(s))return t[s];return null})(i)}Object.assign(r,{"media-url":e,"media-base64":t,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":e["auto-dismiss"],sound:e.sound}),r}case"Loon":{const s={};let i=e.openUrl||e.url||e["open-url"]||t;i&&Object.assign(s,{openUrl:i});let o=e.mediaUrl||e["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=e["open-url"]||e.url||e.openUrl||t;o&&Object.assign(i,{"open-url":o});let r=e["media-url"]||e.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=e["update-pasteboard"]||e.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,i,r(o));break;case"Quantumult X":$notify(t,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let e=["","==============📣系统通知📣=============="];e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t,e);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t,void 0!==e.message?e.message:e,e.stack);break}}wait(e){return new Promise((t=>setTimeout(t,e)))}done(e={}){const t=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${t} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file +function Env(t, e) { + class s { + constructor(t) { + this.env = t + } + send(t, e = 'GET') { + t = 'string' == typeof t ? { url: t } : t + let s = this.get + return ( + 'POST' === e && (s = this.post), + new Promise((e, i) => { + s.call(this, t, (t, s, o) => { + t ? i(t) : e(s) + }) + }) + ) + } + get(t) { + return this.send.call(this.env, t) + } + post(t) { + return this.send.call(this.env, t, 'POST') + } + } + return new (class { + constructor(t, e) { + ;(this.logLevels = { debug: 0, info: 1, warn: 2, error: 3 }), + (this.logLevelPrefixs = { + debug: '[DEBUG] ', + info: '[INFO] ', + warn: '[WARN] ', + error: '[ERROR] ' + }), + (this.logLevel = 'info'), + (this.name = t), + (this.http = new s(this)), + (this.data = null), + (this.dataFile = 'box.dat'), + (this.logs = []), + (this.isMute = !1), + (this.isNeedRewrite = !1), + (this.logSeparator = '\n'), + (this.encoding = 'utf-8'), + (this.startTime = new Date().getTime()), + Object.assign(this, e), + this.log('', `🔔${this.name}, 开始!`) + } + getEnv() { + return 'undefined' != typeof $environment && $environment['surge-version'] + ? 'Surge' + : 'undefined' != typeof $environment && $environment['stash-version'] + ? 'Stash' + : 'undefined' != typeof module && module.exports + ? 'Node.js' + : 'undefined' != typeof $task + ? 'Quantumult X' + : 'undefined' != typeof $loon + ? 'Loon' + : 'undefined' != typeof $rocket + ? 'Shadowrocket' + : void 0 + } + isNode() { + return 'Node.js' === this.getEnv() + } + isQuanX() { + return 'Quantumult X' === this.getEnv() + } + isSurge() { + return 'Surge' === this.getEnv() + } + isLoon() { + return 'Loon' === this.getEnv() + } + isShadowrocket() { + return 'Shadowrocket' === this.getEnv() + } + isStash() { + return 'Stash' === this.getEnv() + } + toObj(t, e = null) { + try { + return JSON.parse(t) + } catch { + return e + } + } + toStr(t, e = null, ...s) { + try { + return JSON.stringify(t, ...s) + } catch { + return e + } + } + getjson(t, e) { + let s = e + if (this.getdata(t)) + try { + s = JSON.parse(this.getdata(t)) + } catch {} + return s + } + setjson(t, e) { + try { + return this.setdata(JSON.stringify(t), e) + } catch { + return !1 + } + } + getScript(t) { + return new Promise((e) => { + this.get({ url: t }, (t, s, i) => e(i)) + }) + } + runScript(t, e) { + return new Promise((s) => { + let i = this.getdata('@chavy_boxjs_userCfgs.httpapi') + i = i ? i.replace(/\n/g, '').trim() : i + let o = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout') + ;(o = o ? 1 * o : 20), (o = e && e.timeout ? e.timeout : o) + const [r, a] = i.split('@'), + n = { + url: `http://${a}/v1/scripting/evaluate`, + body: { script_text: t, mock_type: 'cron', timeout: o }, + headers: { 'X-Key': r, 'Accept': '*/*' }, + timeout: o + } + this.post(n, (t, e, i) => s(i)) + }).catch((t) => this.logErr(t)) + } + loaddata() { + if (!this.isNode()) return {} + { + ;(this.fs = this.fs ? this.fs : require('fs')), + (this.path = this.path ? this.path : require('path')) + const t = this.path.resolve(this.dataFile), + e = this.path.resolve(process.cwd(), this.dataFile), + s = this.fs.existsSync(t), + i = !s && this.fs.existsSync(e) + if (!s && !i) return {} + { + const i = s ? t : e + try { + return JSON.parse(this.fs.readFileSync(i)) + } catch (t) { + return {} + } + } + } + } + writedata() { + if (this.isNode()) { + ;(this.fs = this.fs ? this.fs : require('fs')), + (this.path = this.path ? this.path : require('path')) + const t = this.path.resolve(this.dataFile), + e = this.path.resolve(process.cwd(), this.dataFile), + s = this.fs.existsSync(t), + i = !s && this.fs.existsSync(e), + o = JSON.stringify(this.data) + s + ? this.fs.writeFileSync(t, o) + : i + ? this.fs.writeFileSync(e, o) + : this.fs.writeFileSync(t, o) + } + } + lodash_get(t, e, s) { + const i = e.replace(/\[(\d+)\]/g, '.$1').split('.') + let o = t + for (const t of i) if (((o = Object(o)[t]), void 0 === o)) return s + return o + } + lodash_set(t, e, s) { + return ( + Object(t) !== t || + (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), + (e + .slice(0, -1) + .reduce( + (t, s, i) => + Object(t[s]) === t[s] + ? t[s] + : (t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}), + t + )[e[e.length - 1]] = s)), + t + ) + } + getdata(t) { + let e = this.getval(t) + if (/^@/.test(t)) { + const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), + o = s ? this.getval(s) : '' + if (o) + try { + const t = JSON.parse(o) + e = t ? this.lodash_get(t, i, '') : e + } catch (t) { + e = '' + } + } + return e + } + setdata(t, e) { + let s = !1 + if (/^@/.test(e)) { + const [, i, o] = /^@(.*?)\.(.*?)$/.exec(e), + r = this.getval(i), + a = i ? ('null' === r ? null : r || '{}') : '{}' + try { + const e = JSON.parse(a) + this.lodash_set(e, o, t), (s = this.setval(JSON.stringify(e), i)) + } catch (e) { + const r = {} + this.lodash_set(r, o, t), (s = this.setval(JSON.stringify(r), i)) + } + } else s = this.setval(t, e) + return s + } + getval(t) { + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.read(t) + case 'Quantumult X': + return $prefs.valueForKey(t) + case 'Node.js': + return (this.data = this.loaddata()), this.data[t] + default: + return (this.data && this.data[t]) || null + } + } + setval(t, e) { + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + return $persistentStore.write(t, e) + case 'Quantumult X': + return $prefs.setValueForKey(t, e) + case 'Node.js': + return ( + (this.data = this.loaddata()), + (this.data[e] = t), + this.writedata(), + !0 + ) + default: + return (this.data && this.data[e]) || null + } + } + initGotEnv(t) { + ;(this.got = this.got ? this.got : require('got')), + (this.cktough = this.cktough ? this.cktough : require('tough-cookie')), + (this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar()), + t && + ((t.headers = t.headers ? t.headers : {}), + t && + ((t.headers = t.headers ? t.headers : {}), + void 0 === t.headers.cookie && + void 0 === t.headers.Cookie && + void 0 === t.cookieJar && + (t.cookieJar = this.ckjar))) + } + get(t, e = () => {}) { + switch ( + (t.headers && + (delete t.headers['Content-Type'], + delete t.headers['Content-Length'], + delete t.headers['content-type'], + delete t.headers['content-length']), + t.params && (t.url += '?' + this.queryStr(t.params)), + void 0 === t.followRedirect || + t.followRedirect || + ((this.isSurge() || this.isLoon()) && (t['auto-redirect'] = !1), + this.isQuanX() && + (t.opts + ? (t.opts.redirection = !1) + : (t.opts = { redirection: !1 }))), + this.getEnv()) + ) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + this.isSurge() && + this.isNeedRewrite && + ((t.headers = t.headers || {}), + Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), + $httpClient.get(t, (t, s, i) => { + !t && + s && + ((s.body = i), + (s.statusCode = s.status ? s.status : s.statusCode), + (s.status = s.statusCode)), + e(t, s, i) + }) + break + case 'Quantumult X': + this.isNeedRewrite && + ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), + $task.fetch(t).then( + (t) => { + const { + statusCode: s, + statusCode: i, + headers: o, + body: r, + bodyBytes: a + } = t + e( + null, + { + status: s, + statusCode: i, + headers: o, + body: r, + bodyBytes: a + }, + r, + a + ) + }, + (t) => e((t && t.error) || 'UndefinedError') + ) + break + case 'Node.js': + let s = require('iconv-lite') + this.initGotEnv(t), + this.got(t) + .on('redirect', (t, e) => { + try { + if (t.headers['set-cookie']) { + const s = t.headers['set-cookie'] + .map(this.cktough.Cookie.parse) + .toString() + s && this.ckjar.setCookieSync(s, null), + (e.cookieJar = this.ckjar) + } + } catch (t) { + this.logErr(t) + } + }) + .then( + (t) => { + const { + statusCode: i, + statusCode: o, + headers: r, + rawBody: a + } = t, + n = s.decode(a, this.encoding) + e( + null, + { + status: i, + statusCode: o, + headers: r, + rawBody: a, + body: n + }, + n + ) + }, + (t) => { + const { message: i, response: o } = t + e(i, o, o && s.decode(o.rawBody, this.encoding)) + } + ) + break + } + } + post(t, e = () => {}) { + const s = t.method ? t.method.toLocaleLowerCase() : 'post' + switch ( + (t.body && + t.headers && + !t.headers['Content-Type'] && + !t.headers['content-type'] && + (t.headers['content-type'] = 'application/x-www-form-urlencoded'), + t.headers && + (delete t.headers['Content-Length'], + delete t.headers['content-length']), + void 0 === t.followRedirect || + t.followRedirect || + ((this.isSurge() || this.isLoon()) && (t['auto-redirect'] = !1), + this.isQuanX() && + (t.opts + ? (t.opts.redirection = !1) + : (t.opts = { redirection: !1 }))), + this.getEnv()) + ) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + this.isSurge() && + this.isNeedRewrite && + ((t.headers = t.headers || {}), + Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), + $httpClient[s](t, (t, s, i) => { + !t && + s && + ((s.body = i), + (s.statusCode = s.status ? s.status : s.statusCode), + (s.status = s.statusCode)), + e(t, s, i) + }) + break + case 'Quantumult X': + ;(t.method = s), + this.isNeedRewrite && + ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), + $task.fetch(t).then( + (t) => { + const { + statusCode: s, + statusCode: i, + headers: o, + body: r, + bodyBytes: a + } = t + e( + null, + { + status: s, + statusCode: i, + headers: o, + body: r, + bodyBytes: a + }, + r, + a + ) + }, + (t) => e((t && t.error) || 'UndefinedError') + ) + break + case 'Node.js': + let i = require('iconv-lite') + this.initGotEnv(t) + const { url: o, ...r } = t + this.got[s](o, r).then( + (t) => { + const { + statusCode: s, + statusCode: o, + headers: r, + rawBody: a + } = t, + n = i.decode(a, this.encoding) + e( + null, + { status: s, statusCode: o, headers: r, rawBody: a, body: n }, + n + ) + }, + (t) => { + const { message: s, response: o } = t + e(s, o, o && i.decode(o.rawBody, this.encoding)) + } + ) + break + } + } + time(t, e = null) { + const s = e ? new Date(e) : new Date() + let i = { + 'M+': s.getMonth() + 1, + 'd+': s.getDate(), + 'H+': s.getHours(), + 'm+': s.getMinutes(), + 's+': s.getSeconds(), + 'q+': Math.floor((s.getMonth() + 3) / 3), + 'S': s.getMilliseconds() + } + ;/(y+)/.test(t) && + (t = t.replace( + RegExp.$1, + (s.getFullYear() + '').substr(4 - RegExp.$1.length) + )) + for (let e in i) + new RegExp('(' + e + ')').test(t) && + (t = t.replace( + RegExp.$1, + 1 == RegExp.$1.length + ? i[e] + : ('00' + i[e]).substr(('' + i[e]).length) + )) + return t + } + queryStr(t) { + let e = '' + for (const s in t) { + let i = t[s] + null != i && + '' !== i && + ('object' == typeof i && (i = JSON.stringify(i)), (e += `${s}=${i}&`)) + } + return (e = e.substring(0, e.length - 1)), e + } + msg(e = t, s = '', i = '', o) { + const r = (t) => { + const { $open: e, $copy: s, $media: i, $mediaMime: o } = t + switch (typeof t) { + case void 0: + return t + case 'string': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + default: + return { url: t } + case 'Loon': + case 'Shadowrocket': + return t + case 'Quantumult X': + return { 'open-url': t } + case 'Node.js': + return + } + case 'object': + switch (this.getEnv()) { + case 'Surge': + case 'Stash': + case 'Shadowrocket': + default: { + const r = {} + let a = t.openUrl || t.url || t['open-url'] || e + a && Object.assign(r, { action: 'open-url', url: a }) + let n = t['update-pasteboard'] || t.updatePasteboard || s + if ( + (n && Object.assign(r, { action: 'clipboard', text: n }), i) + ) { + let t, e, s + if (i.startsWith('http')) t = i + else if (i.startsWith('data:')) { + const [t] = i.split(';'), + [, o] = i.split(',') + ;(e = o), (s = t.replace('data:', '')) + } else { + ;(e = i), + (s = ((t) => { + const e = { + 'JVBERi0': 'application/pdf', + 'R0lGODdh': 'image/gif', + 'R0lGODlh': 'image/gif', + 'iVBORw0KGgo': 'image/png', + '/9j/': 'image/jpg' + } + for (var s in e) if (0 === t.indexOf(s)) return e[s] + return null + })(i)) + } + Object.assign(r, { + 'media-url': t, + 'media-base64': e, + 'media-base64-mime': o ?? s + }) + } + return ( + Object.assign(r, { + 'auto-dismiss': t['auto-dismiss'], + 'sound': t.sound + }), + r + ) + } + case 'Loon': { + const s = {} + let i = t.openUrl || t.url || t['open-url'] || e + i && Object.assign(s, { openUrl: i }) + let o = t.mediaUrl || t['media-url'] + return o && Object.assign(s, { mediaUrl: o }), s + } + case 'Quantumult X': { + const i = {} + let o = t['open-url'] || t.url || t.openUrl || e + o && Object.assign(i, { 'open-url': o }) + let r = t['media-url'] || t.mediaUrl + r && Object.assign(i, { 'media-url': r }) + let a = t['update-pasteboard'] || t.updatePasteboard || s + return a && Object.assign(i, { 'update-pasteboard': a }), i + } + case 'Node.js': + return + } + default: + return + } + } + if (!this.isMute) + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + default: + $notification.post(e, s, i, r(o)) + break + case 'Quantumult X': + $notify(e, s, i, r(o)) + break + case 'Node.js': + break + } + if (!this.isMuteLog) { + let t = ['', '==============📣系统通知📣=============='] + t.push(e), + s && t.push(s), + i && t.push(i), + console.log(t.join('\n')), + (this.logs = this.logs.concat(t)) + } + } + debug(...t) { + this.logLevels[this.logLevel] <= this.logLevels.debug && + (t.length > 0 && (this.logs = [...this.logs, ...t]), + console.log( + `${this.logLevelPrefixs.debug}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` + )) + } + info(...t) { + this.logLevels[this.logLevel] <= this.logLevels.info && + (t.length > 0 && (this.logs = [...this.logs, ...t]), + console.log( + `${this.logLevelPrefixs.info}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` + )) + } + warn(...t) { + this.logLevels[this.logLevel] <= this.logLevels.warn && + (t.length > 0 && (this.logs = [...this.logs, ...t]), + console.log( + `${this.logLevelPrefixs.warn}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` + )) + } + error(...t) { + this.logLevels[this.logLevel] <= this.logLevels.error && + (t.length > 0 && (this.logs = [...this.logs, ...t]), + console.log( + `${this.logLevelPrefixs.error}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` + )) + } + log(...t) { + t.length > 0 && (this.logs = [...this.logs, ...t]), + console.log(t.map((t) => t ?? String(t)).join(this.logSeparator)) + } + logErr(t, e) { + switch (this.getEnv()) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + this.log('', `❗️${this.name}, 错误!`, e, t) + break + case 'Node.js': + this.log( + '', + `❗️${this.name}, 错误!`, + e, + void 0 !== t.message ? t.message : t, + t.stack + ) + break + } + } + wait(t) { + return new Promise((e) => setTimeout(e, t)) + } + done(t = {}) { + const e = (new Date().getTime() - this.startTime) / 1e3 + switch ( + (this.log('', `🔔${this.name}, 结束! 🕛 ${e} 秒`), + this.log(), + this.getEnv()) + ) { + case 'Surge': + case 'Loon': + case 'Stash': + case 'Shadowrocket': + case 'Quantumult X': + default: + $done(t) + break + case 'Node.js': + process.exit(1) + } + } + })(t, e) +} From 4a293a952709e14cbcebd1bb3fd3976283cb9ac1 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 01:13:57 +0800 Subject: [PATCH 242/311] =?UTF-8?q?chore:=20=E6=96=B0=E5=A2=9E=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=20boxjs.revert.usercfgs.debugger.js=20=E7=94=A8?= =?UTF-8?q?=E4=BA=8E`=E6=8A=B9=E6=8E=89=E8=B0=83=E8=AF=95=E5=9C=B0?= =?UTF-8?q?=E5=9D=80`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/scripts/boxjs.revert.usercfgs.debugger.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 box/scripts/boxjs.revert.usercfgs.debugger.js diff --git a/box/scripts/boxjs.revert.usercfgs.debugger.js b/box/scripts/boxjs.revert.usercfgs.debugger.js new file mode 100644 index 000000000..5f54210e8 --- /dev/null +++ b/box/scripts/boxjs.revert.usercfgs.debugger.js @@ -0,0 +1,18 @@ +const $ = new Env('BoxJs - 抹掉调试地址') + +$.KEY_web_cache = 'chavy_boxjs_web_cache' +$.KEY_usercfgs = 'chavy_boxjs_userCfgs' + +const usercfgs = $.getjson($.KEY_usercfgs, {}) +usercfgs.isDebugWeb = false +usercfgs.debugger_web = '' + +$.setjson(usercfgs, $.KEY_usercfgs) +$.setjson({}, $.KEY_web_cache) +$.done() + +/** + * EnvJs + */ +// prettier-ignore +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:i,...r}=t;this.got[s](i,r).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} From 51b3bd914249193cd3237009f582ea5cf6251ce8 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 08:45:54 +0800 Subject: [PATCH 243/311] =?UTF-8?q?chore(Env.js):=20=E4=BD=BF=E7=94=A8=20M?= =?UTF-8?q?inifyAll=20=E9=87=8D=E6=96=B0=E6=89=93=E5=8C=85=20Env.min.js=20?= =?UTF-8?q?(=E4=B8=BA=E4=BA=86=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E8=AF=AD=E6=B3=95=E7=B3=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.min.js | 698 +---------------------------------------------------- 1 file changed, 1 insertion(+), 697 deletions(-) diff --git a/Env.min.js b/Env.min.js index 6112400bc..de4c7264e 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1,697 +1 @@ -function Env(t, e) { - class s { - constructor(t) { - this.env = t - } - send(t, e = 'GET') { - t = 'string' == typeof t ? { url: t } : t - let s = this.get - return ( - 'POST' === e && (s = this.post), - new Promise((e, i) => { - s.call(this, t, (t, s, o) => { - t ? i(t) : e(s) - }) - }) - ) - } - get(t) { - return this.send.call(this.env, t) - } - post(t) { - return this.send.call(this.env, t, 'POST') - } - } - return new (class { - constructor(t, e) { - ;(this.logLevels = { debug: 0, info: 1, warn: 2, error: 3 }), - (this.logLevelPrefixs = { - debug: '[DEBUG] ', - info: '[INFO] ', - warn: '[WARN] ', - error: '[ERROR] ' - }), - (this.logLevel = 'info'), - (this.name = t), - (this.http = new s(this)), - (this.data = null), - (this.dataFile = 'box.dat'), - (this.logs = []), - (this.isMute = !1), - (this.isNeedRewrite = !1), - (this.logSeparator = '\n'), - (this.encoding = 'utf-8'), - (this.startTime = new Date().getTime()), - Object.assign(this, e), - this.log('', `🔔${this.name}, 开始!`) - } - getEnv() { - return 'undefined' != typeof $environment && $environment['surge-version'] - ? 'Surge' - : 'undefined' != typeof $environment && $environment['stash-version'] - ? 'Stash' - : 'undefined' != typeof module && module.exports - ? 'Node.js' - : 'undefined' != typeof $task - ? 'Quantumult X' - : 'undefined' != typeof $loon - ? 'Loon' - : 'undefined' != typeof $rocket - ? 'Shadowrocket' - : void 0 - } - isNode() { - return 'Node.js' === this.getEnv() - } - isQuanX() { - return 'Quantumult X' === this.getEnv() - } - isSurge() { - return 'Surge' === this.getEnv() - } - isLoon() { - return 'Loon' === this.getEnv() - } - isShadowrocket() { - return 'Shadowrocket' === this.getEnv() - } - isStash() { - return 'Stash' === this.getEnv() - } - toObj(t, e = null) { - try { - return JSON.parse(t) - } catch { - return e - } - } - toStr(t, e = null, ...s) { - try { - return JSON.stringify(t, ...s) - } catch { - return e - } - } - getjson(t, e) { - let s = e - if (this.getdata(t)) - try { - s = JSON.parse(this.getdata(t)) - } catch {} - return s - } - setjson(t, e) { - try { - return this.setdata(JSON.stringify(t), e) - } catch { - return !1 - } - } - getScript(t) { - return new Promise((e) => { - this.get({ url: t }, (t, s, i) => e(i)) - }) - } - runScript(t, e) { - return new Promise((s) => { - let i = this.getdata('@chavy_boxjs_userCfgs.httpapi') - i = i ? i.replace(/\n/g, '').trim() : i - let o = this.getdata('@chavy_boxjs_userCfgs.httpapi_timeout') - ;(o = o ? 1 * o : 20), (o = e && e.timeout ? e.timeout : o) - const [r, a] = i.split('@'), - n = { - url: `http://${a}/v1/scripting/evaluate`, - body: { script_text: t, mock_type: 'cron', timeout: o }, - headers: { 'X-Key': r, 'Accept': '*/*' }, - timeout: o - } - this.post(n, (t, e, i) => s(i)) - }).catch((t) => this.logErr(t)) - } - loaddata() { - if (!this.isNode()) return {} - { - ;(this.fs = this.fs ? this.fs : require('fs')), - (this.path = this.path ? this.path : require('path')) - const t = this.path.resolve(this.dataFile), - e = this.path.resolve(process.cwd(), this.dataFile), - s = this.fs.existsSync(t), - i = !s && this.fs.existsSync(e) - if (!s && !i) return {} - { - const i = s ? t : e - try { - return JSON.parse(this.fs.readFileSync(i)) - } catch (t) { - return {} - } - } - } - } - writedata() { - if (this.isNode()) { - ;(this.fs = this.fs ? this.fs : require('fs')), - (this.path = this.path ? this.path : require('path')) - const t = this.path.resolve(this.dataFile), - e = this.path.resolve(process.cwd(), this.dataFile), - s = this.fs.existsSync(t), - i = !s && this.fs.existsSync(e), - o = JSON.stringify(this.data) - s - ? this.fs.writeFileSync(t, o) - : i - ? this.fs.writeFileSync(e, o) - : this.fs.writeFileSync(t, o) - } - } - lodash_get(t, e, s) { - const i = e.replace(/\[(\d+)\]/g, '.$1').split('.') - let o = t - for (const t of i) if (((o = Object(o)[t]), void 0 === o)) return s - return o - } - lodash_set(t, e, s) { - return ( - Object(t) !== t || - (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), - (e - .slice(0, -1) - .reduce( - (t, s, i) => - Object(t[s]) === t[s] - ? t[s] - : (t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}), - t - )[e[e.length - 1]] = s)), - t - ) - } - getdata(t) { - let e = this.getval(t) - if (/^@/.test(t)) { - const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), - o = s ? this.getval(s) : '' - if (o) - try { - const t = JSON.parse(o) - e = t ? this.lodash_get(t, i, '') : e - } catch (t) { - e = '' - } - } - return e - } - setdata(t, e) { - let s = !1 - if (/^@/.test(e)) { - const [, i, o] = /^@(.*?)\.(.*?)$/.exec(e), - r = this.getval(i), - a = i ? ('null' === r ? null : r || '{}') : '{}' - try { - const e = JSON.parse(a) - this.lodash_set(e, o, t), (s = this.setval(JSON.stringify(e), i)) - } catch (e) { - const r = {} - this.lodash_set(r, o, t), (s = this.setval(JSON.stringify(r), i)) - } - } else s = this.setval(t, e) - return s - } - getval(t) { - switch (this.getEnv()) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - return $persistentStore.read(t) - case 'Quantumult X': - return $prefs.valueForKey(t) - case 'Node.js': - return (this.data = this.loaddata()), this.data[t] - default: - return (this.data && this.data[t]) || null - } - } - setval(t, e) { - switch (this.getEnv()) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - return $persistentStore.write(t, e) - case 'Quantumult X': - return $prefs.setValueForKey(t, e) - case 'Node.js': - return ( - (this.data = this.loaddata()), - (this.data[e] = t), - this.writedata(), - !0 - ) - default: - return (this.data && this.data[e]) || null - } - } - initGotEnv(t) { - ;(this.got = this.got ? this.got : require('got')), - (this.cktough = this.cktough ? this.cktough : require('tough-cookie')), - (this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar()), - t && - ((t.headers = t.headers ? t.headers : {}), - t && - ((t.headers = t.headers ? t.headers : {}), - void 0 === t.headers.cookie && - void 0 === t.headers.Cookie && - void 0 === t.cookieJar && - (t.cookieJar = this.ckjar))) - } - get(t, e = () => {}) { - switch ( - (t.headers && - (delete t.headers['Content-Type'], - delete t.headers['Content-Length'], - delete t.headers['content-type'], - delete t.headers['content-length']), - t.params && (t.url += '?' + this.queryStr(t.params)), - void 0 === t.followRedirect || - t.followRedirect || - ((this.isSurge() || this.isLoon()) && (t['auto-redirect'] = !1), - this.isQuanX() && - (t.opts - ? (t.opts.redirection = !1) - : (t.opts = { redirection: !1 }))), - this.getEnv()) - ) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - default: - this.isSurge() && - this.isNeedRewrite && - ((t.headers = t.headers || {}), - Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), - $httpClient.get(t, (t, s, i) => { - !t && - s && - ((s.body = i), - (s.statusCode = s.status ? s.status : s.statusCode), - (s.status = s.statusCode)), - e(t, s, i) - }) - break - case 'Quantumult X': - this.isNeedRewrite && - ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), - $task.fetch(t).then( - (t) => { - const { - statusCode: s, - statusCode: i, - headers: o, - body: r, - bodyBytes: a - } = t - e( - null, - { - status: s, - statusCode: i, - headers: o, - body: r, - bodyBytes: a - }, - r, - a - ) - }, - (t) => e((t && t.error) || 'UndefinedError') - ) - break - case 'Node.js': - let s = require('iconv-lite') - this.initGotEnv(t), - this.got(t) - .on('redirect', (t, e) => { - try { - if (t.headers['set-cookie']) { - const s = t.headers['set-cookie'] - .map(this.cktough.Cookie.parse) - .toString() - s && this.ckjar.setCookieSync(s, null), - (e.cookieJar = this.ckjar) - } - } catch (t) { - this.logErr(t) - } - }) - .then( - (t) => { - const { - statusCode: i, - statusCode: o, - headers: r, - rawBody: a - } = t, - n = s.decode(a, this.encoding) - e( - null, - { - status: i, - statusCode: o, - headers: r, - rawBody: a, - body: n - }, - n - ) - }, - (t) => { - const { message: i, response: o } = t - e(i, o, o && s.decode(o.rawBody, this.encoding)) - } - ) - break - } - } - post(t, e = () => {}) { - const s = t.method ? t.method.toLocaleLowerCase() : 'post' - switch ( - (t.body && - t.headers && - !t.headers['Content-Type'] && - !t.headers['content-type'] && - (t.headers['content-type'] = 'application/x-www-form-urlencoded'), - t.headers && - (delete t.headers['Content-Length'], - delete t.headers['content-length']), - void 0 === t.followRedirect || - t.followRedirect || - ((this.isSurge() || this.isLoon()) && (t['auto-redirect'] = !1), - this.isQuanX() && - (t.opts - ? (t.opts.redirection = !1) - : (t.opts = { redirection: !1 }))), - this.getEnv()) - ) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - default: - this.isSurge() && - this.isNeedRewrite && - ((t.headers = t.headers || {}), - Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })), - $httpClient[s](t, (t, s, i) => { - !t && - s && - ((s.body = i), - (s.statusCode = s.status ? s.status : s.statusCode), - (s.status = s.statusCode)), - e(t, s, i) - }) - break - case 'Quantumult X': - ;(t.method = s), - this.isNeedRewrite && - ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })), - $task.fetch(t).then( - (t) => { - const { - statusCode: s, - statusCode: i, - headers: o, - body: r, - bodyBytes: a - } = t - e( - null, - { - status: s, - statusCode: i, - headers: o, - body: r, - bodyBytes: a - }, - r, - a - ) - }, - (t) => e((t && t.error) || 'UndefinedError') - ) - break - case 'Node.js': - let i = require('iconv-lite') - this.initGotEnv(t) - const { url: o, ...r } = t - this.got[s](o, r).then( - (t) => { - const { - statusCode: s, - statusCode: o, - headers: r, - rawBody: a - } = t, - n = i.decode(a, this.encoding) - e( - null, - { status: s, statusCode: o, headers: r, rawBody: a, body: n }, - n - ) - }, - (t) => { - const { message: s, response: o } = t - e(s, o, o && i.decode(o.rawBody, this.encoding)) - } - ) - break - } - } - time(t, e = null) { - const s = e ? new Date(e) : new Date() - let i = { - 'M+': s.getMonth() + 1, - 'd+': s.getDate(), - 'H+': s.getHours(), - 'm+': s.getMinutes(), - 's+': s.getSeconds(), - 'q+': Math.floor((s.getMonth() + 3) / 3), - 'S': s.getMilliseconds() - } - ;/(y+)/.test(t) && - (t = t.replace( - RegExp.$1, - (s.getFullYear() + '').substr(4 - RegExp.$1.length) - )) - for (let e in i) - new RegExp('(' + e + ')').test(t) && - (t = t.replace( - RegExp.$1, - 1 == RegExp.$1.length - ? i[e] - : ('00' + i[e]).substr(('' + i[e]).length) - )) - return t - } - queryStr(t) { - let e = '' - for (const s in t) { - let i = t[s] - null != i && - '' !== i && - ('object' == typeof i && (i = JSON.stringify(i)), (e += `${s}=${i}&`)) - } - return (e = e.substring(0, e.length - 1)), e - } - msg(e = t, s = '', i = '', o) { - const r = (t) => { - const { $open: e, $copy: s, $media: i, $mediaMime: o } = t - switch (typeof t) { - case void 0: - return t - case 'string': - switch (this.getEnv()) { - case 'Surge': - case 'Stash': - default: - return { url: t } - case 'Loon': - case 'Shadowrocket': - return t - case 'Quantumult X': - return { 'open-url': t } - case 'Node.js': - return - } - case 'object': - switch (this.getEnv()) { - case 'Surge': - case 'Stash': - case 'Shadowrocket': - default: { - const r = {} - let a = t.openUrl || t.url || t['open-url'] || e - a && Object.assign(r, { action: 'open-url', url: a }) - let n = t['update-pasteboard'] || t.updatePasteboard || s - if ( - (n && Object.assign(r, { action: 'clipboard', text: n }), i) - ) { - let t, e, s - if (i.startsWith('http')) t = i - else if (i.startsWith('data:')) { - const [t] = i.split(';'), - [, o] = i.split(',') - ;(e = o), (s = t.replace('data:', '')) - } else { - ;(e = i), - (s = ((t) => { - const e = { - 'JVBERi0': 'application/pdf', - 'R0lGODdh': 'image/gif', - 'R0lGODlh': 'image/gif', - 'iVBORw0KGgo': 'image/png', - '/9j/': 'image/jpg' - } - for (var s in e) if (0 === t.indexOf(s)) return e[s] - return null - })(i)) - } - Object.assign(r, { - 'media-url': t, - 'media-base64': e, - 'media-base64-mime': o ?? s - }) - } - return ( - Object.assign(r, { - 'auto-dismiss': t['auto-dismiss'], - 'sound': t.sound - }), - r - ) - } - case 'Loon': { - const s = {} - let i = t.openUrl || t.url || t['open-url'] || e - i && Object.assign(s, { openUrl: i }) - let o = t.mediaUrl || t['media-url'] - return o && Object.assign(s, { mediaUrl: o }), s - } - case 'Quantumult X': { - const i = {} - let o = t['open-url'] || t.url || t.openUrl || e - o && Object.assign(i, { 'open-url': o }) - let r = t['media-url'] || t.mediaUrl - r && Object.assign(i, { 'media-url': r }) - let a = t['update-pasteboard'] || t.updatePasteboard || s - return a && Object.assign(i, { 'update-pasteboard': a }), i - } - case 'Node.js': - return - } - default: - return - } - } - if (!this.isMute) - switch (this.getEnv()) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - default: - $notification.post(e, s, i, r(o)) - break - case 'Quantumult X': - $notify(e, s, i, r(o)) - break - case 'Node.js': - break - } - if (!this.isMuteLog) { - let t = ['', '==============📣系统通知📣=============='] - t.push(e), - s && t.push(s), - i && t.push(i), - console.log(t.join('\n')), - (this.logs = this.logs.concat(t)) - } - } - debug(...t) { - this.logLevels[this.logLevel] <= this.logLevels.debug && - (t.length > 0 && (this.logs = [...this.logs, ...t]), - console.log( - `${this.logLevelPrefixs.debug}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` - )) - } - info(...t) { - this.logLevels[this.logLevel] <= this.logLevels.info && - (t.length > 0 && (this.logs = [...this.logs, ...t]), - console.log( - `${this.logLevelPrefixs.info}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` - )) - } - warn(...t) { - this.logLevels[this.logLevel] <= this.logLevels.warn && - (t.length > 0 && (this.logs = [...this.logs, ...t]), - console.log( - `${this.logLevelPrefixs.warn}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` - )) - } - error(...t) { - this.logLevels[this.logLevel] <= this.logLevels.error && - (t.length > 0 && (this.logs = [...this.logs, ...t]), - console.log( - `${this.logLevelPrefixs.error}${t.map((t) => t ?? String(t)).join(this.logSeparator)}` - )) - } - log(...t) { - t.length > 0 && (this.logs = [...this.logs, ...t]), - console.log(t.map((t) => t ?? String(t)).join(this.logSeparator)) - } - logErr(t, e) { - switch (this.getEnv()) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - case 'Quantumult X': - default: - this.log('', `❗️${this.name}, 错误!`, e, t) - break - case 'Node.js': - this.log( - '', - `❗️${this.name}, 错误!`, - e, - void 0 !== t.message ? t.message : t, - t.stack - ) - break - } - } - wait(t) { - return new Promise((e) => setTimeout(e, t)) - } - done(t = {}) { - const e = (new Date().getTime() - this.startTime) / 1e3 - switch ( - (this.log('', `🔔${this.name}, 结束! 🕛 ${e} 秒`), - this.log(), - this.getEnv()) - ) { - case 'Surge': - case 'Loon': - case 'Stash': - case 'Shadowrocket': - case 'Quantumult X': - default: - $done(t) - break - case 'Node.js': - process.exit(1) - } - } - })(t, e) -} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From 306a9b1e05c04568304fc937bcb355b871f4839e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:47:32 +0800 Subject: [PATCH 244/311] chore(deps): bump follow-redirects from 1.15.4 to 1.15.6 (#481) Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.4 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.4...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 5 +++-- yarn.lock | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6bf4776f..0eebb462c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -248,14 +248,15 @@ "license": "MIT" }, "node_modules/follow-redirects": { - "version": "1.15.4", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", "url": "https://github.com/sponsors/RubenVerborgh" } ], - "license": "MIT", "engines": { "node": ">=4.0" }, diff --git a/yarn.lock b/yarn.lock index c0369ce22..5082283e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -150,7 +150,9 @@ eventemitter3@^4.0.0: integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== follow-redirects@^1.0.0: - version "1.15.4" + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== function-bind@^1.1.1: version "1.1.1" From d1a0ec7046cf141439d326caf3ba869a3a8e9e42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:47:40 +0800 Subject: [PATCH 245/311] chore(deps): bump ecstatic and http-server (#482) Removes [ecstatic](https://github.com/jfhbrook/node-ecstatic). It's no longer used after updating ancestor dependency [http-server](https://github.com/http-party/http-server). These dependencies need to be updated together. Removes `ecstatic` Updates `http-server` from 0.12.3 to 14.1.1 - [Release notes](https://github.com/http-party/http-server/releases) - [Commits](https://github.com/http-party/http-server/compare/v0.12.3...v14.1.1) --- updated-dependencies: - dependency-name: ecstatic dependency-type: indirect - dependency-name: http-server dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 159 ++++++++++++++++++++++++++++++++------------- package.json | 2 +- yarn.lock | 160 ++++++++++++++++++++++++++++++---------------- 3 files changed, 218 insertions(+), 103 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0eebb462c..c013d2a4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "crypto-js": "^4.2.0", "got": "^11.8.5", - "http-server": "^0.12.3", + "http-server": "^14.1.1", "iconv-lite": "0.6.3", "tough-cookie": "^4.1.3" }, @@ -84,6 +84,20 @@ "@types/node": "*" } }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/async": { "version": "2.6.4", "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", @@ -94,12 +108,14 @@ } }, "node_modules/basic-auth": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-1.1.0.tgz", - "integrity": "sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ=", - "license": "MIT", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "dependencies": { + "safe-buffer": "5.1.2" + }, "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/cacheable-lookup": { @@ -142,6 +158,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/clone-response": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", @@ -160,15 +191,22 @@ "node": ">=4" } }, - "node_modules/colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", - "license": "MIT", + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, "engines": { - "node": ">=0.1.90" + "node": ">=7.0.0" } }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, "node_modules/corser": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz", @@ -217,21 +255,6 @@ "node": ">=10" } }, - "node_modules/ecstatic": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz", - "integrity": "sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==", - "license": "MIT", - "dependencies": { - "he": "^1.1.1", - "mime": "^1.6.0", - "minimist": "^1.1.0", - "url-join": "^2.0.5" - }, - "bin": { - "ecstatic": "lib/ecstatic.js" - } - }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -338,6 +361,14 @@ "node": ">= 0.4.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", @@ -354,11 +385,21 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", - "license": "MIT", "bin": { "he": "bin/he" } }, + "node_modules/html-encoding-sniffer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", + "integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==", + "dependencies": { + "whatwg-encoding": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/http-cache-semantics": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", @@ -380,28 +421,29 @@ } }, "node_modules/http-server": { - "version": "0.12.3", - "resolved": "https://registry.npmjs.org/http-server/-/http-server-0.12.3.tgz", - "integrity": "sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA==", - "license": "MIT", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz", + "integrity": "sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A==", "dependencies": { - "basic-auth": "^1.0.3", - "colors": "^1.4.0", + "basic-auth": "^2.0.1", + "chalk": "^4.1.2", "corser": "^2.0.1", - "ecstatic": "^3.3.2", - "http-proxy": "^1.18.0", - "minimist": "^1.2.5", + "he": "^1.2.0", + "html-encoding-sniffer": "^3.0.0", + "http-proxy": "^1.18.1", + "mime": "^1.6.0", + "minimist": "^1.2.6", "opener": "^1.5.1", - "portfinder": "^1.0.25", + "portfinder": "^1.0.28", "secure-compare": "3.0.1", - "union": "~0.5.0" + "union": "~0.5.0", + "url-join": "^4.0.1" }, "bin": { - "hs": "bin/http-server", "http-server": "bin/http-server" }, "engines": { - "node": ">=6" + "node": ">=12" } }, "node_modules/http2-wrapper": { @@ -463,7 +505,6 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", - "license": "MIT", "bin": { "mime": "cli.js" }, @@ -663,6 +704,11 @@ "lowercase-keys": "^2.0.0" } }, + "node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -689,6 +735,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tough-cookie": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", @@ -725,10 +782,9 @@ } }, "node_modules/url-join": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz", - "integrity": "sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=", - "license": "MIT" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" }, "node_modules/url-parse": { "version": "1.5.10", @@ -740,6 +796,17 @@ "requires-port": "^1.0.0" } }, + "node_modules/whatwg-encoding": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz", + "integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 83b4bac0b..ee60f224d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "crypto-js": "^4.2.0", "got": "^11.8.5", - "http-server": "^0.12.3", + "http-server": "^14.1.1", "iconv-lite": "0.6.3", "tough-cookie": "^4.1.3" }, diff --git a/yarn.lock b/yarn.lock index 5082283e9..ba944d948 100644 --- a/yarn.lock +++ b/yarn.lock @@ -48,17 +48,26 @@ dependencies: "@types/node" "*" -async@^2.6.2: +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + +async@^2.6.4: version "2.6.4" - resolved "https://registry.npmjs.org/async/-/async-2.6.4.tgz" + resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221" integrity sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA== dependencies: lodash "^4.17.14" -basic-auth@^1.0.3: - version "1.1.0" - resolved "https://registry.npmjs.org/basic-auth/-/basic-auth-1.1.0.tgz" - integrity sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ= +basic-auth@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a" + integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg== + dependencies: + safe-buffer "5.1.2" cacheable-lookup@^5.0.3: version "5.0.4" @@ -86,6 +95,14 @@ call-bind@^1.0.0: function-bind "^1.1.1" get-intrinsic "^1.0.2" +chalk@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + clone-response@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz" @@ -93,10 +110,17 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -colors@^1.4.0: - version "1.4.0" - resolved "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz" - integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== corser@^2.0.1: version "2.0.1" @@ -108,9 +132,9 @@ crypto-js@^4.2.0: resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz" integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== -debug@^3.1.1: +debug@^3.2.7: version "3.2.7" - resolved "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ== dependencies: ms "^2.1.1" @@ -127,16 +151,6 @@ defer-to-connect@^2.0.0: resolved "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz" integrity sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg== -ecstatic@^3.3.2: - version "3.3.2" - resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.2.tgz" - integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog== - dependencies: - he "^1.1.1" - mime "^1.6.0" - minimist "^1.1.0" - url-join "^2.0.5" - end-of-stream@^1.1.0: version "1.4.4" resolved "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz" @@ -192,6 +206,11 @@ got@^11.8.5: p-cancelable "^2.0.0" responselike "^2.0.0" +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + has-symbols@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz" @@ -204,40 +223,50 @@ has@^1.0.3: dependencies: function-bind "^1.1.1" -he@^1.1.1: +he@^1.2.0: version "1.2.0" - resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz" + resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +html-encoding-sniffer@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz#2cb1a8cf0db52414776e5b2a7a04d5dd98158de9" + integrity sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA== + dependencies: + whatwg-encoding "^2.0.0" + http-cache-semantics@^4.0.0: version "4.1.1" resolved "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz" integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ== -http-proxy@^1.18.0: +http-proxy@^1.18.1: version "1.18.1" - resolved "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz" + resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549" integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ== dependencies: eventemitter3 "^4.0.0" follow-redirects "^1.0.0" requires-port "^1.0.0" -http-server@^0.12.3: - version "0.12.3" - resolved "https://registry.npmjs.org/http-server/-/http-server-0.12.3.tgz" - integrity sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA== +http-server@^14.1.1: + version "14.1.1" + resolved "https://registry.yarnpkg.com/http-server/-/http-server-14.1.1.tgz#d60fbb37d7c2fdff0f0fbff0d0ee6670bd285e2e" + integrity sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A== dependencies: - basic-auth "^1.0.3" - colors "^1.4.0" + basic-auth "^2.0.1" + chalk "^4.1.2" corser "^2.0.1" - ecstatic "^3.3.2" - http-proxy "^1.18.0" - minimist "^1.2.5" + he "^1.2.0" + html-encoding-sniffer "^3.0.0" + http-proxy "^1.18.1" + mime "^1.6.0" + minimist "^1.2.6" opener "^1.5.1" - portfinder "^1.0.25" + portfinder "^1.0.28" secure-compare "3.0.1" union "~0.5.0" + url-join "^4.0.1" http2-wrapper@^1.0.0-beta.5.2: version "1.0.0-beta.5.2" @@ -291,17 +320,17 @@ mimic-response@^3.1.0: resolved "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz" integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ== -minimist@^1.1.0, minimist@^1.2.5: - version "1.2.6" - resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz" - integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== +minimist@^1.2.6: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== -mkdirp@^0.5.5: - version "0.5.5" - resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz" - integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== +mkdirp@^0.5.6: + version "0.5.6" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6" + integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw== dependencies: - minimist "^1.2.5" + minimist "^1.2.6" ms@^2.1.1: version "2.1.3" @@ -335,14 +364,14 @@ p-cancelable@^2.0.0: resolved "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz" integrity sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg== -portfinder@^1.0.25: - version "1.0.28" - resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz" - integrity sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA== +portfinder@^1.0.28: + version "1.0.32" + resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.32.tgz#2fe1b9e58389712429dc2bea5beb2146146c7f81" + integrity sha512-on2ZJVVDXRADWE6jnQaX0ioEylzgBpQk8r55NE4wjXW1ZxO+BgDlY6DXwj20i0V8eB4SenDQ00WEaxfiIQPcxg== dependencies: - async "^2.6.2" - debug "^3.1.1" - mkdirp "^0.5.5" + async "^2.6.4" + debug "^3.2.7" + mkdirp "^0.5.6" prettier@^3.2.5: version "3.2.5" @@ -401,6 +430,11 @@ responselike@^2.0.0: dependencies: lowercase-keys "^2.0.0" +safe-buffer@5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + "safer-buffer@>= 2.1.2 < 3.0.0": version "2.1.2" resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz" @@ -420,6 +454,13 @@ side-channel@^1.0.4: get-intrinsic "^1.0.2" object-inspect "^1.9.0" +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + tough-cookie@^4.1.3: version "4.1.3" resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz" @@ -442,10 +483,10 @@ universalify@^0.2.0: resolved "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz" integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg== -url-join@^2.0.5: - version "2.0.5" - resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz" - integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg= +url-join@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" + integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== url-parse@^1.5.3: version "1.5.10" @@ -455,6 +496,13 @@ url-parse@^1.5.3: querystringify "^2.1.1" requires-port "^1.0.0" +whatwg-encoding@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz#e7635f597fd87020858626805a2729fa7698ac53" + integrity sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg== + dependencies: + iconv-lite "0.6.3" + wrappy@1: version "1.0.2" resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" From b51aa050aa89532ec498d472e23f702d037d76a0 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 12 Apr 2024 22:46:09 +0800 Subject: [PATCH 246/311] =?UTF-8?q?fix(Env.js):=20$.msg=20=E4=B8=8D?= =?UTF-8?q?=E4=BC=A0=20options=20=E5=8F=82=E6=95=B0=E6=97=B6=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 2 +- Env.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Env.js b/Env.js index 4fbf18c08..73547ab92 100644 --- a/Env.js +++ b/Env.js @@ -615,7 +615,7 @@ function Env(name, opts) { * @param {*} opts 通知参数 * */ - msg(title = name, subt = '', desc = '', opts) { + msg(title = name, subt = '', desc = '', opts = {}) { const toEnvOpts = (rawopts) => { const { $open, $copy, $media, $mediaMime } = rawopts switch (typeof rawopts) { diff --git a/Env.min.js b/Env.min.js index de4c7264e..dd5b98a1b 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o={}){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From c7148dbb641717662fea480f1444ae3c0200a0fb Mon Sep 17 00:00:00 2001 From: Chavy Date: Sat, 13 Apr 2024 11:19:13 +0800 Subject: [PATCH 247/311] =?UTF-8?q?fix(Env.js):=20=E4=BF=AE=E5=A4=8D=20qx?= =?UTF-8?q?=20=E5=92=8C=20loon=20=E4=B8=8D=E6=94=AF=E6=8C=81=20$media=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Env.js | 4 ++++ Env.min.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Env.js b/Env.js index 73547ab92..d6f859ab5 100644 --- a/Env.js +++ b/Env.js @@ -718,8 +718,10 @@ function Env(name, opts) { if (openUrl) Object.assign(options, { openUrl }) let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] + if ($media?.startsWith('http')) mediaUrl = $media if (mediaUrl) Object.assign(options, { mediaUrl }) + console.log(JSON.stringify(options)) return options } case 'Quantumult X': { @@ -730,6 +732,7 @@ function Env(name, opts) { if (openUrl) Object.assign(options, { 'open-url': openUrl }) let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl + if ($media?.startsWith('http')) mediaUrl = $media if (mediaUrl) Object.assign(options, { 'media-url': mediaUrl }) let copy = @@ -738,6 +741,7 @@ function Env(name, opts) { $copy if (copy) Object.assign(options, { 'update-pasteboard': copy }) + console.log(JSON.stringify(options)) return options } case 'Node.js': diff --git a/Env.min.js b/Env.min.js index dd5b98a1b..b234dd489 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o={}){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let i=t.openUrl||t.url||t["open-url"]||e;i&&Object.assign(s,{openUrl:i});let o=t.mediaUrl||t["media-url"];return o&&Object.assign(s,{mediaUrl:o}),s}case"Quantumult X":{const i={};let o=t["open-url"]||t.url||t.openUrl||e;o&&Object.assign(i,{"open-url":o});let r=t["media-url"]||t.mediaUrl;r&&Object.assign(i,{"media-url":r});let a=t["update-pasteboard"]||t.updatePasteboard||s;return a&&Object.assign(i,{"update-pasteboard":a}),i}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o={}){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(s,{openUrl:o});let r=t.mediaUrl||t["media-url"];return i?.startsWith("http")&&(r=i),r&&Object.assign(s,{mediaUrl:r}),console.log(JSON.stringify(s)),s}case"Quantumult X":{const o={};let r=t["open-url"]||t.url||t.openUrl||e;r&&Object.assign(o,{"open-url":r});let a=t["media-url"]||t.mediaUrl;i?.startsWith("http")&&(a=i),a&&Object.assign(o,{"media-url":a});let n=t["update-pasteboard"]||t.updatePasteboard||s;return n&&Object.assign(o,{"update-pasteboard":n}),console.log(JSON.stringify(o)),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From fba31acd83b6790dfaacdbe56be3eb57093211da Mon Sep 17 00:00:00 2001 From: Chavy Date: Sun, 14 Apr 2024 12:32:55 +0800 Subject: [PATCH 248/311] =?UTF-8?q?feat(box.switcher.js):=20=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=BC=9A=E5=9C=A82=E7=A7=92=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B6=88=E5=A4=B1.=20=E6=84=9F=E8=B0=A2=20@MuTu888=20?= =?UTF-8?q?PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/switcher/box.switcher.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/box/switcher/box.switcher.js b/box/switcher/box.switcher.js index e29204840..b9316367d 100644 --- a/box/switcher/box.switcher.js +++ b/box/switcher/box.switcher.js @@ -80,15 +80,30 @@ function getCurSessions() { } function showmsg() { - return new Promise((resove) => { - if (!$.CFG_isSilent || $.CFG_isSilent === 'false') { - $.msg($.name, $.subt, $.desc.join('\n')) + return new Promise((resolve) => { + const msgContent = $.desc.join('\n') + // 只有在Surge环境中,才使用特定的通知选项 + if ($.isSurge()) { + const options = { + "auto-dismiss": 2, // 2秒后自动消除通知 + "sound": true // 使用默认推送消息提示音 + } + if (!$.CFG_isSilent || $.CFG_isSilent === 'false') { + $notification.post($.name, $.subt, msgContent, options) + } else { + $.log('', ...$.desc) + } } else { - $.log('', ...$.desc) + // 在其他环境下,维持原有的消息显示逻辑 + if (!$.CFG_isSilent || $.CFG_isSilent === 'false') { + $.msg($.name, $.subt, msgContent) + } else { + $.log('', ...$.desc) + } } - resove() + resolve() }) } // prettier-ignore -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,h]=i.split("@"),a={url:`http://${h}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),h=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(h);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?(this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)})):this.isQuanX()?(this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t))):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)}))}post(t,e=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.post(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status),e(t,s,i)});else if(this.isQuanX())t.method="POST",this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t));else if(this.isNode()){this.initGotEnv(t);const{url:s,...i}=t;this.got.post(s,i).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>{const{message:s,response:i}=t;e(s,i,i&&i.body)})}}time(t){let e={"M+":(new Date).getMonth()+1,"d+":(new Date).getDate(),"H+":(new Date).getHours(),"m+":(new Date).getMinutes(),"s+":(new Date).getSeconds(),"q+":Math.floor(((new Date).getMonth()+3)/3),S:(new Date).getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,((new Date).getFullYear()+"").substr(4-RegExp.$1.length)));for(let s in e)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[s]:("00"+e[s]).substr((""+e[s]).length)));return t}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl;return{"open-url":e,"media-url":s}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):this.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${s} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,e)} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}))}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o={}){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(s,{openUrl:o});let r=t.mediaUrl||t["media-url"];return i?.startsWith("http")&&(r=i),r&&Object.assign(s,{mediaUrl:r}),console.log(JSON.stringify(s)),s}case"Quantumult X":{const o={};let r=t["open-url"]||t.url||t.openUrl||e;r&&Object.assign(o,{"open-url":r});let a=t["media-url"]||t.mediaUrl;i?.startsWith("http")&&(a=i),a&&Object.assign(o,{"media-url":a});let n=t["update-pasteboard"]||t.updatePasteboard||s;return n&&Object.assign(o,{"update-pasteboard":n}),console.log(JSON.stringify(o)),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file From c3d295b2598dedca5aefedf775267a0b0ff69b5f Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Wed, 17 Apr 2024 16:02:26 +0800 Subject: [PATCH 249/311] feat(modalSelects): select items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit items 为字符串时,可读取持久化数据作为 items --- box/chavy.boxjs.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 7e66f6c86..28f6301f3 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1042,7 +1042,7 @@

{{curapp.name}}

:hint="setting.desc" > -
+
{{curapp.name}}

type="number" item-text="label" item-value="key" - :items="setting.items" + :items="getItems(setting.items)" :label="setting.name" :hint="setting.desc" > @@ -1235,7 +1235,7 @@

Surge 费用计算器(open AI 编写)

计算费用

费用:{{ cost.toFixed(2) }}

- + @@ -2569,6 +2569,12 @@

v{{ver.versio this.box.usercfgs.favapps.splice(favAppIdx, 1) } }, + getItems(items){ + if(typeof items==="string"){ + return this.datas[items] || []; + } + return items; + }, // 加载应用信息 loadAppBaseInfo(app) { // 应用图标 From 746b91039e611045f46db577635377fc6aee32d8 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Wed, 17 Apr 2024 16:02:26 +0800 Subject: [PATCH 250/311] feat(modalSelects): select items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit items 为字符串时,可读取持久化数据作为 items --- box/chavy.boxjs.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index bc860ea25..4da921f62 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1067,7 +1067,7 @@

{{curapp.name}}

:hint="setting.desc" > -
+
{{curapp.name}}

type="number" item-text="label" item-value="key" - :items="setting.items" + :items="getItems(setting.items)" :label="setting.name" :hint="setting.desc" > @@ -2605,6 +2605,12 @@

v{{ver.versio this.box.usercfgs.favapps.splice(favAppIdx, 1) } }, + getItems(items){ + if(typeof items==="string"){ + return this.datas[items] || []; + } + return items; + }, // 加载应用信息 loadAppBaseInfo(app) { // 应用图标 From 8dfd0c181f34b1ee752bf85dbf63116ea1d12ea0 Mon Sep 17 00:00:00 2001 From: Chavy Date: Wed, 17 Apr 2024 17:45:37 +0800 Subject: [PATCH 251/311] =?UTF-8?q?feat(boxjs):=20=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E7=9A=84=E9=80=89=E9=A1=B9=E5=8F=AF=E4=BB=A5=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BB=8E=E6=8C=81=E4=B9=85=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=AD=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 2 +- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 19 +++++++++++++++++++ box/release/box.release.tf.json | 19 +++++++++++++++++++ chavy.box.js | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index bc860ea25..8bdc3737a 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2935,7 +2935,7 @@

v{{ver.versio if (!resp) return resp.data.forEach((contributor) => { const { login: id, login, html_url: repo, avatar_url: icon } = contributor - if ([29748519, 39037656, 9592236, 1210282, 65508083].includes(contributor.id)) { + if ([29748519, 39037656, 9592236, 1210282, 65508083, 23498579].includes(contributor.id)) { this.ui.collaborators.push({ id, login, repo, icon }) } else { this.ui.contributors.push({ id, login, repo, icon }) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 35685e595..81e4bad38 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.15.0' +$.version = '0.16.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 7f08fcc77..57a7f5cef 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.16.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "notes": [ + { + "name": "本次更新面向开发者", + "descs": [ + "下拉框的选项可以动态从持久化数据中读取", + "{..., \"type\": \"select\", \"items\": \"@gist.revision_options\", ...}" + ] + }, + { + "name": "感谢", + "descs": ["@dompling PR"] + } + ] + }, { "version": "0.15.0", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index ce30ca2f4..d6aa5738e 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,24 @@ { "releases": [ + { + "version": "0.16.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "notes": [ + { + "name": "本次更新面向开发者", + "descs": [ + "下拉框的选项可以动态从持久化数据中读取", + "{..., \"type\": \"select\", \"items\": \"@gist.revision_options\", ...}" + ] + }, + { + "name": "感谢", + "descs": ["@dompling PR"] + } + ] + }, { "version": "0.15.0", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 35685e595..81e4bad38 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.15.0' +$.version = '0.16.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From f44e804dde7b878155daa811b075859ee2f478d2 Mon Sep 17 00:00:00 2001 From: YY Date: Wed, 17 Apr 2024 17:47:05 +0800 Subject: [PATCH 252/311] feat(modalSelects): select items (#484) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(modalSelects): select items items 为字符串时,可读取持久化数据作为 items * feat(modalSelects): select items items 为字符串时,可读取持久化数据作为 items --------- Co-authored-by: dompling <374779789@qq.com> --- box/chavy.boxjs.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 8bdc3737a..d8dcb05d5 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1067,7 +1067,7 @@

{{curapp.name}}

:hint="setting.desc" > -
+
{{curapp.name}}

type="number" item-text="label" item-value="key" - :items="setting.items" + :items="getItems(setting.items)" :label="setting.name" :hint="setting.desc" > @@ -2605,6 +2605,12 @@

v{{ver.versio this.box.usercfgs.favapps.splice(favAppIdx, 1) } }, + getItems(items){ + if(typeof items==="string"){ + return this.datas[items] || []; + } + return items; + }, // 加载应用信息 loadAppBaseInfo(app) { // 应用图标 From 210c89b25d6fb80c8f6e721cb6773d012955ae8d Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 09:20:17 +0800 Subject: [PATCH 253/311] feat(items): all items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit items 为字符串时,可读取持久化数据作为 items --- box/chavy.boxjs.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 4da921f62..482833e9e 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1075,7 +1075,7 @@

{{curapp.name}}

type="number" item-text="label" item-value="key" - :items="getItems(setting.items)" + :items="setting.items" :label="setting.name" :hint="setting.desc" > @@ -2195,6 +2195,12 @@

v{{ver.versio const appId = decodeURIComponent(decodeURIComponent(this.subview)) const app = this.apps.find((app) => app.id === appId) this.loadAppDataInfo(app) + app.settings = app.settings.map(setting=>{ + if(setting.items && typeof setting.items === "string"){ + return {...setting,items:this.box.datas[setting.items] || []}; + } + return {...setting} + }) return app } }, @@ -2605,12 +2611,6 @@

v{{ver.versio this.box.usercfgs.favapps.splice(favAppIdx, 1) } }, - getItems(items){ - if(typeof items==="string"){ - return this.datas[items] || []; - } - return items; - }, // 加载应用信息 loadAppBaseInfo(app) { // 应用图标 From 6345480374d94ae0241fcbb350f916afe8a8dc13 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 10:29:34 +0800 Subject: [PATCH 254/311] =?UTF-8?q?feat(regulate):=20=E8=BF=91=E6=9C=9F?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E3=80=81=E9=9D=9E=E8=AE=A2=E9=98=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.增加非订阅数据,手动保存可备份到 Gist 2.调整近期查看数据样式,优化 tag 的长度 --- box/chavy.boxjs.html | 63 ++++++++++++++++++++++++++++----- box/release/box.release.json | 11 ++++-- box/release/box.release.tf.json | 11 ++++-- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index bc234b876..74c5e20d0 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -881,6 +881,36 @@ + + + + {{ $t('viewer.dataUnsubscribed') }} ({{gistkeys.length}}) + + + + + + + + + + + {{ $t('viewer.dataRecentlyViewed') }} ({{viewkeys.length}}) + + + + + + + {{ $t('viewer.dataViewer') }} @@ -898,11 +928,6 @@ > - @@ -1578,6 +1603,8 @@

v{{ver.versio dataEditor: 'Data Editor', dataVal: 'Data Value', dataEditable: 'This data is not editable', + dataRecentlyViewed: 'Recently viewed', + dataUnsubscribed:"Unsubscribed data" }, reloadDialog: { title: 'Next', @@ -1733,6 +1760,8 @@

v{{ver.versio dataEditor: '数据编辑器', dataVal: '数据内容', dataEditable: '该数据不可编辑', + dataRecentlyViewed: '近期查看', + dataUnsubscribed: '非订阅数据' }, reloadDialog: { title: '接下来', @@ -2182,6 +2211,17 @@

v{{ver.versio apps.push(...this.sysApps) return apps }, + appsAllKeys(){ + let keys = []; + this.apps.forEach(item=>{ + if(item.keys) keys = [...keys,...item.keys] + if(item.settings && item.settings.length>0){ + const settingKey = item.settings.map((setting)=>setting.id).filter(id=>!keys.includes(id)) + keys=[...keys,...settingKey] + } + }); + return keys; + }, searchApps() { return this.apps.filter((app) => app.id.includes(this.ui.searchBar.input) || app.name.includes(this.ui.searchBar.input)) }, @@ -2214,6 +2254,9 @@

v{{ver.versio }, viewkeys() { return Array.from(new Set(this.box.usercfgs.viewkeys)).filter((k) => k) + }, + gistkeys() { + return Array.from(new Set(this.box.usercfgs.gist_cache_key)).filter((k) => k) } }, watch: { @@ -2971,11 +3014,11 @@

v{{ver.versio this.queryData() }, - delviewkey(key) { + delviewkey(key,type) { if (this.ui.viewer.key == key) { this.ui.viewer.key = '' } - this.box.usercfgs.viewkeys = this.box.usercfgs.viewkeys.filter((k) => k != key) + this.box.usercfgs[type] = this.box.usercfgs[type].filter((k) => k != key) }, // 查询数据 queryData() { @@ -2991,7 +3034,11 @@

v{{ver.versio const key = this.ui.viewer.key const val = this.ui.viewer.val if (key) { - axios.post('/api/saveData/', { key, val }).then((resp) => { + if(!this.appsAllKeys.includes(key) && !this.box.usercfgs.gist_cache_key.includes(key)){ + const newkeys = [key, ...this.box.usercfgs.gist_cache_key] + this.box.usercfgs.gist_cache_key = Array.from(new Set(newkeys)).filter((k) => k) + } + axios.post('/api/saveData/', {key,val}).then((resp) => { this.ui.viewer.val = resp.data.val }) } diff --git a/box/release/box.release.json b/box/release/box.release.json index 57a7f5cef..580c216e3 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -7,9 +7,16 @@ "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", "notes": [ { - "name": "本次更新面向开发者", + "name": "数据查看器", "descs": [ - "下拉框的选项可以动态从持久化数据中读取", + "近期查看样式调整", + "非订阅数据查看和保存" + ] + }, + { + "name": "面向开发者", + "descs": [ + "Items 选项可以动态从持久化数据中读取", "{..., \"type\": \"select\", \"items\": \"@gist.revision_options\", ...}" ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index d6aa5738e..d07f49c76 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -7,9 +7,16 @@ "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", "notes": [ { - "name": "本次更新面向开发者", + "name": "数据查看器", "descs": [ - "下拉框的选项可以动态从持久化数据中读取", + "近期查看样式调整", + "非订阅数据查看和保存" + ] + }, + { + "name": "面向开发者", + "descs": [ + "Items 选项可以动态从持久化数据中读取", "{..., \"type\": \"select\", \"items\": \"@gist.revision_options\", ...}" ] }, From 2f3889df20a2cc8fe28a808dde848c6d74d6e90b Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 10:49:22 +0800 Subject: [PATCH 255/311] =?UTF-8?q?feat(regulate):=20=E8=BF=91=E6=9C=9F?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E3=80=81=E9=9D=9E=E8=AE=A2=E9=98=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.增加非订阅数据,手动保存可备份到 Gist 2.调整近期查看数据样式,优化 tag 的长度 --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 14 +++++++++++--- box/release/box.release.tf.json | 14 +++++++++++--- chavy.box.js | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 81e4bad38..4e5b80a37 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.16.0' +$.version = '0.17.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 580c216e3..27f2cac0b 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,10 +1,10 @@ { "releases": [ { - "version": "0.16.0", + "version": "0.17.0", "tags": ["beta"], "author": "@dompling", - "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "msg": "feat(viewer): 数据查看器", "notes": [ { "name": "数据查看器", @@ -12,7 +12,15 @@ "近期查看样式调整", "非订阅数据查看和保存" ] - }, + } + ] + }, + { + "version": "0.16.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "notes": [ { "name": "面向开发者", "descs": [ diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index d07f49c76..881702e3b 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,10 +1,10 @@ { "releases": [ { - "version": "0.16.0", + "version": "0.17.0", "tags": ["beta"], "author": "@dompling", - "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "msg": "feat(viewer): 数据查看器", "notes": [ { "name": "数据查看器", @@ -12,7 +12,15 @@ "近期查看样式调整", "非订阅数据查看和保存" ] - }, + } + ] + }, + { + "version": "0.16.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "feat(boxjs): 下拉框的选项可以动态从持久化数据中读取", + "notes": [ { "name": "面向开发者", "descs": [ diff --git a/chavy.box.js b/chavy.box.js index 81e4bad38..4e5b80a37 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.16.0' +$.version = '0.17.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 3fe0a9137f87062715667a7ac5d887adefc363d5 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 11:03:15 +0800 Subject: [PATCH 256/311] =?UTF-8?q?feat(BoxGist):=20Gist=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 84 +++++++++++++++++++++++++++++++++++++++------- chavy.box.js | 84 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 144 insertions(+), 24 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 4e5b80a37..742d50ec6 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -454,23 +454,32 @@ function getSystemApps() { { "id": "BoxGist", "name": "Gist备份", - "keys": ["@gist.token", "@gist.username"], + "keys": [ + "@gist.token", + "@gist.username", + "@gist.split", + "@gist.revision_options", + "@gist.backup_type" + ], "author": "@dompling", - "repo": "https://github.com/dompling/Script/tree/master/gist", "icons": [ "https://raw.githubusercontent.com/Former-Years/icon/master/github-bf.png", "https://raw.githubusercontent.com/Former-Years/icon/master/github-bf.png" ], "descs_html": [ - "脚本由 @dompling 提供, 感谢!", - "
", - "Token 获取方式:", - "头像菜单 ->", - "Settings ->", - "Developer settings ->", - "Personal access tokens ->", - "Generate new token ->", - "在里面找到 gist 勾选提交" + "

Token的获取方式

", + "
    头像菜单 ->
", + "
    Settings ->
", + "
    Developer settings ->
", + "
    Personal access tokens ->
", + "
    Generate new token ->
", + "
    在里面找到 gist 勾选提交
", + "

Gist Revision Id

", + "
    打开Gist项目
", + "
    默认为Code,选择Revisions
", + "
    找到需要恢复的版本文件
", + "
    点击右上角【...】>【View file】
", + "
    浏览器地址最后一串为 RevisionId
" ], "scripts": [ { @@ -480,9 +489,60 @@ function getSystemApps() { { "name": "从 Gist 恢复", "script": "https://raw.githubusercontent.com/dompling/Script/master/gist/restore.js" + }, + { + "name": "更新历史版本", + "script": "https://raw.githubusercontent.com/dompling/Script/master/gist/commit.js" } ], "settings": [ + { + "id": "@gist.split", + "name": "用户数据分段", + "val": null, + "type": "number", + "placeholder": "用户数据过大时,请进行拆分防止内存警告⚠️", + "desc": "值为数字,拆分段数比如 2 就拆分成两个 datas." + }, + { + "id": "@gist.revision_id", + "type": "modalSelects", + "name": "历史版本RevisionId", + "desc": "不填写时,默认获取最新,恢复后会自动清空。选择无内容时,请运行上方更新历史版本", + "items": "@gist.revision_options" + }, + { + "id": "@gist.backup_type", + "name": "备份/恢复内容", + "val": "usercfgs,datas,sessions,curSessions,backups,appSubCaches", + "type": "checkboxes", + "items": [ + { + "key": "usercfgs", + "label": "用户偏好" + }, + { + "key": "datas", + "label": "用户数据" + }, + { + "key": "sessions", + "label": "应用会话" + }, + { + "key": "curSessions", + "label": "当前会话" + }, + { + "key": "backups", + "label": "备份索引" + }, + { + "key": "appSubCaches", + "label": "应用订阅缓存" + } + ] + }, { "id": "@gist.username", "name": "用户名", @@ -500,7 +560,7 @@ function getSystemApps() { "desc": "必填" } ] - } + }, ] return sysapps } diff --git a/chavy.box.js b/chavy.box.js index 4e5b80a37..742d50ec6 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -454,23 +454,32 @@ function getSystemApps() { { "id": "BoxGist", "name": "Gist备份", - "keys": ["@gist.token", "@gist.username"], + "keys": [ + "@gist.token", + "@gist.username", + "@gist.split", + "@gist.revision_options", + "@gist.backup_type" + ], "author": "@dompling", - "repo": "https://github.com/dompling/Script/tree/master/gist", "icons": [ "https://raw.githubusercontent.com/Former-Years/icon/master/github-bf.png", "https://raw.githubusercontent.com/Former-Years/icon/master/github-bf.png" ], "descs_html": [ - "脚本由 @dompling 提供, 感谢!", - "
", - "Token 获取方式:", - "头像菜单 ->", - "Settings ->", - "Developer settings ->", - "Personal access tokens ->", - "Generate new token ->", - "在里面找到 gist 勾选提交" + "

Token的获取方式

", + "
    头像菜单 ->
", + "
    Settings ->
", + "
    Developer settings ->
", + "
    Personal access tokens ->
", + "
    Generate new token ->
", + "
    在里面找到 gist 勾选提交
", + "

Gist Revision Id

", + "
    打开Gist项目
", + "
    默认为Code,选择Revisions
", + "
    找到需要恢复的版本文件
", + "
    点击右上角【...】>【View file】
", + "
    浏览器地址最后一串为 RevisionId
" ], "scripts": [ { @@ -480,9 +489,60 @@ function getSystemApps() { { "name": "从 Gist 恢复", "script": "https://raw.githubusercontent.com/dompling/Script/master/gist/restore.js" + }, + { + "name": "更新历史版本", + "script": "https://raw.githubusercontent.com/dompling/Script/master/gist/commit.js" } ], "settings": [ + { + "id": "@gist.split", + "name": "用户数据分段", + "val": null, + "type": "number", + "placeholder": "用户数据过大时,请进行拆分防止内存警告⚠️", + "desc": "值为数字,拆分段数比如 2 就拆分成两个 datas." + }, + { + "id": "@gist.revision_id", + "type": "modalSelects", + "name": "历史版本RevisionId", + "desc": "不填写时,默认获取最新,恢复后会自动清空。选择无内容时,请运行上方更新历史版本", + "items": "@gist.revision_options" + }, + { + "id": "@gist.backup_type", + "name": "备份/恢复内容", + "val": "usercfgs,datas,sessions,curSessions,backups,appSubCaches", + "type": "checkboxes", + "items": [ + { + "key": "usercfgs", + "label": "用户偏好" + }, + { + "key": "datas", + "label": "用户数据" + }, + { + "key": "sessions", + "label": "应用会话" + }, + { + "key": "curSessions", + "label": "当前会话" + }, + { + "key": "backups", + "label": "备份索引" + }, + { + "key": "appSubCaches", + "label": "应用订阅缓存" + } + ] + }, { "id": "@gist.username", "name": "用户名", @@ -500,7 +560,7 @@ function getSystemApps() { "desc": "必填" } ] - } + }, ] return sysapps } From 112ab1230e1213a5dd1daab2d0371e1b6e3227e8 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 15:49:22 +0800 Subject: [PATCH 257/311] =?UTF-8?q?fix(boxjs):=20appid=20=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复不同作者订阅中包含相同的 appid 无法正常跳转问题 --- box/chavy.boxjs.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 74c5e20d0..c726f1a52 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2202,6 +2202,31 @@

v{{ver.versio }, // 获取`订阅`缓存 appSubCaches() { + const ids = []; + this.box.usercfgs.appsubs.forEach((appsub) => { + const sub = this.box.appSubCaches[appsub.url] + if (sub && sub.apps && Array.isArray(sub.apps) && !appsub.isErr) { + sub.apps.forEach((app) => { + ids.push(app.id) + }) + } + }) + + const replyIds = _.filter(ids, (val, i, iteratee) => + _.includes(iteratee, val, i + 1) + ); + + this.box.usercfgs.appsubs.forEach((appsub) => { + const sub = this.box.appSubCaches[appsub.url]; + if (sub && sub.apps && Array.isArray(sub.apps) && !appsub.isErr) { + sub.apps = sub.apps.map((app) => { + if (replyIds.includes(app.id)) { + return { ...app, id: `${app.author}_${app.id}` }; + } + return app; + }) + } + }); return this.box.appSubCaches }, // 获取所有应用`内置应用`+`订阅应用` From 91c93d86f88512d3dc7074267c43590c5b7422bb Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 16:00:00 +0800 Subject: [PATCH 258/311] =?UTF-8?q?fix(boxjs):=20appid=20=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复不同作者订阅中包含相同的 appid 无法正常跳转问题 --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 15 +++++++++++++++ box/release/box.release.tf.json | 10 +++++----- chavy.box.js | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 742d50ec6..629b41bbd 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.17.0' +$.version = '0.18.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 27f2cac0b..778b496b0 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,20 @@ { "releases": [ + { + "version": "0.18.0", + "tags": ["beta"], + "author": "@dompling", + "msg": "fix(boxjs): appid 重复", + "notes": [ + { + "name": "appid重复问题", + "descs": [ + "修复无法正常跳转问题", + "修复无法正常收藏" + ] + } + ] + }, { "version": "0.17.0", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 881702e3b..79563752e 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,16 +1,16 @@ { "releases": [ { - "version": "0.17.0", + "version": "0.18.0", "tags": ["beta"], "author": "@dompling", - "msg": "feat(viewer): 数据查看器", + "msg": "fix(boxjs): appid 重复", "notes": [ { - "name": "数据查看器", + "name": "appid重复问题", "descs": [ - "近期查看样式调整", - "非订阅数据查看和保存" + "修复无法正常跳转问题", + "修复无法正常收藏" ] } ] diff --git a/chavy.box.js b/chavy.box.js index 742d50ec6..629b41bbd 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.17.0' +$.version = '0.18.0' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 9ea476aa48641173364be57f9a144ca1820a4139 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 16:01:05 +0800 Subject: [PATCH 259/311] =?UTF-8?q?fix(boxjs):=20appid=20=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复不同作者订阅中包含相同的 appid 无法正常跳转问题 --- box/release/box.release.tf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 79563752e..1bcad9829 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -9,7 +9,7 @@ { "name": "appid重复问题", "descs": [ - "修复无法正常跳转问题", + "修复无法正常跳转", "修复无法正常收藏" ] } From 76490f3173670a2a57c71d676914ca74484413ba Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 16:43:12 +0800 Subject: [PATCH 260/311] fix(boxjs): debugger_webs --- box/chavy.boxjs.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index c726f1a52..1f4caae9f 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -524,6 +524,21 @@ + + + + + + + + @@ -2282,6 +2297,17 @@

v{{ver.versio }, gistkeys() { return Array.from(new Set(this.box.usercfgs.gist_cache_key)).filter((k) => k) + }, + debuggerWebs() { + const items = [] + const debuggerWebs = this.box.usercfgs.debugger_webs + if (debuggerWebs) { + debuggerWebs.split('\n').forEach((debuggerWeb) => { + const [name, url] = debuggerWeb.split(',') + items.push({ name, url }) + }) + } + return items } }, watch: { From bd4faa42ab55b1e569c84afa47b62d847004ae90 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 16:59:27 +0800 Subject: [PATCH 261/311] fix(boxjs): debugger_webs --- box/chavy.boxjs.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 1f4caae9f..7761a87d4 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -525,12 +525,13 @@ - + v{{ver.versio debugMode: 'Debug Mode', debugModeDesc: 'No page caches', debugPage: 'Debug Page Addr', + debugPages: 'Debug Page caches', debugPageDesc: 'Load page from...' }, profile: { @@ -1734,6 +1736,7 @@

v{{ver.versio debugMode: '调试模式', debugModeDesc: '每次请求都获取最新的页面', debugPage: '调试页面地址', + debugPages:'调试页面缓存', debugPageDesc: '页面源码的获取地址' }, profile: { From 616d57ebc54cdd1119c6c83f07ab3ca7f1e7bb14 Mon Sep 17 00:00:00 2001 From: Chavy Date: Thu, 18 Apr 2024 17:04:49 +0800 Subject: [PATCH 262/311] =?UTF-8?q?feat(box.switcher.js):=20=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E4=BC=9A=E8=AF=9D=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8C=87=E5=AE=9A=E4=BB=85=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=9F=90=E4=BA=9B=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/switcher/box.switcher.js | 44 ++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/box/switcher/box.switcher.js b/box/switcher/box.switcher.js index b9316367d..f76731e75 100644 --- a/box/switcher/box.switcher.js +++ b/box/switcher/box.switcher.js @@ -3,6 +3,10 @@ $.KEY_sessions = 'chavy_boxjs_sessions' $.KEY_curSessions = 'chavy_boxjs_cur_sessions' $.CFG_isSilent = $.getdata('CFG_BoxSwitcher_isSilent') +$.appIds = (globalThis.$intent?.parameter ?? globalThis.$argument ?? '').split( + ',' +) + !(async () => { await execSwitch() await showmsg() @@ -11,20 +15,30 @@ $.CFG_isSilent = $.getdata('CFG_BoxSwitcher_isSilent') .finally(() => $.done()) function execSwitch() { + if (Array.isArray($.appIds) && $.appIds.length) { + $.log(`指定切换: ${$.appIds.join(',')}`) + } $.subt = '' $.desc = [] return new Promise((resove) => { const sessions = getSessions() const curSessions = getCurSessions() // 会话排序: `创建时间`升序 - sessions.sort((a, b) => a.createTime.replace(/-|:| /g, '') - b.createTime.replace(/-|:| /g, '')) + sessions.sort( + (a, b) => + a.createTime.replace(/-|:| /g, '') - b.createTime.replace(/-|:| /g, '') + ) const apps = {} sessions.forEach((session) => { const appId = session.appId - const appName = session.appName - apps[appId] = apps[appId] ? apps[appId] : { id: appId, name: appName, sessions: [] } - const app = apps[appId] - app.sessions.push(session) + if ($.appIds.includes(appId)) { + const appName = session.appName + apps[appId] = apps[appId] + ? apps[appId] + : { id: appId, name: appName, sessions: [] } + const app = apps[appId] + app.sessions.push(session) + } }) const switchkeys = {} Object.keys(apps).forEach((appId) => { @@ -33,7 +47,9 @@ function execSwitch() { $.desc.push(`${app.name}: 跳过! 原因: 只有 1 个会话?`) return true } - let curSessionIdx = app.sessions.findIndex((session) => session.id === curSessions[appId]) + let curSessionIdx = app.sessions.findIndex( + (session) => session.id === curSessions[appId] + ) if (curSessionIdx === -1) { curSessionIdx = app.sessions.length - 1 } @@ -43,13 +59,21 @@ function execSwitch() { const nextSession = app.sessions[nextSessionIdx] nextSession.datas.forEach((_data) => { const key = _data.key - const val = [undefined, null, 'undefined', 'null', ''].includes(_data.val) ? '' : _data.val + const val = [undefined, null, 'undefined', 'null', ''].includes( + _data.val + ) + ? '' + : _data.val if (switchkeys[key]) { const swData = switchkeys[key] const isClash = swData.val !== val ? true : false if (isClash) { nextSession.isClash = true - $.log('', `⚠️【${key}】冲突: `, ` ${nextSession.appName}.${nextSession.name} => ${swData.session.appName}.${swData.session.name}`) + $.log( + '', + `⚠️【${key}】冲突: `, + ` ${nextSession.appName}.${nextSession.name} => ${swData.session.appName}.${swData.session.name}` + ) } } else { switchkeys[key] = {} @@ -61,7 +85,9 @@ function execSwitch() { }) curSessions[appId] = nextSession.id const clashstr = nextSession.isClash === true ? ' (冲突)' : '' - $.desc.push(`${curSession.appName}: ${curSession.name} => #${nextSessionIdx + 1} ${nextSession.name}${clashstr} ${isNewRound ? '(新一轮)' : ''}`) + $.desc.push( + `${curSession.appName}: ${curSession.name} => #${nextSessionIdx + 1} ${nextSession.name}${clashstr} ${isNewRound ? '(新一轮)' : ''}` + ) }) $.setdata(JSON.stringify(curSessions), $.KEY_curSessions) resove() From 551b899db9b340791430d9a9059a1569d0b89d64 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 17:14:45 +0800 Subject: [PATCH 263/311] fix(boxjs): debugger_webs --- box/chavy.boxjs.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index 7761a87d4..c5ff152be 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -534,7 +534,7 @@ :label="$t('prefs.debugPages')" item-text="name" item-value="url" - @change="saveUserCfgs" + @change="saveUserCfgs(true)" > @@ -2793,11 +2793,14 @@

v{{ver.versio }) }, // 保存用户偏好 - saveUserCfgs() { + saveUserCfgs(isReload) { const key = 'chavy_boxjs_userCfgs' const val = JSON.stringify(this.box.usercfgs) axios.post('/api/save', [{ key, val }]).then((resp) => { this.loadTheme() + if(isReload){ + this.reload() + } }) }, // 保存应用设置 From e8b80490a26205297eea328b1760a204c5510b2f Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Thu, 18 Apr 2024 17:26:52 +0800 Subject: [PATCH 264/311] feat(boxjs): debugger_webs --- box/chavy.boxjs.js | 1 + chavy.box.js | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 629b41bbd..2aea8bed2 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -397,6 +397,7 @@ function getSystemApps() { { 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.debugger_webs', name: '调试地址', val: 'Dev体验,https://raw.githubusercontent.com/chavyleung/scripts/boxjs.dev/box/chavy.boxjs.html', type: 'textarea', placeholder: '每行一个配置,用逗号分割每个配置的名字和链接:配置,url', persistentHint:true, autoGrow: true, rows: 2, desc: '逗号分隔名字和链接, 回车分隔多个地址' }, { 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: '' }, diff --git a/chavy.box.js b/chavy.box.js index 629b41bbd..b53485455 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -61,10 +61,10 @@ $.ver = `https://raw.githubusercontent.com/chavyleung/scripts/master/box/release const [, query] = $.path.split('?') $.queries = query ? query.split('&').reduce((obj, cur) => { - const [key, val] = cur.split('=') - obj[key] = val - return obj - }, {}) + const [key, val] = cur.split('=') + obj[key] = val + return obj + }, {}) : {} // 请求类型: GET @@ -312,7 +312,7 @@ async function handleOptions() {} function getBoxData() { const datas = {} - + const extraDatas = $.getdata(`${$.KEY_usercfgs.replace('#', '@')}.gist_cache_key`) || [] @@ -397,6 +397,7 @@ function getSystemApps() { { 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.debugger_webs', name: '调试地址', val: 'Dev体验,https://raw.githubusercontent.com/chavyleung/scripts/boxjs.dev/box/chavy.boxjs.html', type: 'textarea', placeholder: '每行一个配置,用逗号分割每个配置的名字和链接:配置,url', persistentHint:true, autoGrow: true, rows: 2, desc: '逗号分隔名字和链接, 回车分隔多个地址' }, { 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: '' }, From bc4d40ace387c7655434dbeff42f80a16e50a28c Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 19 Apr 2024 14:08:39 +0800 Subject: [PATCH 265/311] =?UTF-8?q?fix(box.switcher.js):=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=8C=87=E5=AE=9A=E5=8F=82=E6=95=B0=E6=97=B6=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=88=87=E6=8D=A2=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/switcher/box.switcher.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/box/switcher/box.switcher.js b/box/switcher/box.switcher.js index f76731e75..3e910b66f 100644 --- a/box/switcher/box.switcher.js +++ b/box/switcher/box.switcher.js @@ -3,9 +3,8 @@ $.KEY_sessions = 'chavy_boxjs_sessions' $.KEY_curSessions = 'chavy_boxjs_cur_sessions' $.CFG_isSilent = $.getdata('CFG_BoxSwitcher_isSilent') -$.appIds = (globalThis.$intent?.parameter ?? globalThis.$argument ?? '').split( - ',' -) +$.appIds = + (globalThis.$intent?.parameter ?? globalThis.$argument)?.split(',') ?? [] !(async () => { await execSwitch() From 02380eaca02ed64b872cfe2822cca1a3b03bf964 Mon Sep 17 00:00:00 2001 From: Chavy Date: Fri, 19 Apr 2024 14:26:36 +0800 Subject: [PATCH 266/311] =?UTF-8?q?fix(box.switcher.js):=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=8C=87=E5=AE=9A=E5=8F=82=E6=95=B0=E6=97=B6=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=88=87=E6=8D=A2=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/switcher/box.switcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box/switcher/box.switcher.js b/box/switcher/box.switcher.js index 3e910b66f..3f0dcd903 100644 --- a/box/switcher/box.switcher.js +++ b/box/switcher/box.switcher.js @@ -30,7 +30,7 @@ function execSwitch() { const apps = {} sessions.forEach((session) => { const appId = session.appId - if ($.appIds.includes(appId)) { + if ($.appIds.length == 0 || $.appIds.includes(appId)) { const appName = session.appName apps[appId] = apps[appId] ? apps[appId] From e6cf0de0c6a9c5da6d04cf9d02a750c2d8f64021 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Fri, 19 Apr 2024 14:37:59 +0800 Subject: [PATCH 267/311] fix(boxjs): app.settings not fond --- box/chavy.boxjs.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index c5ff152be..e65f49a8f 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -2278,12 +2278,14 @@

v{{ver.versio const appId = decodeURIComponent(decodeURIComponent(this.subview)) const app = this.apps.find((app) => app.id === appId) this.loadAppDataInfo(app) - app.settings = app.settings.map(setting=>{ - if(setting.items && typeof setting.items === "string"){ - return {...setting,items:this.box.datas[setting.items] || []}; - } - return {...setting} - }) + if(app.settings){ + app.settings = app.settings.map(setting=>{ + if(setting.items && typeof setting.items === "string"){ + return {...setting,items:this.box.datas[setting.items] || []}; + } + return {...setting} + }) + } return app } }, From 56af0992b098780affbdb5f7e662949826da1c53 Mon Sep 17 00:00:00 2001 From: dompling <374779789@qq.com> Date: Fri, 19 Apr 2024 14:51:14 +0800 Subject: [PATCH 268/311] fix(boxjs): debug_webs --- box/chavy.boxjs.html | 6022 +++++++++++++++++++++--------------------- 1 file changed, 3011 insertions(+), 3011 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index e65f49a8f..e33cb2578 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1,375 +1,375 @@ - - BoxJs - - - - - - - - - - - - - - -
-
- - - - - - + + mdi-delete-circle-outline + mdi-help mdi-new-box - - mdi-calculator-variant-outline - {{box.usercfgs.isLeftBoxIcon ? 'mdi-format-horizontal-align-right' : 'mdi-format-horizontal-align-left'}} @@ -1847,10 +1821,6 @@

v{{ver.versio }, boxServerData: null, box: null, - purchaseDate: null, - cost: 0, - licenseTypes: ["1 Device License", "3 Devices License", "5 Devices License"], - licenseType: '' } }, computed: { @@ -3102,42 +3072,6 @@

v{{ver.versio } } }, - calculateUpgradePrice(purchaseDate, licenseType) { - const licensePrices = { - '1 Device License': 34.99, - '3 Devices License': 48.99, - '5 Devices License': 69.99, - } - - const upgradePrice = licensePrices[licenseType] - if (!upgradePrice) { - throw new Error(`Invalid license type: ${licenseType}`) - } - - const discountEndDate = dayjs('2022-04-15') - const freeDate = dayjs('2022-10-15') - - if (dayjs(purchaseDate).isBefore(discountEndDate)) { - return licensePrices[licenseType] - } - - const equivalentPurchaseDate = dayjs(purchaseDate) - - const diffDays = freeDate.diff(discountEndDate, 'day') - const daysFromDiscountEndDate = equivalentPurchaseDate.diff(discountEndDate, 'day') - - if (daysFromDiscountEndDate >= diffDays) { - // After free upgrade date - return 0 - } else { - const ratio = 1 - daysFromDiscountEndDate / diffDays - const price = Math.ceil(ratio * upgradePrice * 100) / 100 - 0.01 - return price < 1.99 ? 1.99 : price - } - }, - calculateCost() { - this.cost = this.calculateUpgradePrice(this.purchaseDate, this.licenseType) - }, } }) diff --git a/box/release/box.release.json b/box/release/box.release.json index a6fa9307a..0b09761d3 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,19 @@ { "releases": [ + { + "version": "0.19.19", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "feat(ui): 支持首页删除收藏应用", + "notes": [ + { + "name": "UI 更新", + "descs": [ + "支持首页删除收藏应用,开启方式在悬浮按钮上" + ] + } + ] + }, { "version": "0.19.17", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 300107980..61b2b0437 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,19 @@ { "releases": [ + { + "version": "0.19.19", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "feat(ui): 支持首页删除收藏应用", + "notes": [ + { + "name": "UI 更新", + "descs": [ + "支持首页删除收藏应用,开启方式在悬浮按钮上" + ] + } + ] + }, { "version": "0.19.17", "tags": ["beta"], From 4569ce036aa9be04128ae9069bdbe7782bb376e5 Mon Sep 17 00:00:00 2001 From: chavyleung Date: Tue, 29 Oct 2024 08:32:40 +0800 Subject: [PATCH 302/311] =?UTF-8?q?chore(boxjs):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 6 ++---- box/release/box.release.tf.json | 6 ++---- chavy.box.js | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index dbc461396..11bc806c0 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.17' +$.version = '0.19.20' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index 0b09761d3..d6a2cf416 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,16 +1,14 @@ { "releases": [ { - "version": "0.19.19", + "version": "0.19.20", "tags": ["beta"], "author": "@GideonSenku", "msg": "feat(ui): 支持首页删除收藏应用", "notes": [ { "name": "UI 更新", - "descs": [ - "支持首页删除收藏应用,开启方式在悬浮按钮上" - ] + "descs": ["支持首页删除收藏应用,开启方式在悬浮按钮上"] } ] }, diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 61b2b0437..0c7ea3470 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,16 +1,14 @@ { "releases": [ { - "version": "0.19.19", + "version": "0.19.20", "tags": ["beta"], "author": "@GideonSenku", "msg": "feat(ui): 支持首页删除收藏应用", "notes": [ { "name": "UI 更新", - "descs": [ - "支持首页删除收藏应用,开启方式在悬浮按钮上" - ] + "descs": ["支持首页删除收藏应用,开启方式在悬浮按钮上"] } ] }, diff --git a/chavy.box.js b/chavy.box.js index dbc461396..11bc806c0 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.17' +$.version = '0.19.20' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite From 1d2786682bd2888ab0f1f5c329c0cf3ca1a6640b Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Mon, 16 Dec 2024 15:33:57 +0800 Subject: [PATCH 303/311] =?UTF-8?q?feat:=20=E5=B0=9D=E8=AF=95=E9=AD=94?= =?UTF-8?q?=E8=B1=86=E6=8A=BD=E5=A5=96=E8=8E=B7=E5=BE=97=E6=97=A0=E9=97=A8?= =?UTF-8?q?=E6=A7=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- citybox/citybox.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/citybox/citybox.js b/citybox/citybox.js index 99a3a8443..f80b271d8 100644 --- a/citybox/citybox.js +++ b/citybox/citybox.js @@ -7,8 +7,9 @@ const drawRes = [] const har = $.getjson(KEY_har) const headers = har?.headers await sign(headers) - await draw(headers) - await draw(headers) + await getDrawList(headers) + await draw(headers, $.drawIndex0) + await draw(headers, $.drawIndex1) if ($.sign?.signnum) { $.msg($.name, `第${$.sign.signnum}天 签到成功`, drawRes.join('\n')) } else if ($.sign?.message) { @@ -38,16 +39,31 @@ function sign(headers) { }) } -function draw(headers) { +function getDrawList(headers) { return new Promise((resolve) => { const url = { - url: hostApi + '/roulette_draw/draw_results', + url: hostApi + '/roulette_draw/index', + headers, + } + $.get(url, (err, resp, data) => { + const res = JSON.parse(data) + $.drawIndex0 = res.data.draw_list.findIndex(item => item.task_name === '5元无门槛优惠券') + $.drawIndex1 = res.data.draw_list.findIndex(item => item.tag_modou === '500') + }) + }) +} + +function draw(headers, index) { + return new Promise((resolve) => { + const path = index ? 'draw_results?click_num=' + index : 'draw_results' + const url = { + url: hostApi + '/' + path, headers, } $.post(url, (err, resp, data) => { try { - const data = JSON.parse(data) - drawRes.push(data.winning_desc) + const res = JSON.parse(data) + drawRes.push(res.winning_desc) } catch (e) { $.logErr(e, resp) } finally { From baa2893f9c95a720c4e32570caa5df5e4a2a9772 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Mon, 30 Dec 2024 15:36:14 +0800 Subject: [PATCH 304/311] fix: draw --- citybox/citybox.js | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/citybox/citybox.js b/citybox/citybox.js index f80b271d8..f5f0707d7 100644 --- a/citybox/citybox.js +++ b/citybox/citybox.js @@ -7,9 +7,8 @@ const drawRes = [] const har = $.getjson(KEY_har) const headers = har?.headers await sign(headers) - await getDrawList(headers) - await draw(headers, $.drawIndex0) - await draw(headers, $.drawIndex1) + await draw(headers) + await draw(headers) if ($.sign?.signnum) { $.msg($.name, `第${$.sign.signnum}天 签到成功`, drawRes.join('\n')) } else if ($.sign?.message) { @@ -39,31 +38,17 @@ function sign(headers) { }) } -function getDrawList(headers) { +function draw(headers) { return new Promise((resolve) => { + const index = Math.floor(Math.random() * 10) const url = { - url: hostApi + '/roulette_draw/index', - headers, - } - $.get(url, (err, resp, data) => { - const res = JSON.parse(data) - $.drawIndex0 = res.data.draw_list.findIndex(item => item.task_name === '5元无门槛优惠券') - $.drawIndex1 = res.data.draw_list.findIndex(item => item.tag_modou === '500') - }) - }) -} - -function draw(headers, index) { - return new Promise((resolve) => { - const path = index ? 'draw_results?click_num=' + index : 'draw_results' - const url = { - url: hostApi + '/' + path, + url: hostApi + '/roulette_draw/draw_results?click_num=' + index, headers, } $.post(url, (err, resp, data) => { try { - const res = JSON.parse(data) - drawRes.push(res.winning_desc) + const data = JSON.parse(data) + drawRes.push(data.winning_desc) } catch (e) { $.logErr(e, resp) } finally { From 53ded3e858b6fe27fab108ec0dc1e3cbd3f02ff5 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Mon, 10 Mar 2025 15:54:13 +0800 Subject: [PATCH 305/311] =?UTF-8?q?fix(boxjs):=20=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.js | 53 ++++++++++++++++++++++++++------- box/release/box.release.json | 12 ++++++++ box/release/box.release.tf.json | 12 ++++++++ chavy.box.js | 53 ++++++++++++++++++++++++++------- 4 files changed, 108 insertions(+), 22 deletions(-) diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 11bc806c0..0b199fa97 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.20' +$.version = '0.19.21' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -1002,18 +1002,49 @@ function update(obj, path, value) { current[keys[keys.length - 1]] = value } +// 自定义并发控制函数 +async function limitConcurrency(tasks, limit) { + const results = []; + const executing = []; + + for (const task of tasks) { + const promise = task(); // 执行任务 + results.push(promise); + + if (executing.length >= limit) { + await Promise.race(executing); + } + + executing.push(promise); + promise.then(() => { + const index = executing.indexOf(promise); + if (index !== -1) executing.splice(index, 1); + }).catch(() => { + const index = executing.indexOf(promise); + if (index !== -1) executing.splice(index, 1); + }); + } + + return Promise.all(results); +} + async function reloadAppSubCaches() { - $.msg($.name, '更新订阅: 开始!') - const reloadActs = [] - const usercfgs = getUserCfgs() + $.msg($.name, '更新订阅: 开始!'); + const reloadActs = []; + const usercfgs = getUserCfgs(); + + // 收集所有任务(函数形式) usercfgs.appsubs.forEach((sub) => { - reloadActs.push(reloadAppSubCache(sub.url)) - }) - await Promise.all(reloadActs) - $.log(`全部订阅, 完成!`) - const endTime = new Date().getTime() - const costTime = (endTime - $.startTime) / 1000 - $.msg($.name, `更新订阅: 完成! 🕛 ${costTime} 秒`) + reloadActs.push(() => reloadAppSubCache(sub.url)); // 存储函数而不是立即执行的 Promise + }); + + // 使用并发限制执行任务 + await limitConcurrency(reloadActs, 20); // 限制并发数为 20 + + $.log(`全部订阅, 完成!`); + const endTime = new Date().getTime(); + const costTime = (endTime - $.startTime) / 1000; + $.msg($.name, `更新订阅: 完成! 🕛 ${costTime} 秒`); } function upgradeUserData() { diff --git a/box/release/box.release.json b/box/release/box.release.json index d6a2cf416..0f96d0181 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.21", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "fix(boxjs): 订阅更新问题", + "notes": [ + { + "name": "修复", + "descs": ["订阅更新问题"] + } + ] + }, { "version": "0.19.20", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 0c7ea3470..1e2cdf8bd 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.21", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "fix(boxjs): 订阅更新问题", + "notes": [ + { + "name": "修复", + "descs": ["订阅更新问题"] + } + ] + }, { "version": "0.19.20", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index 11bc806c0..0b199fa97 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.20' +$.version = '0.19.21' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -1002,18 +1002,49 @@ function update(obj, path, value) { current[keys[keys.length - 1]] = value } +// 自定义并发控制函数 +async function limitConcurrency(tasks, limit) { + const results = []; + const executing = []; + + for (const task of tasks) { + const promise = task(); // 执行任务 + results.push(promise); + + if (executing.length >= limit) { + await Promise.race(executing); + } + + executing.push(promise); + promise.then(() => { + const index = executing.indexOf(promise); + if (index !== -1) executing.splice(index, 1); + }).catch(() => { + const index = executing.indexOf(promise); + if (index !== -1) executing.splice(index, 1); + }); + } + + return Promise.all(results); +} + async function reloadAppSubCaches() { - $.msg($.name, '更新订阅: 开始!') - const reloadActs = [] - const usercfgs = getUserCfgs() + $.msg($.name, '更新订阅: 开始!'); + const reloadActs = []; + const usercfgs = getUserCfgs(); + + // 收集所有任务(函数形式) usercfgs.appsubs.forEach((sub) => { - reloadActs.push(reloadAppSubCache(sub.url)) - }) - await Promise.all(reloadActs) - $.log(`全部订阅, 完成!`) - const endTime = new Date().getTime() - const costTime = (endTime - $.startTime) / 1000 - $.msg($.name, `更新订阅: 完成! 🕛 ${costTime} 秒`) + reloadActs.push(() => reloadAppSubCache(sub.url)); // 存储函数而不是立即执行的 Promise + }); + + // 使用并发限制执行任务 + await limitConcurrency(reloadActs, 20); // 限制并发数为 20 + + $.log(`全部订阅, 完成!`); + const endTime = new Date().getTime(); + const costTime = (endTime - $.startTime) / 1000; + $.msg($.name, `更新订阅: 完成! 🕛 ${costTime} 秒`); } function upgradeUserData() { From a9e2cc23ccffe22e39a35d0c4fc3ed29f68e655d Mon Sep 17 00:00:00 2001 From: id77 <9592236+id77@users.noreply.github.com> Date: Fri, 25 Apr 2025 22:39:02 +0800 Subject: [PATCH 306/311] =?UTF-8?q?fix(boxjs):=20=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E4=BF=AE=E6=94=B9&=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- box/chavy.boxjs.html | 22 ++++++++++++---------- box/release/box.release.json | 12 ++++++++++++ box/release/box.release.tf.json | 12 ++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index f2e0ab9dc..ef921e8ca 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1200,7 +1200,7 @@

{{curapp.name}}

mdi-dots-vertical - + - + mdi-delete-circle-outline diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 8356a0448..1bd55591b 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.23' +$.version = '0.19.24' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index c7779b9a0..ebe96956e 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.24", + "tags": ["beta"], + "author": "@id77", + "msg": "feat(boxjs): isEditFavApp 只在主页才显示", + "notes": [ + { + "name": "优化", + "descs": ["悬浮按钮的收藏编辑功能只在主页才显示"] + } + ] + }, { "version": "0.19.23", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index 7fe43bc51..dbbf6410b 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.24", + "tags": ["beta"], + "author": "@id77", + "msg": "feat(boxjs): isEditFavApp 只在主页才显示", + "notes": [ + { + "name": "优化", + "descs": ["悬浮按钮的收藏编辑功能只在主页才显示"] + } + ] + }, { "version": "0.19.23", "tags": ["beta"], From c14f160dae0257a9ab62d4b55898885dbb5c123a Mon Sep 17 00:00:00 2001 From: id77 <9592236+id77@users.noreply.github.com> Date: Sat, 26 Apr 2025 17:19:32 +0800 Subject: [PATCH 309/311] =?UTF-8?q?feat(boxjs):=20=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=85=E4=BD=BF=E7=94=A8=E5=92=8C=E5=85=B3?= =?UTF-8?q?=E8=81=94=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅使用会话数据,应用设置修改保存不更新原会话;关联使用会话数据,应用设置修改保存会更新原会话 --- box/chavy.boxjs.html | 66 ++++++++++++++++++++++++++------- box/chavy.boxjs.js | 2 +- box/release/box.release.json | 12 ++++++ box/release/box.release.tf.json | 12 ++++++ 4 files changed, 77 insertions(+), 15 deletions(-) diff --git a/box/chavy.boxjs.html b/box/chavy.boxjs.html index c6561ebe4..106c40bc5 100644 --- a/box/chavy.boxjs.html +++ b/box/chavy.boxjs.html @@ -1249,7 +1249,8 @@

{{curapp.name}}

{{dayjs(session.createTime).format('YYYY-MM-DD HH:mm:ss')}} - {{ $t('base.dialog.apply') }} + {{ $t('base.dialog.use') }} + {{ $t('base.dialog.link') }} @@ -1467,7 +1468,9 @@

v{{ver.versio save: 'Save', view: 'View', close: 'Close', - ok: 'OK' + ok: 'OK', + use: 'Use', + link: 'Link' }, sort: { up: 'Up', @@ -1630,7 +1633,9 @@

v{{ver.versio apply: '应用', save: '保存', close: '关闭', - ok: '好' + ok: '好', + use: '使用', + link: '关联' }, sort: { up: '上移', @@ -2840,20 +2845,53 @@

v{{ver.versio }, // 使用应用会话 useAppSession(sessionId) { - const sessions = this.box.sessions - const session = sessions.find((session) => session.id === sessionId) - this.box.curSessions[session.appId] = sessionId + const sessions = JSON.parse(JSON.stringify(this.box.sessions)); + const session = sessions.find( + (session) => session.id === sessionId + ); + + const datas = session.datas; + delete this.box.curSessions[session.appId]; + const key = 'chavy_boxjs_cur_sessions'; + const val = JSON.stringify({}); + datas.push({ key, val }); + + if (session) { + axios + .post(`/api/save?appid=${this.curapp.id}`, datas) + .then((resp) => { + if (this.curapp.id === 'BoxSetting') { + this.isSaveUserCfgs = false; + } else { + delete resp.data.usercfgs; + } + Object.assign(this.box, resp.data); + + if (this.curapp.id === 'BoxSetting') { + this.setHttpBackend(); + } + }); + } + }, + // 关联应用会话 + linkAppSession(sessionId) { + const sessions = JSON.parse(JSON.stringify(this.box.sessions)); + const session = sessions.find( + (session) => session.id === sessionId + ); - const key = 'chavy_boxjs_cur_sessions' - const val = JSON.stringify(this.box.curSessions) - const curSessions = [{ key, val }] - const datas = [...session.datas, ...curSessions] + const datas = session.datas; + // 记录当前应用正在使用的会话ID + this.box.curSessions[session.appId] = sessionId; + const key = 'chavy_boxjs_cur_sessions'; + const val = JSON.stringify(this.box.curSessions); + datas.push({ key, val }); - this.clearAppDatas() + // 发送单个合并请求,避免竞争条件 axios.post('/api/save', datas).then((resp) => { - delete resp.data.usercfgs - Object.assign(this.box, resp.data) - }) + delete resp.data.usercfgs; + Object.assign(this.box, resp.data); + }); }, // 复制应用数据为对象数据 copyData(curdata) { diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index 1bd55591b..44f9d6a08 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.24' +$.version = '0.19.25' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite diff --git a/box/release/box.release.json b/box/release/box.release.json index ebe96956e..89156f133 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.25", + "tags": ["beta"], + "author": "@id77", + "msg": "feat(boxjs): 会话支持仅使用和关联使用", + "notes": [ + { + "name": "优化", + "descs": ["仅使用会话数据,应用设置修改保存不更新原会话;关联使用会话数据,应用设置修改保存会更新原会话"] + } + ] + }, { "version": "0.19.24", "tags": ["beta"], diff --git a/box/release/box.release.tf.json b/box/release/box.release.tf.json index dbbf6410b..6b8dbdf3a 100644 --- a/box/release/box.release.tf.json +++ b/box/release/box.release.tf.json @@ -1,5 +1,17 @@ { "releases": [ + { + "version": "0.19.25", + "tags": ["beta"], + "author": "@id77", + "msg": "feat(boxjs): 会话支持仅使用和关联使用", + "notes": [ + { + "name": "优化", + "descs": ["仅使用会话数据,应用设置修改保存不更新原会话;关联使用会话数据,应用设置修改保存会更新原会话"] + } + ] + }, { "version": "0.19.24", "tags": ["beta"], From 0cf9879a278b4e16dd57e13ecc8aa877f566cb83 Mon Sep 17 00:00:00 2001 From: MartinsKing <42362589+ClydeTime@users.noreply.github.com> Date: Wed, 7 May 2025 17:19:13 +0800 Subject: [PATCH 310/311] Fix: msg notification call exception (#511) --- Env.js | 25 ++++++++++++------------- Env.min.js | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Env.js b/Env.js index e3432a00b..d2ed4cbfd 100644 --- a/Env.js +++ b/Env.js @@ -676,19 +676,20 @@ function Env(name, opts) { Object.assign(options, { action: 'clipboard', text: copy }) } - if ($media) { - let mediaUrl = undefined + // 图片通知 + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media + if (mediaUrl) { let media = undefined let mime = undefined // http 开头的网络地址 - if ($media.startsWith('http')) { - mediaUrl = $media + if (mediaUrl.startsWith('http')) { + //不做任何操作 } // 带标识的 Base64 字符串 // data:image/png;base64,iVBORw0KGgo... - else if ($media.startsWith('data:')) { - const [data] = $media.split(';') - const [, base64str] = $media.split(',') + else if (mediaUrl.startsWith('data:')) { + const [data] = mediaUrl.split(';') + const [, base64str] = mediaUrl.split(',') media = base64str mime = data.replace('data:', '') } @@ -711,8 +712,8 @@ function Env(name, opts) { } return null } - media = $media - mime = getMimeFromBase64($media) + media = mediaUrl + mime = getMimeFromBase64(mediaUrl) } Object.assign(options, { @@ -735,8 +736,7 @@ function Env(name, opts) { rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open if (openUrl) Object.assign(options, { openUrl }) - let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] - if ($media?.startsWith('http')) mediaUrl = $media + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media if (mediaUrl) Object.assign(options, { mediaUrl }) console.log(JSON.stringify(options)) @@ -749,8 +749,7 @@ function Env(name, opts) { rawopts['open-url'] || rawopts.url || rawopts.openUrl || $open if (openUrl) Object.assign(options, { 'open-url': openUrl }) - let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl - if ($media?.startsWith('http')) mediaUrl = $media + let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media if (mediaUrl) Object.assign(options, { 'media-url': mediaUrl }) let copy = diff --git a/Env.min.js b/Env.min.js index b64b5e469..0d0bc12f4 100644 --- a/Env.min.js +++ b/Env.min.js @@ -1 +1 @@ -function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;"POST"===e&&(s=this.post);const i=new Promise(((e,i)=>{s.call(this,t,((t,s,o)=>{t?i(t):e(s)}))}));return t.timeout?((t,e=1e3)=>Promise.race([t,new Promise(((t,s)=>{setTimeout((()=>{s(new Error("请求超时"))}),e)}))]))(i,t.timeout):i}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null,...s){try{return JSON.stringify(t,...s)}catch{return e}}getjson(t,e){let s=e;if(this.getdata(t))try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise((e=>{this.get({url:t},((t,s,i)=>e(i)))}))}runScript(t,e){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=e&&e.timeout?e.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},policy:"DIRECT",timeout:o};this.post(n,((t,e,i)=>s(i)))})).catch((t=>this.logErr(t)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),o=JSON.stringify(this.data);s?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(e,o):this.fs.writeFileSync(t,o)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return s;return o}lodash_set(t,e,s){return Object(t)!==t||(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce(((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{}),t)[e[e.length-1]]=s),t}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),o=s?this.getval(s):"";if(o)try{const t=JSON.parse(o);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(e),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const e=JSON.parse(a);this.lodash_set(e,o,t),s=this.setval(JSON.stringify(e),i)}catch(e){const r={};this.lodash_set(r,o,t),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(t,e);return s}getval(t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(t);case"Quantumult X":return $prefs.valueForKey(t);case"Node.js":return this.data=this.loaddata(),this.data[t];default:return this.data&&this.data[t]||null}}setval(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(t,e);case"Quantumult X":return $prefs.setValueForKey(t,e);case"Node.js":return this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0;default:return this.data&&this.data[e]||null}}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.cookie&&void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar)))}get(t,e=(()=>{})){switch(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"],delete t.headers["content-type"],delete t.headers["content-length"]),t.params&&(t.url+="?"+this.queryStr(t.params)),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",((t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}})).then((t=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=t,n=s.decode(a,this.encoding);e(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:i,response:o}=t;e(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";switch(t.body&&t.headers&&!t.headers["Content-Type"]&&!t.headers["content-type"]&&(t.headers["content-type"]="application/x-www-form-urlencoded"),t.headers&&(delete t.headers["Content-Length"],delete t.headers["content-length"]),void 0===t.followRedirect||t.followRedirect||((this.isSurge()||this.isLoon())&&(t["auto-redirect"]=!1),this.isQuanX()&&(t.opts?t.opts.redirection=!1:t.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,((t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)}));break;case"Quantumult X":t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then((t=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=t;e(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(t=>e(t&&t.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(t);const{url:o,...r}=t;this.got[s](o,r).then((t=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=t,n=i.decode(a,this.encoding);e(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(t=>{const{message:s,response:o}=t;e(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",o={}){const r=t=>{const{$open:e,$copy:s,$media:i,$mediaMime:o}=t;switch(typeof t){case void 0:return t;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:t};case"Loon":case"Shadowrocket":return t;case"Quantumult X":return{"open-url":t};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=t.openUrl||t.url||t["open-url"]||e;a&&Object.assign(r,{action:"open-url",url:a});let n=t["update-pasteboard"]||t.updatePasteboard||s;if(n&&Object.assign(r,{action:"clipboard",text:n}),i){let t,e,s;if(i.startsWith("http"))t=i;else if(i.startsWith("data:")){const[t]=i.split(";"),[,o]=i.split(",");e=o,s=t.replace("data:","")}else{e=i,s=(t=>{const e={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in e)if(0===t.indexOf(s))return e[s];return null})(i)}Object.assign(r,{"media-url":t,"media-base64":e,"media-base64-mime":o??s})}return Object.assign(r,{"auto-dismiss":t["auto-dismiss"],sound:t.sound}),r}case"Loon":{const s={};let o=t.openUrl||t.url||t["open-url"]||e;o&&Object.assign(s,{openUrl:o});let r=t.mediaUrl||t["media-url"];return i?.startsWith("http")&&(r=i),r&&Object.assign(s,{mediaUrl:r}),console.log(JSON.stringify(s)),s}case"Quantumult X":{const o={};let r=t["open-url"]||t.url||t.openUrl||e;r&&Object.assign(o,{"open-url":r});let a=t["media-url"]||t.mediaUrl;i?.startsWith("http")&&(a=i),a&&Object.assign(o,{"media-url":a});let n=t["update-pasteboard"]||t.updatePasteboard||s;return n&&Object.assign(o,{"update-pasteboard":n}),console.log(JSON.stringify(o)),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(e,s,i,r(o));break;case"Quantumult X":$notify(e,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}debug(...t){this.logLevels[this.logLevel]<=this.logLevels.debug&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.debug}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}info(...t){this.logLevels[this.logLevel]<=this.logLevels.info&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.info}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}warn(...t){this.logLevels[this.logLevel]<=this.logLevels.warn&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.warn}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}error(...t){this.logLevels[this.logLevel]<=this.logLevels.error&&(t.length>0&&(this.logs=[...this.logs,...t]),console.log(`${this.logLevelPrefixs.error}${t.map((t=>t??String(t))).join(this.logSeparator)}`))}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.map((t=>t??String(t))).join(this.logSeparator))}logErr(t,e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,e,t);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,e,void 0!==t.message?t.message:t,t.stack);break}}wait(t){return new Promise((e=>setTimeout(e,t)))}done(t={}){const e=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${e} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(t);break;case"Node.js":process.exit(1)}}}(t,e)} \ No newline at end of file +function Env(e,t){class s{constructor(e){this.env=e}send(e,t="GET"){e="string"==typeof e?{url:e}:e;let s=this.get;"POST"===t&&(s=this.post);const i=new Promise(((t,i)=>{s.call(this,e,((e,s,o)=>{e?i(e):t(s)}))}));return e.timeout?((e,t=1e3)=>Promise.race([e,new Promise(((e,s)=>{setTimeout((()=>{s(new Error("请求超时"))}),t)}))]))(i,e.timeout):i}get(e){return this.send.call(this.env,e)}post(e){return this.send.call(this.env,e,"POST")}}return new class{constructor(e,t){this.logLevels={debug:0,info:1,warn:2,error:3},this.logLevelPrefixs={debug:"[DEBUG] ",info:"[INFO] ",warn:"[WARN] ",error:"[ERROR] "},this.logLevel="info",this.name=e,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,t),this.log("",`🔔${this.name}, 开始!`)}getEnv(){return"undefined"!=typeof $environment&&$environment["surge-version"]?"Surge":"undefined"!=typeof $environment&&$environment["stash-version"]?"Stash":"undefined"!=typeof module&&module.exports?"Node.js":"undefined"!=typeof $task?"Quantumult X":"undefined"!=typeof $loon?"Loon":"undefined"!=typeof $rocket?"Shadowrocket":void 0}isNode(){return"Node.js"===this.getEnv()}isQuanX(){return"Quantumult X"===this.getEnv()}isSurge(){return"Surge"===this.getEnv()}isLoon(){return"Loon"===this.getEnv()}isShadowrocket(){return"Shadowrocket"===this.getEnv()}isStash(){return"Stash"===this.getEnv()}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}toStr(e,t=null,...s){try{return JSON.stringify(e,...s)}catch{return t}}getjson(e,t){let s=t;if(this.getdata(e))try{s=JSON.parse(this.getdata(e))}catch{}return s}setjson(e,t){try{return this.setdata(JSON.stringify(e),t)}catch{return!1}}getScript(e){return new Promise((t=>{this.get({url:e},((e,s,i)=>t(i)))}))}runScript(e,t){return new Promise((s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let o=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");o=o?1*o:20,o=t&&t.timeout?t.timeout:o;const[r,a]=i.split("@"),n={url:`http://${a}/v1/scripting/evaluate`,body:{script_text:e,mock_type:"cron",timeout:o},headers:{"X-Key":r,Accept:"*/*"},policy:"DIRECT",timeout:o};this.post(n,((e,t,i)=>s(i)))})).catch((e=>this.logErr(e)))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t);if(!s&&!i)return{};{const i=s?e:t;try{return JSON.parse(this.fs.readFileSync(i))}catch(e){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const e=this.path.resolve(this.dataFile),t=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(e),i=!s&&this.fs.existsSync(t),o=JSON.stringify(this.data);s?this.fs.writeFileSync(e,o):i?this.fs.writeFileSync(t,o):this.fs.writeFileSync(e,o)}}lodash_get(e,t,s){const i=t.replace(/\[(\d+)\]/g,".$1").split(".");let o=e;for(const e of i)if(o=Object(o)[e],void 0===o)return s;return o}lodash_set(e,t,s){return Object(e)!==e||(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce(((e,s,i)=>Object(e[s])===e[s]?e[s]:e[s]=Math.abs(t[i+1])>>0==+t[i+1]?[]:{}),e)[t[t.length-1]]=s),e}getdata(e){let t=this.getval(e);if(/^@/.test(e)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(e),o=s?this.getval(s):"";if(o)try{const e=JSON.parse(o);t=e?this.lodash_get(e,i,""):t}catch(e){t=""}}return t}setdata(e,t){let s=!1;if(/^@/.test(t)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(t),r=this.getval(i),a=i?"null"===r?null:r||"{}":"{}";try{const t=JSON.parse(a);this.lodash_set(t,o,e),s=this.setval(JSON.stringify(t),i)}catch(t){const r={};this.lodash_set(r,o,e),s=this.setval(JSON.stringify(r),i)}}else s=this.setval(e,t);return s}getval(e){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.read(e);case"Quantumult X":return $prefs.valueForKey(e);case"Node.js":return this.data=this.loaddata(),this.data[e];default:return this.data&&this.data[e]||null}}setval(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":return $persistentStore.write(e,t);case"Quantumult X":return $prefs.setValueForKey(e,t);case"Node.js":return this.data=this.loaddata(),this.data[t]=e,this.writedata(),!0;default:return this.data&&this.data[t]||null}}initGotEnv(e){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,e&&(e.headers=e.headers?e.headers:{},e&&(e.headers=e.headers?e.headers:{},void 0===e.headers.cookie&&void 0===e.headers.Cookie&&void 0===e.cookieJar&&(e.cookieJar=this.ckjar)))}get(e,t=(()=>{})){switch(e.headers&&(delete e.headers["Content-Type"],delete e.headers["Content-Length"],delete e.headers["content-type"],delete e.headers["content-length"]),e.params&&(e.url+="?"+this.queryStr(e.params)),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let s=require("iconv-lite");this.initGotEnv(e),this.got(e).on("redirect",((e,t)=>{try{if(e.headers["set-cookie"]){const s=e.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),t.cookieJar=this.ckjar}}catch(e){this.logErr(e)}})).then((e=>{const{statusCode:i,statusCode:o,headers:r,rawBody:a}=e,n=s.decode(a,this.encoding);t(null,{status:i,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:i,response:o}=e;t(i,o,o&&s.decode(o.rawBody,this.encoding))}));break}}post(e,t=(()=>{})){const s=e.method?e.method.toLocaleLowerCase():"post";switch(e.body&&e.headers&&!e.headers["Content-Type"]&&!e.headers["content-type"]&&(e.headers["content-type"]="application/x-www-form-urlencoded"),e.headers&&(delete e.headers["Content-Length"],delete e.headers["content-length"]),void 0===e.followRedirect||e.followRedirect||((this.isSurge()||this.isLoon())&&(e["auto-redirect"]=!1),this.isQuanX()&&(e.opts?e.opts.redirection=!1:e.opts={redirection:!1})),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:this.isSurge()&&this.isNeedRewrite&&(e.headers=e.headers||{},Object.assign(e.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](e,((e,s,i)=>{!e&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),t(e,s,i)}));break;case"Quantumult X":e.method=s,this.isNeedRewrite&&(e.opts=e.opts||{},Object.assign(e.opts,{hints:!1})),$task.fetch(e).then((e=>{const{statusCode:s,statusCode:i,headers:o,body:r,bodyBytes:a}=e;t(null,{status:s,statusCode:i,headers:o,body:r,bodyBytes:a},r,a)}),(e=>t(e&&e.error||"UndefinedError")));break;case"Node.js":let i=require("iconv-lite");this.initGotEnv(e);const{url:o,...r}=e;this.got[s](o,r).then((e=>{const{statusCode:s,statusCode:o,headers:r,rawBody:a}=e,n=i.decode(a,this.encoding);t(null,{status:s,statusCode:o,headers:r,rawBody:a,body:n},n)}),(e=>{const{message:s,response:o}=e;t(s,o,o&&i.decode(o.rawBody,this.encoding))}));break}}time(e,t=null){const s=t?new Date(t):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let t in i)new RegExp("("+t+")").test(e)&&(e=e.replace(RegExp.$1,1==RegExp.$1.length?i[t]:("00"+i[t]).substr((""+i[t]).length)));return e}queryStr(e){let t="";for(const s in e){let i=e[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),t+=`${s}=${i}&`)}return t=t.substring(0,t.length-1),t}msg(t=e,s="",i="",o={}){const r=e=>{const{$open:t,$copy:s,$media:i,$mediaMime:o}=e;switch(typeof e){case void 0:return e;case"string":switch(this.getEnv()){case"Surge":case"Stash":default:return{url:e};case"Loon":case"Shadowrocket":return e;case"Quantumult X":return{"open-url":e};case"Node.js":return}case"object":switch(this.getEnv()){case"Surge":case"Stash":case"Shadowrocket":default:{const r={};let a=e.openUrl||e.url||e["open-url"]||t;a&&Object.assign(r,{action:"open-url",url:a});let n=e["update-pasteboard"]||e.updatePasteboard||s;n&&Object.assign(r,{action:"clipboard",text:n});let h=e.mediaUrl||e["media-url"]||i;if(h){let e,t;if(h.startsWith("http"));else if(h.startsWith("data:")){const[s]=h.split(";"),[,i]=h.split(",");e=i,t=s.replace("data:","")}else{e=h,t=(e=>{const t={JVBERi0:"application/pdf",R0lGODdh:"image/gif",R0lGODlh:"image/gif",iVBORw0KGgo:"image/png","/9j/":"image/jpg"};for(var s in t)if(0===e.indexOf(s))return t[s];return null})(h)}Object.assign(r,{"media-url":h,"media-base64":e,"media-base64-mime":o??t})}return Object.assign(r,{"auto-dismiss":e["auto-dismiss"],sound:e.sound}),r}case"Loon":{const s={};let o=e.openUrl||e.url||e["open-url"]||t;o&&Object.assign(s,{openUrl:o});let r=e.mediaUrl||e["media-url"]||i;return r&&Object.assign(s,{mediaUrl:r}),console.log(JSON.stringify(s)),s}case"Quantumult X":{const o={};let r=e["open-url"]||e.url||e.openUrl||t;r&&Object.assign(o,{"open-url":r});let a=e.mediaUrl||e["media-url"]||i;a&&Object.assign(o,{"media-url":a});let n=e["update-pasteboard"]||e.updatePasteboard||s;return n&&Object.assign(o,{"update-pasteboard":n}),console.log(JSON.stringify(o)),o}case"Node.js":return}default:return}};if(!this.isMute)switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":default:$notification.post(t,s,i,r(o));break;case"Quantumult X":$notify(t,s,i,r(o));break;case"Node.js":break}if(!this.isMuteLog){let e=["","==============📣系统通知📣=============="];e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n")),this.logs=this.logs.concat(e)}}debug(...e){this.logLevels[this.logLevel]<=this.logLevels.debug&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.debug}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}info(...e){this.logLevels[this.logLevel]<=this.logLevels.info&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.info}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}warn(...e){this.logLevels[this.logLevel]<=this.logLevels.warn&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.warn}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}error(...e){this.logLevels[this.logLevel]<=this.logLevels.error&&(e.length>0&&(this.logs=[...this.logs,...e]),console.log(`${this.logLevelPrefixs.error}${e.map((e=>e??String(e))).join(this.logSeparator)}`))}log(...e){e.length>0&&(this.logs=[...this.logs,...e]),console.log(e.map((e=>e??String(e))).join(this.logSeparator))}logErr(e,t){switch(this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:this.log("",`❗️${this.name}, 错误!`,t,e);break;case"Node.js":this.log("",`❗️${this.name}, 错误!`,t,void 0!==e.message?e.message:e,e.stack);break}}wait(e){return new Promise((t=>setTimeout(t,e)))}done(e={}){const t=((new Date).getTime()-this.startTime)/1e3;switch(this.log("",`🔔${this.name}, 结束! 🕛 ${t} 秒`),this.log(),this.getEnv()){case"Surge":case"Loon":case"Stash":case"Shadowrocket":case"Quantumult X":default:$done(e);break;case"Node.js":process.exit(1)}}}(e,t)} \ No newline at end of file From eecdc39a407df13734d5ef276d5917f107393e91 Mon Sep 17 00:00:00 2001 From: GideonSenku Date: Tue, 11 Nov 2025 13:36:27 +0800 Subject: [PATCH 311/311] fix: citybox api host --- citybox/citybox.cookie.js | 6 +++--- citybox/citybox.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/citybox/citybox.cookie.js b/citybox/citybox.cookie.js index 1800835e8..4c66d42c7 100644 --- a/citybox/citybox.cookie.js +++ b/citybox/citybox.cookie.js @@ -3,15 +3,15 @@ * hostname = api.icitybox.cn * * # Surge - * Rewrite: citybox = type=http-request,pattern=^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_info,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js,debug=true + * Rewrite: citybox = type=http-request,pattern=^https:\/\/api\.icitybox\/api\/user\/get_user_info,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js,debug=true * Tasks: citybox-签到 = type=cron,cronexp=10 0 * * *,script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js,wake-system=true * * # QuanX - * ^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_info url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js + * ^https:\/\/api\.icitybox\/api\/user\/get_user_info url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js * 10 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js, tag=citybox-签到 * * # Loon - * http-request ^https:\/\/api\.icitybox\.cn\/index.php\/api\/user\/get_user_infoscript-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js, tag=citybox + * http-request ^https:\/\/api\.icitybox\/api\/user\/get_user_infoscript-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.cookie.js, tag=citybox * cron "10 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/citybox/citybox.js * * # 获取方式:进入签到页面获取,进入citybox小程序即可 diff --git a/citybox/citybox.js b/citybox/citybox.js index f5f0707d7..1461bd71e 100644 --- a/citybox/citybox.js +++ b/citybox/citybox.js @@ -1,5 +1,5 @@ const $ = new Env('魔盒') -const hostApi = 'https://api.icitybox.cn/index.php/api' +const hostApi = 'https://api.icitybox.cn/api' const drawRes = [] !(async () => {