Greasy Fork

店小秘统计当前订单件数

发货时对一下数量,对于一个订单有多件的比较方便

目前为 2023-03-30 提交的版本。查看 最新版本

// ==UserScript==
// @name         店小秘统计当前订单件数
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  发货时对一下数量,对于一个订单有多件的比较方便
// @author       Huang
// @match        https://www.dianxiaomi.com/order/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=dianxiaomi.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    window.addEventListener("load",addStyle);
    function addStyle(){
        const style = document.createElement('style');
        style.textContent = `
          h3.total-num {
            color: red;
            position: absolute;
            left: 200px;
            top: 8px;
            font-size:14px;
          }
        `;
        document.head.appendChild(style);
    }

    function main(){
        var tbody = document.querySelector(".xianshishujudate");
        if(!tbody) return;

        var trs = tbody.children;
        var itemList=[];

        for (var i = 0; i < trs.length; i++) {
            if (trs[i].tagName === "TR") {
                itemList.push(trs[i])
            }
        }

        if(itemList.length == 0)return;
        const len = itemList.length;


        for (let i = 0; i < itemList.length; i++) {
            if (i%2 === 0) continue;
            let v = itemList[i];
            if(v.hasAttribute('cur-total'))return;

            let curNum = 0;
            var numberBox = v.querySelectorAll(".p0-imp .pairProInfo");
            numberBox.forEach(item=>{

                const secondTd = item.querySelector("td:nth-of-type(2)");
                const span = secondTd.querySelector("p:first-of-type span");
                curNum+=Number(span.innerText)
                v.setAttribute('cur-total',curNum);
            })
        }

        addEle(itemList);
    }


    function addEle(itemList){
        for (let i = 0; i < itemList.length; i++) {
            if (i%2 != 0) continue;
            let v = itemList[i];

            v.style.position="relative";
            var newElement = document.createElement("h3");
            var num = itemList[i+1].getAttribute('cur-total');

            newElement.textContent = `${num}件`
            newElement.classList.add('total-num');
            v.appendChild(newElement);
        }
    }

    jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
        const { url } = options;
        const keywords = ['list.htm','splitList.htm','mergeList.htm'];
        for (let i=0 ;i<keywords.length;i++){
            if(url.includes(keywords[i])){
                jqXHR.done(function(data) {
                    if (data) {
                       setTimeout(main,200)
                    }
                })
            }
        }
    });

})();