Refactor code structure for improved readability and maintainability

This commit is contained in:
QLHazyCoder
2026-04-17 10:07:53 +08:00
parent 4dc4f65a70
commit 1a7ae1dc27
3 changed files with 296 additions and 131 deletions
+27
View File
@@ -365,6 +365,32 @@ function inspectSignupEntryState() {
};
}
function getSignupEntryDiagnostics() {
const actionCandidates = document.querySelectorAll(
'a, button, [role="button"], [role="link"], input[type="button"], input[type="submit"]'
);
const visibleActions = Array.from(actionCandidates)
.filter(isVisibleElement)
.slice(0, 12)
.map((el) => ({
tag: (el.tagName || '').toLowerCase(),
type: el.getAttribute?.('type') || '',
text: getActionText(el).slice(0, 80),
enabled: isActionEnabled(el),
}))
.filter((item) => item.text);
return {
url: location.href,
title: document.title || '',
readyState: document.readyState || '',
hasEmailInput: Boolean(getSignupEmailInput()),
hasPasswordInput: Boolean(getSignupPasswordInput()),
visibleActions,
bodyTextPreview: getPageTextSnapshot().slice(0, 240),
};
}
async function waitForSignupEntryState(options = {}) {
const {
timeout = 15000,
@@ -410,6 +436,7 @@ async function ensureSignupEntryReady(timeout = 15000) {
};
}
log(`注册入口识别失败,诊断快照:${JSON.stringify(getSignupEntryDiagnostics())}`, 'warn');
throw new Error('当前页面没有可用的注册入口,也不在邮箱/密码页。URL: ' + location.href);
}