Ignore <code> tag (#266)

* refactor: Getting out early will speed things up

* feat: Ignore <code> tags
This commit is contained in:
Alex Kozack 2021-03-08 16:29:35 +02:00 committed by GitHub
parent 21f16c00af
commit a1ffd7a44a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,13 +20,19 @@ init();
let prevSelectedText = "";
const handleMouseUp = async e => {
await waitTime(10);
const isLeftClick = e.button === 0;
if (!isLeftClick) return;
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 =
document.querySelector("#simple-translate") &&
document.querySelector("#simple-translate").contains(e.target);
if (!isLeftClick) return;
if (isInPasswordField) return;
if (isInThisElement) return;
removeTranslatecontainer();