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

Function extractSemanticFromElement

scripts/content.js:601–630  ·  view source on GitHub ↗

* 从元素中提取语义信息(class, id, data-* 属性)

(element)

Source from the content-addressed store, hash-verified

599 * 从元素中提取语义信息(class, id, data-* 属性)
600 */
601function 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 * 检测字段所属分组

Callers 1

getExpandedContextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected