// ==UserScript== // @name 亚马逊批量下载业务报告 // @namespace https://github.com/MaiXiaoMeng // @version 0.0.3 // @description // @author XiaoMeng Mai // @license GPLv3 // @match https://*.amazon.com/* // @match https://*.amazon.co.uk/* // @match https://*.amazon.co.de/* // @match https://*.amazon.fr/* // @match https://*.amazon.it/* // @match https://*.amazon.es/* // @match https://*.amazon.co.jp/* // @match https://*.amazon.com.au/* // @match https://*.amazon.sg/* // @grant GM_xmlhttpRequest // @grant GM_getResourceText // @grant GM_download // @grant GM_addStyle // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant unsafeWindow // @compatible firefox Tampermonkey // @compatible chrome Tampermonkey // @compatible edge Tampermonkey // @require https://unpkg.com/jquery // @require https://unpkg.com/sweetalert2 // @resource element-plus https://unpkg.com/element-plus/dist/index.css // @note 0.0.3 新添加亚马逊企业购(B2B)相关数据列 // @note 0.0.2 修复下载报告没有子ASIN列的问题 // @note 0.0.1 支持业务报告批量下载 // @description 垃圾亚马逊,连批量下载业务报告的方法都没有,只好自己写一个了 // @downloadURL none // ==/UserScript== initializationScript() // 业务报告页面 waitForKeyElements(".css-1lafdix", getBusinessReport, ['business-reports/']) function waitForKeyElements(selectorTxt, actionFunction, activeURL, bWaitOnce, iframeSelector) { var active_url = false if (typeof activeURL == "object") { for (let index = 0; index < activeURL.length; index++) { if (window.location.href.indexOf(activeURL[index]) > -1) { active_url = true break } } } else if (typeof activeURL == "string") { if (window.location.href.indexOf(activeURL) > -1) active_url = true } if (active_url) { var targetNodes, btargetsFound; if (typeof iframeSelector == "undefined") { targetNodes = $(selectorTxt); } else { targetNodes = $(iframeSelector).contents().find(selectorTxt); } if (targetNodes && targetNodes.length > 0) { btargetsFound = true; targetNodes.each(function () { var jThis = $(this); var alreadyFound = jThis.data("alreadyFound") || false; if (!alreadyFound) { logPrint(`selectorTxt > ${selectorTxt} activeURL > ${activeURL} bWaitOnce > ${bWaitOnce} iframeSelector > ${iframeSelector}`) console.log(jThis); var cancelFound = false if (typeof actionFunction == "object") { actionFunction.forEach(element => { cancelFound = element(jThis, selectorTxt, activeURL); }) } else if (typeof actionFunction == "function") { cancelFound = actionFunction(jThis, selectorTxt, activeURL); } if (cancelFound) { btargetsFound = false } else { jThis.data("alreadyFound", true); } } }) } else { btargetsFound = false; } var controlObj = waitForKeyElements.controlObj || {}; var controlKey = selectorTxt.replace(/[^\w]/g, "_"); var timeControl = controlObj[controlKey]; if (btargetsFound && bWaitOnce && timeControl) { clearInterval(timeControl); delete controlObj[controlKey]; } else { if (!timeControl) { timeControl = setInterval(function () { waitForKeyElements(selectorTxt, actionFunction, activeURL, bWaitOnce, iframeSelector); }, 300); controlObj[controlKey] = timeControl; } } waitForKeyElements.controlObj = controlObj; } } function getFormatDate(date) { var seperator1 = "-"; var year = date.getFullYear(); var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = year + seperator1 + month + seperator1 + strDate; return currentdate; } function makeGetRequest(url, method = 'GET', data = null) { logPrint(`${method} -> ${url}`) return new Promise((resolve, reject) => { GM_xmlhttpRequest({ url: url, method: method, data: data, onload: function (response) { resolve(response); }, onerror: function (error) { reject(error); } }); }); } function logPrint(params) { var date_time = $.trim(new Date(new Date().setHours(new Date().getHours() + 8)).toISOString().replace("Z", " ").replace("T", " ")) var function_name = (new Error()).stack.split("\n")[2].trim().split(" ")[1] console.log(`[${date_time}][DEBUG] ${function_name} - ${params}`) } function sleep(interval) { return new Promise(resolve => { setTimeout(resolve, interval) }) } function getBusinessReport(jNode, selectorTxt, activeURL) { if (jNode.attr("class").indexOf("beibei") == -1) { jNode.after($(`