阅读 5419

掘金抽奖来梭哈!!!(内含油猴脚本)

1.jpg

掘金抽奖来梭哈!!!

攒了这么久的掘金矿石,不梭哈一把实在对不起自己,对不起掘金,对不起广大工友们,看到一些朋友写的梭哈代码,有bug啊,索性自己来一个,抽奖结束有汇总表格方便兄弟们截图到沸点哟。

(async () => {
  const res = await fetch('https://api.juejin.cn/growth_api/v1/get_cur_point', {
    headers: {
      cookie: document.cookie
    },
    method: 'GET',
    credentials: 'include'
  }).then((res) => res.json());

  let score = res.data; // 当前分数
  if (score < 200) return console.warn('分都不够想啥呢?');

  const award = {};
  const draw = async () => {
    if (score < 200) {
      console.log('梭哈结束!');
      console.table(award);
      alert(JSON.stringify(award, null, 2));
      return;
    }

    const result = await fetch('https://api.juejin.cn/growth_api/v1/lottery/draw', {
      headers: {
        cookie: document.cookie
      },
      method: 'POST',
      credentials: 'include'
    }).then((res) => res.json());
    
    if (result.err_no !== 0) {
      console.log('梭哈结束!');
      console.table(award);
      alert(JSON.stringify(award, null, 2));
      return;
    }
    
    score -= 200;

    if (result.data.lottery_type === 1) score += 66;

    if (award[result.data.lottery_name]) award[result.data.lottery_name]++;
    else award[result.data.lottery_name] = 1;

    console.log(`获得:${result.data.lottery_name}`);
    draw();
  };

  console.log('开始梭哈!');
  draw();
})();

复制代码

复制上述代码到浏览器控制台,回车开始!!!

油猴脚本

经过工友们的提醒,更新一下,添加一个油猴脚本,有需要的直接复制到油猴里,在此感谢一下西门飘飘 提供的建议

更新加了5连抽、10连抽的功能。

// ==UserScript==
// @name         掘金梭哈抽奖
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  一键梭哈抽奖
// @author       无仙
// @match        https://juejin.cn/*
// @icon         https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web//static/favicons/favicon-32x32.png
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // 抽奖逻辑
  let loading = false;
  const draw = async (times) => {
    if (loading) return;
    const res = await fetch('https://api.juejin.cn/growth_api/v1/get_cur_point', {
      headers: {
        cookie: document.cookie
      },
      method: 'GET',
      credentials: 'include'
    }).then((res) => res.json());

    let score = res.data; // 当前分数
    if (score < 200 * (times || 1)) return console.warn('分都不够想啥呢?');

    let i = 0;
    const award = {};
    const draw = async () => {
      if (score < 200 || i === times) {
        loading = false;
        i = 0;
        console.log(`${times ? times + '连抽' : '梭哈'}结束!`);
        console.table(award);
        alert(JSON.stringify(award, null, 2));
        return;
      }

      const result = await fetch('https://api.juejin.cn/growth_api/v1/lottery/draw', {
        headers: {
          cookie: document.cookie
        },
        method: 'POST',
        credentials: 'include'
      }).then((res) => res.json());
      
      if (result.err_no !== 0) {
        loading = false;
        i = 0;
        console.log(`${times ? times + '连抽' : '梭哈'}结束!`);
        console.table(award);
        alert(JSON.stringify(award, null, 2));
        return;
      }

      i++;
      score -= 200;

      if (result.data.lottery_type === 1) score += 66;

      if (award[result.data.lottery_name]) award[result.data.lottery_name]++;
      else award[result.data.lottery_name] = 1;

      console.log(`抽到:${result.data.lottery_name}`);
      draw();
    };

    console.log(`开始${times ? times + '连抽' : '梭哈'}!`);
    loading = true;
    draw();
  };

  // 插入DOM
  const container = document.createElement('div');
  container.id = 'wx_draw_wrap';
  container.innerHTML = `
    <div id="wx_draw_all_in">梭哈抽奖</div>
    <ul id="wx_draw_list">
      <li id="wx_draw_5">5连抽</li>
      <li id="wx_draw_10">10连抽</li>
    </ul>
  `;
  document.body.appendChild(container);

  // 获取DOM
  const all_in_btn = document.getElementById('wx_draw_all_in');
  const draw_5_btn = document.getElementById('wx_draw_5');
  const draw_10_btn = document.getElementById('wx_draw_10');

  // 事件绑定
  all_in_btn.addEventListener('click', draw);
  draw_5_btn.addEventListener('click', () => draw(5));
  draw_10_btn.addEventListener('click', () => draw(10));

  // 处理样式
  const style = `
    #wx_draw_wrap {
      box-sizing: border-box;
      position: fixed;
      top: 50%;
      left: 0px;
      z-index: 999999;
      margin-top: -20px;
    }
    #wx_draw_all_in {
      box-sizing: border-box;
      width: 40px;
      height: 40px;
      line-height: 16px;
      font-size: 12px;
      padding: 4px;
      background-color: rgb(232, 243, 255);
      border: 1px solid rgb(232, 243, 255);
      color: rgb(30, 128, 255);
      text-align: center;
      overflow: hidden;
      cursor: pointer;
    }
    #wx_draw_wrap:hover {
      width: 128px;
    }
    #wx_draw_wrap:hover #wx_draw_list {
      display: block;
    }
    #wx_draw_list {
      display: none;
      width: 80px;
      position: absolute;
      right: 0;
      top: 0;
    }
    #wx_draw_list li {
      box-sizing: border-box;
      cursor: pointer;
      margin-bottom: 4px;
      background-color: rgb(232, 243, 255);
      border: 1px solid rgb(232, 243, 255);
      color: rgb(30, 128, 255);
      font-size: 12px;
      height: 18px;
      line-height: 18px;
      text-align: center;
    }
  `;

  const styleEl = document.createElement('style');
  styleEl.textContent = style;
  document.head.appendChild(styleEl);
})();

复制代码

最新可视化油猴

最新脚本使用了petite-vue做可视化,代码地址

油猴安装地址,最新脚本预览:

demo.png

文章分类
前端
文章标签