Ignore <code> tag (#266)
* refactor: Getting out early will speed things up * feat: Ignore <code> tags
This commit is contained in:
parent
21f16c00af
commit
a1ffd7a44a
|
@ -20,13 +20,19 @@ init();
|
||||||
let prevSelectedText = "";
|
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;
|
||||||
|
if (!isLeftClick) return;
|
||||||
|
|
||||||
const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password";
|
const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password";
|
||||||
|
if (isInPasswordField) return;
|
||||||
|
|
||||||
|
const inCodeElement = e.target.tagName === 'CODE' || !!e.target.closest('code')
|
||||||
|
if (inCodeElement) return;
|
||||||
|
|
||||||
const isInThisElement =
|
const isInThisElement =
|
||||||
document.querySelector("#simple-translate") &&
|
document.querySelector("#simple-translate") &&
|
||||||
document.querySelector("#simple-translate").contains(e.target);
|
document.querySelector("#simple-translate").contains(e.target);
|
||||||
if (!isLeftClick) return;
|
|
||||||
if (isInPasswordField) return;
|
|
||||||
if (isInThisElement) return;
|
if (isInThisElement) return;
|
||||||
|
|
||||||
removeTranslatecontainer();
|
removeTranslatecontainer();
|
||||||
|
|
Loading…
Reference in a new issue