// ==UserScript== // @name temu Seller Assistant // @name:zh-CN temu批量加入发货台 // @include http*://kuajing.pinduoduo.com/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js // @description temu batch add // @description:zh-cn temu批量加入发货 // @grant GM_getValue // @grant GM_setValue // @version 3.0.8 // @run-at document-end // @compatible chrome 测试通过 // @namespace https://greasyfork.org/users/1123819 // @downloadURL none // ==/UserScript== // 验证网址是否包含某字符串 // ==/UserScript== // 验证网址是否包含某字符串 function UrlExp(textStr) { return RegExp(textStr).test(window.location.href); } // 创建选择器的简化写法 function dQuery(selector) { return document.querySelector(selector); } function dQueryAll(selector) { return document.querySelectorAll(selector); } //初始化参数 function init(){ //清除定时任务 localStorage.removeItem("intervalId") // 我的备货单页面 if (UrlExp(/order-manage-urgency|order-manage|shipping-desk/)) { setTimeout(() => { let contactMsgs = [ ["GM_START_DELIVERY", "开始加入发货台"], ["GM_END_DELIVERY" , "结束加入发货台"], ["GM_START_INVOICE" , "开始创建发货单"], ["GM_END_INVOICE" , "结束创建发货单"] ] // 创建快捷留言按钮 let button = dQuery('.GM_START'); if(null === button){ let buttonBar = document.createElement('div'); contactMsgs.forEach((item) => { buttonBar.innerHTML += ``; }); dQuery('.index-module__sidebarBox___3W6IS').appendChild(buttonBar); dQuery('.GM_START_DELIVERY').addEventListener('click', (event) => { startAddShippedTable(); }); dQuery('.GM_END_DELIVERY').addEventListener('click', (event) => { endAddShippedTable(); }); dQuery('.GM_START_INVOICE').addEventListener('click', (event) => { startCreateInvoice(); }); dQuery('.GM_END_INVOICE').addEventListener('click', (event) => { endCreateInvoice(); }); } },3000) urlHasChange(); } } //开始加入发货台 function startAddShippedTable(){ console.log("定时任务开关" + localStorage.getItem("IS_OPEN")) if(null !== localStorage.getItem("intervalId")){ console.log("任务已存在") }else{ var intervalId = addDeliverTable(); console.log( "定时任务开关" + intervalId); localStorage.setItem("intervalId", intervalId) } } //结束加入发货台 function endAddShippedTable(){ if(null !== localStorage.getItem("intervalId")){ console.log("清除已存在定时任务" + localStorage.getItem("intervalId")); clearInterval(localStorage.getItem("intervalId")); localStorage.removeItem("intervalId") } } //开始创建发货单 function startCreateInvoice(){ if(null !== localStorage.getItem("intervalId")){ console.log("任务已存在") }else{ var intervalId = createInvoice(); console.log( "定时任务开关" + intervalId); localStorage.setItem("createInvoiceId", intervalId) } var intervalId = createInvoice(); return intervalId; } //结束创建发货单 function endCreateInvoice(){ if(null !== localStorage.getItem("createInvoiceId")){ console.log("清除已存在定时任务" + localStorage.getItem("createInvoiceId")); clearInterval(localStorage.getItem("createInvoiceId")); localStorage.removeItem("createInvoiceId") } } //加入发货台 function addDeliverTable(){ var intervalId = setInterval(() => { //获取加入发货台按钮 let btnArr = $('a[data-tracking-id="custom-t3wO-KG-3BT_5xyK"]').filter( function( index , e) { var a = e.getAttribute("disabled"); if(a == null){ return true; }else{ return false; } } ); //点击加入发货台 btnArr.each(function(index , e){ e.click(); }); //获取确认按钮 let comfirmArr = dQueryAll('.PP_popoverContent_5-72-0 .body-module__popover___3LRit .body-module__footer___APhLF'); //逐个点击 comfirmArr.forEach(e =>{ setTimeout(function(){ let btn = e.querySelectorAll('button')[0] btn.click() },1000) }) },3000); return intervalId } //创建发货单 function createInvoice(){ var intervalId = setInterval(() => { let inputArr = dQueryAll('.CBX_squareInputWrapper_5-72-0'); inputArr.forEach((element, index) => { if (index === 0) { return; } //点击创建发货单 element.click(); setTimeout(function(){ //点击创建发货单 let createInvoiceBtn = $('button[data-tracking-id="O2EwJMyrt0ciAraT"]'); createInvoiceBtn.click(); },6000); //点击确认创建发货单 setTimeout(function(){ document.querySelector('.body-module__footer___APhLF').querySelector('button').click(); },1000); console.log(element); }); }, 60000) } (function(jQuery){ 'use strict'; console.log('脚本开始执行'); //初始化参数 init(); })(); function urlHasChange(){ // 获取当前URL var currentUrl = window.location.href; // 定时检测URL是否发生变化 setInterval(function() { if (window.location.href !== currentUrl) { if (UrlExp(/order-manage-urgency|order-manage/)) { endAddShippedTable(); }else{ endCreateInvoice(); } console.log('URL发生变化'); currentUrl = window.location.href; }}, 1000); }