// ==UserScript== // @name 店小秘统计当前订单件数 // @namespace http://tampermonkey.net/ // @version 0.1 // @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 // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... function main(){ var tbody = document.querySelector(".xianshishujudate"); var trs = tbody.children; var itemList=[]; for (var i = 0; i < trs.length; i++) { if (trs[i].tagName === "TR") { itemList.push(trs[i]) } } itemList.forEach((v,i)=>{ if(i%2 == 0)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); }) }) itemList.forEach((v,i)=>{ if(i%2 != 0)return; v.style.position="relative"; var newElement = document.createElement("h3"); var num = itemList[i+1].getAttribute('cur-total'); newElement.textContent = `${num}件` newElement.style.position="absolute"; newElement.style.left="200px"; newElement.style.top="8px"; newElement.style.color = "red"; newElement.style.fontSize = "12px"; v.appendChild(newElement); }) } function waitForElement() { var target = document.querySelector(".xianshishujudate"); if (!target) return; observer.disconnect(); main(); } var observer = new MutationObserver(waitForElement); observer.observe(document.body, { childList: true, subtree: true }); window.addEventListener("load", waitForElement); })();