/* 阿里云盘签到-lowking-v1.1.3 按下面配置完之后,打开阿里云盘获取token(如获取不到,等一段时间再打开),下面配置只验证过surge的,其他的自行测试 ⚠️只测试过surge没有其他app自行测试 ************************ Surge 4.2.0+ 脚本配置(其他APP自行转换配置): ************************ [Script] # > 阿里云盘签到 https://auth.alipan.com/v2/account/token 阿里云盘签到cookie = requires-body=1,type=http-response,pattern=https:\/\/auth.(aliyundrive|alipan).com\/v2\/account\/token,script-path=https://raw.githubusercontent.com/lowking/Scripts/master/ali/aliYunPanCheckIn.js 阿里云盘签到 = type=cron,cronexp="0 10 0 * * ?",wake-system=1,script-path=https://raw.githubusercontent.com/lowking/Scripts/master/ali/aliYunPanCheckIn.js [MITM] hostname = %APPEND% auth.alipan.com */ const lk = new ToolKit(`阿里云盘签到`, `AliYunPanCheckIn`, {"httpApi": "ffff@10.0.0.19:6166"}) const aliYunPanTokenKey = 'lkAliYunPanTokenKey' let aliYunPanToken = lk.getVal(aliYunPanTokenKey, '') const aliYunPanRefreshTokenKey = 'lkAliYunPanRefreshTokenKey' let aliYunPanRefreshToken = lk.getVal(aliYunPanRefreshTokenKey, '') const checkSignInRepeatKey = 'aliYunPanSignInRepeat' const checkSignInRepeat = lk.getVal(checkSignInRepeatKey, '') const joinTeamRepeatKey = 'aliYunPanJoinTeamRepeat' const joinTeamRepeat = lk.getVal(joinTeamRepeatKey, -1) lk.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 D/C501C6D2-FAF6-4DA8-B65B-7B8B392901EB" if(!lk.isExecComm) { if (lk.isRequest()) { getCookie() lk.done() } else { lk.boxJsJsonBuilder({ "icons": [ "https://raw.githubusercontent.com/lowking/Scripts/master/doc/icon/aliYunPana.png", "https://raw.githubusercontent.com/lowking/Scripts/master/doc/icon/aliYunPan.png" ], "settings": [ { "id": aliYunPanTokenKey, "name": "阿里云盘token", "val": "", "type": "text", "desc": "阿里云盘token" }, { "id": aliYunPanRefreshTokenKey, "name": "阿里云盘refresh_token", "val": "", "type": "text", "desc": "阿里云盘refresh_token" } ], "keys": [aliYunPanTokenKey, aliYunPanRefreshTokenKey] }, { "script_url": "https://github.com/lowking/Scripts/blob/master/ali/aliYunPanCheckIn.js", "author": "@lowking", "repo": "https://github.com/lowking/Scripts", }) all() } } function getCookie() { if (lk.isMatch(/\/v2\/account\/token/)) { lk.log(`开始获取cookie`) let data = lk.getResponseBody() // lk.log(`获取到的cookie:${data}`) try { data = data.o() let refreshToken = data["refresh_token"] if (refreshToken) { lk.setVal(aliYunPanRefreshTokenKey, refreshToken) lk.appendNotifyInfo('🎉成功获取阿里云盘refresh_token,可以关闭相应脚本') } else { lk.execFail() lk.appendNotifyInfo('❌获取阿里云盘token失败,请稍后再试') } } catch (e) { lk.execFail() lk.appendNotifyInfo('❌获取阿里云盘token失败') } lk.msg('') } } async function all() { let hasNeedSendNotify = true if (aliYunPanRefreshToken == '') { lk.execFail() lk.appendNotifyInfo(`⚠️请先打开阿里云盘登录获取refresh_token`) } else { await refreshToken() let hasAlreadySignIn = await signIn() // await joinTeam() } if (hasNeedSendNotify) { lk.msg(``) } lk.done() } function refreshToken() { return new Promise((resolve, _reject) => { const t = '获取token' let url = { url: 'https://auth.alipan.com/v2/account/token', headers: { "Content-Type": "application/json; charset=utf-8", }, body: { "grant_type": "refresh_token", "app_id": "pJZInNHN2dZWk8qg", "refresh_token": aliYunPanRefreshToken }.s() } lk.post(url, (error, _response, data) => { try { if (error) { lk.execFail() lk.appendNotifyInfo(`❌${t}失败,请稍后再试`) } else { let dataObj = data.o() if (dataObj.hasOwnProperty("refresh_token")) { aliYunPanToken = `Bearer ${dataObj["access_token"]}` aliYunPanRefreshToken = dataObj["refresh_token"] lk.setVal(aliYunPanTokenKey, aliYunPanToken) lk.setVal(aliYunPanRefreshTokenKey, aliYunPanRefreshToken) } else { lk.execFail() lk.appendNotifyInfo(dataObj.message) } } } catch (e) { lk.logErr(e) lk.log(`阿里云盘${t}返回数据:${data}`) lk.execFail() lk.appendNotifyInfo(`❌${t}错误,请带上日志联系作者,或稍后再试`) } finally { resolve() } }) }) } function getReward(day) { return new Promise((resolve, _reject) => { const t = '领取奖励' let url = { url: 'https://member.alipan.com/v1/activity/sign_in_reward?_rx-s=mobile', headers: { "Content-Type": "application/json", Authorization: aliYunPanToken, "User-Agent": lk.userAgent }, body: { "signInDay": day }.s() } lk.post(url, (error, _response, data) => { try { if (error) { lk.execFail() lk.appendNotifyInfo(`❌第${day}天${t}失败,请稍后再试`) } else { lk.log(data) let dataObj = data.o() if (dataObj.success) { lk.appendNotifyInfo(`✓${t}(第${day}天),${dataObj?.result?.notice}`) } else { lk.execFail() lk.appendNotifyInfo(`❌第${day}天${t}失败,${dataObj.message}`) } } } catch (e) { lk.logErr(e) lk.log(`阿里云盘${t}返回数据:${data}`) lk.execFail() lk.appendNotifyInfo(`❌第${day}天${t}错误,请带上日志联系作者,或稍后再试`) } finally { resolve() } }) }) } function doJoinTeam(joinTeamId) { return new Promise(async (resolve, _reject) => { const t = '加入队伍' let url = { url: 'https://member.alipan.com/v1/activity/sign_in_team_pk?_rx-s=mobile', headers: { "Content-Type": "application/json", Authorization: aliYunPanToken, "User-Agent": lk.userAgent }, body: { id: joinTeamId, team: "blue" }.s() } lk.post(url, async (error, _response, data) => { try { if (error) { lk.execFail() lk.appendNotifyInfo(`❌${t}失败,请稍后再试`) } else { let dataObj = data.o() if (!dataObj.success) { lk.execFail() lk.prependNotifyInfo(dataObj.message) } } } catch (e) { lk.logErr(e) lk.log(`阿里云盘${t}返回数据:${data}`) lk.execFail() lk.appendNotifyInfo(`❌${t}错误,请带上日志联系作者,或稍后再试`) } finally { resolve() } }) }) } function joinTeam(layer = 0) { return new Promise(async (resolve, _reject) => { let firstDayOfYear = new Date(lk.now.getFullYear(), 0, 1) const weekOfYear = Math.ceil((Math.round((lk.now.valueOf() - firstDayOfYear.valueOf()) / 86400000) + ((firstDayOfYear.getDay() + 1) - 1)) / 7) // if (joinTeamRepeat == weekOfYear) { // } const t = '加入PK' let url = { url: 'https://member.alipan.com/v1/activity/sign_in_team?_rx-s=mobile', headers: { "Content-Type": "application/json", Authorization: aliYunPanToken, "User-Agent": lk.userAgent }, body: {}.s() } lk.post(url, async (error, _response, data) => { try { if (error) { lk.execFail() lk.appendNotifyInfo(`❌${t}失败,请稍后再试`) } else { let dataObj = data.o() if (dataObj.success) { let joinedTeam = dataObj?.result?.joinTeam let joinTeamId = dataObj?.result?.id if (joinedTeam && joinTeamId) { lk.appendNotifyInfo(`🎉${t}成功\n${dataObj?.result?.period}:${dataObj?.result?.joinCount}(${dataObj?.result[joinedTeam + "WinRate"]})`) lk.setVal(joinTeamRepeatKey, weekOfYear.s()) } else { if (layer === 0) { await doJoinTeam(joinTeamId) await joinTeam(++layer) } else { lk.log(`请求加入队伍异常:${data}`) } } } else { lk.execFail() lk.prependNotifyInfo(dataObj.message) } } } catch (e) { lk.logErr(e) lk.log(`阿里云盘${t}返回数据:${data}`) lk.execFail() lk.appendNotifyInfo(`❌${t}错误,请带上日志联系作者,或稍后再试`) } finally { resolve() } }) }) } function signIn() { return new Promise(async (resolve, _reject) => { let nowString = lk.formatDate(new Date(), 'yyyyMMdd') if (nowString == checkSignInRepeat) { lk.prependNotifyInfo('今日已经签到,无法重复签到~~') resolve(1) return } const t = '签到' let url = { url: 'https://member.alipan.com/v1/activity/sign_in_list', headers: { "Content-Type": "application/json", Authorization: aliYunPanToken, "User-Agent": lk.userAgent }, body: {}.s() } lk.post(url, async (error, _response, data) => { try { if (error) { lk.execFail() lk.appendNotifyInfo(`❌${t}失败,请稍后再试`) } else { let dataObj = data.o() if (dataObj.success) { let prefix = "" if (dataObj?.result?.signInLogs.length > 0) { for (const l of dataObj.result.signInLogs) { if (l?.status != "miss") { prefix = `第${l?.day}天` // if (!l?.isReward) { // await getReward(l?.day) // } } } } lk.prependNotifyInfo(`🎉${prefix}${t}成功`) lk.setVal(checkSignInRepeatKey, nowString) } else { lk.execFail() lk.prependNotifyInfo(dataObj.message) } } } catch (e) { lk.logErr(e) lk.log(`阿里云盘${t}返回数据:${data}`) lk.execFail() lk.appendNotifyInfo(`❌${t}错误,请带上日志联系作者,或稍后再试`) } finally { resolve() } }) }) } // * ToolKit v1.5.0 build 204 function ToolKit(scriptName,scriptId,options){class Request{constructor(tk){this.tk=tk}fetch(options,method="GET"){options=typeof options=="string"?{url:options}:options;let fetcher;switch(method){case"PUT":fetcher=this.put;break;case"POST":fetcher=this.post;break;default:fetcher=this.get}const doFetch=new Promise((resolve,reject)=>{fetcher.call(this,options,(error,resp,data)=>error?reject({error,resp,data}):resolve({error,resp,data}))}),delayFetch=(promise,timeout=5e3)=>Promise.race([promise,new Promise((_,reject)=>setTimeout(()=>reject(new Error("请求超时")),timeout))]);return options.timeout>0?delayFetch(doFetch,options.timeout):doFetch}async get(options){return this.fetch.call(this.tk,options)}async post(options){return this.fetch.call(this.tk,options,"POST")}async put(options){return this.fetch.call(this.tk,options,"PUT")}}return new class{ab={info:1<<1,warn:1<<2,error:1<<3,debug:1<<4};aa={info:1<<1,warn:1<<2,error:1<<3,debug:1<<4};constructor(scriptName,scriptId,options){Object.prototype.s=function(replacer,space){return typeof this=="string"?this:JSON.stringify(this,replacer,space)},Object.prototype.o=function(reviver){return JSON.parse(this,reviver)},Object.prototype.getIgnoreCase=function(key){if(!key)throw"Key required";let target=this;try{typeof this=="string"&&(target=JSON.stringify(this))}catch{throw"It's not a JSON object or string!"}const ret=Object.keys(target).reduce((obj,key)=>(obj[key.toLowerCase()]=target[key],obj),{});return ret[key]},this.ab.warn|=this.aa.info,this.ab.error|=this.ab.warn,this.ab.debug|=this.ab.error,this.ac=this.ab.debug,this.userAgent=`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15`,this.a=`lk`,this.name=scriptName,this.id=scriptId,this.req=new Request(this),this.data=null,this.b=this.fb(`${this.a}${this.id}.dat`),this.c=this.fb(`${this.a}${this.id}.boxjs.json`),this.d=options,this.d?.logLevel&&(this.ac=this.ab[this.d.logLevel]),this.isExecComm=!1,this.f=this.getVal(`${this.a}IsEnableLog${this.id}`),this.f=!!this.isEmpty(this.f)||this.f.o(),this.g=this.getVal(`${this.a}NotifyOnlyFail${this.id}`),this.g=!this.isEmpty(this.g)&&this.g.o(),this.h=this.getVal(`${this.a}IsEnableTgNotify${this.id}`),this.h=!this.isEmpty(this.h)&&this.h.o(),this.i=this.getVal(`${this.a}TgNotifyUrl${this.id}`),this.h=this.h?!this.isEmpty(this.i):this.h,this.j=`${this.a}CostTotalString${this.id}`,this.k=this.getVal(this.j),this.k=this.isEmpty(this.k)?`0,0`:this.k.replace('"',""),this.l=this.k.split(",")[0],this.m=this.k.split(",")[1],this.n=0,this.o="█",this.p=" ",this.now=new Date,this.q=this.now.getTime(),this.node=(()=>{if(this.isNode()){const request=require("request");return{request}}return null})(),this.r=!0,this.s=[],this.t="chavy_boxjs_cur__acs",this.u="chavy_boxjs__acs",this.v={"|`|":",backQuote,"},this.w={",backQuote,":"`","%2CbackQuote%2C":"`"},this.y={"_":"\\_","*":"\\*","`":"\\`"},this.x={"_":"\\_","*":"\\*","[":"\\[","]":"\\]","(":"\\(",")":"\\)","~":"\\~","`":"\\`",">":"\\>","#":"\\#","+":"\\+","-":"\\-","=":"\\=","|":"\\|","{":"\\{","}":"\\}",".":"\\.","!":"\\!"},this.log(`${this.name}, 开始执行!`),this.fd()}fb(_a){if(!this.isNode())return _a;let _b=process.argv.slice(1,2)[0].split("/");return _b[_b.length-1]=_a,_b.join("/")}fc(_a){const _c=this.path.resolve(_a),_d=this.path.resolve(process.cwd(),_a),_e=this.fs.existsSync(_c),_f=!_e&&this.fs.existsSync(_d);return{_c,_d,_e,_f}}async fd(){if(!this.isNode())return;if(this.e=process.argv.slice(1),this.e[1]!="p")return;this.isExecComm=!0,this.log(`开始执行指令【${this.e[1]}】=> 发送到其他终端测试脚本!`);let httpApi=this.d?.httpApi,_h;if(this.isEmpty(this?.d?.httpApi))this.log(`未设置options,使用默认值`),this.isEmpty(this?.d)&&(this.d={}),this.d.httpApi=`ffff@10.0.0.6:6166`,httpApi=this.d.httpApi,_h=httpApi.split("@")[1];else{if(typeof httpApi=="object")if(_h=this.isNumeric(this.e[2])?this.e[3]||"unknown":this.e[2],httpApi[_h])httpApi=httpApi[_h];else{const keys=Object.keys(httpApi);keys[0]?(_h=keys[0],httpApi=httpApi[keys[0]]):httpApi="error"}if(!/.*?@.*?:[0-9]+/.test(httpApi)){this.log(`❌httpApi格式错误!格式: ffff@3.3.3.18:6166`),this.done();return}}this.fe(this.e[2],_h,httpApi)}fe(timeout,_h,httpApi){let _i=this.e[0];const[_j,_k]=httpApi.split("@");this.log(`获取【${_i}】内容传给【${_h||_k}】`),this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const{_c,_d,_e,_f}=this.fc(_i);if(!_e&&!_f){lk.done();return}const _m=_e?_c:_d;let options={url:`http://${_k}/v1/scripting/evaluate`,headers:{"X-Key":_j},body:{script_text:new String(this.fs.readFileSync(_m)),mock_type:"cron",timeout:!this.isEmpty(timeout)&&timeout>5?timeout:5},json:!0};this.req.post(options).then(({error,resp,data})=>{this.log(`已将脚本【${_i}】发给【${_h||_k}】,执行结果: ${this.p}error: ${error} ${this.p}resp: ${resp?.s()} ${this.p}data: ${this.fj(data)}`),this.done()}).catch(e=>{let _ae="",_l=!1;if(e?.error?.code)switch(e.error.code){case"EHOSTDOWN":_ae=`请检查配置的目标设备【${_h||_k}】是否在线!`,_l=!0;break;case"ECONNREFUSED":_ae=`目标设备【${_h||_k}】拒绝连接,请确认服务端口已开启且可访问!`,_l=!0;break;case"EHOSTUNREACH":_ae=`无法到达目标设备【${_h||_k}】,请检查网络连接和路由设置!`,_l=!0;break;case"ENETUNREACH":_ae=`网络不可达,无法访问目标设备【${_h||_k}】,请检查本地网络环境!`,_l=!0;break;case"ETIMEDOUT":_ae=`连接目标设备【${_h||_k}】超时,请检查网络状况或目标设备响应状态!`,_l=!0;break;case"ECONNRESET":_ae=`与目标设备【${_h||_k}】的连接被重置,可能是设备重启或网络异常!`,_l=!0;break;case"ENOTFOUND":_ae=`未能解析目标设备地址【${_h||_k}】,请检查配置的主机名或DNS设置!`,_l=!0;break;case"EADDRINUSE":_ae=`本地端口已被占用,无法建立与目标设备【${_h||_k}】的连接!`,_l=!0;break;case"EACCES":_ae=`权限不足,无法访问目标设备【${_h||_k}】!`,_l=!0;break;default:_l=!1}if(!_l)throw e;this.log(_ae)})}boxJsJsonBuilder(info,param){if(!this.isNode())return;if(!this.isJsonObject(info)||!this.isJsonObject(param)){this.log("构建BoxJsJson传入参数格式错误,请传入json对象");return}let _p=param?.targetBoxjsJsonPath||"/Users/lowking/Desktop/Scripts/lowking.boxjs.json";if(!this.fs.existsSync(_p))return;this.log("using node");let _q=["settings","keys"];const _r="https://raw.githubusercontent.com/Orz-3";let boxJsJson={},scritpUrl="#lk{script_url}";if(boxJsJson.id=`${this.a}${this.id}`,boxJsJson.name=this.name,boxJsJson.desc_html=`⚠️使用说明
详情【点我查看】`,boxJsJson.icons=[`${_r}/mini/master/Alpha/${this.id.toLocaleLowerCase()}.png`,`${_r}/mini/master/Color/${this.id.toLocaleLowerCase()}.png`],boxJsJson.keys=[],boxJsJson.settings=[{id:`${this.a}IsEnableLog${this.id}`,name:"开启/关闭日志",val:!0,type:"boolean",desc:"默认开启"},{id:`${this.a}NotifyOnlyFail${this.id}`,name:"只当执行失败才通知",val:!1,type:"boolean",desc:"默认关闭"},{id:`${this.a}IsEnableTgNotify${this.id}`,name:"开启/关闭Telegram通知",val:!1,type:"boolean",desc:"默认关闭"},{id:`${this.a}TgNotifyUrl${this.id}`,name:"Telegram通知地址",val:"",type:"text",desc:"Tg的通知地址,如: https://api.telegram.org/bot-token/sendMessage?chat_id=-100140&parse_mode=Markdown&text="}],boxJsJson.author="#lk{author}",boxJsJson.repo="#lk{repo}",boxJsJson.script=`${scritpUrl}?raw=true`,!this.isEmpty(info))for(let key of _q){if(this.isEmpty(info[key]))break;if(key==="settings")for(let i=0;iapp.id==boxJsJson.id)[0]);targetIdx>=0?boxjsJson.apps[targetIdx]=boxJsJson:boxjsJson.apps.push(boxJsJson);let ret=boxjsJson.s(null,2);if(!this.isEmpty(param))for(const key in param){let val=param[key];if(!val)switch(key){case"author":val="@lowking";break;case"repo":val="https://github.com/lowking/Scripts";break;default:continue}ret=ret.replaceAll(`#lk{${key}}`,val)}const regex=/(?:#lk\{)(.+?)(?=\})/;let m=regex.exec(ret);m!==null&&this.log(`⚠️生成BoxJs还有未配置的参数,请参考: ${this.p}https://github.com/lowking/Scripts/blob/master/util/example/ToolKitDemo.js#L17-L19 ${this.p}传入参数: `);let _n=new Set;for(;(m=regex.exec(ret))!==null;)_n.add(m[1]),ret=ret.replace(`#lk{${m[1]}}`,``);_n.forEach(p=>console.log(`${this.p}${p}`)),this.fs.writeFileSync(_p,ret)}isJsonObject(obj){return typeof obj=="object"&&Object.prototype.toString.call(obj).toLowerCase()=="[object object]"&&!obj.length}appendNotifyInfo(info,type){type==1?this.s=info:this.s.push(info)}prependNotifyInfo(info){this.s.splice(0,0,info)}execFail(){this.r=!1}isRequest(){return typeof $request!="undefined"}isSurge(){return typeof $httpClient!="undefined"}isQuanX(){return typeof $task!="undefined"}isLoon(){return typeof $loon!="undefined"}isJSBox(){return typeof $app!="undefined"&&typeof $http!="undefined"}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}isNode(){return typeof require=="function"&&!this.isJSBox()}sleep(ms){return this.n+=ms,new Promise(resolve=>setTimeout(resolve,ms))}randomSleep(minMs,maxMs){return this.sleep(this.randomNumber(minMs,maxMs))}randomNumber(min,max){return Math.floor(Math.random()*(max-min+1)+min)}log(message){if(!this.f)return;this.ac===this.ab.debug&&console.log(` ${this.o}DEBUG${this.o}${message}`)}info(message){if(!this.f)return;this.ac&this.aa.info&&console.log(` ${this.o}INFO${this.o}${message}`)}warn(message){if(!this.f)return;this.ac&this.aa.warn&&console.log(` ${this.o}WARN${this.o}${message}`)}error(message){if(!this.f)return;this.ac&this.aa.error&&console.log(` ${this.o}ERROR${this.o}${message}`)}debug(message){if(!this.f)return;this.ac===this.ab.debug&&console.log(` ${this.o}DEBUG${this.o}${message}`)}logErr(message){if(this.r=!0,this.f){let msg="";this.isEmpty(message.error)||(msg=`${msg} ${this.p}${message.error.s()}`),this.isEmpty(message.message)||(msg=`${msg} ${this.p}${message.message.s()}`),msg=`${this.o}${this.name}执行异常:${this.p}${msg}`,message&&(msg=`${msg} ${this.p}${message.s()}`),console.log(msg)}}ff(mapping,message){for(let key in mapping){if(!mapping.hasOwnProperty(key))continue;message=message.replaceAll(key,mapping[key])}return message}msg(subtitle,message,openUrl,mediaUrl,copyText,disappearS){if(!this.isRequest()&&this.g&&this.r)return;if(this.isEmpty(message)&&(Array.isArray(this.s)?message=this.s.join(` `):message=this.s),this.isEmpty(message))return;if(this.h){this.log(`${this.name}Tg通知开始`);const fa=this.i&&this.i.indexOf("parse_mode=Markdown")!=-1;if(fa){message=this.ff(this.v,message);let _t=this.y;this.i.indexOf("parse_mode=MarkdownV2")!=-1&&(_t=this.x),message=this.ff(_t,message)}message=`📌${this.name} ${message}`,fa&&(message=this.ff(this.w,message));let u=`${this.i}${encodeURIComponent(message)}`;this.req.get({url:u})}else{let options={};const _u=!this.isEmpty(openUrl),_v=!this.isEmpty(mediaUrl),_w=!this.isEmpty(copyText),_x=disappearS>0;this.isSurge()||this.isLoon()||this.isStash()?(_u&&(options.url=openUrl,options.action="open-url"),_w&&(options.text=copyText,options.action="clipboard"),this.isSurge()&&_x&&(options["auto-dismiss"]=disappearS),_v&&(options["media-url"]=mediaUrl),$notification.post(this.name,subtitle,message,options)):this.isQuanX()?(_u&&(options["open-url"]=openUrl),_v&&(options["media-url"]=mediaUrl),$notify(this.name,subtitle,message,options)):this.isNode()?this.log("⭐️"+this.name+` `+subtitle+` `+message):this.isJSBox()&&$push.schedule({title:this.name,body:subtitle?subtitle+` `+message:message})}}getVal(key,defaultValue){let value;return this.isSurge()||this.isLoon()||this.isStash()?value=$persistentStore.read(key):this.isQuanX()?value=$prefs.valueForKey(key):this.isNode()?(this.data=this.fh(),value=process.env[key]||this.data[key]):value=this.data&&this.data[key]||null,value||defaultValue}fg(key,val){if(key==this.u)return;const _y=`${this.a}${this.id}`;let _z=this.getVal(this.t,"{}").o();if(!_z.hasOwnProperty(_y))return;let curSessionId=_z[_y],_aa=this.getVal(this.u,"[]").o();if(_aa.length==0)return;let _ab=[];if(_aa.forEach(_ac=>{_ac.id==curSessionId&&(_ab=_ac.datas)}),_ab.length==0)return;let _ad=!1;_ab.forEach(kv=>{kv.key==key&&(kv.val=val,_ad=!0)}),_ad||_ab.push({key,val}),_aa.forEach(_ac=>{_ac.id==curSessionId&&(_ac.datas=_ab)}),this.setVal(this.u,_aa.s())}setVal(key,val){return this.isSurge()||this.isLoon()||this.isStash()?(this.fg(key,val),$persistentStore.write(val,key)):this.isQuanX()?(this.fg(key,val),$prefs.setValueForKey(val,key)):this.isNode()?(this.data=this.fh(),this.data[key]=val,this.fi(),!0):this.data&&this.data[key]||null}fh(){if(!this.isNode())return{};this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const{_c,_d,_e,_f}=this.fc(this.b);if(_e||_f){const _m=_e?_c:_d;return this.fs.readFileSync(_m).o()}return{}}fi(){if(!this.isNode())return;this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const{_c,_d,_e,_f}=this.fc(this.b),_g=this.data.s();_e?this.fs.writeFileSync(_c,_g):_f?this.fs.writeFileSync(_d,_g):this.fs.writeFileSync(_c,_g)}fj(data){const _s=`${this.p}${this.p}`;let ret="";return Object.keys(data).forEach(key=>{let lines=data[key]?.s().split(` `);key=="output"&&(lines=lines.slice(0,-2)),ret=`${ret} ${_s}${key}: ${_s}${this.p}${lines?.join(` ${_s}${this.p}`)}`}),ret}fk(response){return response&&(response.status=response?.status||response?.statusCode,delete response.statusCode,response)}get(options,callback=()=>{}){this.isSurge()||this.isLoon()||this.isStash()?$httpClient.get(options,(error,response,body)=>{callback(error,this.fk(response),body)}):this.isQuanX()?(typeof options=="string"&&(options={url:options}),options.method="GET",$task.fetch(options).then(response=>{callback(null,this.fk(response),response.body)},reason=>callback(reason.error,null,null))):this.isNode()?this.node.request(options,(error,response,body)=>{callback(error,this.fk(response),body)}):this.isJSBox()&&(typeof options=="string"&&(options={url:options}),options.header=options.headers,options.handler=function(resp){let error=resp.error;error&&(error=resp.error.s());let body=resp.data;typeof body=="object"&&(body=resp.data.s()),callback(error,this.adapterStatus(resp.response),body)},$http.get(options))}post(options,callback=()=>{}){this.isSurge()||this.isLoon()||this.isStash()?$httpClient.post(options,(error,response,body)=>{callback(error,this.fk(response),body)}):this.isQuanX()?(typeof options=="string"&&(options={url:options}),options.method="POST",$task.fetch(options).then(response=>{callback(null,this.fk(response),response.body)},reason=>callback(reason.error,null,null))):this.isNode()?this.node.request.post(options,(error,response,body)=>{callback(error,this.fk(response),body)}):this.isJSBox()&&(typeof options=="string"&&(options={url:options}),options.header=options.headers,options.handler=function(resp){let error=resp.error;error&&(error=resp.error.s());let body=resp.data;typeof body=="object"&&(body=resp.data.s()),callback(error,this.adapterStatus(resp.response),body)},$http.post(options))}put(options,callback=()=>{}){this.isSurge()||this.isLoon()||this.isStash()?(options.method="PUT",$httpClient.put(options,(error,response,body)=>{callback(error,this.fk(response),body)})):this.isQuanX()?(typeof options=="string"&&(options={url:options}),options.method="PUT",$task.fetch(options).then(response=>{callback(null,this.fk(response),response.body)},reason=>callback(reason.error,null,null))):this.isNode()?(options.method="PUT",this.node.request.put(options,(error,response,body)=>{callback(error,this.fk(response),body)})):this.isJSBox()&&(typeof options=="string"&&(options={url:options}),options.header=options.headers,options.handler=function(resp){let error=resp.error;error&&(error=resp.error.s());let body=resp.data;typeof body=="object"&&(body=resp.data.s()),callback(error,this.adapterStatus(resp.response),body)},$http.post(options))}sum(a,b){let aa=Array.from(a,Number),bb=Array.from(b,Number),ret=[],c=0,i=Math.max(a.length,b.length);for(;i--;)c+=(aa.pop()||0)+(bb.pop()||0),ret.unshift(c%10),c=Math.floor(c/10);for(;c;)ret.unshift(c%10),c=Math.floor(c/10);return ret.join("")}fl(){let info=`${this.name}, 执行完毕!`;this.isNode()&&this.isExecComm&&(info=`指令【${this.e[1]}】执行完毕!`);const endTime=(new Date).getTime(),ms=endTime-this.q,fl=ms/1e3,count=this.sum(this.m,"1"),total=this.sum(this.l,ms.s()),average=(Number(total)/Number(count)/1e3).toFixed(4);info=`${info} ${this.p}耗时【${fl}】秒(含休眠${this.n?(this.n/1e3).toFixed(4):0}秒)`,info=`${info} ${this.p}总共执行【${count}】次,平均耗时【${average}】秒`,info=`${info} ${this.p}ToolKit v1.5.0 build 204.`,this.log(info),this.setVal(this.j,`${total},${count}`.s())}done(value={}){this.fl(),(this.isSurge()||this.isQuanX()||this.isLoon()||this.isStash())&&$done(value)}getRequestUrl(){return $request.url}getResponseBody(){return $response.body}isMatch(reg){return!!($request.method!="OPTIONS"&&this.getRequestUrl().match(reg))}isEmpty(obj){return typeof obj=="undefined"||obj==null||obj.s()=="{}"||obj==""||obj.s()=='""'||obj.s()=="null"||obj.s()=="undefined"||obj.length===0}isNumeric(s){return!isNaN(parseFloat(s))&&isFinite(s)}randomString(len,chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"){len=len||32;let maxPos=chars.length,pwd="";for(let i=0;i