Greasy Fork

店小秘统计当前订单件数

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

目前为 2023-07-06 提交的版本。查看 最新版本

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

(function() {
    'use strict';
    const attributeName = `cur-total`;

    let css = `
    h3.total-num {
        color: red;
        position: absolute;
        left: 250px;
        top: 7px;
        font-size:14px;
    }
    #orderListTable tr.goodsId {
        position: relative;
    }
    `
    GM_addStyle(css);

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

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

        for (let titleRow of titleRows) {
            let contentRow = titleRow.nextElementSibling;
            let numBoxes = contentRow.querySelectorAll('[class^="circularSpan"]');

            let sum = 0;
            for (let numBox of numBoxes) {
                let num = parseInt(numBox.textContent);
                sum += num;
            }

            titleRow.insertAdjacentHTML("beforeend", `<h3 class='total-num'>${sum}件</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;
        const len = keywords.length;
        for (let i=0 ;i<len;i++){
            if(url.includes(keywords[i])){
                jqXHR.done(function(data) {
                    if (data) {
                        setTimeout(main,50);
                    }
                })
            }
        }
    });

})();