* 通过标签文本查找字段
(fieldName)
| 61 | * 通过标签文本查找字段 |
| 62 | */ |
| 63 | function findFieldByLabel(fieldName) { |
| 64 | const keywords = LABEL_KEYWORDS[fieldName]; |
| 65 | if (!keywords || keywords.length === 0) return null; |
| 66 | |
| 67 | // 获取所有可见的输入框 |
| 68 | const inputs = Array.from(document.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="button"]), select, textarea')); |
| 69 | |
| 70 | for (const input of inputs) { |
| 71 | if (input.disabled || input.readOnly || !isVisible(input)) continue; |
| 72 | |
| 73 | // 如果该输入框已经被其他规则匹配过,可能需要跳过(这里简化处理,优先匹配) |
| 74 | |
| 75 | const text = getLabelText(input); |
| 76 | if (!text) continue; |
| 77 | |
| 78 | for (const keyword of keywords) { |
| 79 | // 简单的包含匹配 |
| 80 | if (text.includes(keyword.toLowerCase().replace(/\s+/g, ''))) { |
| 81 | return input; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * 查找表单字段(单个) |
no test coverage detected