* 执行截图操作 * @param {Object} params * @param {String} params.captureType 截图类型:'visible'或'whole'
(params)
| 997 | * @param {String} params.captureType 截图类型:'visible'或'whole' |
| 998 | */ |
| 999 | function goCapture(params) { |
| 1000 | // 如果正在截图中,则忽略新的请求 |
| 1001 | if (isCapturing) { |
| 1002 | return; |
| 1003 | } |
| 1004 | |
| 1005 | // 如果不是http/https,就不处理 |
| 1006 | if (!isValidUrl(location.href)) { |
| 1007 | alert('截图功能仅支持HTTP/HTTPS协议的网页!'); |
| 1008 | return; |
| 1009 | } |
| 1010 | |
| 1011 | isCapturing = true; |
| 1012 | isCancelled = false; |
| 1013 | |
| 1014 | // console.log('开始执行截图,模式:' + params.captureType); |
| 1015 | |
| 1016 | // 根据截图模式执行不同的操作 |
| 1017 | if (params.captureType === 'visible') { |
| 1018 | captureVisible() |
| 1019 | .then(result => { |
| 1020 | if (result && result.success) { |
| 1021 | // console.log('可视区域截图完成'); |
| 1022 | } |
| 1023 | }) |
| 1024 | .catch(error => { |
| 1025 | // console.error('截图失败:', error); |
| 1026 | alert('截图失败: ' + (error.message || '未知错误')); |
| 1027 | }) |
| 1028 | .finally(() => { |
| 1029 | // 确保截图状态重置 |
| 1030 | isCapturing = false; |
| 1031 | |
| 1032 | // 确保进度UI被移除 |
| 1033 | const progressUI = document.getElementById('fehelper_screenshot_progress'); |
| 1034 | if (progressUI) { |
| 1035 | progressUI.remove(); |
| 1036 | } |
| 1037 | }); |
| 1038 | } else { |
| 1039 | captureFullPage() |
| 1040 | .then(result => { |
| 1041 | if (result && result.success) { |
| 1042 | // console.log('全页面截图完成'); |
| 1043 | } |
| 1044 | }) |
| 1045 | .catch(error => { |
| 1046 | // console.error('截图失败:', error); |
| 1047 | alert('截图失败: ' + (error.message || '未知错误')); |
| 1048 | }) |
| 1049 | .finally(() => { |
| 1050 | // 确保截图状态重置 |
| 1051 | isCapturing = false; |
| 1052 | |
| 1053 | // 确保进度UI被移除 |
| 1054 | const progressUI = document.getElementById('fehelper_screenshot_progress'); |
| 1055 | if (progressUI) { |
| 1056 | progressUI.remove(); |
no test coverage detected