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

Function detectSiblingRelation

scripts/content.js:675–714  ·  view source on GitHub ↗

* 检测相邻字段关系

(element, allInputs)

Source from the content-addressed store, hash-verified

673 * 检测相邻字段关系
674 */
675function detectSiblingRelation(element, allInputs) {
676 const info = {
677 prevField: null,
678 nextField: null,
679 sameNamePrefix: []
680 };
681
682 const currentIndex = allInputs.indexOf(element);
683
684 // 前一个字段
685 if (currentIndex > 0) {
686 const prev = allInputs[currentIndex - 1];
687 if (prev.name || prev.id) {
688 info.prevField = prev.name || prev.id;
689 }
690 }
691
692 // 后一个字段
693 if (currentIndex < allInputs.length - 1) {
694 const next = allInputs[currentIndex + 1];
695 if (next.name || next.id) {
696 info.nextField = next.name || next.id;
697 }
698 }
699
700 // 相同 name 前缀的字段(如 address_1, address_2)
701 const currentName = element.name || '';
702 if (currentName) {
703 const prefix = currentName.replace(/[\[\]_-]?\d+[\[\]_-]?$/, '').replace(/[\[\]_-]$/, '');
704 if (prefix && prefix !== currentName) {
705 allInputs.forEach(input => {
706 if (input !== element && input.name && input.name.startsWith(prefix)) {
707 info.sameNamePrefix.push(input.name);
708 }
709 });
710 }
711 }
712
713 return info;
714}
715
716/**
717 * 分析页面上下文(增强版)

Callers 1

scanFormFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected