feat: auto submit after filling phone

This commit is contained in:
chick
2026-05-31 17:23:30 +08:00
parent 6424862cc9
commit 2b127d070b
2 changed files with 58 additions and 6 deletions
+55 -3
View File
@@ -79,7 +79,58 @@
const input = findBestInput();
if (!input) throw new Error('当前页面没有找到可填写的输入框。请先点一下目标输入框再获取。');
setValue(input, phoneNumber);
return { phoneNumber, tag: input.tagName, name: input.name || '', id: input.id || '' };
return { phoneNumber, input, tag: input.tagName, name: input.name || '', id: input.id || '' };
}
function scoreSubmitButton(button, input) {
if (!button || panel?.contains(button)) return -1000;
const style = window.getComputedStyle(button);
const rect = button.getBoundingClientRect();
if (button.disabled || style.visibility === 'hidden' || style.display === 'none' || rect.width <= 0 || rect.height <= 0) return -1000;
const text = [
button.innerText, button.textContent, button.value, button.name, button.id,
button.getAttribute('aria-label'), button.getAttribute('title')
].join(' ').toLowerCase();
let score = 0;
if (/下一步|继续|发送验证码|获取验证码|发送代码|发送短信|验证|提交|next|continue|send\s*(code|sms)?|verify|submit/.test(text)) score += 100;
if (/取消|返回|back|cancel|关闭|close|skip|跳过|resend|重发/.test(text)) score -= 140;
if (button.type === 'submit') score += 35;
if (input) {
const inputRect = input.getBoundingClientRect();
const dy = rect.top - inputRect.bottom;
const dx = Math.abs((rect.left + rect.right) / 2 - (inputRect.left + inputRect.right) / 2);
if (dy >= -20 && dy < 260) score += Math.max(0, 60 - dy / 5);
if (dx < 360) score += Math.max(0, 30 - dx / 20);
}
return score;
}
function findSubmitButton(input) {
const formButton = input?.form?.querySelector('button[type="submit"], input[type="submit"]');
const candidates = Array.from(document.querySelectorAll('button, input[type="button"], input[type="submit"], [role="button"]'))
.filter((el) => !panel || !panel.contains(el));
if (formButton && !candidates.includes(formButton)) candidates.unshift(formButton);
const ranked = candidates.map((el) => ({ el, score: scoreSubmitButton(el, input) })).sort((a, b) => b.score - a.score);
return ranked[0]?.score > 30 ? ranked[0].el : null;
}
async function autoSubmitPhone(input) {
await sleep(250);
const button = findSubmitButton(input);
if (button) {
button.scrollIntoView?.({ block: 'center', inline: 'center' });
button.click();
return { method: 'button', text: String(button.innerText || button.textContent || button.value || button.getAttribute('aria-label') || '').trim().slice(0, 40) };
}
const form = input?.form;
if (form) {
if (typeof form.requestSubmit === 'function') form.requestSubmit();
else form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
return { method: 'form' };
}
input?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', code: 'Enter', bubbles: true }));
input?.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter', code: 'Enter', bubbles: true }));
return { method: 'enter' };
}
function send(type, payload = {}) {
@@ -166,13 +217,14 @@
const res = await send('FETCH_NEXT_PHONE', { reason, releaseAction });
const phone = res.activation.phoneNumber;
await copyText(phone);
fillPhone(phone);
const filled = fillPhone(phone);
$('.sb-current-phone').textContent = phone;
lastErroredPhoneNumber = '';
$('.sb-current-id').textContent = res.activation.activationId;
const codeNode = $('.sb-current-code');
if (codeNode) codeNode.textContent = '无';
setStatus(`已切换、填入并复制:${phone}`);
const submit = await autoSubmitPhone(filled.input);
setStatus(`已切换、填入、复制并自动提交:${phone}${submit.text ? `${submit.text}` : ''}`);
} catch (error) {
setStatus(error.message || String(error), true);
} finally {