// ==UserScript== // @name WPS 灵犀每日自动签到 // @namespace https://bbs.tampermonkey.net.cn/ // @version 1.1.0 // @description 利用 ScriptCat 后台定时任务自动完成 WPS 灵犀每日签到,支持用户自定义重复签到通知配置 // @author tfsn20 // @crontab * */4 once * * // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_getValue // @grant GM_setValue // @grant CAT_userConfig // @grant GM_registerMenuCommand // @connect lingxi.kdocs.cn // @connect account.kdocs.cn // @license MIT // ==/UserScript== /* ==UserConfig== 通知设置: notify_on_repeat: title: 重复签到提醒 description: 今日已经签到过时,是否弹出系统通知提示(关闭后将静默跳过) type: checkbox default: true ==/UserConfig== */ (async function () { // 1. 获取今天日期 (YYYY-MM-DD) function getTodayDateStr() { const now = new Date(); const y = now.getFullYear(); const m = String(now.getMonth() + 1).padStart(2, '0'); const d = String(now.getDate()).padStart(2, '0'); return `${y}-${m}-${d}`; } // 2. 封装网络请求 function request(options) { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ timeout: 10000, headers: { "Content-Type": "application/json", "Referer": "https://lingxi.kdocs.cn/", "Origin": "https://lingxi.kdocs.cn" }, ...options, onload: (res) => { try { const data = JSON.parse(res.responseText); resolve(data); } catch (e) { resolve(res.responseText); } }, onerror: reject, ontimeout: () => reject(new Error("请求超时")) }); }); } // 3. 常驻系统通知封装 function notify(title, text) { if (typeof GM_notification === "function") { GM_notification({ title: title, text: text, timeout: 0 // 0 为常驻通知中心,等待用户点击或手动划除 }); } } // 注册脚本菜单(支持在扩展菜单一键打开用户配置界面) if (typeof GM_registerMenuCommand === "function" && typeof CAT_userConfig === "function") { GM_registerMenuCommand("⚙️ 打开签到配置", () => CAT_userConfig()); } // 4. 读取用户设置 (默认值为 true,即默认通知) const notifyOnRepeat = GM_getValue("通知设置.notify_on_repeat", true); const todayStr = getTodayDateStr(); const lastCheckinDate = GM_getValue("last_checkin_date", ""); // ----------------- 重复场景 1:本地缓存已记录今日完成 ----------------- if (lastCheckinDate === todayStr) { console.log(`【灵犀签到】本地记录显示今日 (${todayStr}) 已完成签到。`); // 根据用户配置判断是否弹窗 if (notifyOnRepeat) { notify("WPS 灵犀签到提醒", `今日 (${todayStr}) 已完成签到,无需重复操作。`); } else { console.log("【灵犀签到】已开启“重复时不通知”,静默跳过。"); } return; } console.log("【灵犀签到】开始执行签到任务..."); try { // 5. 校验用户登录态 const authData = await request({ method: "POST", url: "https://account.kdocs.cn/p/auth/check" }); if (!authData || authData.result !== "ok") { const errMsg = "未检测到有效登录状态,Cookie 可能已过期,请重新登录 WPS 网页端。"; console.error(`【灵犀签到】${errMsg}`); notify("WPS 灵犀签到失败", errMsg); return; } const nickname = authData.nickname || authData.userid || "用户"; console.log(`【灵犀签到】当前登录账号: ${nickname}`); // 6. 发起签到请求 const claimData = await request({ method: "POST", url: "https://lingxi.kdocs.cn/api/public/v1/tasks/daily_check_in/claim" }); // ----------------- 重复场景 2:服务端返回已签到 ----------------- if (claimData.result !== "ok") { const serverMsg = claimData.msg || claimData.result || JSON.stringify(claimData); const isAlreadyClaimed = /(已签到|已领取|重复|already|claimed)/i.test(serverMsg); if (isAlreadyClaimed) { console.log(`【灵犀签到】服务端提示今日已签到过: ${serverMsg}`); // 补记本地缓存 GM_setValue("last_checkin_date", todayStr); if (notifyOnRepeat) { notify("WPS 灵犀签到提醒", `账号: ${nickname}\n今日已经签到过了,无需重复领取。`); } else { console.log("【灵犀签到】已开启“重复时不通知”,静默结束。"); } return; } // 其他未知错误依然告警 console.warn(`【灵犀签到】签到失败: ${serverMsg}`); notify("WPS 灵犀签到未成功", `账号: ${nickname}\n原因: ${serverMsg}`); return; } // ----------------- 场景 3:本次签到成功 ----------------- const reward = claimData.data?.today_reward ?? claimData.data?.reward_amount ?? 0; const days = claimData.data?.consecutive_days ?? 0; const checkInMsg = `签到成功!获得 +${reward} 算力点数,已连续签到 ${days} 天。`; console.log(`【灵犀签到】${checkInMsg}`); // 记录本地成功日期 GM_setValue("last_checkin_date", todayStr); // 7. 查询最新算力点数 let balanceMsg = ""; const balanceData = await request({ method: "GET", url: "https://lingxi.kdocs.cn/api/public/v1/credits/balance" }); if (balanceData.result === "ok" && balanceData.data) { balanceMsg = `\n当前总算力余额: ${balanceData.data.total_balance}`; } // 首次签到成功必然发出通知 notify("WPS 灵犀签到成功", `账号: ${nickname}\n${checkInMsg}${balanceMsg}`); } catch (err) { console.error("【灵犀签到】执行异常:", err); notify("WPS 灵犀签到异常", err.message || "网络请求异常"); } })();