1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
| const $ = new Env('掘金-社区签到'); const JuejinHelper = require("juejin-helper");
const juejin = new JuejinHelper();
const notify = require('../../sendNotify');
const COOKIE = process.env.JJ_COOKIE
const state = { simulateSpeed: 100, signStatus:'', sumPoint: 0, incrPoint:0, contCount:0, sumCount:0, luckyValue: 0,
lottery: [], pointCost: 0, freeCount: 0, counter: 0,
supplyPoint: 0, prize: {} };
!(async () => { await $.wait(500); if (!COOKIE) { console.log($.name, "【提示】请先获取一cookie", "https://juejin.cn/"); return; } await juejin.login(COOKIE); const api = juejin.growth(); const recordInfo = []; console.log("--------模拟访问---------"); try { const browser = juejin.browser(); await browser.open(); try { await browser.visitPage("/"); console.log("掘金首页:页面访问成功"); } catch (e) { console.log("掘金首页:页面访问失败"); } await $.wait(2000); try { await browser.visitPage("/user/center/signin"); console.log("掘金每日签到:页面访问成功"); } catch (e) { console.log("掘金每日签到:页面访问失败"); } await $.wait(2000); await browser.close(); } catch { console.log("浏览器API异常"); } console.log("-------------------------");
console.log("------事件埋点追踪-------");
const sdk = juejin.sdk(); calledSdkSetting = false; calledTrackGrowthEvent = false; calledTrackOnloadEvent = false; try { await sdk.slardarSDKSetting(); calledSdkSetting = true; } catch { calledSdkSetting = false; } console.log(`SDK状态: ${calledSdkSetting ? "加载成功" : "加载失败"}`);
try { const result = await sdk.mockTrackGrowthEvent(); if (result && result.e === 0) { calledTrackGrowthEvent = true; } else { throw result; } } catch { calledTrackGrowthEvent = false; } console.log(`成长API事件埋点: ${calledTrackGrowthEvent ? "调用成功" : "调用失败"}`);
try { const result = await sdk.mockTrackOnloadEvent(); if (result && result.e === 0) { calledTrackOnloadEvent = true; } else { throw result; } } catch { calledTrackOnloadEvent = false; } console.log(`OnLoad事件埋点: ${calledTrackOnloadEvent ? "调用成功" : "调用失败"}`);
recordInfo.push("=====[签到详情]====="); const checkInStatus = await api.getTodayStatus(); if (!checkInStatus) { const checkInResult = await api.checkIn(); state.incrPoint = checkInResult.incr_point; state.sumPoint = checkInResult.sum_point; state.signStatus = "本次签到成功"; recordInfo.push("今日签到成功:++"+state.incrPoint+"矿石"); } else { const sumPoint = await api.getCurrentPoint(); state.sumPoint = sumPoint; state.signStatus = "今日已签到"; recordInfo.push("今日已签到"); }
const counts = await api.getCounts(); state.contCount = counts.cont_count; state.sumCount = counts.sum_count; recordInfo.push("连续签到:"+state.contCount+"天"); recordInfo.push("累计签到:"+state.sumCount+"天"); try { const luckyusersResult = await api.getLotteriesLuckyUsers(); if (luckyusersResult.count > 0) { const no1LuckyUser = luckyusersResult.lotteries[0]; const dipLuckyResult = await api.dipLucky(no1LuckyUser.history_id); if (dipLuckyResult.has_dip) { console.log(`今天你已经沾过喜气,明天再来吧!`); } else { console.log(`沾喜气 +${dipLuckyResult.dip_value} 幸运值`); } } } catch(e) { console.log(e); }
const luckyResult = await api.getMyLucky(); state.luckyValue = luckyResult.total_value; console.log(`当前幸运值:${state.luckyValue}/6000`);
const lotteryConfig = await api.getLotteryConfig(); state.lottery = lotteryConfig.lottery; state.pointCost = lotteryConfig.point_cost; state.freeCount = lotteryConfig.free_count; state.sumPoint += state.freeCount * state.pointCost; console.log(`免费抽奖次数: ${state.freeCount}`);
console.group("奖品实况");
const getSupplyPoint = draw => { const maybe = [ ["lottery_id", "6981716980386496552"], ["lottery_name", "随机矿石"], ["lottery_type", 1] ]; if (maybe.findIndex(([prop, value]) => draw[prop] === value) !== -1) { const supplyPoint = Number.parseInt(draw.lottery_name); if (!isNaN(supplyPoint)) { return supplyPoint; } } return 0; };
const lottery = async () => { const result = await api.drawLottery(); state.sumPoint -= state.pointCost; state.sumPoint += getSupplyPoint(result); state.luckyValue += result.draw_lucky_value; state.counter++; state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1; console.log(`[第${state.counter}抽]:${result.lottery_name}`); };
while (state.freeCount > 0) { await lottery(); state.freeCount--; await $.wait(500); }
console.groupEnd("奖品实况");
recordInfo.push("当前余额:"+state.sumPoint+"矿石"); recordInfo.push("当前幸运值:"+state.luckyValue+"/6000"); recordInfo.push("=====[抽奖详情]====="); if (state.counter > 0) { const prizeList = []; for (const key in state.prize) { prizeList.push(`${key}: ${state.prize[key]}`); } recordInfo.push(...prizeList); recordInfo.push("-------------------"); recordInfo.push(`共计: ${state.counter}`); } else { recordInfo.push("暂无奖品"); }
try { const bugfix = juejin.bugfix(); const notCollectBugList = await bugfix.getNotCollectBugList(); recordInfo.push("=====[bugfix]====="); await bugfix.collectBugBatch(notCollectBugList); recordInfo.push(`收集Bug ${notCollectBugList.length}`);
const competition = await bugfix.getCompetition(); const bugfixInfo = await bugfix.getUser(competition); recordInfo.push(`未消除Bug数量 ${bugfixInfo.user_own_bug}`); } catch(e) { console.log(e); }
await juejin.logout(); notify.sendNotify("掘金每日签到", recordInfo.join("\n")); })() .catch((e) => { console.error(`❗️ ${$.name} 运行错误!\n${e}`); }) .finally(() => $.done());
function Env(name, opts) { class Http { constructor(env) { this.env = env; }
send(opts, method = "GET") { opts = typeof opts === "string" ? { url: opts, } : opts; let sender = this.get; if (method === "POST") { sender = this.post; } return new Promise((resolve, reject) => { sender.call(this, opts, (err, resp, body) => { if (err) reject(err); else resolve(resp); }); }); }
get(opts) { return this.send.call(this.env, opts); }
post(opts) { return this.send.call(this.env, opts, "POST"); } }
return new (class { constructor(name, opts) { this.name = name; this.http = new Http(this); this.data = null; this.dataFile = "box.dat"; this.logs = []; this.isMute = false; this.isNeedRewrite = false; this.logSeparator = "\n"; this.startTime = new Date().getTime(); Object.assign(this, opts); this.log("", `🔔${this.name}, 开始!`); }
initAxios() { if (!this.axios) { this.axios = axios.create(); } }
restApi(opts, callback = () => { }) { this.initAxios(); this.axios(opts) .then(resp => { const {status, headers, data} = resp; callback(null, { status, headers, data, }, data); }, (err) => { const {message: error, response: resp} = err; callback(error, resp, resp && resp.data); }); }
log(...logs) { if (logs.length > 0) { this.logs = [...this.logs, ...logs]; } console.log(logs.join(this.logSeparator)); }
wait(time) { return new Promise((resolve) => setTimeout(resolve, time)); }
done() { const endTime = new Date().getTime(); const costTime = (endTime - this.startTime) / 1000; this.log("", `🔔${this.name}, 结束! 🕛 ${costTime} 秒`); } }
) (name, opts); }
|