Greasy Fork

Greasy Fork is available in English.

自动生成亚马逊账单报告

每月自动操作一次,替代用户点击生成亚马逊账单报告

当前为 2020-04-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         自动生成亚马逊账单报告
// @namespace    liu12
// @version      0.3
// @description  每月自动操作一次,替代用户点击生成亚马逊账单报告
// @author       刘一二
// @match        *://sellercentral.amazon.com/*
// @match        *://sellercentral.amazon.ca/*
// @match        *://sellercentral.amazon.com.mx/*
// @match        *://sellercentral.amazon.co.uk/*
// @match        *://sellercentral.amazon.de/*
// @match        *://sellercentral.amazon.fr/*
// @match        *://sellercentral.amazon.it/*
// @match        *://sellercentral.amazon.es/*
// @match        *://sellercentral.amazon.jp/*
// @require      https://code.jquery.com/jquery-latest.js
// ==/UserScript==

(function() {
    'use strict';

    var AmazonReport = {

        year: 0,
        month: 0,

        /**
        * 获取账号
        */
        getAccount: function() {
            return $("#sc-mkt-switcher-form .sc-mkt-picker-switcher-txt")[0].html()
        },

        /**
        * 申请生成报告
        */
        requestReport: function() {
            var sKey = 'amazon-request-report-' + year + '-' + month
            console.log(localStorage.getItem(sKey));
            if (localStorage.getItem(sKey) == null) {
                var postData = {
                    reportType: "Transaction",
                    timeRangeType: "Monthly",
                    year: this.year,
                    month: this.month
                };

                $.ajax({
                    type: "POST",
                    url: "/payments/reports/custom/submit/generateReports",
                    data: JSON.stringify(postData),
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function(response) {
                        // {"status":"SUCCESS","message":"请求交易月份:3年份:2020"}
                        console.log(response);
                        if (response.status == "SUCCESS") {
                            localStorage.setItem(sKey, 1);
                        }
                    }
                });
            }
        },

        /**
        * 通知账单系统拉取报告,
        */
        notify: function() {
            var _this = this;
            $.ajax({
                type: "POST",
                url: "账单系统网址",
                data: {
                    account:_this.getAccount(),
                    yearMonth: (_this.year + "=" + _this.month)
                },
                success: function(response) {
                    console.log(response);
                }
            });
        },

        init: function() {
            var account = this.getAccount();
            if (!account) {
                return;
            }

            var date = new Date();
            var year = parseInt(date.getFullYear());
            var month = parseInt(date.getMonth());
            if (month == 0) {
                year--;
                month = 12;
            }

            this.year = year;
            this.month = month;
            this.requestReport();
            //this.notify();
        }
    };

    $(function() {
        AmazonReport.init();
    });

})();