Greasy Fork

Greasy Fork is available in English.

EPIC游戏库存导出

自动点击“显示更多”按钮,并捕获 AJAX 响应数据,支持手动启动导出操作。

当前为 2025-06-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         EPIC游戏库存导出
// @namespace    http://tampermonkey.net/
// @version      1.3
// @license PaperTiger
// @description  自动点击“显示更多”按钮,并捕获 AJAX 响应数据,支持手动启动导出操作。
// @author       Paper Tiger
// @match         *://*.epicgames.com/account/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js
// @grant        none
// ==/UserScript==

/* global XLSX */
(function() {
    'use strict';

    let responses = [];

    function createExportButton() {
        const button = document.createElement('button');
        button.textContent = '开始导出';
        button.style.position = 'fixed';
        button.style.top = '10px';
        button.style.right = '400px';
        button.style.zIndex = '99999';
        button.style.padding = '10px';
        button.style.backgroundColor = 'rgba(40, 167, 69, 1)';
        button.style.color = 'white';
        button.style.border = '2px solid red';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        document.body.appendChild(button);

        button.addEventListener('click', function() {
            clickTransactions(); // 点击交易按钮
        });
    }

    function clickTransactions() {
        const transactionsButton = document.querySelector('#nav-link-transactions');
        if (transactionsButton) {
            transactionsButton.click();
            console.log('点击了交易按钮');
            setTimeout(clickMore, 1000);
        } else {
            console.log("找不到交易按钮。");
        }
    }

    function clickMore() {
        // 选择新的箭头按钮(请根据实际class修改)
        const moreButton = document.querySelector('.am-1yzbym3');
        if (moreButton) {
            moreButton.click();
            console.log('点击了箭头加载更多按钮');
            setTimeout(clickMore, 1000);
        } else {
            console.log("没有更多内容可以加载。");
            exportResponses();
        }
    }

    function exportResponses() {
        // 这里假设 responses 已经被填充为订单数据
        // 你可能需要根据实际页面结构,补充抓取订单数据的逻辑
        const exportData = responses.flatMap(response =>
            response.orders.flatMap(order =>
                order.items.map(item => ({
                    '游戏名称': item.description,
                    '付款金额': order.presentmentTotal
                }))
            )
        );

        const workbook = XLSX.utils.book_new();
        const worksheet = XLSX.utils.json_to_sheet(exportData);
        XLSX.utils.book_append_sheet(workbook, worksheet, '订单历史');
        XLSX.writeFile(workbook, '游戏订单历史.xlsx');
    }

    createExportButton();
})();