// ==UserScript== // @name CH技术联盟每日签到 // @namespace https://bbs.tampermonkey.net.cn/ // @version 3.0 // @description 自动签到CH技术联盟领积分 // @author Magic,lan // @icon https://www.chinahonker.cn/favicon.ico // @crontab * 8-23 once * * // @connect www.chinahonker.cn // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_cookie // @grant GM_setValue // @grant GM_getValue // @grant GM_log // @license MIT // ==/UserScript== (function () { 'use strict'; var API = 'https://www.chinahonker.cn/wp-json/b2/v1/'; var today = new Date().toISOString().slice(0, 10); GM_cookie.list({ url: 'https://www.chinahonker.cn', name: 'b2_token' }, function (cookies, err) { if (err || !cookies || cookies.length === 0) { notify('未登录', '请先登录 chinahonker.cn', true); return; } sign(cookies[0].value, 0); }); function sign(token, n) { GM_xmlhttpRequest({ method: 'POST', url: API + 'userMission', headers: { 'Authorization': 'Bearer ' + token }, responseType: 'json', timeout: 15000, onload: function (r) { GM_log('[签到] HTTP ' + r.status); if (r.status === 200) { GM_setValue('done_' + today, true); try { var d = JSON.parse(r.responseText); if (d.mission && d.mission.credit !== undefined) { notify('签到成功', '获得 ' + d.mission.credit + ' 积分'); } else if (d.message) { notify('签到结果', d.message); } else { notify('今日已签到', '积分 ' + r.responseText); } } catch (e) { notify('今日已签到', '积分 ' + r.responseText); } } else if (r.status === 403) { notify('登录已过期', '请重新登录后重试', true); } else { retry(token, n); } }, onerror: function () { retry(token, n); }, ontimeout: function () { retry(token, n); } }); } function retry(token, n) { if (n >= 2) { notify('签到失败', '请手动签到'); return; } setTimeout(function () { sign(token, n + 1); }, 3000 + Math.random() * 2000); } function notify(t, d, login) { var o = { title: 'CH联盟:' + t, text: d || ' ', timeout: 15000 }; if (login) o.onclick = function () { window.open('https://www.chinahonker.cn/wp-login.php'); }; GM_notification(o); } })();