feat: 增强注册入口诊断功能,添加对可见操作的识别和筛选
This commit is contained in:
@@ -369,6 +369,25 @@ function getSignupEntryDiagnostics() {
|
|||||||
const actionCandidates = document.querySelectorAll(
|
const actionCandidates = document.querySelectorAll(
|
||||||
'a, button, [role="button"], [role="link"], input[type="button"], input[type="submit"]'
|
'a, button, [role="button"], [role="link"], input[type="button"], input[type="submit"]'
|
||||||
);
|
);
|
||||||
|
const allActions = Array.from(actionCandidates).map((el) => {
|
||||||
|
const rect = typeof el?.getBoundingClientRect === 'function'
|
||||||
|
? el.getBoundingClientRect()
|
||||||
|
: null;
|
||||||
|
const text = getActionText(el);
|
||||||
|
return {
|
||||||
|
tag: (el.tagName || '').toLowerCase(),
|
||||||
|
type: el.getAttribute?.('type') || '',
|
||||||
|
text: text.slice(0, 80),
|
||||||
|
visible: isVisibleElement(el),
|
||||||
|
enabled: isActionEnabled(el),
|
||||||
|
rect: rect
|
||||||
|
? {
|
||||||
|
width: Math.round(rect.width || 0),
|
||||||
|
height: Math.round(rect.height || 0),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
const visibleActions = Array.from(actionCandidates)
|
const visibleActions = Array.from(actionCandidates)
|
||||||
.filter(isVisibleElement)
|
.filter(isVisibleElement)
|
||||||
.slice(0, 12)
|
.slice(0, 12)
|
||||||
@@ -379,6 +398,9 @@ function getSignupEntryDiagnostics() {
|
|||||||
enabled: isActionEnabled(el),
|
enabled: isActionEnabled(el),
|
||||||
}))
|
}))
|
||||||
.filter((item) => item.text);
|
.filter((item) => item.text);
|
||||||
|
const signupLikeActions = allActions
|
||||||
|
.filter((item) => item.text && SIGNUP_ENTRY_TRIGGER_PATTERN.test(item.text))
|
||||||
|
.slice(0, 12);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: location.href,
|
url: location.href,
|
||||||
@@ -386,6 +408,8 @@ function getSignupEntryDiagnostics() {
|
|||||||
readyState: document.readyState || '',
|
readyState: document.readyState || '',
|
||||||
hasEmailInput: Boolean(getSignupEmailInput()),
|
hasEmailInput: Boolean(getSignupEmailInput()),
|
||||||
hasPasswordInput: Boolean(getSignupPasswordInput()),
|
hasPasswordInput: Boolean(getSignupPasswordInput()),
|
||||||
|
bodyContainsSignupText: SIGNUP_ENTRY_TRIGGER_PATTERN.test(getPageTextSnapshot()),
|
||||||
|
signupLikeActions,
|
||||||
visibleActions,
|
visibleActions,
|
||||||
bodyTextPreview: getPageTextSnapshot().slice(0, 240),
|
bodyTextPreview: getPageTextSnapshot().slice(0, 240),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ function extractFunction(name) {
|
|||||||
|
|
||||||
test('signup entry diagnostics summarizes current page inputs and visible actions', () => {
|
test('signup entry diagnostics summarizes current page inputs and visible actions', () => {
|
||||||
const api = new Function(`
|
const api = new Function(`
|
||||||
|
const SIGNUP_ENTRY_TRIGGER_PATTERN = /免费注册|立即注册|注册|sign\\s*up|register|create\\s*account|create\\s+account/i;
|
||||||
const location = { href: 'https://chatgpt.com/' };
|
const location = { href: 'https://chatgpt.com/' };
|
||||||
const document = {
|
const document = {
|
||||||
title: 'ChatGPT',
|
title: 'ChatGPT',
|
||||||
@@ -67,6 +68,9 @@ const document = {
|
|||||||
tagName: 'BUTTON',
|
tagName: 'BUTTON',
|
||||||
textContent: 'Get started',
|
textContent: 'Get started',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
getBoundingClientRect() {
|
||||||
|
return { width: 120, height: 40 };
|
||||||
|
},
|
||||||
getAttribute(name) {
|
getAttribute(name) {
|
||||||
return name === 'type' ? 'button' : '';
|
return name === 'type' ? 'button' : '';
|
||||||
},
|
},
|
||||||
@@ -75,6 +79,9 @@ const document = {
|
|||||||
tagName: 'A',
|
tagName: 'A',
|
||||||
textContent: 'Log in',
|
textContent: 'Log in',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
getBoundingClientRect() {
|
||||||
|
return { width: 96, height: 40 };
|
||||||
|
},
|
||||||
getAttribute() {
|
getAttribute() {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
@@ -129,6 +136,8 @@ return {
|
|||||||
assert.equal(result.readyState, 'complete');
|
assert.equal(result.readyState, 'complete');
|
||||||
assert.equal(result.hasEmailInput, false);
|
assert.equal(result.hasEmailInput, false);
|
||||||
assert.equal(result.hasPasswordInput, false);
|
assert.equal(result.hasPasswordInput, false);
|
||||||
|
assert.equal(result.bodyContainsSignupText, false);
|
||||||
|
assert.deepStrictEqual(result.signupLikeActions, []);
|
||||||
assert.deepStrictEqual(result.visibleActions, [
|
assert.deepStrictEqual(result.visibleActions, [
|
||||||
{ tag: 'button', type: 'button', text: 'Get started', enabled: true },
|
{ tag: 'button', type: 'button', text: 'Get started', enabled: true },
|
||||||
{ tag: 'a', type: '', text: 'Log in', enabled: true },
|
{ tag: 'a', type: '', text: 'Log in', enabled: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user