* 执行可视区域截图
()
| 635 | * 执行可视区域截图 |
| 636 | */ |
| 637 | async function captureVisible() { |
| 638 | if (window._fh_screenshot_in_progress) { |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | window._fh_screenshot_in_progress = true; |
| 643 | |
| 644 | // 保存原始滚动位置 |
| 645 | originalScrollTop = window.scrollY || document.documentElement.scrollTop; |
| 646 | originalScrollLeft = window.scrollX || document.documentElement.scrollLeft; |
| 647 | |
| 648 | // 隐藏工具条 |
| 649 | let screenshotContainer = document.getElementById('fehelper_screenshot_container'); |
| 650 | if (screenshotContainer) { |
| 651 | screenshotContainer.style.display = 'none'; |
| 652 | } |
| 653 | |
| 654 | const progressUI = createProgressUI('正在截取可视区域...'); |
| 655 | |
| 656 | window._fh_screenshot_cancel_callback = cleanup; |
| 657 | |
| 658 | // 隐藏干扰UI |
| 659 | hideFeHelperUI(); |
| 660 | hideFixedElements(); |
| 661 | |
| 662 | // 等待DOM更新 |
| 663 | setTimeout(() => { |
| 664 | updateProgressUI(0.3, '正在截取可视区域...'); |
| 665 | |
| 666 | // 从background.js导入MSG_TYPE不现实,这里直接使用特定值 |
| 667 | chrome.runtime.sendMessage({ |
| 668 | type: 'fh-screenshot-capture-visible' |
| 669 | }, response => { |
| 670 | if (response) { |
| 671 | // 加载截图并处理 |
| 672 | const img = new Image(); |
| 673 | img.onload = function() { |
| 674 | updateProgressUI(0.8, '正在处理截图...'); |
| 675 | |
| 676 | // 创建与index.js中showResult函数期望的格式一致的数据 |
| 677 | const screenshotData = { |
| 678 | filename: buildFilenameFromUrl(), |
| 679 | screenshots: [{ |
| 680 | dataUri: response, |
| 681 | index: 0, |
| 682 | row: 0, |
| 683 | col: 0, |
| 684 | left: 0, |
| 685 | top: 0, |
| 686 | right: img.width, |
| 687 | bottom: img.height, |
| 688 | width: img.width, |
| 689 | height: img.height |
| 690 | }], |
| 691 | totalWidth: img.width, |
| 692 | totalHeight: img.height |
| 693 | }; |
| 694 |
no test coverage detected