TEMU抢发货台的油猴脚本

这个平台的发货台有时候很难抢到货物,因为网上的方法都是通过点击网页按钮来获取货物,但在高网络负载时很可能导致按钮无法弹出,影响抢货成功率。因此,我使用GPT写了一个post脚本来直接提交发货请求,成功率比较高。

针对Anti-Content这部分,需要自行填写。

备货单部分可以填写一个或多个,多个备货单需要每行填写一个。

// ==UserScript==
// [url=home.php?mod=space&uid=15785]@name[/url]         TEMU发货台
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Send POST requests at intervals with data from input fields inside a specific div, using MutationObserver to ensure element is loaded
// @AuThor       YourName
// [url=home.php?mod=space&uid=56072]@Match[/url]        https://seller.kuajingmaihuo.com/*
// @grant        none
// ==/UserScript==

(function() {
   'use strict';
   const targetClass = 'index-module__menuBox___3Wpx6 bg-shell-theme-menuBox bg-shell-theme-mmsMenuBox';
   let targetDiv = document.querySelector(`.${targetClass.replace(/\s/g, '.')}`);

   // 检查目标div是否存在,如果不存在则设置MutationObserver监听
   function checkAndSetup() {
       if (targetDiv) {
           setupInterface();
       } else {
           const observer = new MutationObserver((mutations) => {
               targetDiv = document.querySelector(`.${targetClass.replace(/\s/g, '.')}`);
               if (targetDiv) {
                   observer.disconnect(); // 停止观察
                   setupInterface();
               }
           });
           observer.observe(document.body, {
               childList: true,
               subtree: true
           });
       }
   }

   function setupInterface() {

       // 创建文本输入框3,用于获取参数
       const input3 = document.createElement('input');
       input3.placeholder = '这里填写Anti-Content的值';
       input3.type = 'text';
       input3.className = "IPT_input_5-111-0";
       targetDiv.appendChild(input3);

       // 创建输入框1
       const input1 = document.createElement('textarea');
       input1.placeholder = '这里按行输入备货单号';
       input1.style.width = '95%';
       input1.style.height = '100px';
       input1.style.margin = '5px';
       input1.className = "IPT_input_5-111-0";
       targetDiv.appendChild(input1);

       // 创建按钮1
       const button1 = document.createElement('button');
       button1.textContent = '开始抢夺';
       button1.className = "BTN_outerWrapper_5-111-0 BTN_primary_5-111-0 BTN_medium_5-111-0 BTN_outerWrapperBtn_5-111-0";
       targetDiv.appendChild(button1);

       // 创建文本输入框2,用于展示响应结果
       const input2 = document.createElement('textarea');
       input2.placeholder = '这里显示抢夺结果';
       input2.style.width = '95%';
       input2.style.height = '200px';
       input2.style.margin = '5px';
       input2.className = "IPT_input_5-111-0";
       targetDiv.appendChild(input2);

       let isSending = false;
       let intervalId;

       // 发送POST请求的函数
       function sendPostRequest() {
           const mallId = localStorage.getItem('mall-info-id');
           const cookieValue = document.cookie.split('; ').find(row => row.startsWith('SUB_PASS_ID='))?.split('=')[1];
           const subPurchaseOrderSnList = input1.value.split('\n').filter(line => line.trim() !== '');
           const AntiContent = input3.value;
           const requestBody = JSON.stringify({
               joinDeliveryPlatformRequestList: subPurchaseOrderSnList.map(sn => ({ subPurchaseOrderSn: sn }))
           });
           const xhr = new XMLHttpRequest();
           xhr.open('POST', 'https://seller.kuajingmaihuo.com/oms/bg/venom/api/supplier/purchase/manager/batchJoinDeliveryOrderPlatformV2', true);
           xhr.setRequestHeader('Content-Type', 'application/json');
           xhr.setRequestHeader('Mallid', mallId);
           xhr.setRequestHeader('Anti-Content', AntiContent);
           xhr.onreadystatechange = function() {
               if (xhr.readyState === 4 && xhr.status === 200) {
                   const response = JSON.parse(xhr.responseText);
                   if (response.error_msg) {
                       input2.value += '抢夺失败\n';
                   } else {
                       input2.value += '抢夺成功,已加入发货台\n';
                   }
                   // 确保文本输入框2始终聚焦在文本内容的最后一行
                   input2.scrollTop = input2.scrollHeight;
               }
           };
           xhr.send(requestBody);
       }

       // 点击按钮1的事件处理函数
       button1.addEventListener('click', function() {
           if (isSending) {
               // 停止发送请求
               clearInterval(intervalId);
               isSending = false;
               button1.textContent = '开始抢夺';
           } else {
               // 开始发送请求
               isSending = true;
               button1.textContent = '停止抢夺';
               intervalId = setInterval(sendPostRequest, 500);
           }
       });
   }

   // 当文档加载完成后执行
   window.onload = function() {
       checkAndSetup(); // 开始检查并设置界面
   };

   // 或者使用 DOMContentLoaded 事件
   document.addEventListener('DOMContentLoaded', function() {
       checkAndSetup(); // 开始检查并设置界面
   });
})();

图片[1]-TEMU抢发货台的油猴脚本-清玖博客

© 版权声明
THE END
喜欢就支持一下吧
点赞40赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容