// ==UserScript== // @name walmart 绩效快速统计 // @namespace http://tampermonkey.net/ // @version 1.4 // @description 用在沃尔玛运营时候简化一部分操作用 私人脚本 // @author w1w // @match *://seller.walmart.com/partner-analytics/performance/financials* // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/noty/3.1.4/noty.min.js // @icon https://www.google.com/s2/favicons?domain=walmart.com // @grant none // @license MIT // @downloadURL none // ==/UserScript== //缝缝补补用三年 简化下沃尔玛后台的运营操作。 window.hide = (el, showtime, time) => { let alpha = 100; el.style.opacity = alpha / 100; setTimeout(() => { let a = setInterval(() => { //console.log(alpha) el.style.opacity = alpha / 100; alpha -= 2; if (alpha <= 15) { el.style.opacity = 0; clearInterval(a); } }, time / 50); }, showtime); }; window.copy = () => { let transfer = document.querySelector("#textarea22588"); transfer.style.display = ""; transfer.value = copyData; // 这里表示想要复制的内容 transfer.focus(); transfer.select(); //alert("复制完成"); hide(document.querySelector("artDilog"), 1.6e3, 1.6e3); if (document.execCommand("copy")) { document.execCommand("copy"); } transfer.blur(); transfer.style.display = "none"; console.log("复制成功"); //document.body.removeChild(transfer); }; window.todayValue = function () { var d = new Date(); var todayValue = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate(); return todayValue; }; window.addZero = function (data) { if (data.length < 2) { return "0" + data; } else { return data; } }; window.id = "tab" + Date.now(); window.timeIsRight = 1; var tem = `
开始时间: 结束时间: 时间跨度单次上限100天(不要改系统时区,时间计算会出错的)

复制成功
`; window.templete = ` Data ITEM ID DEPARTMENT BRAND GMV COMMISSION GMV - COMMISSION AUR TOTAL UNITS SOLD CANCELLED UNITS CANCELLED SALES CANCELLED SALES % CANCELLED UNITS % ITEM CONVERSION RATE BASE ITEM ID SKU TOTAL PRODUCT VISITS `; window.getDayilyData = (dateTime) => { window.tempVal = []; let offsetTime = new Date(dateTime); offsetTime = offsetTime.getTime() - 86400000 * 1; offsetTime = new Date(offsetTime); offsetTime = offsetTime.getFullYear() + "-" + addZero("" + (offsetTime.getMonth() + 1)) + "-" + addZero("" + offsetTime.getDate()); $.ajax({ url: "https://seller.walmart.com/api/aurora/financial/getItemSales", type: "POST", async: false, contentType: "application/json", dataType: "json", tryCount: 0, retryLimit: 5, headers: { Accept: "application/json", "x-xsrf-token": window.xtoken, }, data: '{"filter":{"filterBy":{"duration":["' + offsetTime + '","' + offsetTime + '"],"program":"ALL"},"sortBy":{}},"pagination":{"pageNumber":1,"pageSize":25}}', success(e) { console.log("seccucs..."); allDate.push(e["data"]); tempVal.push(e); }, error(xhr, textStatus, errorThrown) { this.tryCount++; if (this.tryCount <= this.retryLimit) { //try again $.ajax(this); return; } }, }); }; window.getDaily = function () { window.allDate = []; window.tableData = ""; window.timeList = []; let stt = $("#stt").val(); let ent = $("#ent").val(); stt = new Date(stt); ent = new Date(ent); if (stt == "Invalid Date" || ent == "Invalid Date") { alert("请输入正确时间格式!"); timeIsRight = 0; return 0; } var stt_T = stt.getTime(); var ent_T = ent.getTime(); if (stt_T > ent_T) { alert("请输入正确时间顺序!"); timeIsRight = 0; return 0; } else { timeIsRight = 1; } ent = ent.getFullYear() + "-" + addZero("" + (ent.getMonth() + 1)) + "-" + addZero("" + ent.getDate()); var iii = 100; //单次搜索上限 let temp = stt.getFullYear() + "-" + addZero("" + (stt.getMonth() + 1)) + "-" + addZero("" + stt.getDate()); timeList.push(temp); if (temp != ent) { while (iii > 0) { stt_T = 86400000 + stt_T; let temDate = new Date(stt_T); temp = temDate.getFullYear() + "-" + addZero("" + (temDate.getMonth() + 1)) + "-" + addZero("" + temDate.getDate()); timeList.push(temp); if (temp == ent) { break; } else { iii--; } } } return 0; }; window.mainLunch = function () { var getXToken = () => { var r = new RegExp("XSRF-TOKEN=(.*?);"); window.xtoken = document.cookie.match(r)[1].toString(); }; window.fetchFishedCount = 0; getXToken(); console.log("点击开始运行"); getDaily(); if (timeIsRight == 0) { return 0; } console.log(timeList.length); for (var i = 0; i < timeList.length; i++) { console.log("dataTime: " + timeList[i]); getDayilyData2(timeList[i], i); } window.runMaxTime = 20; //最长等待时间 1 = 0.5s var checkState = setInterval(() => { if (runMaxTime <= 0 || window.fetchFishedCount === timeList.length) { tempVal2.sort((a, b) => { return a[0] - b[0]; }); tempVal2.forEach((data) => { allDate.push(data[1]); }); formatTable(); clearTable(); insertTable(); $("#copyData")[0].style.background = "#f99"; clearInterval(checkState); } if (runMaxTime > 0) { runMaxTime -= 1; } }, 500); }; window.clearTable = function () { if ($("#" + id).children().length > 1) { $("#" + id) .children()[0] .remove(); } }; window.insertTable = function () { window.allTable = window.templete + window.tableData; window.div_tab = document.createElement("table"); div_tab.innerHTML = allTable; $("#" + id) .children()[0] .before(div_tab); $("#" + id).children()[0].style.fontSize = "6px"; $("#" + id).children()[0].style.border = "1px solid"; $("#" + id).children()[0].style.textAlign = "center"; }; window.formatTable = function () { window.copyData = ""; for (var i = 0; i < allDate.length; i++) { let temp = allDate[i]; if (temp == []) { if (i !== allDate.length) { alert(i + "是空白"); } continue; } else { for (var ii = 0; ii < temp.length; ii++) { var tempDate = temp[ii]; window.copyData += timeList[i] + "\t" + tempDate["catlgItemId"] + "\t" + tempDate["department"] + "\t" + tempDate["brandName"] + "\t" + tempDate["TotalGMV"] + "\t" + tempDate["TotalCommissions"] + "\t" + (tempDate["TotalGMV"] - tempDate["TotalCommissions"]) + "\t" + tempDate["AuthAUR"] + "\t" + tempDate["TotalUnits"] + "\t" + tempDate["TotalCancelUnits"] + "\t" + tempDate["TotalCancelAmt"] + "\t" + tempDate["TotalCancelAmt"] / tempDate["TotalAuthAmt"] + "\t" + tempDate["TotalCancelUnits"] / tempDate["TotalAuthUnits"] + "\t" + tempDate["Conversion"] + "\t" + tempDate["baseItemId"] + "\t" + tempDate["skuId"] + "\t" + tempDate["TotalProductVisitsItemLvl"] + //似乎这里有修改 "\r\n"; window.tableData = window.tableData + "" + timeList[i] + "" + tempDate["catlgItemId"] + "" + tempDate["department"] + "" + tempDate["brandName"] + "" + tempDate["TotalGMV"] + "" + tempDate["TotalCommissions"] + "" + (tempDate["TotalGMV"] - tempDate["TotalCommissions"]) + "" + tempDate["AuthAUR"] + "" + tempDate["TotalUnits"] + "" + tempDate["TotalCancelUnits"] + "" + tempDate["TotalCancelAmt"] + "" + tempDate["TotalCancelAmt"] / tempDate["TotalAuthAmt"] + "" + tempDate["TotalCancelUnits"] / tempDate["TotalAuthUnits"] + "" + tempDate["Conversion"] + "" + tempDate["baseItemId"] + "" + tempDate["skuId"] + "" + tempDate["TotalProductVisitsItemLvl"] + //似乎这里有修改 ""; } } } }; $().ready(function () { let date = new Date(); date = date.getTime(); let div_section = document.createElement("section"); let tempDate; div_section.innerHTML = tem; setTimeout(() => { document .querySelector( "#subapp-main-0 > div > div:nth-child(1) > div > div:nth-child(3) > div" ) .before(div_section); tempDate = date - 86400000 * 5; tempDate = new Date(tempDate); $("#ent").val(todayValue()); $("#stt").val( tempDate.getFullYear() + "-" + addZero("" + (tempDate.getMonth() + 1)) + "-" + addZero("" + tempDate.getDate()) ); $("#sameDay").bind("click", function () { $("#ent").val($("#stt").val()); }); $("#TDay").bind("click", function () { $("#ent").val(todayValue()); tempDate = date - 86400000 * 3; tempDate = new Date(tempDate); $("#stt").val( tempDate.getFullYear() + "-" + addZero("" + (tempDate.getMonth() + 1)) + "-" + addZero("" + tempDate.getDate()) ); }); $("#SDay").bind("click", function () { $("#ent").val(todayValue()); tempDate = date - 86400000 * 7; tempDate = new Date(tempDate); $("#stt").val( tempDate.getFullYear() + "-" + addZero("" + (tempDate.getMonth() + 1)) + "-" + addZero("" + tempDate.getDate()) ); }); $("#go").bind("click", function () { mainLunch(); }); $("#today").bind("click", function () { $("#ent").val(todayValue()); }); $("#copyData").bind("click", function () { copy(); }); var nowTime = () => { let d = new Date(); $("#nowTime").val( "" + d.getHours() + ":" + addZero("" + d.getMinutes()) + ":" + addZero("" + d.getSeconds()) ); }; setInterval(nowTime, 500); }, 1500); }); window.getDayilyData2 = (dateTime, sort) => { window.tempVal2 = []; let offsetTime = new Date(dateTime); offsetTime = offsetTime.getTime() - 86400000 * 1; offsetTime = new Date(offsetTime); offsetTime = offsetTime.getFullYear() + "-" + addZero("" + (offsetTime.getMonth() + 1)) + "-" + addZero("" + offsetTime.getDate()); async function postData(url = "") { // Default options are marked with * const response = await fetch(url, { method: "POST", // *GET, POST, PUT, DELETE, etc. contentType: "application/json", dataType: "json", credentials: "same-origin", headers: { Accept: "application/json", "x-xsrf-token": window.xtoken, "X-Requested-With": "XMLHttpRequest", "Content-Type": "application/json", }, body: '{"filter":{"filterBy":{"duration":["' + offsetTime + '","' + offsetTime + '"],"program":"ALL"},"sortBy":{}},"pagination":{"pageNumber":1,"pageSize":25}}', }); return response.json(); } postData("https://seller.walmart.com/api/aurora/financial/getItemSales").then( (data) => { tempVal2.push([sort, data["data"]]); window.fetchFishedCount += 1; } ); };