/* new Env('春风摩托'); @Author: Leiyiyan @Date: 2024-06-12 09:55 @Description: 春风摩托 每日签到、会员任务,积分可兑换实物 获取 Cookie 方式:cfmoto app - 我的 [Script] # 获取 Cookie http-response ^https:\/\/c\.cfmoto\.com\/jv\/user\/user_info script-path=https://raw.githubusercontent.com/leiyiyan/resource/main/script/cfmoto/cfmoto.js, requires-body=true, timeout=60, tag=春风摩托 Cookie # 脚本任务 cron "0 7 * * *" script-path=https://raw.githubusercontent.com/leiyiyan/resource/main/script/cfmoto/cfmoto.js, tag=春风摩托 [Rewrite] # 开屏广告 ^https:\/\/c\.cfmoto\.com\/cfmotoservermall\/app\/ad$ reject-dict # 弹窗广告 ^https:\/\/c\.cfmoto\.com\/cfmotoservermall\/app\/popwindow reject-dict [MITM] hostname = c.cfmoto.com ==================================== ⚠️【免责声明】 ------------------------------------------ 1、此脚本仅用于学习研究,不保证其合法性、准确性、有效性,请根据情况自行判断,本人对此不承担任何保证责任。 2、由于此脚本仅用于学习研究,您必须在下载后 24 小时内将所有内容从您的计算机或手机或任何存储设备中完全删除,若违反规定引起任何事件本人对此均不负责。 3、请勿将此脚本用于任何商业或非法目的,若违反规定请自行对此负责。 4、此脚本涉及应用与本人无关,本人对因此引起的任何隐私泄漏或其他后果不承担任何责任。 5、本人对任何脚本引发的问题概不负责,包括但不限于由脚本错误引起的任何损失和损害。 6、如果任何单位或个人认为此脚本可能涉嫌侵犯其权利,应及时通知并提供身份证明,所有权证明,我们将在收到认证文件确认后删除此脚本。 7、所有直接或间接使用、查看此脚本的人均应该仔细阅读此声明。本人保留随时更改或补充此声明的权利。一旦您使用或复制了此脚本,即视为您已接受此免责声明。 */ // env.js 全局 const $ = new Env("春风摩托"); const ckName = "cfmoto_data"; //-------------------- 一般不动变量区域 ------------------------------------- const Notify = 1;//0为关闭通知,1为打开通知,默认为1 const notify = $.isNode() ? require('./sendNotify') : ''; let envSplitor = ["@"]; //多账号分隔符 var userCookie = ($.isNode() ? process.env[ckName] : $.getdata(ckName)) || ''; let userList = []; let userIdx = 0; let userCount = 0; // 调试 $.is_debug = ($.isNode() ? process.env.IS_DEDUG : $.getdata('is_debug')) || 'false'; // 为多用户准备的通知数组 $.notifyList = []; // 为通知准备的空数组 $.notifyMsg = []; //---------------------- 自定义变量区域 ----------------------------------- //脚本入口函数main() async function main() { try { $.log('\n================== 任务 ==================\n'); for (let user of userList) { console.log(`🔷账号${user.index} >> Start work`) console.log(`随机延迟${user.getRandomTime()}ms`); // 签到 const integral = await user.signin(); if (user.ckStatus) { await $.wait(user.getRandomTime()); // 查看签到记录 const {count, prize} = await user.getSignRecord() await $.wait(user.getRandomTime()); if(prize) { // 盲盒抽奖 await user.lottery() await $.wait(user.getRandomTime()); } // 限时抽奖 await user.getLotteryList() await $.wait(user.getRandomTime()); for(let i = 0; i < 3; i++) { // 创建帖子 const postId = await user.createArticle() await $.wait(user.getRandomTime()); // 评论帖子 await user.postComments(postId) await $.wait(user.getRandomTime()); // 点赞 await user.thumbsUp(postId) await $.wait(user.getRandomTime()); // 分享帖子 await user.share(postId) await $.wait(user.getRandomTime()); // 删除帖子 await user.deletePost(postId) await $.wait(user.getRandomTime()); } //查询待领取积分 const integralTotal = await user.getSignInfo(); $.title = `本次运行共获得${(integral + 36)}积分`; DoubleLog(`「${user.userName}」当前积分:${integralTotal}分,累计签到:${count}天`); } else { //将ck过期消息存入消息数组 $.notifyMsg.push(`❌账号${user.userName || user.index} >> Check ck error!`) } //账号通知 $.notifyList.push({ "id": user.index, "avatar": user.avatar, "message": $.notifyMsg }); //清空数组 $.notifyMsg = []; } } catch (e) { $.log(`⛔️ main run error => ${e}`); throw new Error(`⛔️ main run error => ${e}`); } } class UserInfo { constructor(user) { //默认属性 this.index = ++userIdx; this.token = user.token || user; this.userId = user.userId; this.userName = user.userName; this.avatar = user.avatar; this.ckStatus = true; //请求封装 this.baseUrl = ``; this.host = "https://c.cfmoto.com"; this.headers = { "Cookie": this.token, "User-Agent": "'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 cfmoto/1.0.0" } this.getRandomTime = () => randomInt(1e3, 3e3); this.fetch = async (o) => { try { if (typeof o === 'string') o = { url: o }; if (o?.url?.startsWith("/")) o.url = this.host + o.url const res = await Request({ ...o, headers: o.headers || this.headers, url: o.url || this.baseUrl }) debug(res, o?.url?.replace(/\/+$/, '').substring(o?.url?.lastIndexOf('/') + 1)); if (res?.code == 40001) throw new Error(res?.message || `用户需要去登录`); return res; } catch (e) { this.ckStatus = false; $.log(`⛔️ 请求发起失败!${e}`); } } } //签到 async signin() { try { const opts = { url: this.host + "/cfmotoservermall/app/integral/task/complete/v1", method: "put", headers: { "Cookie": this.token, "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 cfmoto/1.0.0", "Content-Type": "application/json;charset=UTF-8" }, body: JSON.stringify({ completeStatu: 1, taskDetail: 8 }) } let res = await new Promise((resolve, reject) => { $.http['post'](opts) .then((response) => { var resp = response.body; try { resp = $.toObj(resp) || resp; } catch (e) { } resolve(resp); }) .catch((err) => reject(err)); }); if (res.code == 0) { $.log(`✅ 签到任务: 已完成`); const point = parseInt(res.data) return point } else { $.log(`✅ 签到任务: 今日已签到`); return null } } catch (e) { this.ckStatus = false; $.log(`⛔️ 签到失败! ${e}`); } } // 开启盲盒 async lottery() { try { const opts = { url: `/cfmotoservermall/app/user/prize/sign`, type: "post", dataType: "json", body: {} } let res = await this.fetch(opts); if(res?.code == 0) { const prizeSignName = res?.data?.prizeSignName $.log(`✅ 盲盒抽奖获得: ${prizeSignName}`); }else{ $.log(`⛔️ 盲盒抽奖失败! ${res?.msg}`); } } catch (e) { this.ckStatus = false; $.log(`⛔️ 盲盒抽奖失败! ${e}`); } } // 创建帖子 async createArticle() { try { const opts = { url: `/jv/bbs/post/create-v5/`, type: "post", dataType: "json", body: { share_content: "", media_type: "TEXT", longitude: "0.000000", latitude: "0.000000", share_type: "", share_title: "", address: "", share_product_type: "", share_whether_journey: "", share_image: "", city_code: "", is_vote: false, content: "加油" } } let res = await this.fetch(opts); const postId = res.data.id $.log(`✅ 创建帖子: ${postId}`); return postId } catch (e) { this.ckStatus = false; $.log(`⛔️ 创建帖子失败! ${e}`); } } // 评论帖子 async postComments(postId) { try { const opts = { url: `/jv/bbs/article/comment-v1/`, type: "post", dataType: "json", body: { post_id: postId, content: "666" } } await this.fetch(opts); $.log(`✅ 评论帖子: ${postId}`) } catch (e) { this.ckStatus = false; $.log(`⛔️ 评论帖子失败! ${e}`); } } // 点赞帖子 async thumbsUp(postId) { try { const opts = { url: `/jv/bbs/post/thumbs_up/${postId}`, type: "post", dataType: "json", body: {} } await this.fetch(opts); $.log(`✅ 点赞帖子: ${postId}`) } catch (e) { this.ckStatus = false; $.log(`⛔️ 点赞帖子失败! ${e}`); } } // 删除帖子 async deletePost(postId) { try { const opts = { url: this.host + "/jv/bbs/post/?id=" + postId, method: "delete", headers: { "Cookie": this.token, "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 cfmoto/1.0.0", "Content-Type": "application/json;charset=UTF-8" }, body: JSON.stringify({}) } await new Promise((resolve, reject) => { $.http['post'](opts) .then((response) => { var resp = response.body; try { resp = $.toObj(resp) || resp; } catch (e) { } resolve(resp); }) .catch((err) => reject(err)); }); $.log(`✅ 删除帖子: ${postId}`) } catch (e) { this.ckStatus = false; $.log(`⛔️ 删除帖子失败! ${e}`); } } // 分享帖子 async share(postId) { try { const opts = { url: this.host + "/cfmotoservermall/app/integral/task/complete", method: "put", headers: { "Cookie": this.token, "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 cfmoto/1.0.0", "Content-Type": "application/json;charset=UTF-8" }, body: JSON.stringify({ completeStatu: 1, taskDetail: 13 }) } await new Promise((resolve, reject) => { $.http['post'](opts) .then((response) => { var resp = response.body; try { resp = $.toObj(resp) || resp; } catch (e) { } resolve(resp); }) .catch((err) => reject(err)); }); $.log(`✅ 分享帖子: ${postId}`) } catch (e) { this.ckStatus = false; $.log(`⛔️ 分享失败! ${e}`); } } // 查询用户信息 async getSignInfo() { try { const opts = { url: `/cfmotoservermall/app/user/integral/current/user/info`, type: "get", dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { const integralTotal = res.data.integralTotal return integralTotal } return null } catch (e) { this.ckStatus = false; $.log(`⛔️ 查询用户信息失败! ${e}`); } } // 查询签到记录 async getSignRecord() { try { const opts = { url: `/cfmotoservermall/app/integral/task/signinlist/v1`, type: "get", params: { year: new Date().getFullYear(), month: new Date().getMonth() + 1 }, dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { const count = res?.data?.count const prize = res?.data?.prize $.log(prize ? `✅ 满足盲盒抽奖条件` : `✅ 未满足盲盒抽奖条件`) return {count, prize} } return null } catch (e) { this.ckStatus = false; $.log(`⛔️ 查询签到记录失败! ${e}`); } } // 获取限时抽奖活动列表 async getLotteryList() { try { const opts = { url: `/jv/bbs/lottery/listgoing/`, type: "get", params: {}, dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { const list = res?.data?.list if(list && list.length) { for(let item of list) { if(item.lottery_status_name === "进行中") { $.log(`✅ 开始参与限时抽奖活动`) await this.getLotteryDetail(item.id) } } if(list[list.length - 1].lottery_status_name !== '进行中') { $.log(`✅ 当前无限时抽奖活动`) } } else { $.log(`✅ 当前无限时抽奖活动`) } } } catch (e) { this.ckStatus = false; $.log(`⛔️ 查询限时抽奖活动列表失败! ${e}`); } } // 获取限时抽奖活动详情 async getLotteryDetail(id) { try { const opts = { url: `/jv/bbs/lottery/${id}/detail/`, type: "get", params: {}, dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { const tickitList = res?.data?.lottery_user_ticket_list if(!tickitList) { await this.lotteryApply(id) } await this.lotteryShare(id) } } catch (e) { this.ckStatus = false; $.log(`⛔️ 查询限时抽奖活动详情失败! ${e}`); } } // 报名限时抽奖活动 async lotteryApply(id) { try { const opts = { url: `/jv/bbs/lottery/${id}/apply/`, type: "get", params: {}, dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { $.log(`✅ 报名限时抽奖活动成功!`) } } catch (e) { this.ckStatus = false; $.log(`⛔️ 报名限时抽奖活动失败! ${e}`); } } // 报名限时抽奖活动 async lotteryShare(id) { try { const opts = { url: `/jv/bbs/lottery/${id}/share/`, type: "get", params: {}, dataType: "json" } let res = await this.fetch(opts); if (res.code == 0) { $.log(`✅ 分享限时抽奖活动成功!`) } } catch (e) { this.ckStatus = false; $.log(`⛔️ 分享限时抽奖活动失败! ${e}`); } } } async function getCookie() { if ($request && $request.method === 'OPTIONS') return; const header = ObjectKeys2LowerCase($request.headers); const cookie = header.cookie; const body = $.toObj($response.body); if (!(body?.data)) { $.msg($.name, `❌获取Cookie失败!`, "") return; } const { id, nickname, photo } = body?.data; const newData = { "userId": id, "avatar": photo, "token": cookie, "userName": nickname, } userCookie = userCookie ? JSON.parse(userCookie) : []; const index = userCookie.findIndex(e => e.userId == newData.userId); userCookie[index] ? userCookie[index] = newData : userCookie.push(newData); $.setjson(userCookie, ckName); $.msg($.name, `🎉${newData.userName}更新token成功!`, ``); } //-------------------------- 辅助函数区域 ----------------------------------- //请求二次封装 async function Request(o) { if (typeof o === 'string') o = { url: o }; try { if (!o?.url) throw new Error('[发送请求] 缺少 url 参数'); // type => 因为env中使用method处理post的特殊请求(put/delete/patch), 所以这里使用type let { url: u, type, headers = {}, body: b, params, dataType = 'form', resultType = 'data' } = o; // post请求需要处理params参数(get不需要, env已经处理) const method = type ? type?.toLowerCase() : ('body' in o ? 'post' : 'get'); const url = u.concat(method === 'post' ? '?' + $.queryStr(params) : ''); const timeout = o.timeout ? ($.isSurge() ? o.timeout / 1e3 : o.timeout) : 1e4 // 根据jsonType处理headers if (dataType === 'json') headers['Content-Type'] = 'application/json;charset=UTF-8'; // post请求处理body const body = b && dataType == 'form' ? $.queryStr(b) : $.toStr(b); const request = { ...o, ...(o?.opts ? o.opts : {}), url, headers, ...(method === 'post' && { body }), ...(method === 'get' && params && { params }), timeout: timeout } const httpPromise = $.http[method.toLowerCase()](request) .then(response => resultType == 'data' ? ($.toObj(response.body) || response.body) : ($.toObj(response) || response)) .catch(err => $.log(`❌请求发起失败!原因为:${err}`)); // 使用Promise.race来强行加入超时处理 return Promise.race([ new Promise((_, e) => setTimeout(() => e('当前请求已超时'), timeout)), httpPromise ]); } catch (e) { console.log(`❌请求发起失败!原因为:${e}`); } }; //生成随机数 function randomInt(n, r) { return Math.round(Math.random() * (r - n) + n) }; //控制台打印 function DoubleLog(data) { if (data && $.isNode()) { console.log(`${data}`); $.notifyMsg.push(`${data}`) } else if (data) { console.log(`${data}`); $.notifyMsg.push(`${data}`) } }; //调试 function debug(t, l = 'debug') { if ($.is_debug === 'true') { $.log(`\n-----------${l}------------\n`); $.log(typeof t == "string" ? t : $.toStr(t) || `debug error => t=${t}`); $.log(`\n-----------${l}------------\n`) } }; //对多账号通知进行兼容 async function SendMsgList(l) { await Promise.allSettled(l?.map(u => SendMsg(u.message.join('\n'), u.avatar))); }; //账号通知 async function SendMsg(n, o) { n && (0 < Notify ? $.isNode() ? await notify.sendNotify($.name, n) : $.msg($.name, $.title || "", n, { "media-url": o }) : console.log(n)) }; //将请求头转换为小写 function ObjectKeys2LowerCase(obj) { return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v])) } //---------------------- 主程序执行入口 ----------------------------------- !(async () => { if (typeof $request != "undefined") { await getCookie(); } else { const e = envSplitor.find(o => userCookie.includes(o)) || envSplitor[0]; userCookie = $.toObj(userCookie) || userCookie.split(e); userList.push(...userCookie.map(n => new UserInfo(n)).filter(Boolean)); userCount = userList.length; console.log(`共找到${userCount}个账号`); if (userList.length > 0) await main(); } })() .catch(e => $.notifyMsg.push(e.message || e)) .finally(async () => { await SendMsgList($.notifyList); $.done({ ok: 1 }); }); /** ---------------------------------固定不动区域----------------------------------------- */ // prettier-ignore //From chavyleung's Env.js 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) }