Greasy Fork

店小秘统计当前订单件数

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

目前为 2023-04-13 提交的版本。查看 最新版本

// ==UserScript==
// @name         店小秘统计当前订单件数
// @namespace    https://greasyfork.org/zh-CN/scripts/462551
// @version      0.5
// @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';
    const attributeName = `cur-total`;

    // 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;
          }
          #orderListTable tr.goodsId {
          	position: relative;
          }
        `;
        document.head.appendChild(style);
    }

    function main(){
        let table = document.querySelector("#orderListTable");
        if(!table) return;

        let fromHere = $('#profitPermission');
        let itemList = $(fromHere.nextAll());

        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];

            let curNum = 0;
            let 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(attributeName,curNum);
            })
        }

        addEle(itemList);
    }


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

            if(nextRow && nextRow.hasAttribute(attributeName)){
            	let num = itemList[i+1].getAttribute(attributeName);
            	let newElement = document.createElement("h3");
            	$(headerRow).append(`<h3 class="total-num">${num}件</h3>`)
            }
        }
    }

    jQuery.ajaxPrefilter(function(options, originalOptions, jqXHR) {
        const { url } = options;
        const keywords = ['list.htm','splitList.htm','mergeList.htm','searchPackage.htm'];
        const regex = /<tbody[^>]*>([\s\S]*?)<\/tbody>/gi;
        for (let i=0 ;i<keywords.length;i++){
            if(url.includes(keywords[i])){
                jqXHR.done(function(data) {
                    if (data) {
                        setTimeout(main,200)
                    }
                })
            }
        }
    });

})();