验收20%

This commit is contained in:
2026-07-16 07:42:07 +08:00
parent 0dec90ffdd
commit cb25317412
108 changed files with 6477 additions and 1308 deletions
+77 -22
View File
@@ -6,7 +6,7 @@ const renderSettleMilliseconds = 900
const chromeDebuggingPort = process.env.CHROME_DEBUGGING_PORT || '9222'
if (!url || !selector || !output) {
throw new Error('Usage: node scripts/capture-chrome-page.js <url> <selector> <output> [width] [height] [sms-tab|g06-results|g06-empty|fresh-navigation]')
throw new Error('Usage: node scripts/capture-chrome-page.js <url> <selector> <output> [width] [height] [password-tab|sms-tab|g06-results|g06-empty|g06-invite|fresh-navigation]')
}
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
@@ -54,6 +54,36 @@ const waitForLoadedImages = async (send) => {
}
}
const prepareA01LoginState = async (send, action) => {
if (action !== 'password-tab' && action !== 'sms-tab') return
const tabIndex = action === 'password-tab' ? 0 : 1
for (let attempt = 0; attempt < 30; attempt += 1) {
const prepared = await send('Runtime.evaluate', {
expression: `(() => {
const tabs = document.querySelectorAll('.login-tab')
if (tabs.length < 2) return false
tabs[${tabIndex}].click()
return true
})()`,
returnByValue: true
})
if (prepared.result?.value) break
if (attempt === 29) throw new Error(`A01 login tabs did not render for ${action}`)
await sleep(100)
}
for (let attempt = 0; attempt < 30; attempt += 1) {
const active = await send('Runtime.evaluate', {
expression: `document.querySelectorAll('.login-tab')[${tabIndex}]?.classList.contains('active') === true`,
returnByValue: true
})
if (active.result?.value) return
if (attempt === 29) throw new Error(`A01 did not enter the requested ${action} state`)
await sleep(100)
}
}
const waitForRequestedUrl = async (send, url) => {
for (let attempt = 0; attempt < 30; attempt += 1) {
const result = await send('Runtime.evaluate', {
@@ -79,24 +109,53 @@ const waitForFreshDocument = async (send, documentTimeOrigin) => {
}
const prepareG06State = async (send, action) => {
if (action !== 'g06-results' && action !== 'g06-empty') return
if (action !== 'g06-results' && action !== 'g06-empty' && action !== 'g06-invite') return
const keyword = action === 'g06-results' ? '汤' : '不存在的家谱'
const prepared = await send('Runtime.evaluate', {
expression: `(() => {
const input = document.querySelector('.search-input input')
const button = document.querySelector('.search-action')
if (!input || !button) return false
input.value = ${JSON.stringify(keyword)}
input.dispatchEvent(new Event('input', { bubbles: true }))
button.click()
return true
})()`,
returnByValue: true
})
if (!prepared.result?.value) throw new Error(`Could not prepare ${action}`)
if (action === 'g06-invite') {
const switched = await send('Runtime.evaluate', {
expression: `(() => {
const tab = document.querySelectorAll('.mode-tab')[1]
if (!tab) return false
tab.click()
return true
})()`,
returnByValue: true
})
if (!switched.result?.value) throw new Error('Could not switch G06 to invite mode')
await sleep(100)
const prepared = await send('Runtime.evaluate', {
expression: `(() => {
const input = document.querySelector('.invite-input input')
const button = document.querySelector('.invite-controls .search-action')
if (!input || !button) return false
input.value = 'JP2026'
input.dispatchEvent(new Event('input', { bubbles: true }))
return true
})()`,
returnByValue: true
})
if (!prepared.result?.value) throw new Error('Could not prepare G06 invite code')
await sleep(100)
await send('Runtime.evaluate', { expression: "document.querySelector('.invite-controls .search-action').click()" })
} else {
const stateSelector = action === 'g06-results' ? '.search-results .genealogy-card' : '.search-empty'
const keyword = action === 'g06-results' ? '汤' : '不存在的家谱'
const prepared = await send('Runtime.evaluate', {
expression: `(() => {
const input = document.querySelector('.search-input input')
if (!input) return false
input.value = ${JSON.stringify(keyword)}
input.dispatchEvent(new Event('input', { bubbles: true }))
return true
})()`,
returnByValue: true
})
if (!prepared.result?.value) throw new Error(`Could not prepare ${action}`)
await sleep(100)
await send('Runtime.evaluate', { expression: "document.querySelector('.search-action').click()" })
}
const stateSelector = action === 'g06-results' ? '.search-results .genealogy-card' : action === 'g06-empty' ? '.search-empty' : '.invite-result .genealogy-card'
for (let attempt = 0; attempt < 30; attempt += 1) {
const result = await send('Runtime.evaluate', {
expression: `Boolean(document.querySelector(${JSON.stringify(stateSelector)}))`,
@@ -146,11 +205,7 @@ const capture = async () => {
await sleep(100)
}
if (action === 'sms-tab') {
await send('Runtime.evaluate', {
expression: "document.querySelectorAll('.login-tab')[1]?.click()"
})
}
await prepareA01LoginState(send, action)
await prepareG06State(send, action)
await waitForLoadedImages(send)