fix: remove hardcoded max run count and adjust fallback risk warning logic
This commit is contained in:
+1
-1
@@ -450,7 +450,7 @@ function normalizeRunCount(value) {
|
|||||||
if (!Number.isFinite(numeric)) {
|
if (!Number.isFinite(numeric)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return Math.min(50, Math.max(1, Math.floor(numeric)));
|
return Math.max(1, Math.floor(numeric));
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeAutoRunTimerKind(value = '') {
|
function normalizeAutoRunTimerKind(value = '') {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<div class="run-group">
|
<div class="run-group">
|
||||||
<button id="btn-contribution-mode" class="btn btn-outline btn-sm btn-contribution-mode" type="button"
|
<button id="btn-contribution-mode" class="btn btn-outline btn-sm btn-contribution-mode" type="button"
|
||||||
aria-pressed="false" title="进入贡献模式并打开上传页">贡献/使用</button>
|
aria-pressed="false" title="进入贡献模式并打开上传页">贡献/使用</button>
|
||||||
<input type="number" id="input-run-count" class="run-count-input" value="1" min="1" max="50" title="运行次数" />
|
<input type="number" id="input-run-count" class="run-count-input" value="1" min="1" title="运行次数" />
|
||||||
<button id="btn-auto-run" class="btn btn-success" title="自动执行全部步骤">
|
<button id="btn-auto-run" class="btn btn-success" title="自动执行全部步骤">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
|
||||||
<polygon points="5 3 19 12 5 21 5 3" />
|
<polygon points="5 3 19 12 5 21 5 3" />
|
||||||
|
|||||||
+5
-10
@@ -249,8 +249,7 @@ const DEFAULT_MAIL_2925_MODE = MAIL_2925_MODE_PROVIDE;
|
|||||||
const AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-skip-failures-prompt-dismissed';
|
const AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-skip-failures-prompt-dismissed';
|
||||||
const AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-run-fallback-risk-prompt-dismissed';
|
const AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-run-fallback-risk-prompt-dismissed';
|
||||||
const CONTRIBUTION_CONTENT_PROMPT_DISMISSED_VERSION_STORAGE_KEY = 'multipage-contribution-content-prompt-dismissed-version';
|
const CONTRIBUTION_CONTENT_PROMPT_DISMISSED_VERSION_STORAGE_KEY = 'multipage-contribution-content-prompt-dismissed-version';
|
||||||
const AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS = 15;
|
const AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS = 3;
|
||||||
const AUTO_RUN_FALLBACK_RISK_RECOMMENDED_THREAD_INTERVAL_MINUTES = 5;
|
|
||||||
const HOTMAIL_SERVICE_MODE_REMOTE = 'remote';
|
const HOTMAIL_SERVICE_MODE_REMOTE = 'remote';
|
||||||
const HOTMAIL_SERVICE_MODE_LOCAL = 'local';
|
const HOTMAIL_SERVICE_MODE_LOCAL = 'local';
|
||||||
const ICLOUD_PROVIDER = 'icloud';
|
const ICLOUD_PROVIDER = 'icloud';
|
||||||
@@ -897,14 +896,10 @@ async function openAutoSkipFailuresConfirmModal() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openAutoRunFallbackRiskConfirmModal(totalRuns, fallbackThreadIntervalMinutes) {
|
async function openAutoRunFallbackRiskConfirmModal(totalRuns) {
|
||||||
const intervalLabel = Number.isFinite(fallbackThreadIntervalMinutes)
|
|
||||||
? `${fallbackThreadIntervalMinutes} 分钟`
|
|
||||||
: '未设置';
|
|
||||||
|
|
||||||
const result = await openConfirmModalWithOption({
|
const result = await openConfirmModalWithOption({
|
||||||
title: '自动运行风险提醒',
|
title: '自动运行风险提醒',
|
||||||
message: `当前设置为 ${totalRuns} 轮自动化,已开启自动重试,线程间隔为 ${intervalLabel}。轮数过多时,可能会因为 IP 短时间注册过多而集中失败。建议控制在 ${AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS} 轮以下,并将线程间隔设置在 ${AUTO_RUN_FALLBACK_RISK_RECOMMENDED_THREAD_INTERVAL_MINUTES} 分钟以上。是否继续?`,
|
message: `当前轮数已经不适合单节点情况,请确保已经配置并打开节点轮询功能(若没有配置,请点击贡献/使用按钮,根据网页中使用教程进行配置),避免连续使用一个节点注册,导致出现手机号验证。`,
|
||||||
confirmLabel: '继续',
|
confirmLabel: '继续',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1179,7 +1174,7 @@ function formatAutoStepDelayInputValue(value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRunCountValue() {
|
function getRunCountValue() {
|
||||||
return Math.min(50, Math.max(1, parseInt(inputRunCount.value, 10) || 1));
|
return Math.max(1, parseInt(inputRunCount.value, 10) || 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFallbackThreadIntervalInputState() {
|
function updateFallbackThreadIntervalInputState() {
|
||||||
@@ -3853,7 +3848,7 @@ async function startAutoRunFromCurrentSettings() {
|
|||||||
|
|
||||||
if (shouldWarnAutoRunFallbackRisk(totalRuns, autoRunSkipFailures)
|
if (shouldWarnAutoRunFallbackRisk(totalRuns, autoRunSkipFailures)
|
||||||
&& !isAutoRunFallbackRiskPromptDismissed()) {
|
&& !isAutoRunFallbackRiskPromptDismissed()) {
|
||||||
const result = await openAutoRunFallbackRiskConfirmModal(totalRuns, fallbackThreadIntervalMinutes);
|
const result = await openAutoRunFallbackRiskConfirmModal(totalRuns);
|
||||||
if (!result.confirmed) {
|
if (!result.confirmed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
|
||||||
|
function extractFunction(source, name) {
|
||||||
|
const markers = [`async function ${name}(`, `function ${name}(`];
|
||||||
|
const start = markers
|
||||||
|
.map((marker) => source.indexOf(marker))
|
||||||
|
.find((index) => index >= 0);
|
||||||
|
if (start < 0) {
|
||||||
|
throw new Error(`missing function ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let parenDepth = 0;
|
||||||
|
let signatureEnded = false;
|
||||||
|
let braceStart = -1;
|
||||||
|
for (let i = start; i < source.length; i += 1) {
|
||||||
|
const ch = source[i];
|
||||||
|
if (ch === '(') {
|
||||||
|
parenDepth += 1;
|
||||||
|
} else if (ch === ')') {
|
||||||
|
parenDepth -= 1;
|
||||||
|
if (parenDepth === 0) {
|
||||||
|
signatureEnded = true;
|
||||||
|
}
|
||||||
|
} else if (ch === '{' && signatureEnded) {
|
||||||
|
braceStart = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (braceStart < 0) {
|
||||||
|
throw new Error(`missing body for function ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let depth = 0;
|
||||||
|
let end = braceStart;
|
||||||
|
for (; end < source.length; end += 1) {
|
||||||
|
const ch = source[end];
|
||||||
|
if (ch === '{') depth += 1;
|
||||||
|
if (ch === '}') {
|
||||||
|
depth -= 1;
|
||||||
|
if (depth === 0) {
|
||||||
|
end += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.slice(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('sidepanel run count input no longer hardcodes max=50', () => {
|
||||||
|
const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
|
||||||
|
const inputTag = html.match(/<input type="number" id="input-run-count"[^>]+>/);
|
||||||
|
|
||||||
|
assert.ok(inputTag, 'run count input should exist');
|
||||||
|
assert.doesNotMatch(inputTag[0], /\smax="50"/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sidepanel getRunCountValue no longer clamps run count to 50', () => {
|
||||||
|
const source = fs.readFileSync('sidepanel/sidepanel.js', 'utf8');
|
||||||
|
const bundle = extractFunction(source, 'getRunCountValue');
|
||||||
|
|
||||||
|
const api = new Function(`
|
||||||
|
const inputRunCount = { value: '88' };
|
||||||
|
${bundle}
|
||||||
|
return {
|
||||||
|
getRunCountValue,
|
||||||
|
setValue(value) {
|
||||||
|
inputRunCount.value = value;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
`)();
|
||||||
|
|
||||||
|
assert.equal(api.getRunCountValue(), 88);
|
||||||
|
api.setValue('0');
|
||||||
|
assert.equal(api.getRunCountValue(), 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('background normalizeRunCount no longer clamps values to 50', () => {
|
||||||
|
const source = fs.readFileSync('background.js', 'utf8');
|
||||||
|
const bundle = extractFunction(source, 'normalizeRunCount');
|
||||||
|
|
||||||
|
const api = new Function(`
|
||||||
|
${bundle}
|
||||||
|
return { normalizeRunCount };
|
||||||
|
`)();
|
||||||
|
|
||||||
|
assert.equal(api.normalizeRunCount(88), 88);
|
||||||
|
assert.equal(api.normalizeRunCount('120'), 120);
|
||||||
|
assert.equal(api.normalizeRunCount(0), 1);
|
||||||
|
assert.equal(api.normalizeRunCount('bad'), 1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
|
||||||
|
const source = fs.readFileSync('sidepanel/sidepanel.js', 'utf8');
|
||||||
|
|
||||||
|
function extractFunction(name) {
|
||||||
|
const markers = [`async function ${name}(`, `function ${name}(`];
|
||||||
|
const start = markers
|
||||||
|
.map((marker) => source.indexOf(marker))
|
||||||
|
.find((index) => index >= 0);
|
||||||
|
if (start < 0) {
|
||||||
|
throw new Error(`missing function ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let parenDepth = 0;
|
||||||
|
let signatureEnded = false;
|
||||||
|
let braceStart = -1;
|
||||||
|
for (let i = start; i < source.length; i += 1) {
|
||||||
|
const ch = source[i];
|
||||||
|
if (ch === '(') {
|
||||||
|
parenDepth += 1;
|
||||||
|
} else if (ch === ')') {
|
||||||
|
parenDepth -= 1;
|
||||||
|
if (parenDepth === 0) {
|
||||||
|
signatureEnded = true;
|
||||||
|
}
|
||||||
|
} else if (ch === '{' && signatureEnded) {
|
||||||
|
braceStart = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (braceStart < 0) {
|
||||||
|
throw new Error(`missing body for function ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let depth = 0;
|
||||||
|
let end = braceStart;
|
||||||
|
for (; end < source.length; end += 1) {
|
||||||
|
const ch = source[end];
|
||||||
|
if (ch === '{') depth += 1;
|
||||||
|
if (ch === '}') {
|
||||||
|
depth -= 1;
|
||||||
|
if (depth === 0) {
|
||||||
|
end += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.slice(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('auto-run fallback risk warning starts at 3 runs', () => {
|
||||||
|
const bundle = extractFunction('shouldWarnAutoRunFallbackRisk');
|
||||||
|
|
||||||
|
const api = new Function(`
|
||||||
|
const AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS = 3;
|
||||||
|
${bundle}
|
||||||
|
return { shouldWarnAutoRunFallbackRisk };
|
||||||
|
`)();
|
||||||
|
|
||||||
|
assert.equal(api.shouldWarnAutoRunFallbackRisk(2, false), false);
|
||||||
|
assert.equal(api.shouldWarnAutoRunFallbackRisk(3, false), true);
|
||||||
|
assert.equal(api.shouldWarnAutoRunFallbackRisk(10, true), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('auto-run fallback risk modal uses the single-node warning copy', async () => {
|
||||||
|
const bundle = extractFunction('openAutoRunFallbackRiskConfirmModal');
|
||||||
|
|
||||||
|
const api = new Function(`
|
||||||
|
let capturedOptions = null;
|
||||||
|
async function openConfirmModalWithOption(options) {
|
||||||
|
capturedOptions = options;
|
||||||
|
return { confirmed: true, optionChecked: false };
|
||||||
|
}
|
||||||
|
${bundle}
|
||||||
|
return {
|
||||||
|
openAutoRunFallbackRiskConfirmModal,
|
||||||
|
getCapturedOptions() {
|
||||||
|
return capturedOptions;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
`)();
|
||||||
|
|
||||||
|
const result = await api.openAutoRunFallbackRiskConfirmModal(3);
|
||||||
|
const options = api.getCapturedOptions();
|
||||||
|
|
||||||
|
assert.deepStrictEqual(result, { confirmed: true, dismissPrompt: false });
|
||||||
|
assert.equal(options.title, '自动运行风险提醒');
|
||||||
|
assert.equal(
|
||||||
|
options.message,
|
||||||
|
'当前轮数已经不适合单节点情况,请确保已经配置并打开节点轮询功能(若没有配置,请点击贡献/使用按钮,根据网页中使用教程进行配置),避免连续使用一个节点注册,导致出现手机号验证。'
|
||||||
|
);
|
||||||
|
assert.equal(options.confirmLabel, '继续');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user