Auto SBC Submitter (Manual Trigger)

Auto-submit SBCs on EA FC Web App after manual start with "[" and stop with "]"

当前为 2025-05-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto SBC Submitter (Manual Trigger)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Auto-submit SBCs on EA FC Web App after manual start with "[" and stop with "]"
// @match        https://www.ea.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // === CONFIGURABLE SELECTOR ===
    // Default SBC is currently set to Daily Gold SBC
    const SBC_TILE_SELECTOR = 'div.ut-sbc-set-tile-view[data-id="867"]'; // Update data-id as needed

    let running = false;

    // Simulate a full user-like click with mouse events
    function simulateFullClick(element) {
        ['mousedown', 'mouseup', 'click'].forEach(eventType => {
            const event = new MouseEvent(eventType, {
                view: window,
                bubbles: true,
                cancelable: true,
                buttons: 1
            });
            element.dispatchEvent(event);
        });
    }

    // Wait for an element to appear on the page
    function waitForElement(selector, interval = 500, timeout = 15000) {
        return new Promise((resolve, reject) => {
            const start = Date.now();
            const timer = setInterval(() => {
                const el = document.querySelector(selector);
                if (el) {
                    clearInterval(timer);
                    resolve(el);
                } else if (Date.now() - start > timeout) {
                    clearInterval(timer);
                    reject(new Error(`Timeout waiting for element: ${selector}`));
                }
            }, interval);
        });
    }

    async function performSequence() {
        if (!running) return;

        try {
            console.log('Starting sequence');

            const sbcTile = await waitForElement(SBC_TILE_SELECTOR);
            simulateFullClick(sbcTile);
            console.log('SBC tile clicked');

            const buildBtn = await waitForElement('button#use-template.btn-standard');
            simulateFullClick(buildBtn);
            console.log('Build Using Template clicked');

            await new Promise(res => setTimeout(res, 2000));

            const submitBtnSelector = 'button.ut-squad-tab-button-control.actionTab.right.call-to-action:not([disabled])';
            await waitForElement(submitBtnSelector);
            const submitBtn = document.querySelector(submitBtnSelector);
            simulateFullClick(submitBtn);
            console.log('Submit button clicked');

            await new Promise(res => setTimeout(res, 2000));

            const claimBtnSelector = 'div.game-rewards-view footer > button.btn-standard.call-to-action';
            const claimBtn = await waitForElement(claimBtnSelector);
            simulateFullClick(claimBtn);
            console.log('Claim Rewards clicked');

            await new Promise(res => setTimeout(res, 3000));

            if (running) performSequence();

        } catch (err) {
            console.error('Error in sequence:', err.message);

            if (running) {
                setTimeout(performSequence, 5000);
            }
        }
    }

    // Listen for "[" to start and "]" to stop
    window.addEventListener('keydown', (e) => {
        if (e.key === '[') {
            if (!running) {
                running = true;
                console.log('Automation started');
                performSequence();
            }
        } else if (e.key === ']') {
            if (running) {
                running = false;
                console.log('Automation stopped');
            }
        }
    });

})();