Auto-submit SBCs on EA FC Web App after manual start with "[" and stop with "]"
当前为
// ==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');
}
}
});
})();