// ==UserScript== // @name hostloc自动签到【脚本猫专用】 // @namespace https://bbs.tampermonkey.net.cn/ // @description 支持检测是否登录和PushCat消息推送 // @version 0.1.3 // @author Qixing // @crontab * * once * * // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_getValue // @grant GM_setValue // @grant GM_log // @grant GM_cookie // @connect hostloc.com // @homepage https://scriptcat.org/zh-CN/script-show-page/1365/ // @supportURL https://t.me/qixing_chat // @require https://scriptcat.org/lib/946/%5E1.0.1/PushCat.js // @exportValue PushCat.AccessKey // @background // ==/UserScript== /* ==UserConfig== PushCat: AccessKey: title: 消息推送key description: 消息推送key https://sct.icodef.com/ type: text ==/UserConfig== */ // 参考自 https://scriptcat.org/scripts/code/1060/必应积分商城每日签到.user.js let accessKey = GM_getValue("PushCat.AccessKey"); if (accessKey == "") { // 由于脚本猫v0.13的UserConfig有bug,如果你需要消息推送服务的话,请在此手动设置 GM_setValue("PushCat.AccessKey", ""); accessKey = GM_getValue("PushCat.AccessKey"); } // 消息推送: https://sct.icodef.com/ const push = new PushCat({ accessKey, }); function pushSend(content, title = "hostloc自动签到【脚本猫专用】") { GM_log("推送消息", "info", { title, content }); return new Promise(async resolve => { if (accessKey) { await push.send(title, content); } GM_notification({ title: title, text: content, }); resolve(); }) } function notification(status, message, resolve, reject) { pushSend(message); if (status) { resolve(message); } else { reject(message); } } function checkLogin() { return new Promise((resolve, reject) => { GM_cookie("list", { domain: "hostloc.com" }, (cookies) => { if (!cookies.some(obj => obj.name === "hkCM_2132_auth")) { reject('每日签到失败,hostloc未登录'); } else { resolve('hostloc已登录') } }); }) } // 参考自 https://greasyfork.org/zh-CN/scripts/414005-%E5%85%A8%E7%90%83%E4%B8%BB%E6%9C%BA%E4%BA%A4%E6%B5%81%E8%AE%BA%E5%9D%9B%E5%A2%9E%E5%BC%BA // 自动签到(访问空间 10 次 = 20 积分 + 当天首次访问论坛 2 积分) function autoSignIn(resolve, reject) { checkLogin().then(res => { console.log(res); let timeNow = new Date().getFullYear() + "/" + (new Date().getMonth() + 1) + "/" + new Date().getDate(), timeOld = GM_getValue('checkInTime'); if (!timeOld || timeOld != timeNow) { // 是新的一天 GM_setValue('checkInTime', timeNow); // 写入签到时间以供后续比较 let url_list = [], url = 0; // 随机生成 12 个空间地址(2 个冗余) for (let i = 0; i < 12; i++) { url_list[i] = "https://hostloc.com/space-uid-" + Math.floor(Math.random() * (50000 - 10000 + 1) + 10000) + ".html"; } // 每 5 秒访问一次(避免触发网站防御机制,而且还可以适当浏览论坛) let signIn = setInterval(function () { GM_xmlhttpRequest({ url: url_list[url++], method: 'GET', timeout: 4000 }); console.log(`[全球主机交流论坛 增强] 积分 +2 (${url_list[url]})`); if (url === 11) { // 次数够了就取消定时循环 clearInterval(signIn); console.log('[全球主机交流论坛 增强] 签到完成!'); notification(true, '签到完成!积分 +22 ~', resolve, reject); } }, 5000); } else { notification(false, '还没到时间呢,别心急', resolve, reject); } }, error => { console.log(error); notification(false, error, resolve, reject); }); } return new Promise((resolve, reject) => { autoSignIn(resolve, reject) });