/* * 2Libra 自动签到脚本 (Quantumult X) * * [task_local] * 0 9 * * * https://raw.githubusercontent.com/e0ab09e002ab/modules/main/qx/js/2libra_sign.js, tag=2Libra签到, enabled=true * * [rewrite_local] * ^https:\/\/2libra\.com\/ url script-request-header 2libra_sign.js * */ // -------------------------- 配置参数 -------------------------- let cookie = ""; // -------------------------- 脚本逻辑 -------------------------- const $ = init(); const JOB_NAME = "2Libra 签到"; const SIGN_URL = "https://2libra.com/api/sign"; const storedCookie = $.getdata("2libra_cookie"); if (storedCookie) { cookie = storedCookie; } if (typeof $request !== "undefined") { getCookie(); } else { execSign(); } function getCookie() { if ($request.headers) { const cookieVal = $request.headers["Cookie"] || $request.headers["cookie"]; if (cookieVal && cookieVal.indexOf("access_token") !== -1) { $.setdata(cookieVal, "2libra_cookie"); $.msg(JOB_NAME, "Cookie 获取成功", "请在 Task 中禁用 Rewrite 以免重复获取"); console.log(`[${JOB_NAME}] Cookie 获取成功: ${cookieVal}`); } } $.done(); } function execSign() { if (!cookie) { $.msg(JOB_NAME, "签到失败", "未配置 Cookie,请启用 Rewrite 访问网站获取"); $.done(); return; } const headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36", "Accept": "application/json, text/plain, */*", "Accept-Language": "zh-CN,zh;q=0.9", "Content-Type": "application/json;charset=UTF-8", "Origin": "https://2libra.com", "Referer": "https://2libra.com/", "Connection": "keep-alive", "Cookie": cookie }; const myRequest = { url: SIGN_URL, method: "POST", headers: headers, body: "{}", // 必须发送空对象 timeout: 15000 }; $.post(myRequest, (error, response, data) => { let status = "失败"; let detail = ""; try { if (error) { detail = `请求异常: ${error}`; } else { const statusCode = response.statusCode; // 解析 JSON 响应以便获取详细信息 let resJson = {}; try { resJson = JSON.parse(data); } catch(e) {} const msg = resJson.m || data; // 获取服务器返回的提示信息 console.log(`[${JOB_NAME}] HTTP状态: ${statusCode}, 响应: ${msg}`); // 判定逻辑修改 if (statusCode === 201 && data.indexOf("签到成功") !== -1) { status = "成功"; detail = "签到成功!"; } // 新增:处理 "已经签到过" 的情况 (即使状态码是 400) else if (data.indexOf("已经签到") !== -1) { status = "成功 (重复)"; detail = "今天已经签到过了,无需重复。"; } else if (statusCode === 400) { status = "失败"; detail = `请求被拒绝 (400): ${msg}`; } else if (statusCode === 401 || statusCode === 403) { status = "失败"; detail = "Cookie 已失效,请重新登录获取。"; } else { detail = `未知状态 (HTTP ${statusCode}): ${msg}`; } } } catch (e) { detail = `脚本解析错误: ${e.message}`; } $.msg(JOB_NAME, `签到状态: ${status}`, detail); console.log(`[${JOB_NAME}] 最终结果: ${status}, 详情: ${detail}`); $.done(); }); } // -------------------------- QX 工具函数 -------------------------- function init() { const isQX = typeof $task !== "undefined"; return { getdata: (key) => { if (isQX) return $prefs.valueForKey(key); return null; }, setdata: (val, key) => { if (isQX) return $prefs.setValueForKey(val, key); return false; }, msg: (title, subtitle, body) => { if (isQX) $notify(title, subtitle, body); }, post: (options, callback) => { if (isQX) { if (typeof options === "string") options = { url: options }; options.method = "POST"; $task.fetch(options).then( response => { callback(null, response, response.body); }, reason => { callback(reason.error, null, null); } ); } }, done: (val) => { if (isQX) $done(val); } }; }