Refactor content/index.js

This commit is contained in:
sienori 2021-03-08 23:54:34 +09:00
parent a2c9b4823a
commit 2937233ec6

View file

@ -27,7 +27,7 @@ const handleMouseUp = async e => {
const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password"; const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password";
if (isInPasswordField) return; if (isInPasswordField) return;
const inCodeElement = e.target.tagName === 'CODE' || !!e.target.closest('code'); const inCodeElement = e.target.tagName === "CODE" || !!e.target.closest("code");
if (inCodeElement && getSettings("isDisabledInCodeElement")) return; if (inCodeElement && getSettings("isDisabledInCodeElement")) return;
const isInThisElement = const isInThisElement =
@ -37,7 +37,7 @@ const handleMouseUp = async e => {
removeTranslatecontainer(); removeTranslatecontainer();
const ignoredDocumentLang = getSettings('ignoredDocumentLang').split(',').map(s => s.trim()).filter(s => !!s) const ignoredDocumentLang = getSettings("ignoredDocumentLang").split(",").map(s => s.trim()).filter(s => !!s);
if (!!document.documentElement.lang && ignoredDocumentLang.includes(document.documentElement.lang)) return; if (!!document.documentElement.lang && ignoredDocumentLang.includes(document.documentElement.lang)) return;
const selectedText = getSelectedText(); const selectedText = getSelectedText();
@ -92,9 +92,9 @@ const getSelectedPosition = () => {
const selectedRect = isInTextField const selectedRect = isInTextField
? element.getBoundingClientRect() ? element.getBoundingClientRect()
: window : window
.getSelection() .getSelection()
.getRangeAt(0) .getRangeAt(0)
.getBoundingClientRect(); .getBoundingClientRect();
let selectedPosition; let selectedPosition;
const panelReferencePoint = getSettings("panelReferencePoint"); const panelReferencePoint = getSettings("panelReferencePoint");