feat: add configurable operation delay

This commit is contained in:
root
2026-05-08 12:50:20 -04:00
parent 872f382815
commit c23461261b
44 changed files with 4770 additions and 193 deletions
+15
View File
@@ -577,6 +577,21 @@
</div>
</div>
</div>
<div class="data-row" id="row-operation-delay-settings">
<span class="data-label">操作间延迟</span>
<div class="data-inline setting-pair operation-delay-setting-pair">
<div class="setting-group setting-group-primary operation-delay-setting">
<label class="toggle-switch" for="input-operation-delay-enabled" title="开启后,页面输入、选择、点击、提交、继续、授权操作完成后等待 2 秒">
<input type="checkbox" id="input-operation-delay-enabled" checked />
<span class="toggle-switch-track" aria-hidden="true">
<span class="toggle-switch-thumb"></span>
</span>
<span>启用</span>
</label>
<span class="setting-caption">页面输入、选择、点击、提交、继续、授权后等待 2 秒</span>
</div>
</div>
</div>
<div class="data-row">
<span class="data-label">自动重试</span>
<div class="data-inline setting-pair">
+62
View File
@@ -380,6 +380,7 @@ const inputStep6CookieCleanupEnabled = document.getElementById('input-step6-cook
const inputAutoDelayEnabled = document.getElementById('input-auto-delay-enabled');
const inputAutoDelayMinutes = document.getElementById('input-auto-delay-minutes');
const inputAutoStepDelaySeconds = document.getElementById('input-auto-step-delay-seconds');
const inputOperationDelayEnabled = document.getElementById('input-operation-delay-enabled');
const inputOAuthFlowTimeoutEnabled = document.getElementById('input-oauth-flow-timeout-enabled');
const inputVerificationResendCount = document.getElementById('input-verification-resend-count');
const rowPhoneVerificationEnabled = document.getElementById('row-phone-verification-enabled');
@@ -518,6 +519,7 @@ const DEFAULT_SIGNUP_METHOD = SIGNUP_METHOD_EMAIL;
let currentPlusModeEnabled = false;
let currentPlusPaymentMethod = DEFAULT_PLUS_PAYMENT_METHOD;
let currentSignupMethod = DEFAULT_SIGNUP_METHOD;
let lastConfirmedOperationDelayEnabled = true;
let heroSmsCountrySelectionOrder = [];
let phoneSmsProviderOrderSelection = [];
let heroSmsCountryMenuSearchKeyword = '';
@@ -2050,6 +2052,53 @@ function syncLatestState(nextState) {
renderAccountRecords(latestState);
}
function normalizeOperationDelayEnabled(value) {
return typeof value === 'boolean' ? value : true;
}
function appendOperationDelayLog(enabled, level = 'info', message = '') {
appendLog({
timestamp: Date.now(),
level,
message: message || (enabled
? '操作间延迟已开启:页面输入、选择、点击、提交、继续、授权后等待 2 秒。'
: '操作间延迟已关闭:页面操作将连续执行。'),
});
}
function applyOperationDelayState(state = latestState, options = {}) {
const enabled = options.restoreFailed ? true : normalizeOperationDelayEnabled(state?.operationDelayEnabled);
lastConfirmedOperationDelayEnabled = enabled;
if (inputOperationDelayEnabled) inputOperationDelayEnabled.checked = enabled;
if (typeof syncLatestState === 'function') {
syncLatestState({ operationDelayEnabled: enabled });
}
if (options.restoreFailed) {
appendOperationDelayLog(true, 'warn', '操作间延迟设置读取失败,已回退为默认开启。');
}
}
async function persistOperationDelayToggle() {
const nextEnabled = normalizeOperationDelayEnabled(inputOperationDelayEnabled?.checked);
try {
const response = await chrome.runtime.sendMessage({
type: 'SAVE_SETTING',
source: 'sidepanel',
payload: { operationDelayEnabled: nextEnabled },
});
if (response?.error) throw new Error(response.error);
const confirmed = normalizeOperationDelayEnabled(response?.state?.operationDelayEnabled ?? nextEnabled);
lastConfirmedOperationDelayEnabled = confirmed;
if (inputOperationDelayEnabled) inputOperationDelayEnabled.checked = confirmed;
syncLatestState({ operationDelayEnabled: confirmed });
appendOperationDelayLog(confirmed);
} catch (error) {
if (inputOperationDelayEnabled) inputOperationDelayEnabled.checked = lastConfirmedOperationDelayEnabled;
appendOperationDelayLog(lastConfirmedOperationDelayEnabled, 'error', `操作间延迟设置保存失败,已恢复为上一次确认的状态:${error.message}`);
throw error;
}
}
function normalizePlusPaymentMethod(value = '') {
const rootScope = typeof window !== 'undefined' ? window : globalThis;
if (rootScope.GoPayUtils?.normalizePlusPaymentMethod) {
@@ -7964,6 +8013,9 @@ function applySettingsState(state) {
return Math.max(1, Math.min(1440, numeric));
};
syncLatestState(state);
if (typeof applyOperationDelayState === 'function') {
applyOperationDelayState(state);
}
syncAutoRunState(state);
renderStepStatuses(latestState);
@@ -8470,6 +8522,9 @@ async function restoreState() {
renderContributionMode();
} catch (err) {
console.error('Failed to restore state:', err);
if (typeof applyOperationDelayState === 'function') {
applyOperationDelayState(undefined, { restoreFailed: true });
}
}
}
@@ -11413,6 +11468,10 @@ inputPlusModeEnabled?.addEventListener('change', () => {
saveSettings({ silent: true }).catch(() => { });
});
inputOperationDelayEnabled?.addEventListener('change', () => {
persistOperationDelayToggle().catch(() => { });
});
selectPlusPaymentMethod?.addEventListener('change', () => {
selectPlusPaymentMethod.value = normalizePlusPaymentMethod(selectPlusPaymentMethod.value);
updatePlusModeUI();
@@ -13159,6 +13218,9 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
case 'DATA_UPDATED': {
syncLatestState(message.payload);
if (message.payload.operationDelayEnabled !== undefined && typeof applyOperationDelayState === 'function') {
applyOperationDelayState(message.payload);
}
if (message.payload.email !== undefined) {
inputEmail.value = message.payload.email || '';
queueCustomEmailPoolRefresh();