阅读 234

掘金抽奖-掘金梭哈一梭到底

版本特性:

  • 内置仿真抽机制,预防稀有奖品命中不高!
  • 掘金签到!
  • 免费抽奖!
  • 缓存矿石!
  • 奖品统计!

👇复制代码,打开控制台并粘贴,即可一梭到底!

!(into => {
  into({
    log: msg => console.log(msg),
    clear: () => console.clear(),
    logGroupStart: name => console.group(name),
    logGroupEnd: name => console.groupEnd(name),
    async wait(time = 0) {
      return new Promise(resolve => setTimeout(resolve, time));
    },
    async fetch({ path, method }) {
      return fetch(path, {
        headers: {
          cookie: document.cookie
        },
        method: method,
        credentials: "include"
      })
        .then(res => res.json())
        .then(res => {
          if (res.err_no) {
            throw new Error(res.err_msg);
          }
          return res.data;
        });
    },
    async getCurrentPoint() {
      return this.fetch({
        path: "https://api.juejin.cn/growth_api/v1/get_cur_point",
        method: "GET"
      });
    },
    async drawLottery() {
      return this.fetch({
        path: "https://api.juejin.cn/growth_api/v1/lottery/draw",
        method: "POST"
      });
    },
    async getLotteryConfig() {
      return this.fetch({
        path: "https://api.juejin.cn/growth_api/v1/lottery_config/get",
        method: "GET"
      });
    },
    async checkIn() {
      return this.fetch({
        path: "https://api.juejin.cn/growth_api/v1/check_in",
        method: "POST"
      });
    },
    checkGold(result) {
      const list = [
        ["lottery_id", "6981716980386496552"],
        ["lottery_name", "66矿石"],
        ["lottery_type", 1]
      ];
      return list.findIndex(([prop, value]) => result[prop] === value) !== -1;
    },
    state: {
      simulateSpeed: 1, // ms/进行一次抽奖
      oneConsume: 200, // 一次消耗
      supplyPoint: 66,
      sumPoint: 0,
      counter: 0,
      prize: {},
      freeCount: 0
    },
    async lottery() {
      const state = this.state;
      const result = await this.drawLottery();
      state.sumPoint -= state.oneConsume;
      if (this.checkGold(result)) {
        state.sumPoint += state.supplyPoint;
      }
      state.counter++;
      state.prize[result.lottery_name] = (state.prize[result.lottery_name] || 0) + 1;
      this.log(`[第${state.counter}抽]:${result.lottery_name}`);
    }
  });
})(async api => {
  await api.wait(100);
  api.clear();
  const state = api.state;

  try {
    const checkInResult = await api.checkIn();
    const incrPoint = checkInResult.incr_point;
    api.log(`签到成功 +${incrPoint} 矿石`);

    const sumPoint = checkInResult.sum_point;
    state.sumPoint = sumPoint;
  } catch (e) {
    api.log(e.message);

    const sumPoint = await api.getCurrentPoint();
    state.sumPoint = sumPoint;
  }

  api.log(`当前余额:${state.sumPoint} 矿石`);

  const lotteryConfig = await api.getLotteryConfig();
  state.freeCount = lotteryConfig.free_count;
  state.sumPoint += state.freeCount * state.oneConsume;
  api.log(`免费抽奖次数: ${state.freeCount}`);

  api.log(`准备梭哈!`);

  api.logGroupStart("奖品实况");
  while (state.freeCount > 0) {
    await api.lottery();
    state.freeCount--;
    await api.wait(state.simulateSpeed);
  }

  while (state.sumPoint >= state.oneConsume) {
    await api.lottery();
    await api.wait(state.simulateSpeed);
  }
  api.logGroupEnd("奖品实况");

  api.log(`弹药不足,当前余额:${state.sumPoint} 矿石`);
  api.log(`养精蓄锐来日再战!`);

  const recordInfo = [];
  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("暂无奖品");
  }
  recordInfo.push("===============");
  api.log(recordInfo.join("\n"));
});
复制代码

祝你好运!

抽奖截图

image.png

效果示意仅供参考!

文章分类
前端