* 从元素中提取语义信息(class, id, data-* 属性)
(element)
| 599 | * 从元素中提取语义信息(class, id, data-* 属性) |
| 600 | */ |
| 601 | function extractSemanticFromElement(element) { |
| 602 | const hints = []; |
| 603 | |
| 604 | // 检查 class |
| 605 | const className = element.className; |
| 606 | if (className && typeof className === 'string') { |
| 607 | // 常见语义关键词 |
| 608 | const semanticKeywords = ['personal', 'contact', 'address', 'payment', 'billing', 'shipping', |
| 609 | 'account', 'profile', 'login', 'register', 'signup', 'form', 'info', 'details', |
| 610 | '个人', '联系', '地址', '支付', '账户', '注册', '登录']; |
| 611 | |
| 612 | for (const keyword of semanticKeywords) { |
| 613 | if (className.toLowerCase().includes(keyword)) { |
| 614 | hints.push(`class:${keyword}`); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | // 检查 data-* 属性 |
| 620 | for (const attr of element.attributes) { |
| 621 | if (attr.name.startsWith('data-') && attr.value) { |
| 622 | const value = attr.value.toLowerCase(); |
| 623 | if (value.length < 50 && !/^\d+$/.test(value)) { |
| 624 | hints.push(`${attr.name}:${value}`); |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | return hints.length > 0 ? hints.join(', ') : ''; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * 检测字段所属分组 |
no outgoing calls
no test coverage detected