From a1ffd7a44a95760f1c12b08923fafa09ec97e84a Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Mon, 8 Mar 2021 16:29:35 +0200 Subject: [PATCH] Ignore tag (#266) * refactor: Getting out early will speed things up * feat: Ignore tags --- src/content/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/content/index.js b/src/content/index.js index c2caa28..0fe4f36 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -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();