自动抢单

暑假时需要对某网站实现抢单功能,所以通过浏览器插件Tampermonkey实现抢单功能脚本。其主要思路是:

  1. 首先定义了一个变量timeHandler和一个状态变量functionalityEnabled,用于记录抢单功能是否开启;
  2. 通过GM_addStyle函数添加了一个悬浮窗口,其中包含一个复选框,用于控制抢单功能的开启和关闭;
  3. 定义了toggleFunctionality函数,用于切换抢单功能的状态,并通过GM_setValue函数将状态保存在浏览器的缓存中;
  4. 定义了sendRequest函数,用于向服务器发送请求并进行抢单;
  5. 在页面加载完成后,根据缓存中的状态来决定是否自动开启抢单功能,并为复选框绑定事件,用于控制抢单功能的开启和关闭。
// ==UserScript==
// @name         抢单
// @namespace    https://rensr.site
// @version      0.2
// @description  try to take over the world!
// @author       任尚仁
// @match        https://kuajing.pinduoduo.com/main/order-manage
// @icon         https://bpic.588ku.com/element_pic/19/04/04/669edc93405cbe43292be19cb6224d75.jpg
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    var timeHandler;
    var functionalityEnabled = GM_getValue('functionalityEnabled', false);

    GM_addStyle(`
        #floating-window {
            position: fixed;
            top: 15%;
            right: 20px;
            padding: 10px;
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 10px;
            z-index: 9999;
        }
    `);

    var floatingWindow = document.createElement('div');
    floatingWindow.setAttribute('id', 'floating-window');
    floatingWindow.innerHTML = `
        <label>
            <input type="checkbox" id="toggle-switch"> 启用抢单功能
        </label>
    `;
    document.body.appendChild(floatingWindow);

    function toggleFunctionality() {
        functionalityEnabled = !functionalityEnabled;
        GM_setValue('functionalityEnabled', functionalityEnabled);

        if (functionalityEnabled) {
            timeHandler = setInterval(sendRequest, 500);
        } else {
            clearInterval(timeHandler);
        }
    }

    document.getElementById('toggle-switch').addEventListener('change', toggleFunctionality);

    function sendRequest() {
        document.querySelectorAll(".BTN_textPrimary_5-72-0").forEach(div => {
            if (div.innerHTML.indexOf("加入发货台") > -1 && div.className.indexOf("BTN_disabled_") == -1) {
                div.click();
                setTimeout(() => {
                    document.querySelectorAll(".PP_popoverContent_5-72-0 button").forEach(btn => {
                        btn.click()
                    });
                }, 200);
            }
        });
    }

    if (functionalityEnabled) {
        document.getElementById('toggle-switch').checked = true;
        timeHandler = setInterval(sendRequest, 500);
    }

})();
本文作者:任尚仁
版权声明:本文为原创内容,转载请注明出处。如需获取更多相关资讯,可访问官网:https://blog.rensr.site/。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇