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

Function analyzePageContext

scripts/content.js:719–764  ·  view source on GitHub ↗

* 分析页面上下文(增强版)

()

Source from the content-addressed store, hash-verified

717 * 分析页面上下文(增强版)
718 */
719function analyzePageContext() {
720 const pageTitle = document.title;
721 const metaDesc = document.querySelector('meta[name="description"]')?.content || '';
722 const url = window.location.href;
723 const language = document.documentElement.lang || navigator.language || 'en';
724
725 // 检测页面类型
726 const pageType = detectPageType(url, pageTitle, metaDesc);
727
728 // 获取表单 action
729 const forms = document.querySelectorAll('form');
730 const formActions = [];
731 forms.forEach(form => {
732 if (form.action) {
733 formActions.push(form.action);
734 }
735 });
736
737 // 获取页面主标题
738 const h1 = document.querySelector('h1');
739 const mainHeading = h1 ? h1.innerText.trim() : '';
740
741 // 检测是否有 CAPTCHA
742 const hasCaptcha = !!(
743 document.querySelector('[class*="captcha"]') ||
744 document.querySelector('[id*="captcha"]') ||
745 document.querySelector('[class*="recaptcha"]') ||
746 document.querySelector('iframe[src*="recaptcha"]')
747 );
748
749 // 检测提交按钮文本
750 const submitBtn = document.querySelector('button[type="submit"], input[type="submit"], button:not([type])');
751 const submitText = submitBtn ? (submitBtn.innerText || submitBtn.value || '').trim() : '';
752
753 return {
754 title: pageTitle,
755 description: metaDesc,
756 url: url,
757 language: language,
758 pageType: pageType,
759 mainHeading: mainHeading,
760 formActions: formActions,
761 hasCaptcha: hasCaptcha,
762 submitButtonText: submitText
763 };
764}
765
766/**
767 * 检测页面类型

Callers 1

scanFormFunction · 0.85

Calls 1

detectPageTypeFunction · 0.85

Tested by

no test coverage detected