MCPcopy Create free account
hub / github.com/debbide/GeoFill / findFieldByLabel

Function findFieldByLabel

scripts/content.js:63–86  ·  view source on GitHub ↗

* 通过标签文本查找字段

(fieldName)

Source from the content-addressed store, hash-verified

61 * 通过标签文本查找字段
62 */
63function 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 * 查找表单字段(单个)

Callers 1

findFieldFunction · 0.85

Calls 2

isVisibleFunction · 0.85
getLabelTextFunction · 0.85

Tested by

no test coverage detected