Fix text in iframe not getting from popup
This commit is contained in:
parent
c78a27a7e0
commit
6f43d626f0
|
@ -17,6 +17,7 @@ const init = async () => {
|
||||||
};
|
};
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
let prevSelectedText = "";
|
||||||
const handleMouseUp = async e => {
|
const handleMouseUp = async e => {
|
||||||
await waitTime(10);
|
await waitTime(10);
|
||||||
const isLeftClick = e.button === 0;
|
const isLeftClick = e.button === 0;
|
||||||
|
@ -30,6 +31,7 @@ const handleMouseUp = async e => {
|
||||||
removeTranslatecontainer();
|
removeTranslatecontainer();
|
||||||
|
|
||||||
const selectedText = getSelectedText();
|
const selectedText = getSelectedText();
|
||||||
|
prevSelectedText = selectedText;
|
||||||
if (selectedText.length === 0) return;
|
if (selectedText.length === 0) return;
|
||||||
|
|
||||||
const clickedPosition = { x: e.clientX, y: e.clientY };
|
const clickedPosition = { x: e.clientX, y: e.clientY };
|
||||||
|
@ -99,12 +101,10 @@ const handleMessage = async request => {
|
||||||
if (!isEnabled) return empty;
|
if (!isEnabled) return empty;
|
||||||
if (window == window.parent) return location.href;
|
if (window == window.parent) return location.href;
|
||||||
else return empty;
|
else return empty;
|
||||||
case "getSelectedText": {
|
case "getSelectedText":
|
||||||
if (!isEnabled) return empty;
|
if (!isEnabled) return empty;
|
||||||
const selectedText = getSelectedText();
|
if (prevSelectedText.length === 0) return empty;
|
||||||
if (selectedText.length === 0) return empty;
|
else return prevSelectedText;
|
||||||
else return selectedText;
|
|
||||||
}
|
|
||||||
case "translateSelectedText": {
|
case "translateSelectedText": {
|
||||||
if (!isEnabled) return empty;
|
if (!isEnabled) return empty;
|
||||||
const selectedText = getSelectedText();
|
const selectedText = getSelectedText();
|
||||||
|
|
Loading…
Reference in a new issue