mirror of
https://github.com/fmz200/wool_scripts.git
synced 2025-12-19 13:41:18 +08:00
307 lines
26 KiB
JavaScript
307 lines
26 KiB
JavaScript
/*
|
||
------------------------------------------
|
||
@Date: 2024.10.17
|
||
@Description:雨晨ios 每日签到
|
||
@Description:在boxjs填写账号#密码,多账号用&分割,如账号1#密码1&账号2#密码2
|
||
------------------------------------------
|
||
|
||
⚠️【免责声明】
|
||
------------------------------------------
|
||
1、此脚本仅用于学习研究,不保证其合法性、准确性、有效性,请根据情况自行判断,本人对此不承担任何保证责任。
|
||
2、由于此脚本仅用于学习研究,您必须在下载后 24 小时内将所有内容从您的计算机或手机或任何存储设备中完全删除,若违反规定引起任何事件本人对此均不负责。
|
||
3、请勿将此脚本用于任何商业或非法目的,若违反规定请自行对此负责。
|
||
4、此脚本涉及应用与本人无关,本人对因此引起的任何隐私泄漏或其他后果不承担任何责任。
|
||
5、本人对任何脚本引发的问题概不负责,包括但不限于由脚本错误引起的任何损失和损害。
|
||
6、如果任何单位或个人认为此脚本可能涉嫌侵犯其权利,应及时通知并提供身份证明,所有权证明,我们将在收到认证文件确认后删除此脚本。
|
||
7、所有直接或间接使用、查看此脚本的人均应该仔细阅读此声明。本人保留随时更改或补充此声明的权利。一旦您使用或复制了此脚本,即视为您已接受此免责声明。
|
||
*/
|
||
const $ = new Env("雨晨ios签到");
|
||
//notify
|
||
const notify = $.isNode() ? require('./sendNotify') : '';
|
||
const ckName = "yuchenios_data";
|
||
const userCookie = getEnvByNode();
|
||
//用户多账号配置
|
||
$.userIdx = 0, $.userList = [], $.notifyMsg = [];
|
||
//成功个数
|
||
$.succCount = 0;
|
||
//debug
|
||
$.is_debug = ($.isNode() ? process.env.IS_DEDUG : $.getdata('is_debug')) || 'false';
|
||
$.host = ($.isNode() ? process.env["yuchenios_host"] : $.getdata('yuchenios_host')) || 'yc.yuchengyouxi.com';
|
||
//------------------------------------------
|
||
async function main() {
|
||
for (let user of $.userList) {
|
||
//$.notifyMsg = [], $.title = "";
|
||
try {
|
||
let token = await user.getToken();
|
||
await user.Login(token);
|
||
if (user.ckStatus) {
|
||
let { points: pointF } = await user.getUserInfo();
|
||
await user.signin();
|
||
let { points: pointE, username } = await user.getUserInfo();
|
||
$.notifyMsg.push(`用户: ${user.userName} 积分:${pointF}${pointE >= pointF ? "+" : ""}${pointE - 0 - pointF}`);
|
||
$.succCount++;
|
||
} else {
|
||
DoubleLog(`用户: ${user?.userName} 积分: 查询失败,用户需要去登录`)
|
||
}
|
||
} catch (e) {
|
||
throw e
|
||
}
|
||
}
|
||
$.title = `共${$.userList.length}个账号,成功${$.succCount}个,失败${$.userList.length - 0 - $.succCount}个`
|
||
//notify
|
||
await sendMsg($.notifyMsg.join("\n"), { $media: $.avatar });
|
||
}
|
||
|
||
//用户
|
||
class UserInfo {
|
||
constructor(user) {
|
||
//默认属性
|
||
this.index = ++$.userIdx;
|
||
this.token = "" || user.token || user;
|
||
this.userId = "" || user.userId;
|
||
this.avatar = user.avatar;
|
||
this.phone = user.phone;
|
||
this.password = user.password;
|
||
this.userName = phone_num(this.phone);
|
||
this.ckStatus = true;
|
||
//请求封装
|
||
this.baseUrl = `https://${$.host}`;
|
||
this.headers = {
|
||
'X-Requested-With': `XMLHttpRequest`,
|
||
'Connection': `keep-alive`,
|
||
'Accept-Encoding': `gzip, deflate, br`,
|
||
'Content-Type': `application/x-www-form-urlencoded; charset=UTF-8`,
|
||
'Origin': `https://${$.host}`,
|
||
'User-Agent': `Mozilla/5.0 (iPhone; CPU iPhone OS 15_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Mobile/15E148 Safari/604.1`,
|
||
'Cookie': "",
|
||
'Host': `${$.host}`,
|
||
'Referer': `https://${$.host}/`,
|
||
'Accept-Language': `zh-CN,zh-Hans;q=0.9`,
|
||
'Accept': `application/json, text/javascript, */*; q=0.01`
|
||
};
|
||
this.getRandomTime = () => randomInt(1e3, 3e3);
|
||
this.fetch = async (o) => {
|
||
try {
|
||
if (typeof o === 'string') o = { url: o };
|
||
if ((!o?.url) || o?.url?.startsWith("/") || o?.url?.startsWith(":")) o.url = this.baseUrl + (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?.msg && res?.msg?.match(/请重新登录/)) throw new Error(res?.msg);
|
||
return res;
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.index}]请求发起失败!${e}`);
|
||
}
|
||
}
|
||
}
|
||
//查询用户信息
|
||
async getUserInfo() {
|
||
try {
|
||
const opts = {
|
||
url: `/mxq-backend-miniprogram-service/mxq/integral/member_info`,
|
||
}
|
||
let res = await this.fetch(opts);
|
||
this.userName = res?.data?.nickname;
|
||
return res?.data;
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.userId}] 错误!${e}`);
|
||
}
|
||
}
|
||
//登录接口
|
||
async Login(token) {
|
||
try {
|
||
const opts = {
|
||
url: "/wp-admin/admin-ajax.php",
|
||
type: "post",
|
||
dataType: "form",
|
||
resultType: "all",
|
||
body: `user_login=${this.phone}&password=${this.password}&rememberme=1&redirect=https%3A%2F%2Fyc.yuchengyouxi.com%2F&action=userlogin_form&token=${token}`
|
||
|
||
}
|
||
let res = await this.fetch(opts);
|
||
let headers = ObjectKeys2LowerCase(res?.headers) ?? {};
|
||
//对青龙进行兼容
|
||
let session = Array.isArray(headers['set-cookie']) ? [...new Set(headers['set-cookie'])].join("") : headers['set-cookie'];
|
||
res = session?.match(/(wordpress_(sec|logged_in)_[a-f0-9]{32})=.+?;/g) ?? [];
|
||
this.session = res.join("")
|
||
if (!this.session) throw new Error("获取session失败!")
|
||
this.headers.Cookie = this.session;
|
||
$.info(`[${this.userName}] 登录成功`);
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.userId}] 错误!${e}`);
|
||
}
|
||
}
|
||
//获取登录token
|
||
async getToken() {
|
||
try {
|
||
const opts = {
|
||
url: "/login",
|
||
}
|
||
let html = await this.fetch(opts);
|
||
|
||
const query = $.Cheerio.load(html);
|
||
|
||
const token = query('input[name="token"]').attr('value');
|
||
if (!token) throw new Error("获取token失败");
|
||
$.info(`[${this.userName}] 获取token成功!${token}`);
|
||
return token;
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.userId}] 错误!${e}`);
|
||
}
|
||
}
|
||
//签到
|
||
async signin() {
|
||
try {
|
||
const opts = {
|
||
url: "/wp-admin/admin-ajax.php",
|
||
type: "post",
|
||
dataType: "form",
|
||
body: `action=daily_sign`
|
||
}
|
||
let res = await this.fetch(opts);
|
||
$.info(`[${this.userName}] 签到:${res?.msg}`);
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.userId}] 错误!${e}`);
|
||
}
|
||
}
|
||
//查询用户信息
|
||
async getUserInfo() {
|
||
try {
|
||
const opts = {
|
||
url: "/users?tab=credit",
|
||
}
|
||
let html = await this.fetch(opts);
|
||
|
||
const query = $.Cheerio.load(html);
|
||
|
||
// 提取用户名
|
||
const username = query('.name_user').text().trim();
|
||
// 提取积分
|
||
const points = query('.user_setting_num p:nth-child(2) em').text();
|
||
return { username, points }
|
||
} catch (e) {
|
||
this.ckStatus = false;
|
||
$.error(`[${this.userName || this.userId}] 错误!${e}`);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
function phone_num(phone_num) { if (phone_num.length == 11) { let data = phone_num.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2"); return data; } else { return phone_num; } }
|
||
|
||
//远程通知
|
||
async function getNotice() {
|
||
const urls = [
|
||
"https://fastly.jsdelivr.net/gh/Sliverkiss/GoodNight@main/notice.json",
|
||
"https://fastly.jsdelivr.net/gh/Sliverkiss/GoodNight@main/tip.json"
|
||
];
|
||
|
||
try {
|
||
const responses = await Promise.all(urls.map(url => Request(url)));
|
||
responses.map(result => $.log(result?.notice || "获取通知失败"));
|
||
if (responses[0]?.notice) return true;
|
||
} catch (error) {
|
||
console.log(`❌获取通知时发生错误:${error}`);
|
||
}
|
||
}
|
||
|
||
async function loadCheerio() {
|
||
let code = ($.isNode() ? require('cheerio') : $.getdata('Cheerio_code')) || '';
|
||
if (code && Object.keys(code).length) {
|
||
$.info(`缓存中存在Cheerio模块,跳过下载`);
|
||
if($.isNode()) return code;
|
||
eval(code);
|
||
return createCheerio()
|
||
}
|
||
$.info(`开始下载Cheerio模块`);
|
||
return new Promise(async (resolve) => {
|
||
$.getScript('https://fastly.jsdelivr.net/gh/Sliverkiss/QuantumultX@main/Utils/cheerio.js').then((fn) => {
|
||
$.setdata(fn, "Cheerio_code");
|
||
eval(fn);
|
||
const Cheerio = createCheerio();
|
||
$.info(`Cheerio模块加载成功,请继续`);
|
||
resolve(Cheerio)
|
||
})
|
||
})
|
||
};
|
||
|
||
// 获取Cookie
|
||
async function getCookie() {
|
||
try {
|
||
if ($request && $request.method === 'OPTIONS') return;
|
||
const Body = $.toObj($request.body);
|
||
|
||
if (!Body["unionid"]) throw new Error("获取token失败!参数缺失");
|
||
|
||
const newData = {
|
||
"userId": Body["unionid"]
|
||
}
|
||
const index = userCookie.findIndex(e => e.userId == newData.userId);
|
||
|
||
userCookie[index] ? userCookie[index] = newData : userCookie.push(newData);
|
||
|
||
$.setjson(userCookie, ckName);
|
||
let userName = index != -1 ? index : userCookie.length;
|
||
$.msg($.name, `🎉账号[${userName}]更新token成功!`, ``);
|
||
} catch (e) {
|
||
throw e;
|
||
}
|
||
}
|
||
|
||
//处理node
|
||
function getEnvByNode() {
|
||
let ckList = $.isNode() ? process.env[ckName] : $.getdata(ckName);
|
||
// 判断ckList是否是数组
|
||
if (!Array.isArray(ckList)) {
|
||
ckList = ckList.split("&"); // 将字符串分割为数组
|
||
ckList = ckList.map(e => {
|
||
const [phone, password] = e.split('#');
|
||
let newData = {
|
||
"userId": phone,
|
||
"phone": phone,
|
||
"password": password,
|
||
"userName": phone
|
||
};
|
||
return newData;
|
||
});
|
||
}
|
||
return ckList;
|
||
}
|
||
|
||
//主程序执行入口
|
||
!(async () => {
|
||
try {
|
||
if (typeof $request != "undefined") {
|
||
await getCookie();
|
||
} else {
|
||
if (!(await getNotice())) throw new Error("网络状况不好,请重新尝试~")
|
||
await checkEnv();
|
||
$.Cheerio = await loadCheerio();
|
||
await main();
|
||
}
|
||
} catch (e) {
|
||
throw e;
|
||
}
|
||
})()
|
||
.catch((e) => { $.logErr(e), $.msg($.name, `⛔️ script run error!`, e.message || e) })
|
||
.finally(async () => {
|
||
$.done({});
|
||
});
|
||
|
||
/** ---------------------------------固定不动区域----------------------------------------- */
|
||
//prettier-ignore
|
||
|
||
async function sendMsg(a, e) { a && ($.isNode() ? await notify.sendNotify($.name, a) : $.msg($.name, $.title || "", a, e)) }
|
||
function DoubleLog(o) { o && ($.log(`${o}`), $.notifyMsg.push(`${o}`)) };
|
||
async function checkEnv() { try { if (!userCookie?.length) throw new Error("no available accounts found"); $.log(`\n[INFO] 检测到 ${userCookie?.length ?? 0} 个账号\n`), $.userList.push(...userCookie.map((o => new UserInfo(o))).filter(Boolean)) } catch (o) { throw o } }
|
||
function debug(g, e = "debug") { "true" === $.is_debug && ($.log(`\n-----------${e}------------\n`), $.log("string" == typeof g ? g : $.toStr(g) || `debug error => t=${g}`), $.log(`\n-----------${e}------------\n`)) }
|
||
//From xream's ObjectKeys2LowerCase
|
||
function ObjectKeys2LowerCase(obj) { return !obj ? {} : Object.fromEntries(Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v])) };
|
||
//From sliverkiss's Request
|
||
async function Request(t) { "string" == typeof t && (t = { url: t }); try { if (!t?.url) throw new Error("[URL][ERROR] 缺少 url 参数"); let { url: o, type: e, headers: r = {}, body: s, params: a, dataType: n = "form", resultType: u = "data" } = t; const p = e ? e?.toLowerCase() : "body" in t ? "post" : "get", c = o.concat("post" === p ? "?" + $.queryStr(a) : ""), i = t.timeout ? $.isSurge() ? t.timeout / 1e3 : t.timeout : 1e4; "json" === n && (r["Content-Type"] = "application/json;charset=UTF-8"); const y = "string" == typeof s ? s : (s && "form" == n ? $.queryStr(s) : $.toStr(s)), l = { ...t, ...t?.opts ? t.opts : {}, url: c, headers: r, ..."post" === p && { body: y }, ..."get" === p && a && { params: a }, timeout: i }, m = $.http[p.toLowerCase()](l).then((t => "data" == u ? $.toObj(t.body) || t.body : $.toObj(t) || t)).catch((t => $.log(`[${p.toUpperCase()}][ERROR] ${t}\n`))); return Promise.race([new Promise(((t, o) => setTimeout((() => o("当前请求已超时")), i))), m]) } catch (t) { console.log(`[${p.toUpperCase()}][ERROR] ${t}\n`) } }
|
||
//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, 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) } |