From 6f43d626f0bc0d9448d7b273d392f36d724baacf Mon Sep 17 00:00:00 2001 From: sienori Date: Sun, 20 Oct 2019 18:58:27 +0900 Subject: [PATCH] Fix text in iframe not getting from popup --- src/content/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/index.js b/src/content/index.js index db9177d..9c3cbdd 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -17,6 +17,7 @@ const init = async () => { }; init(); +let prevSelectedText = ""; const handleMouseUp = async e => { await waitTime(10); const isLeftClick = e.button === 0; @@ -30,6 +31,7 @@ const handleMouseUp = async e => { removeTranslatecontainer(); const selectedText = getSelectedText(); + prevSelectedText = selectedText; if (selectedText.length === 0) return; const clickedPosition = { x: e.clientX, y: e.clientY }; @@ -99,12 +101,10 @@ const handleMessage = async request => { if (!isEnabled) return empty; if (window == window.parent) return location.href; else return empty; - case "getSelectedText": { + case "getSelectedText": if (!isEnabled) return empty; - const selectedText = getSelectedText(); - if (selectedText.length === 0) return empty; - else return selectedText; - } + if (prevSelectedText.length === 0) return empty; + else return prevSelectedText; case "translateSelectedText": { if (!isEnabled) return empty; const selectedText = getSelectedText();