MCPcopy
hub / github.com/zxlie/FeHelper / captureFullPage

Function captureFullPage

apps/screenshot/content-script.js:734–992  ·  view source on GitHub ↗

* 执行全页面截图

()

Source from the content-addressed store, hash-verified

732 * 执行全页面截图
733 */
734 async function captureFullPage() {
735 if (window._fh_screenshot_in_progress) {
736 return;
737 }
738
739 window._fh_screenshot_in_progress = true;
740 window._fh_screenshot_canceled = false; // 重命名 cancel 标志以避免冲突
741
742 // 保存原始滚动位置
743 originalScrollTop = window.scrollY || document.documentElement.scrollTop;
744 originalScrollLeft = window.scrollX || document.documentElement.scrollLeft;
745
746 // 计算页面尺寸
747 const pageWidth = Math.max(
748 document.documentElement.scrollWidth,
749 document.body.scrollWidth,
750 document.documentElement.offsetWidth,
751 document.body.offsetWidth
752 );
753
754 const pageHeight = Math.max(
755 document.documentElement.scrollHeight,
756 document.body.scrollHeight,
757 document.documentElement.offsetHeight,
758 document.body.offsetHeight
759 );
760
761 // 获取视窗尺寸
762 const windowWidth = window.innerWidth;
763 const windowHeight = window.innerHeight;
764
765 // 使用视窗尺寸作为滚动步长,并计算大致步数用于UI显示
766 const totalSteps = Math.ceil(pageHeight / windowHeight) * Math.ceil(pageWidth / windowWidth);
767
768 // 隐藏工具条
769 let screenshotContainer = document.getElementById('fehelper_screenshot_container');
770 if (screenshotContainer) {
771 screenshotContainer.style.display = 'none';
772 }
773
774 // 创建进度UI和取消回调
775 const progressUI = createProgressUI(`正在截取全页面 (共${totalSteps}步)...`);
776 window._fh_screenshot_cancel_callback = () => {
777 window._fh_screenshot_canceled = true; // Set the cancel flag
778 cleanup(); // Execute cleanup
779 };
780
781 // 隐藏其他干扰UI(但不隐藏固定元素)
782 hideFeHelperUI(); // 保存原始UI状态
783
784 // 创建存储截图数据的数组和已捕获位置的集合
785 const screenshots = [];
786 const capturedPositions = new Set();
787 let currentStep = 0; // 用于进度显示
788
789 // 使用异步函数和循环进行截图
790 setTimeout(async () => {
791 try {

Callers 1

goCaptureFunction · 0.85

Calls 12

createProgressUIFunction · 0.85
hideFeHelperUIFunction · 0.85
setTimeoutFunction · 0.85
hideFixedElementsFunction · 0.85
updateProgressUIFunction · 0.85
showFixedElementsFunction · 0.85
captureFailureHandlerFunction · 0.85
finishCaptureFunction · 0.85
hasMethod · 0.80
cleanupFunction · 0.70
resolveFunction · 0.50
addMethod · 0.45

Tested by

no test coverage detected