From 4ba70a858f98ada1708d09f2bfe4793f39d2c7e2 Mon Sep 17 00:00:00 2001 From: Cunninger <1803912219@qq.com> Date: Wed, 15 Jan 2025 08:23:43 +0800 Subject: [PATCH] fix: resolve issue with .gitignore$ being copied in recognized content --- .gitignore | 1 + worker.js | 29 +++++------------------------ 2 files changed, 6 insertions(+), 24 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80d571c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +".idea/" diff --git a/worker.js b/worker.js index a25f1b4..8c15e21 100644 --- a/worker.js +++ b/worker.js @@ -1139,7 +1139,7 @@ function getHTML() { ' ', ' ', ' ', - '
${record.result || \'无识别结果\'}
', + '
${record.result || \'无识别结果\'}
', ' ', ' ', ' `;', @@ -1286,11 +1286,7 @@ function getHTML() { ' const result = recognizeData.result || \'识别失败\';', ' // 保存原始文本到属性中,确保 LaTeX 格式完整', - ' const formattedResult = result', - ' .replace(/\$\$(.*?)\$\$/g, (_, formula) => `$${formula}$$`)', - ' .replace(/\$([^$]+)\$/g, (_, formula) => `$${formula}$`);', - - ' resultDiv.setAttribute(\'data-original-text\', formattedResult);', + ' resultDiv.setAttribute(\'data-original-text\', result);', ' resultDiv.innerHTML = result;', ' waitForMathJax(() => {', ' try {', @@ -1511,29 +1507,14 @@ function getHTML() { ' async function copyHistoryResult(index, btn) {', ' try {', ' const history = historyManager.loadHistory(currentToken);', - ' const result = history[index]?.result;', + ' const historyItem = document.querySelector(`.history-item[data-index="${index}"] .history-text`);', + ' const result = historyItem?.getAttribute(\'data-original-text\') || history[index]?.result;', ' if (!result) {', ' throw new Error(\'无法复制:结果为空\');', ' }', - ' // 使用临时输入框来执行复制', - ' const tempInput = document.createElement(\'textarea\');', - ' tempInput.value = result;', - ' document.body.appendChild(tempInput);', - ' tempInput.select();', - - ' // 尝试使用 execCommand 作为后备方案', - ' if (!navigator.clipboard) {', - ' document.execCommand("copy");', - ' tempInput.remove();', - ' } else {', - ' // 优先使用 clipboard API', - ' await navigator.clipboard.writeText(result);', - ' tempInput.remove();', - ' }', - - ' // 更新按钮状态 - 使用传入的按钮元素', + ' await navigator.clipboard.writeText(result);', ' btn.textContent = \'已复制\';', ' btn.classList.add(\'copied\');',