This is the 19th day of my participation in the August More Text Challenge.

preface

Play the Nuggets series and add some interesting features to the Nuggets, such as:

  • The Nuggets column is being generated as a PDF file
  • [Playing nuggets] Nuggets signing author, force parameter analysis, data
  • 【 play turn nuggets 】 my praise, my 💗, who gave, have you?

Today we realize the visual intelligent lottery, or see the effect first!!

Results demonstrate

Because my ore is too little, so the effect is not obvious, forgive me !!!!

The source code

Nuggets intelligent lottery source code: JJSignAndLD

You need to install the monkey script, or FEHelper plugin, paste the relevant code!!

The data analysis

API request has two general parameters, a AID a UUID, useful, estimated have, do not need to line line, line !!!!

Get prize pool information

Request address: https://api.juejin.cn/growth_api/v1/lottery_config/get?aid= [an] & uuid = [uuid]

Request mode: GET

Request parameters: QueryString AID and UUID

Return result:

Is the prize pool of information, do display after use!

{
    "data": {
        "lottery": [{
            "lottery_id": "6981716980386496552".ID / / award
            "lottery_name": "66 ore".Name / / award
            "lottery_type": 1."lottery_image": "https://xxxx.image".// Prize picture
            "unlock_count": 0},... ] }}Copy the code

Lucky draw

Request address: https://api.juejin.cn/growth_api/v1/lottery/draw?aid= [an] 8 & uuid = [uuid]

Request mode: POST

Request parameters: QueryString AID and UUID

Returns the result

{
    data: {
        history_id: "6997575438109261838".id: 19.lottery_id: "6981716980386496552".lottery_image: "".lottery_name: "66 ore"./ / the winning name
        lottery_type: 1,}}Copy the code

Train of thought

Thinking is often more important than the code itself!

Swim monkey script | FeHelper + JS script, very simple!

  1. Get prize pool information
  2. Perform draw
  3. Based on the execution result status code, the response action is performed

Code implementation

Style injection

Dynamically create a style tag and inject it under the head node

 const styleContent = ` ._jj_draw_container { position:fixed; top: 80px; right: 0; z-index: 9999; Background - color: rgba (0,0,0,0.6); padding: 20px; } `
    
     function appendStyle(text) {
        const styleEl = document.createElement('style');
        styleEl.textContent = text;
        document.head.appendChild(styleEl);
    }
    
     appendStyle(styleContent);

Copy the code

Loop requests and terminations

Double judgment

  1. isDrawingThe delegate is raffling
  2. Returns the resulterr_noDoes not mean failure,err_msgRepresents an error message,The most likely cause of failure here is lack of ore
    async function onDraw(ev) {
        if (isDrawing) {
            return;
        }
        isDrawing = true;

        try {
            let errNo = 0;
            do {
                if(! isDrawing){break;
                }

                const res = await doDraw();
                errNo = res.err_no;

                if(errNo ! = =0) {
                    alert(res.err_msg);
                    isDrawing = false;
                    break;
                }

                // Add rewards
                addPrize(res.data)
                / / rendering
                renderPrizes();
                / / pause 16 ms
                await delay(undefined.16).run();
                    
                // Use this command
                //isDrawing = false;
                //break;

            } while (errNo == 0)}catch (err) {
            isDrawing = falsealert(err.message); }}Copy the code

See JJSignAndLD for more code, about 250 lines of CSS + JS.

Write in the last

3-5 minutes, 500-1000 words, gain, but not tired, if you feel good, your praise and comment is the biggest motivation for me to move forward.

Technical group please come here. Or add my wechat Dirge-Cloud and learn together.