// ==UserScript== // @name iKuuu自动签到(ScriptCat版) // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.5 // @description 每日执行自动签到 // @author d3f4ult // @crontab * * once * * // @grant GM_xmlhttpRequest // @grant GM_log // @grant GM_notification // @grant GM_openInTab // @grant GM_closeNotification // @homepage https://ikuuu.one // ==/UserScript== /* ######################################################### */ /* #██████╗ ██████╗ ███████╗██╗ ██╗██╗ ██╗██╗ ████████╗# */ /* #██╔══██╗╚════██╗██╔════╝██║ ██║██║ ██║██║ ╚══██╔══╝# */ /* #██║ ██║ █████╔╝█████╗ ███████║██║ ██║██║ ██║ # */ /* #██║ ██║ ╚═══██╗██╔══╝ ╚════██║██║ ██║██║ ██║ # */ /* #██████╔╝██████╔╝██║ ██║╚██████╔╝███████╗██║ # */ /* #╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ # */ /* ######################################################### */ return new Promise((resolve, reject) => { const domain = "https://ikuuu.one" const error_count = 0 const timeout_count = 0 const MAX_RETRIES = 7; // 定义最大重试次数为常量 // 检查是否登录 function check_login() { GM_xmlhttpRequest({ method: "GET", url: `${domain}/user`, timeout: 5000, onload: function (response) { if (response.finalUrl == `${domain}/auth/login`) { GM_notification({ title: "iKuuu", text: "请点击,登陆后重新运行脚本", onclick: (id) => { GM_openInTab(`${domain}/auth/login`); GM_closeNotification(id); } }); reject("未登录"); } else if (xhr.finalUrl == "https://ikuuu.eu/user") { // } else { reject("网页跳转向了一个未知的网址"); } }, onerror: function (error) { reject('获取Cookie失败:' + error); }, ontimeout: () => { check_login() } }); } // 自动签到 function auto_check() { if (error_count !== 0) setTimeout(() => { }, 5000) GM_xmlhttpRequest({ method: "POST", url: `${domain}/user/checkin`, timeout: 5000, onload: (response) => { // GM_log("完整响应数据: " + response.responseText, "info") let result = JSON.parse(response.responseText) GM_log("解析后的 JSON 数据:" + JSON.stringify(result, null, 2), "info") if (result.ret === 1) { GM_notification({ title: "iKuuu 自动签到提醒", text: `签到成功:${result.msg}`, timeout: 10000 }) resolve('签到成功') } else { GM_notification({ title: "iKuuu 自动签到提醒", highlight: true, // 高亮显示通知 text: `签到失败:${result.msg}` }) reject('签到失败') } }, onerror: () => { if (error_count === MAX_RETRIES) { GM_notification({ title: "iKuuu 自动签到提醒", text: "签到失败,请检查网络连接或登录状态", highlight: true, // 高亮显示通知 onclick: (id) => { GM_openInTab(domain); GM_closeNotification(id); }, }); reject(`签到失败:系统已重试${MAX_RETRIES}次。请检查网络连接或登录状态后重试`); } GM_log(`请求错误,正在进行第 ${error_count++} 次重试...`, "info"); auto_check() }, ontimeout: () => { // 记录日志 GM_log(`网络请求超时 (${timeout_count}/${MAX_RETRIES})`, "info"); // 达到最大重试次数 if (timeout_count === MAX_RETRIES) { GM_notification({ title: "iKuuu 自动签到提醒", text: "无法连接到服务器,请检查网络设置", highlight: true, // 高亮显示通知 onclick: (id) => { GM_openInTab(domain); GM_closeNotification(id); } }); reject(`连接失败:系统已重试${MAX_RETRIES}次。请检查网络后重试`); } // 继续重试 GM_log(`请求超时,正在进行第 ${timeout_count++} 次重试...`, "info"); auto_check(); } }) } auto_check() });